forked from schierlm/Oberon2013Modifications
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LSPHelper.patch
1428 lines (1372 loc) · 60.2 KB
/
LSPHelper.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--- LSPhORS.Mod.txt
+++ LSPhORS.Mod.txt
@@ -1,5 +1,5 @@
-MODULE ORS; (* NW 19.9.93 / 15.3.2017 Scanner in Oberon-07*)
- IMPORT SYSTEM, Texts, Oberon;
+MODULE LSPhORS; (* NW 19.9.93 / 15.3.2017 Scanner in Oberon-07*)
+ IMPORT SYSTEM, Texts, Oberon, RS232, LSPhConstants;
(* Oberon Scanner does lexical analysis. Input is Oberon-Text, output is
sequence of symbols, i.e identifiers, numbers, strings, and special symbols.
@@ -28,7 +28,7 @@
to* = 50; by* = 51; semicolon* = 52; end* = 53; bar* = 54;
else* = 55; elsif* = 56; until* = 57; return* = 58;
array* = 60; record* = 61; pointer* = 62; const* = 63; type* = 64;
- var* = 65; procedure* = 66; begin* = 67; import* = 68; module* = 69; eot = 70;
+ var* = 65; procedure* = 66; begin* = 67; import* = 68; module* = 69; eot* = 70;
TYPE Ident* = ARRAY IdLen OF CHAR;
@@ -41,7 +41,9 @@
ch: CHAR; (*last character read*)
errpos: LONGINT;
R: Texts.Reader;
- W: Texts.Writer;
+ lspMode*: INTEGER;
+ syntaxType, formatType: ARRAY eot+1 OF INTEGER;
+ lastIdentStart: INTEGER;
k: INTEGER;
KWX: ARRAY 10 OF INTEGER;
keyTab: ARRAY NKW OF
@@ -58,9 +60,10 @@
PROCEDURE Mark*(msg: ARRAY OF CHAR);
VAR p: LONGINT;
BEGIN p := Pos();
- IF (p > errpos) & (errcnt < 25) THEN
- Texts.WriteLn(W); Texts.WriteString(W, " pos "); Texts.WriteInt(W, p, 1); Texts.Write(W, " ");
- Texts.WriteString(W, msg); Texts.Append(Oberon.Log, W.buf)
+ IF (p > errpos) & (errcnt < 500) & (lspMode = LSPhConstants.GetModuleInfo) THEN
+ RS232.Send(LSPhConstants.Error);
+ RS232.SendIntRaw(p);
+ RS232.SendStrRaw(msg)
END ;
INC(errcnt); errpos := p + 4
END Mark;
@@ -71,7 +74,7 @@
REPEAT
IF i < IdLen-1 THEN id[i] := ch; INC(i) END ;
Texts.Read(R, ch)
- UNTIL (ch < "0") OR (ch > "9") & (ch < "A") OR (ch > "Z") & (ch < "a") OR (ch > "z");
+ UNTIL (ch < "0") & ((lspMode # LSPhConstants.AutoComplete) OR (ch # 3X)) OR (ch > "9") & (ch < "A") OR (ch > "Z") & (ch < "a") OR (ch > "z");
id[i] := 0X;
IF i < 10 THEN k := KWX[i-1]; (*search for keyword*)
WHILE (id # keyTab[k].id) & (k < KWX[i]) DO INC(k) END ;
@@ -191,24 +194,117 @@
END
END Number;
- PROCEDURE comment;
+ PROCEDURE SetMode* (m: INTEGER);
+ BEGIN lspMode := m
+ END SetMode;
+
+ PROCEDURE ModuleTag*(tag: INTEGER);
+ BEGIN
+ IF lspMode = LSPhConstants.GetModuleInfo THEN RS232.Send(tag) END
+ END ModuleTag;
+
+ PROCEDURE ModuleTagPP*(tag, pos: INTEGER);
+ BEGIN
+ IF lspMode = LSPhConstants.GetModuleInfo THEN RS232.Send(tag); RS232.SendIntRaw(pos) END
+ END ModuleTagPP;
+
+ PROCEDURE ModuleTagP*(tag: INTEGER);
+ BEGIN ModuleTagPP(tag, Pos())
+ END ModuleTagP;
+
+ PROCEDURE FormatTokenTag*(tag: INTEGER);
+ BEGIN
+ IF lspMode = LSPhConstants.ReFormat THEN RS232.Send(tag) END
+ END FormatTokenTag;
+
+ PROCEDURE FormatTokenUpdate*(type: INTEGER);
+ BEGIN
+ IF lspMode = LSPhConstants.ReFormat THEN
+ RS232.Send(LSPhConstants.FormatTokenUpdate);
+ RS232.Send(type);
+ END
+ END FormatTokenUpdate;
+
+ PROCEDURE ClassifyIdent*(syntaxType, defPos: INTEGER; defModName: ARRAY OF CHAR);
+ BEGIN
+ IF lspMode = LSPhConstants.GetModuleInfo THEN
+ ASSERT(lastIdentStart # -1);
+ RS232.Send(LSPhConstants.SyntaxElement);
+ RS232.SendIntRaw(lastIdentStart);
+ RS232.SendIntRaw(Pos());
+ RS232.Send(syntaxType);
+ IF defPos = -1 THEN
+ RS232.SendIntRaw(-1);
+ ELSE
+ RS232.SendIntRaw(defPos);
+ RS232.SendStrRaw(defModName);
+ END;
+ lastIdentStart := -1
+ END
+ END ClassifyIdent;
+
+ PROCEDURE SymbolFileIndex*(index, defEndPos: INTEGER; defModName: ARRAY OF CHAR);
+ BEGIN
+ IF lspMode = LSPhConstants.GetModuleInfo THEN
+ RS232.Send(LSPhConstants.SymbolFileIndex);
+ RS232.SendIntRaw(index);
+ RS232.SendStrRaw(defModName);
+ RS232.SendIntRaw(defEndPos);
+ END
+ END SymbolFileIndex;
+
+ PROCEDURE AddCompletion*(syntaxType: INTEGER; suggestion: ARRAY OF CHAR);
+ VAR i: INTEGER;
+ BEGIN
+ IF lspMode = LSPhConstants.AutoComplete THEN
+ i := 0; WHILE (suggestion[i] # 0X) & (suggestion[i] = id[i]) DO INC(i) END;
+ IF (id[i] = 3X) & (id[i+1] = 0X) THEN
+ RS232.Send(LSPhConstants.Completion);
+ RS232.Send(syntaxType);
+ RS232.SendStrRaw(suggestion);
+ END
+ END
+ END AddCompletion;
+
+ PROCEDURE comment(nested: BOOLEAN);
BEGIN Texts.Read(R, ch);
+ IF ~nested & (lspMode = LSPhConstants.GetModuleInfo) THEN
+ RS232.Send(LSPhConstants.SyntaxElement);
+ RS232.SendIntRaw(Pos() - 2);
+ ELSIF ~nested & (lspMode = LSPhConstants.ReFormat) THEN
+ RS232.Send(LSPhConstants.FormatToken);
+ RS232.SendIntRaw(Pos() - 2);
+ END;
REPEAT
WHILE ~R.eot & (ch # "*") DO
IF ch = "(" THEN Texts.Read(R, ch);
- IF ch = "*" THEN comment END
+ IF ch = "*" THEN comment(TRUE) END
ELSE Texts.Read(R, ch)
END
END ;
WHILE ch = "*" DO Texts.Read(R, ch) END
UNTIL (ch = ")") OR R.eot;
- IF ~R.eot THEN Texts.Read(R, ch) ELSE Mark("unterminated comment") END
+ IF ~nested & (lspMode = LSPhConstants.GetModuleInfo) THEN
+ RS232.SendIntRaw(Pos() + 1);
+ RS232.Send(LSPhConstants.SynComment);
+ RS232.SendIntRaw(-1);
+ ELSIF ~nested & (lspMode = LSPhConstants.ReFormat) THEN
+ RS232.SendIntRaw(Pos() + 1);
+ RS232.Send(99);
+ END;
+ IF ~R.eot THEN Texts.Read(R, ch) ELSIF ~nested THEN Mark("unterminated comment") END
END comment;
PROCEDURE Get*(VAR sym: INTEGER);
+ VAR begpos: INTEGER;
BEGIN
+ IF lastIdentStart # -1 THEN
+ Mark("LSP: Unclassified identifier");
+ lastIdentStart := -1
+ END;
REPEAT
- WHILE ~R.eot & (ch <= " ") DO Texts.Read(R, ch) END;
+ WHILE ~R.eot & (ch <= " ") & ((lspMode # LSPhConstants.AutoComplete) OR (ch # 3X)) DO Texts.Read(R, ch) END;
+ begpos := Pos();
IF R.eot THEN sym := eot
ELSIF ch < "A" THEN
IF ch < "0" THEN
@@ -217,7 +313,7 @@
ELSIF ch = "$" THEN HexString; sym := string
ELSIF ch = "&" THEN Texts.Read(R, ch); sym := and
ELSIF ch = "(" THEN Texts.Read(R, ch);
- IF ch = "*" THEN sym := null; comment ELSE sym := lparen END
+ IF ch = "*" THEN sym := null; comment(FALSE) ELSE sym := lparen END
ELSIF ch = ")" THEN Texts.Read(R, ch); sym := rparen
ELSIF ch = "*" THEN Texts.Read(R, ch); sym := times
ELSIF ch = "+" THEN Texts.Read(R, ch); sym := plus
@@ -226,6 +322,8 @@
ELSIF ch = "." THEN Texts.Read(R, ch);
IF ch = "." THEN Texts.Read(R, ch); sym := upto ELSE sym := period END
ELSIF ch = "/" THEN Texts.Read(R, ch); sym := rdiv
+ ELSIF (lspMode = LSPhConstants.AutoComplete) & (ch = 3X) THEN
+ Identifier(sym)
ELSE Texts.Read(R, ch); (* ! % ' *) sym := null
END
ELSIF ch < ":" THEN Number(sym)
@@ -258,17 +356,61 @@
Texts.Read(R, ch)
END
UNTIL sym # null
+ ;IF lspMode = LSPhConstants.GetModuleInfo THEN
+ IF sym = ident THEN
+ lastIdentStart := begpos;
+ ELSIF syntaxType[sym] # 0 THEN
+ RS232.Send(LSPhConstants.SyntaxElement);
+ RS232.SendIntRaw(begpos);
+ RS232.SendIntRaw(Pos());
+ RS232.Send(syntaxType[sym]);
+ RS232.SendIntRaw(-1);
+ END
+ ELSIF (lspMode = LSPhConstants.ReFormat) & (formatType[sym] # 100) THEN
+ RS232.Send(LSPhConstants.FormatToken);
+ RS232.SendIntRaw(begpos);
+ RS232.SendIntRaw(Pos());
+ RS232.Send(formatType[sym]);
+ END;
END Get;
PROCEDURE Init*(T: Texts.Text; pos: LONGINT);
- BEGIN errpos := pos; errcnt := 0; Texts.OpenReader(R, T, pos); Texts.Read(R, ch)
+ BEGIN errpos := pos - 1; lastIdentStart := -1; errcnt := 0; Texts.OpenReader(R, T, pos); Texts.Read(R, ch)
END Init;
PROCEDURE EnterKW(sym: INTEGER; name: ARRAY OF CHAR);
BEGIN keyTab[k].id := name; keyTab[k].sym := sym; INC(k)
+ ;syntaxType[sym] := LSPhConstants.SynKeyword
END EnterKW;
-BEGIN Texts.OpenWriter(W); k := 0; KWX[0] := 0; KWX[1] := 0;
+BEGIN KWX[0] := 0; KWX[1] := 0;
+ FOR k := 0 TO eot DO syntaxType[k] := 0; formatType[k] := 11 END;
+ formatType[null] := 100;
+ formatType[eot] := 100;
+ formatType[arrow] := 08;
+ formatType[period] := 00;
+ formatType[char] := 99;
+ formatType[int] := 99;
+ formatType[real] := 99;
+ formatType[false] := 99;
+ formatType[true] := 99;
+ formatType[nil] := 99;
+ formatType[string] := 99;
+ formatType[not] := 10;
+ formatType[lparen] := 10;
+ formatType[lbrak] := 00;
+ formatType[lbrace] := 10;
+ formatType[ident] := 99;
+ formatType[comma] := 01;
+ formatType[colon] := 01;
+ formatType[rparen] := 01;
+ formatType[rbrak] := 09;
+ formatType[rbrace] := 01;
+ formatType[semicolon] := 01;
+ formatType[const] := 21;
+ formatType[type] := 21;
+ formatType[begin] := 21;
+ k := 0; lastIdentStart := -1;
EnterKW(if, "IF");
EnterKW(do, "DO");
EnterKW(of, "OF");
@@ -307,6 +449,33 @@
KWX[6] := k;
EnterKW(pointer, "POINTER");
KWX[7] := k; KWX[8] := k;
+ syntaxType[times] := LSPhConstants.SynOperator;
+ syntaxType[rdiv] := LSPhConstants.SynOperator;
+ syntaxType[div] := LSPhConstants.SynOperator;
+ syntaxType[mod] := LSPhConstants.SynOperator;
+ syntaxType[and] := LSPhConstants.SynOperator;
+ syntaxType[plus] := LSPhConstants.SynOperator;
+ syntaxType[minus] := LSPhConstants.SynOperator;
+ syntaxType[or] := LSPhConstants.SynOperator;
+ syntaxType[eql] := LSPhConstants.SynOperator;
+ syntaxType[neq] := LSPhConstants.SynOperator;
+ syntaxType[lss] := LSPhConstants.SynOperator;
+ syntaxType[leq] := LSPhConstants.SynOperator;
+ syntaxType[gtr] := LSPhConstants.SynOperator;
+ syntaxType[geq] := LSPhConstants.SynOperator;
+ syntaxType[in] := LSPhConstants.SynOperator;
+ syntaxType[is] := LSPhConstants.SynOperator;
+ syntaxType[arrow] := LSPhConstants.SynOperator;
+ syntaxType[period] := LSPhConstants.SynOperator;
+ syntaxType[char] := LSPhConstants.SynType;
+ syntaxType[int] := LSPhConstants.SynType;
+ syntaxType[real] := LSPhConstants.SynType;
+ syntaxType[false] := LSPhConstants.SynConstant;
+ syntaxType[true] := LSPhConstants.SynConstant;
+ syntaxType[nil] := LSPhConstants.SynConstant;
+ syntaxType[string] := LSPhConstants.SynString;
+ syntaxType[not] := LSPhConstants.SynOperator;
+ syntaxType[upto] := LSPhConstants.SynOperator;
EnterKW(procedure, "PROCEDURE");
KWX[9] := k
-END ORS.
+END LSPhORS.
--- LSPhORB.Mod.txt
+++ LSPhORB.Mod.txt
@@ -1,5 +1,5 @@
-MODULE ORB; (*NW 25.6.2014 / AP 4.3.2020 / 8.3.2019 in Oberon-07*)
- IMPORT Files, ORS;
+MODULE LSPhORB; (*NW 25.6.2014 / AP 4.3.2020 / 8.3.2019 in Oberon-07*)
+ IMPORT Files, LSPhConstants, ORS := LSPhORS;
(*Definition of data types Object and Type, which together form the data structure
called "symbol table". Contains procedures for creation of Objects, and for search:
NewObj, this, thisimport, thisfield (and OpenScope, CloseScope).
@@ -22,12 +22,12 @@
Type* = POINTER TO TypeDesc;
ObjDesc*= RECORD
- class*, exno*: BYTE;
+ class*, lspClass*, exno*: BYTE;
expo*, rdo*: BOOLEAN; (*exported / read-only*)
- lev*: INTEGER;
+ lev*, defEndPos*: INTEGER;
next*, dsc*: Object;
type*: Type;
- name*: ORS.Ident;
+ name*, defModId*: ORS.Ident;
val*: LONGINT
END ;
@@ -68,12 +68,26 @@
nofmod, Ref: INTEGER;
typtab: ARRAY maxTypTab OF Type;
- PROCEDURE NewObj*(VAR obj: Object; id: ORS.Ident; class: INTEGER); (*insert new Object with name id*)
+ PROCEDURE SymbolMatch(VAR obj: Object);
+ BEGIN
+ IF obj = NIL THEN
+ ORS.ClassifyIdent(LSPhConstants.SynUndefined, -1, "")
+ ELSE
+ ORS.ClassifyIdent(obj.lspClass, obj.defEndPos, obj.defModId)
+ END
+ END SymbolMatch;
+
+ PROCEDURE SymbolMisMatch(VAR obj: Object);
+ BEGIN ORS.AddCompletion(obj.lspClass, obj.name)
+ END SymbolMisMatch;
+
+ PROCEDURE NewObj*(VAR obj: Object; id, modid: ORS.Ident; class, lspClass: INTEGER); (*insert new Object with name id*)
VAR new, x: Object;
BEGIN x := topScope;
WHILE (x.next # NIL) & (x.next.name # id) DO x := x.next END ;
IF x.next = NIL THEN
NEW(new); new.name := id; new.class := class; new.next := NIL; new.rdo := FALSE; new.dsc := NIL;
+ new.lspClass := lspClass; new.defEndPos := ORS.Pos(); new.defModId := modid;
x.next := new; obj := new
ELSE obj := x.next; ORS.Mark("mult def")
END
@@ -83,9 +97,10 @@
VAR s, x: Object;
BEGIN s := topScope;
REPEAT x := s.next;
- WHILE (x # NIL) & (x.name # ORS.id) DO x := x.next END ;
+ WHILE (x # NIL) & (x.name # ORS.id) DO SymbolMisMatch(x); x := x.next END ;
s := s.dsc
UNTIL (x # NIL) OR (s = NIL);
+ SymbolMatch(x);
RETURN x
END thisObj;
@@ -95,18 +110,20 @@
IF mod.rdo THEN
IF mod.name[0] # 0X THEN
obj := mod.dsc;
- WHILE (obj # NIL) & (obj.name # ORS.id) DO obj := obj.next END
+ WHILE (obj # NIL) & (obj.name # ORS.id) DO SymbolMisMatch(obj); obj := obj.next END
ELSE obj := NIL
END
ELSE obj := NIL
END ;
+ SymbolMatch(obj);
RETURN obj
END thisimport;
PROCEDURE thisfield*(rec: Type): Object;
VAR fld: Object;
BEGIN fld := rec.dsc;
- WHILE (fld # NIL) & (fld.name # ORS.id) DO fld := fld.next END ;
+ WHILE (fld # NIL) & (fld.name # ORS.id) DO SymbolMisMatch(fld); fld := fld.next END ;
+ SymbolMatch(fld);
RETURN fld
END thisfield;
@@ -129,7 +146,7 @@
FName[i] := 0X
END MakeFileName;
- PROCEDURE ThisModule(name, orgname: ORS.Ident; decl: BOOLEAN; key: LONGINT): Object;
+ PROCEDURE ThisModule(name, orgname, defModId: ORS.Ident; decl: BOOLEAN; defEndPos, key: LONGINT): Object;
VAR mod: Module; obj, obj1: Object;
BEGIN obj1 := topScope; obj := obj1.next; (*search for module*)
WHILE (obj # NIL) & (obj(Module).orgname # orgname) DO obj1 := obj; obj := obj1.next END ;
@@ -138,6 +155,7 @@
WHILE (obj # NIL) & (obj.name # name) DO obj := obj.next END ;
IF obj = NIL THEN (*insert new module*)
NEW(mod); mod.class := Mod; mod.rdo := FALSE;
+ mod.lspClass := LSPhConstants.SynModule; mod.defEndPos := defEndPos; mod.defModId := defModId;
mod.name := name; mod.orgname := orgname; mod.val := key;
mod.lev := nofmod; INC(nofmod); mod.dsc := NIL; mod.next := NIL;
IF decl THEN mod.type := noType ELSE mod.type := nilType END ;
@@ -158,7 +176,7 @@
IF b < 80H THEN x := b ELSE x := b - 100H END
END Read;
- PROCEDURE InType(VAR R: Files.Rider; thismod: Object; VAR T: Type);
+ PROCEDURE InType(VAR R: Files.Rider; thismod: Object; VAR T: Type; VAR nextSymIdx: INTEGER);
VAR key: LONGINT;
ref, class, form, np, readonly: INTEGER;
fld, par, obj, mod, last: Object;
@@ -168,11 +186,11 @@
IF ref < 0 THEN T := typtab[-ref] (*already read*)
ELSE NEW(t); T := t; typtab[ref] := t; t.mno := thismod.lev;
Read(R, form); t.form := form;
- IF form = Pointer THEN InType(R, thismod, t.base); t.size := 4
+ IF form = Pointer THEN InType(R, thismod, t.base, nextSymIdx); t.size := 4
ELSIF form = Array THEN
- InType(R, thismod, t.base); Files.ReadNum(R, t.len); Files.ReadNum(R, t.size)
+ InType(R, thismod, t.base, nextSymIdx); Files.ReadNum(R, t.len); Files.ReadNum(R, t.size)
ELSIF form = Record THEN
- InType(R, thismod, t.base);
+ InType(R, thismod, t.base, nextSymIdx);
IF t.base.form = NoTyp THEN t.base := NIL; obj := NIL ELSE obj := t.base.dsc END ;
Files.ReadNum(R, t.len); (*TD adr/exno*)
Files.ReadNum(R, t.nofpar); (*ext level*)
@@ -182,28 +200,34 @@
NEW(fld); fld.class := class; Files.ReadString(R, fld.name);
IF last = NIL THEN t.dsc := fld ELSE last.next := fld END ;
last := fld;
- IF fld.name[0] # 0X THEN fld.expo := TRUE; InType(R, thismod, fld.type) ELSE fld.expo := FALSE; fld.type := nilType END ;
+ IF fld.name[0] # 0X THEN
+ Read(R, key); fld.lspClass := key;
+ fld.defModId := thismod(Module).orgname;
+ fld.defEndPos := nextSymIdx; DEC(nextSymIdx);
+ fld.expo := TRUE; InType(R, thismod, fld.type, nextSymIdx)
+ ELSE fld.expo := FALSE; fld.type := nilType END ;
Files.ReadNum(R, fld.val); Read(R, class)
END ;
IF last = NIL THEN t.dsc := obj ELSE last.next := obj END
ELSIF form = Proc THEN
- InType(R, thismod, t.base);
+ InType(R, thismod, t.base, nextSymIdx);
obj := NIL; np := 0; Read(R, class);
WHILE class # 0 DO (*parameters*)
NEW(par); par.class := class; Read(R, readonly); par.rdo := readonly = 1;
- InType(R, thismod, par.type); par.next := obj; obj := par; INC(np); Read(R, class)
+ InType(R, thismod, par.type, nextSymIdx); par.next := obj; obj := par; INC(np); Read(R, class)
END ;
t.dsc := obj; t.nofpar := np; t.size := 4
END ;
Files.ReadString(R, modname);
IF modname[0] # 0X THEN (*re-import ========*)
Files.ReadInt(R, key); Files.ReadString(R, name);
- mod := ThisModule(modname, modname, FALSE, key);
+ mod := ThisModule(modname, modname, modname, FALSE, -1, key);
obj := mod.dsc; (*search type*)
WHILE (obj # NIL) & (obj.name # name) DO obj := obj.next END ;
IF obj # NIL THEN T := obj.type (*type object found in object list of mod*)
ELSE (*insert new type object in object list of mod*)
NEW(obj); obj.name := name; obj.class := Typ; obj.next := mod.dsc; mod.dsc := obj; obj.type := t;
+ obj.lspClass := LSPhConstants.SynType; obj.defEndPos := -1;
t.mno := mod.lev; t.typobj := obj; T := t
END ;
typtab[ref] := T
@@ -211,26 +235,28 @@
END
END InType;
- PROCEDURE Import*(VAR modid, modid1: ORS.Ident);
- VAR key: LONGINT; class, k: INTEGER;
+ PROCEDURE Import*(VAR modid, modid1, thisModId: ORS.Ident; defEndPos: INTEGER);
+ VAR key: LONGINT; class, k, nextSymIdx: INTEGER;
obj: Object; t: Type;
thismod: Object;
modname, fname: ORS.Ident;
F: Files.File; R: Files.Rider;
BEGIN
IF modid1 = "SYSTEM" THEN
- thismod := ThisModule(modid, modid1, TRUE, key); DEC(nofmod);
+ thismod := ThisModule(modid, modid1, thisModId, TRUE, defEndPos, key); DEC(nofmod);
thismod.lev := 0; thismod.dsc := system; thismod.rdo := TRUE
- ELSE MakeFileName(fname, modid1, ".smb"); F := Files.Old(fname);
+ ELSE MakeFileName(fname, modid1, ".smL"); F := Files.Old(fname); nextSymIdx := -10;
IF F # NIL THEN
Files.Set(R, F, 0); Files.ReadInt(R, key); Files.ReadInt(R, key); Files.ReadString(R, modname);
- thismod := ThisModule(modid, modid1, TRUE, key); thismod.rdo := TRUE;
+ thismod := ThisModule(modid, modid1, thisModId, TRUE, defEndPos, key); thismod.rdo := TRUE;
Read(R, class); (*version key*)
IF class # versionkey THEN ORS.Mark("wrong version") END ;
Read(R, class);
WHILE class # 0 DO
NEW(obj); obj.class := class; Files.ReadString(R, obj.name);
- InType(R, thismod, obj.type); obj.lev := -thismod.lev;
+ Read(R, k); obj.lspClass := k;
+ obj.defModId := modid1; obj.defEndPos := nextSymIdx; DEC(nextSymIdx);
+ InType(R, thismod, obj.type, nextSymIdx); obj.lev := -thismod.lev;
IF class = Typ THEN
t := obj.type; t.typobj := obj; Read(R, k); (*fixup bases of previously declared pointer types*)
WHILE k # 0 DO typtab[k].base := t; Read(R, k) END
@@ -253,17 +279,17 @@
BEGIN Files.WriteByte(R, x)
END Write;
- PROCEDURE OutType(VAR R: Files.Rider; t: Type);
+ PROCEDURE OutType(VAR R: Files.Rider; VAR modid: ORS.Ident; t: Type; VAR nextSymIdx: INTEGER);
VAR obj, mod, fld, bot: Object;
- PROCEDURE OutPar(VAR R: Files.Rider; par: Object; n: INTEGER);
+ PROCEDURE OutPar(VAR R: Files.Rider; VAR modid: ORS.Ident; par: Object; n: INTEGER; VAR nextSymIdx: INTEGER);
VAR cl: INTEGER;
BEGIN
IF n > 0 THEN
- OutPar(R, par.next, n-1); cl := par.class;
+ OutPar(R, modid, par.next, n-1, nextSymIdx); cl := par.class;
Write(R, cl);
IF par.rdo THEN Write(R, 1) ELSE Write(R, 0) END ;
- OutType(R, par.type)
+ OutType(R, modid, par.type, nextSymIdx)
END
END OutPar;
@@ -283,22 +309,24 @@
ELSE obj := t.typobj;
IF obj # NIL THEN Write(R, Ref); t.ref := Ref; INC(Ref) ELSE (*anonymous*) Write(R, 0) END ;
Write(R, t.form);
- IF t.form = Pointer THEN OutType(R, t.base)
- ELSIF t.form = Array THEN OutType(R, t.base); Files.WriteNum(R, t.len); Files.WriteNum(R, t.size)
+ IF t.form = Pointer THEN OutType(R, modid, t.base, nextSymIdx)
+ ELSIF t.form = Array THEN OutType(R, modid, t.base, nextSymIdx); Files.WriteNum(R, t.len); Files.WriteNum(R, t.size)
ELSIF t.form = Record THEN
- IF t.base # NIL THEN OutType(R, t.base); bot := t.base.dsc ELSE OutType(R, noType); bot := NIL END ;
+ IF t.base # NIL THEN OutType(R, modid, t.base, nextSymIdx); bot := t.base.dsc ELSE OutType(R, modid, noType, nextSymIdx); bot := NIL END ;
IF obj # NIL THEN Files.WriteNum(R, obj.exno) ELSE Write(R, 0) END ;
Files.WriteNum(R, t.nofpar); Files.WriteNum(R, t.size);
fld := t.dsc;
WHILE fld # bot DO (*fields*)
IF fld.expo THEN
- Write(R, Fld); Files.WriteString(R, fld.name); OutType(R, fld.type); Files.WriteNum(R, fld.val) (*offset*)
+ Write(R, Fld); Files.WriteString(R, fld.name);
+ Write(R, fld.lspClass); ORS.SymbolFileIndex(nextSymIdx, fld.defEndPos, fld.defModId); DEC(nextSymIdx);
+ OutType(R, modid, fld.type, nextSymIdx); Files.WriteNum(R, fld.val) (*offset*)
ELSE FindHiddenPointers(R, fld.type, fld.val)
END ;
fld := fld.next
END ;
Write(R, 0)
- ELSIF t.form = Proc THEN OutType(R, t.base); OutPar(R, t.dsc, t.nofpar); Write(R, 0)
+ ELSIF t.form = Proc THEN OutType(R, modid, t.base, nextSymIdx); OutPar(R, modid, t.dsc, t.nofpar, nextSymIdx); Write(R, 0)
END ;
IF (t.mno > 0) & (obj # NIL) THEN (*re-export, output name*)
mod := topScope.next;
@@ -312,11 +340,11 @@
END OutType;
PROCEDURE Export*(VAR modid: ORS.Ident; VAR newSF: BOOLEAN; VAR key: LONGINT);
- VAR x, sum, oldkey: LONGINT;
+ VAR x, sum, oldkey, nextSymIdx: LONGINT;
obj, obj0: Object;
filename: ORS.Ident;
F, F1: Files.File; R, R1: Files.Rider;
- BEGIN Ref := Record + 1; MakeFileName(filename, modid, ".smb");
+ BEGIN Ref := Record + 1; MakeFileName(filename, modid, ".smL"); nextSymIdx := -10;
F := Files.New(filename); Files.Set(R, F, 0);
Files.WriteInt(R, 0); (*placeholder*)
Files.WriteInt(R, 0); (*placeholder for key to be inserted at the end*)
@@ -325,7 +353,9 @@
WHILE obj # NIL DO
IF obj.expo THEN
Write(R, obj.class); Files.WriteString(R, obj.name);
- OutType(R, obj.type);
+ Write(R, obj.lspClass);
+ ORS.SymbolFileIndex(nextSymIdx, obj.defEndPos, obj.defModId); DEC(nextSymIdx);
+ OutType(R, modid, obj.type, nextSymIdx);
IF obj.class = Typ THEN
IF obj.type.form = Record THEN
obj0 := topScope.next; (*check whether this is base of previously declared pointer types*)
@@ -373,7 +403,8 @@
PROCEDURE enter(name: ARRAY OF CHAR; cl: INTEGER; type: Type; n: LONGINT);
VAR obj: Object;
BEGIN NEW(obj); obj.name := name; obj.class := cl; obj.type := type; obj.val := n; obj.dsc := NIL;
- IF cl = Typ THEN type.typobj := obj END ;
+ obj.lspClass := LSPhConstants.SynProcedure; obj.defEndPos := -1;
+ IF cl = Typ THEN obj.lspClass := LSPhConstants.SynType; type.typobj := obj END ;
obj.next := system; system := obj
END enter;
@@ -437,4 +468,4 @@
enter("COPY", SProc, noType, 123);
enter("PUT", SProc, noType, 112);
enter("GET", SProc, noType, 102);
-END ORB.
+END LSPhORB.
--- LSPhORG.Mod.txt
+++ LSPhORG.Mod.txt
@@ -1,5 +1,5 @@
-MODULE ORG; (* N.Wirth, 16.4.2016 / 4.4.2017 / 31.5.2019 Oberon compiler; code generator for RISC*)
- IMPORT SYSTEM, Files, ORS, ORB;
+MODULE LSPhORG; (* N.Wirth, 16.4.2016 / 4.4.2017 / 31.5.2019 Oberon compiler; code generator for RISC*)
+ IMPORT SYSTEM, Files, ORS := LSPhORS, ORB := LSPhORB;
(*Code generator for Oberon compiler for RISC processor.
Procedural interface to Parser OSAP; result in array "code".
Procedure Close writes code-files*)
@@ -45,7 +45,6 @@
version: INTEGER; (* 0 = RISC-0, 1 = RISC-5 *)
relmap: ARRAY 6 OF INTEGER; (*condition codes for relations*)
- code: ARRAY maxCode OF LONGINT;
data: ARRAY maxTD OF LONGINT; (*type descriptors*)
str: ARRAY maxStrx OF CHAR;
@@ -53,13 +52,12 @@
PROCEDURE Put0(op, a, b, c: LONGINT);
BEGIN (*emit format-0 instruction*)
- code[pc] := ((a*10H + b) * 10H + op) * 10000H + c; INC(pc)
+ INC(pc)
END Put0;
PROCEDURE Put1(op, a, b, im: LONGINT);
BEGIN (*emit format-1 instruction, -10000H <= im < 10000H*)
- IF im < 0 THEN INC(op, V) END ;
- code[pc] := (((a+40H) * 10H + b) * 10H + op) * 10000H + (im MOD 10000H); INC(pc)
+ INC(pc)
END Put1;
PROCEDURE Put1a(op, a, b, im: LONGINT);
@@ -73,12 +71,12 @@
PROCEDURE Put2(op, a, b, off: LONGINT);
BEGIN (*emit load/store instruction*)
- code[pc] := ((op * 10H + a) * 10H + b) * 100000H + (off MOD 100000H); INC(pc)
+ INC(pc)
END Put2;
PROCEDURE Put3(op, cond, off: LONGINT);
BEGIN (*emit branch instruction*)
- code[pc] := ((op+12) * 10H + cond) * 1000000H + (off MOD 1000000H); INC(pc)
+ INC(pc)
END Put3;
PROCEDURE incR;
@@ -110,7 +108,7 @@
END negated;
PROCEDURE fix(at, with: LONGINT);
- BEGIN code[at] := code[at] DIV C24 * C24 + (with MOD C24)
+ BEGIN
END fix;
PROCEDURE FixOne*(at: LONGINT);
@@ -120,25 +118,16 @@
PROCEDURE FixLink*(L: LONGINT);
VAR L1: LONGINT;
BEGIN
- WHILE L # 0 DO L1 := code[L] MOD 40000H; fix(L, pc-L-1); L := L1 END
END FixLink;
PROCEDURE FixLinkWith(L0, dst: LONGINT);
VAR L1: LONGINT;
BEGIN
- WHILE L0 # 0 DO
- L1 := code[L0] MOD C24;
- code[L0] := code[L0] DIV C24 * C24 + ((dst - L0 - 1) MOD C24); L0 := L1
- END
END FixLinkWith;
PROCEDURE merged(L0, L1: LONGINT): LONGINT;
VAR L2, L3: LONGINT;
BEGIN
- IF L0 # 0 THEN L3 := L0;
- REPEAT L2 := L3; L3 := code[L2] MOD 40000H UNTIL L3 = 0;
- code[L2] := code[L2] + L1; L1 := L0
- END ;
RETURN L1
END merged;
@@ -209,7 +198,6 @@
IF x.type.form = ORB.Bool THEN
IF x.mode = ORB.Const THEN x.r := 15 - x.a*8
ELSE load(x);
- IF code[pc-1] DIV 40000000H # -2 THEN Put1(Cmp, x.r, x.r, 0) END ;
x.r := NE; DEC(RH)
END ;
x.mode := Cond; x.a := 0; x.b := 0
@@ -573,7 +561,6 @@
BEGIN
IF (y.mode = ORB.Const) & (y.type.form # ORB.Proc) THEN
load(x);
- IF (y.a # 0) OR ~(op IN {ORS.eql, ORS.neq}) OR (code[pc-1] DIV 40000000H # -2) THEN Put1a(Cmp, x.r, x.r, y.a) END ;
DEC(RH)
ELSE
IF (x.mode = Cond) OR (y.mode = Cond) THEN ORS.Mark("not implemented") END ;
@@ -1002,7 +989,6 @@
PROCEDURE Open*(v: INTEGER);
BEGIN pc := 0; tdx := 0; strx := 0; RH := 0; fixorgP := 0; fixorgD := 0; fixorgT := 0; check := v # 0; version := v;
IF v = 0 THEN pc := 1;
- REPEAT code[pc] := 0; INC(pc) UNTIL pc = 8
END
END Open;
@@ -1012,9 +998,6 @@
PROCEDURE Header*;
BEGIN entry := pc*4;
- IF version = 0 THEN code[0] := 0E7000000H-1 + pc; Put1a(Mov, SP, 0, StkOrg0) (*RISC-0*)
- ELSE Put1(Sub, SP, SP, 4); Put2(Str, LNK, SP, 0)
- END
END Header;
PROCEDURE NofPtrs(typ: ORB.Type): LONGINT;
@@ -1049,6 +1032,7 @@
name: ORS.Ident;
F: Files.File; R: Files.Rider;
BEGIN (*exit code*)
+ (* Disable writing of output file
IF version = 0 THEN Put1(Mov, 0, 0, 0); Put3(BR, 7, 0) (*RISC-0*)
ELSE Put2(Ldr, LNK, SP, 0); Put1(Add, SP, SP, 4); Put3(BR, 7, LNK)
END ;
@@ -1114,7 +1098,8 @@
Files.WriteInt(R, -1);
Files.WriteInt(R, fixorgP); Files.WriteInt(R, fixorgD); Files.WriteInt(R, fixorgT); Files.WriteInt(R, entry);
Files.Write(R, "O"); Files.Register(F)
+ *)
END Close;
BEGIN relmap[0] := 1; relmap[1] := 9; relmap[2] := 5; relmap[3] := 6; relmap[4] := 14; relmap[5] := 13;
-END ORG.
+END LSPhORG.
--- LSPhORP.Mod.txt
+++ LSPhORP.Mod.txt
@@ -1,5 +1,5 @@
-MODULE ORP; (*N. Wirth 1.7.97 / 8.3.2020 Oberon compiler for RISC in Oberon-07*)
- IMPORT Texts, Oberon, ORS, ORB, ORG;
+MODULE LSPhORP; (*N. Wirth 1.7.97 / 8.3.2020 Oberon compiler for RISC in Oberon-07*)
+ IMPORT Texts, Oberon, RS232, LSPhConstants, ORS := LSPhORS, ORB := LSPhORB, ORG := LSPhORG;
(*Author: Niklaus Wirth, 2014.
Parser of Oberon-RISC compiler. Uses Scanner ORS to obtain symbols (tokens),
ORB for definition of data structures and for handling import and export, and
@@ -8,7 +8,7 @@
TYPE PtrBase = POINTER TO PtrBaseDesc;
PtrBaseDesc = RECORD (*list of names of pointer base types*)
- name: ORS.Ident; type: ORB.Type; next: PtrBase
+ name: ORS.Ident; type: ORB.Type; symPos: INTEGER; next: PtrBase;
END ;
VAR sym: INTEGER; (*last symbol read*)
@@ -21,7 +21,6 @@
modid: ORS.Ident;
pbsList: PtrBase; (*list of names of pointer base types*)
dummy: ORB.Object;
- W: Texts.Writer;
PROCEDURE Check(s: INTEGER; msg: ARRAY OF CHAR);
BEGIN
@@ -81,6 +80,8 @@
PROCEDURE CheckExport(VAR expo: BOOLEAN);
BEGIN
IF sym = ORS.times THEN
+ ORS.FormatTokenUpdate(01);
+ ORS.ModuleTag(LSPhConstants.NameExported);
expo := TRUE; ORS.Get(sym);
IF level # 0 THEN ORS.Mark("remove asterisk") END
ELSE expo := FALSE
@@ -117,11 +118,12 @@
IF ~guard THEN x.type := ORB.boolType END
END TypeTest;
- PROCEDURE selector(VAR x: ORG.Item);
+ PROCEDURE selector(VAR x: ORG.Item; VAR symAtEnd: BOOLEAN);
VAR y: ORG.Item; obj: ORB.Object;
- BEGIN
+ BEGIN symAtEnd := TRUE;
WHILE (sym = ORS.lbrak) OR (sym = ORS.period) OR (sym = ORS.arrow)
OR (sym = ORS.lparen) & (x.type.form IN {ORB.Record, ORB.Pointer}) DO
+ symAtEnd := FALSE;
IF sym = ORS.lbrak THEN
REPEAT ORS.Get(sym); expression(y);
IF x.type.form = ORB.Array THEN
@@ -132,6 +134,7 @@
Check(ORS.rbrak, "no ]")
ELSIF sym = ORS.period THEN ORS.Get(sym);
IF sym = ORS.ident THEN
+ symAtEnd := TRUE;
IF x.type.form = ORB.Pointer THEN ORG.DeRef(x); x.type := x.type.base END ;
IF x.type.form = ORB.Record THEN
obj := ORB.thisfield(x.type); ORS.Get(sym);
@@ -225,12 +228,14 @@
IF sym # ORS.rparen THEN
Parameter(par); n := 1;
WHILE sym <= ORS.comma DO
+ ORS.ModuleTagP(LSPhConstants.ParamNext);
Check(ORS.comma, "comma?");
IF par # NIL THEN par := par.next END ;
INC(n); Parameter(par)
END ;
+ ORS.ModuleTagP(LSPhConstants.ParamEnd);
Check(ORS.rparen, ") missing")
- ELSE ORS.Get(sym);
+ ELSE ORS.ModuleTagP(LSPhConstants.ParamEnd); ORS.Get(sym);
END ;
IF n < x.type.nofpar THEN ORS.Mark("too few params")
ELSIF n > x.type.nofpar THEN ORS.Mark("too many params")
@@ -239,9 +244,11 @@
PROCEDURE StandFunc(VAR x: ORG.Item; fct: LONGINT; restyp: ORB.Type);
VAR y: ORG.Item; n, npar: LONGINT;
- BEGIN Check(ORS.lparen, "no (");
+ BEGIN
+ ORS.ModuleTagP(LSPhConstants.CallParamStart); ORS.FormatTokenUpdate(00);
+ Check(ORS.lparen, "no (");
npar := fct MOD 10; fct := fct DIV 10; expression(x); n := 1;
- WHILE sym = ORS.comma DO ORS.Get(sym); expression(y); INC(n) END ;
+ WHILE sym = ORS.comma DO ORS.ModuleTagP(LSPhConstants.ParamNext); ORS.Get(sym); expression(y); INC(n) END ;
Check(ORS.rparen, "no )");
IF n = npar THEN
IF fct = 0 THEN (*ABS*)
@@ -307,7 +314,7 @@
END set;
PROCEDURE factor(VAR x: ORG.Item);
- VAR obj: ORB.Object; rx: LONGINT;
+ VAR obj: ORB.Object; rx: LONGINT; dummy: BOOLEAN;
BEGIN (*sync*)
IF (sym < ORS.char) OR (sym > ORS.ident) THEN ORS.Mark("expression expected");
REPEAT ORS.Get(sym) UNTIL (sym >= ORS.char) & (sym <= ORS.for) OR (sym >= ORS.then)
@@ -315,8 +322,9 @@
IF sym = ORS.ident THEN
qualident(obj);
IF obj.class = ORB.SFunc THEN StandFunc(x, obj.val, obj.type)
- ELSE ORG.MakeItem(x, obj, level); selector(x);
+ ELSE ORG.MakeItem(x, obj, level); selector(x, dummy);
IF sym = ORS.lparen THEN
+ ORS.FormatTokenUpdate(00); ORS.ModuleTagP(LSPhConstants.CallParamStart);
ORS.Get(sym);
IF (x.type.form = ORB.Proc) & (x.type.base.form # ORB.NoTyp) THEN
ORG.PrepCall(x, rx); ParamList(x); ORG.Call(x, rx); x.type := x.type.base
@@ -364,9 +372,9 @@
PROCEDURE SimpleExpression(VAR x: ORG.Item);
VAR y: ORG.Item; op: INTEGER;
BEGIN
- IF sym = ORS.minus THEN ORS.Get(sym); term(x);
+ IF sym = ORS.minus THEN ORS.FormatTokenUpdate(10); ORS.Get(sym); term(x);
IF x.type.form IN {ORB.Int, ORB.Real, ORB.Set} THEN ORG.Neg(x) ELSE CheckInt(x) END
- ELSIF sym = ORS.plus THEN ORS.Get(sym); term(x);
+ ELSIF sym = ORS.plus THEN ORS.FormatTokenUpdate(10); ORS.Get(sym); term(x);
ELSE term(x)
END ;
WHILE (sym >= ORS.plus) & (sym <= ORS.or) DO
@@ -426,13 +434,15 @@
PROCEDURE StandProc(pno: LONGINT);
VAR nap, npar: LONGINT; (*nof actual/formal parameters*)
x, y, z: ORG.Item;
- BEGIN Check(ORS.lparen, "no (");
+ BEGIN ORS.FormatTokenUpdate(00); ORS.ModuleTagP(LSPhConstants.CallParamStart); Check(ORS.lparen, "no (");
npar := pno MOD 10; pno := pno DIV 10; expression(x); nap := 1;
IF sym = ORS.comma THEN
+ ORS.ModuleTagP(LSPhConstants.ParamNext);
ORS.Get(sym); expression(y); nap := 2; z.type := ORB.noType;
- WHILE sym = ORS.comma DO ORS.Get(sym); expression(z); INC(nap) END
+ WHILE sym = ORS.comma DO ORS.ModuleTagP(LSPhConstants.ParamNext); ORS.Get(sym); expression(z); INC(nap) END
ELSE y.type := ORB.noType
END ;
+ ORS.ModuleTagP(LSPhConstants.ParamEnd);
Check(ORS.rparen, "no )");
IF (npar = nap) OR (pno IN {0, 1}) THEN
IF pno IN {0, 1} THEN (*INC, DEC*)
@@ -462,6 +472,7 @@
PROCEDURE StatSequence;
VAR obj: ORB.Object;
+ symAtEnd: BOOLEAN;
orgtype: ORB.Type; (*original type of case var*)
x, y, z, w: ORG.Item;
L0, L1, rx: LONGINT;
@@ -493,8 +504,9 @@
IF sym = ORS.ident THEN
qualident(obj); ORG.MakeItem(x, obj, level);
IF x.mode = ORB.SProc THEN StandProc(obj.val)
- ELSE selector(x);
+ ELSE selector(x, symAtEnd);
IF sym = ORS.becomes THEN (*assignment*)
+ IF symAtEnd THEN ORS.ModuleTag(LSPhConstants.VarModified) END;
ORS.Get(sym); CheckReadOnly(x); expression(y);
IF CompTypes(x.type, y.type, FALSE) THEN
IF (x.type.form <= ORB.Pointer) OR (x.type.form = ORB.Proc) THEN ORG.Store(x, y)
@@ -511,6 +523,7 @@
END
ELSIF sym = ORS.eql THEN ORS.Mark("should be :="); ORS.Get(sym); expression(y)
ELSIF sym = ORS.lparen THEN (*procedure call*)
+ ORS.FormatTokenUpdate(00); ORS.ModuleTagP(LSPhConstants.CallParamStart);
ORS.Get(sym);
IF (x.type.form = ORB.Proc) & (x.type.base.form = ORB.NoTyp) THEN
ORG.PrepCall(x, rx); ParamList(x); ORG.Call(x, rx)
@@ -525,27 +538,39 @@
END
ELSIF sym = ORS.if THEN
ORS.Get(sym); expression(x); CheckBool(x); ORG.CFJump(x);
+ ORS.FormatTokenTag(LSPhConstants.IndentNextLine);
Check(ORS.then, "no THEN");
StatSequence; L0 := 0;
WHILE sym = ORS.elsif DO
+ ORS.FormatTokenTag(LSPhConstants.OutdentThisLine);
ORS.Get(sym); ORG.FJump(L0); ORG.Fixup(x); expression(x); CheckBool(x);
+ ORS.FormatTokenTag(LSPhConstants.IndentNextLine);
ORG.CFJump(x); Check(ORS.then, "no THEN"); StatSequence
END ;
- IF sym = ORS.else THEN ORS.Get(sym); ORG.FJump(L0); ORG.Fixup(x); StatSequence
+ IF sym = ORS.else THEN
+ ORS.FormatTokenTag(LSPhConstants.OutdentThisLine);
+ ORS.FormatTokenTag(LSPhConstants.IndentNextLine);
+ ORS.Get(sym); ORG.FJump(L0); ORG.Fixup(x); StatSequence
ELSE ORG.Fixup(x)
END ;
+ ORS.FormatTokenTag(LSPhConstants.OutdentThisLine);
ORG.FixLink(L0); Check(ORS.end, "no END")
ELSIF sym = ORS.while THEN
ORS.Get(sym); L0 := ORG.Here(); expression(x); CheckBool(x); ORG.CFJump(x);
+ ORS.FormatTokenTag(LSPhConstants.IndentNextLine);
Check(ORS.do, "no DO"); StatSequence; ORG.BJump(L0);
WHILE sym = ORS.elsif DO
ORS.Get(sym); ORG.Fixup(x); expression(x); CheckBool(x); ORG.CFJump(x);
+ ORS.FormatTokenTag(LSPhConstants.IndentNextLine);
Check(ORS.do, "no DO"); StatSequence; ORG.BJump(L0)
END ;
+ ORS.FormatTokenTag(LSPhConstants.OutdentThisLine);
ORG.Fixup(x); Check(ORS.end, "no END")
ELSIF sym = ORS.repeat THEN
+ ORS.FormatTokenTag(LSPhConstants.IndentNextLine);
ORS.Get(sym); L0 := ORG.Here(); StatSequence;
IF sym = ORS.until THEN
+ ORS.FormatTokenTag(LSPhConstants.OutdentThisLine);
ORS.Get(sym); expression(x); CheckBool(x); ORG.CBJump(x, L0)
ELSE ORS.Mark("missing UNTIL")
END
@@ -554,13 +579,17 @@
IF sym = ORS.ident THEN
qualident(obj); ORG.MakeItem(x, obj, level); CheckInt(x); CheckReadOnly(x);
IF sym = ORS.becomes THEN
+ ORS.ModuleTag(LSPhConstants.VarModified);
ORS.Get(sym); expression(y); CheckInt(y); ORG.For0(x, y); L0 := ORG.Here();
Check(ORS.to, "no TO"); expression(z); CheckInt(z); obj.rdo := TRUE;
IF sym = ORS.by THEN ORS.Get(sym); expression(w); CheckConst(w); CheckInt(w)
ELSE ORG.MakeConstItem(w, ORB.intType, 1)
END ;
+ ORS.FormatTokenTag(LSPhConstants.IndentNextLine);
Check(ORS.do, "no DO"); ORG.For1(x, y, z, w, L1);
- StatSequence; Check(ORS.end, "no END");
+ StatSequence;
+ ORS.FormatTokenTag(LSPhConstants.OutdentThisLine);
+ Check(ORS.end, "no END");
ORG.For2(x, y, w); ORG.BJump(L0); ORG.FixLink(L1); obj.rdo := FALSE
ELSE ORS.Mark(":= expected")
END
@@ -571,17 +600,20 @@
IF sym = ORS.ident THEN
qualident(obj); orgtype := obj.type;
IF (orgtype.form = ORB.Pointer) OR (orgtype.form = ORB.Record) & (obj.class = ORB.Par) THEN
+ ORS.FormatTokenTag(LSPhConstants.IndentNextLine);
Check(ORS.of, "OF expected"); TypeCase(obj, x); L0 := 0;
WHILE sym = ORS.bar DO
ORS.Get(sym); ORG.FJump(L0); ORG.Fixup(x); obj.type := orgtype; TypeCase(obj, x)
END ;
ORG.Fixup(x); ORG.FixLink(L0); obj.type := orgtype
ELSE ORS.Mark("numeric case not implemented");
+ ORS.FormatTokenTag(LSPhConstants.IndentNextLine);
Check(ORS.of, "OF expected"); SkipCase;
WHILE sym = ORS.bar DO SkipCase END
END
ELSE ORS.Mark("ident expected")
END ;
+ ORS.FormatTokenTag(LSPhConstants.OutdentThisLine);
Check(ORS.end, "no END")
END ;
ORG.CheckRegs;
@@ -593,19 +625,23 @@
(* Types and declarations *)
- PROCEDURE IdentList(class: INTEGER; VAR first: ORB.Object);
+ PROCEDURE IdentList(class, lspClass: INTEGER; VAR first: ORB.Object; procdecl, proctype: BOOLEAN);
VAR obj: ORB.Object;
BEGIN
IF sym = ORS.ident THEN
- ORB.NewObj(first, ORS.id, class); ORS.Get(sym); CheckExport(first.expo);
+ ORS.ClassifyIdent(lspClass, ORS.Pos(), modid);
+ IF proctype THEN ORS.ModuleTag(LSPhConstants.DefinitionUsed) END;
+ ORB.NewObj(first, ORS.id, modid, class, lspClass); ORS.Get(sym); CheckExport(first.expo);
WHILE sym = ORS.comma DO
+ IF procdecl THEN ORS.ModuleTagP(LSPhConstants.ParamNext) END;
ORS.Get(sym);
- IF sym = ORS.ident THEN ORB.NewObj(obj, ORS.id, class); ORS.Get(sym); CheckExport(obj.expo)
+ IF sym = ORS.ident THEN ORS.ClassifyIdent(lspClass, ORS.Pos(), modid); ORB.NewObj(obj, ORS.id, modid, class, lspClass); ORS.Get(sym); CheckExport(obj.expo)
ELSE ORS.Mark("ident?")
END
END;
+ ORS.ModuleTagP(LSPhConstants.DefinitionListValue);
IF sym = ORS.colon THEN ORS.Get(sym) ELSE ORS.Mark(":?") END
- ELSE first := NIL
+ ELSE ORS.ModuleTagP(LSPhConstants.DefinitionListValue); first := NIL
END
END IdentList;