-
Notifications
You must be signed in to change notification settings - Fork 1
/
SymbolTable.cs
1349 lines (1194 loc) · 46.4 KB
/
SymbolTable.cs
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
/*
* TADS3 documentation generator.
*
* Copyright Edward L. Stauff 2003.
* This code may be freely distributed and modified for non-commercial purposes.
*
*/
using System;
using System.Collections;
using System.IO;
/*
* The classes in this file contain all the information gathered from the source
* files. These classes are independent of both the front-end (parser) and
* back-end (output generator).
*/
namespace DocGen
{
/// <summary>
/// Contains all the information gathered from the source files.
/// </summary>
public class SymbolTable
{
/// <summary>
/// All the files (SourceFile) in all the source files.
/// </summary>
public ArrayList Files = new ArrayList();
/// <summary>
/// All the classes (ClassDef) in all the source files.
/// </summary>
public ArrayList Classes = new ArrayList();
/// <summary>
/// All the GrammarProd objects (GrammarProd) in all the source files.
/// </summary>
public ArrayList GrammarProds = new ArrayList();
/// <summary>
/// All the macros (MacroDef) in all the source files.
/// </summary>
public ArrayList Macros = new ArrayList();
/// <summary>
/// All the enum groups (EnumGroup) in all the source files.
/// </summary>
public ArrayList EnumGroups = new ArrayList();
/// <summary>
/// All the enums (EnumDef) in all the source files.
/// </summary>
public ArrayList Enums = new ArrayList();
/// <summary>
/// All the templates (TemplateDef) in all the source files.
/// </summary>
public ArrayList Templates = new ArrayList();
/// <summary>
/// All the global objects (ObjectDef) in all the source files.
/// </summary>
public ArrayList GlobalObjects = new ArrayList();
/// <summary>
/// All the global functions (FunctionDef) in all the source files.
/// </summary>
public ArrayList GlobalFunctions = new ArrayList();
/// <summary>
/// All the "modify" statements (Modification) in all the source files.
/// </summary>
public ArrayList Modifications = new ArrayList();
/// <summary>
/// All object filenames. We use this to ensure that object file
/// names are unique, even in case-insensitive file systems. See
/// SetObjectFileName() for details.
/// </summary>
public ArrayList ObjectFileNames = new ArrayList();
/// <summary>
/// All the messages (BMsg and DMsg) extracted from the source files
/// </summary>
public ArrayList Messages = new ArrayList();
//=====================================================================
/// <summary>
/// Constructor
/// </summary>
public SymbolTable()
{
}
//=====================================================================
/// <summary>
/// Adds a new SourceFile to the SymbolTable and returns it.
/// </summary>
/// <param name="fileName">the name of the source file</param>
public SourceFile AddFile (String fileName)
{
SourceFile sf = new SourceFile(fileName);
this.Files.Add(sf);
return sf;
}
//=====================================================================
/// <summary>
/// Sets an object symbol's filename member such that the filename
/// is unique among all object symbols so far, even in file systems
/// that are insensitive to case.
/// </summary>
public void SetObjectFileName(Modification obj)
{
// start with the object name
String fname = obj.Name;
String lcname;
// keep going until we find a unique name
for (int i = 1 ; ; i++)
{
// get the lower-case version of the name - we'll use this
// as the filename for indexing purposes, since we want to
// ignore case in order to respect case-insensitive file
// systems
lcname = fname.ToLower();
// see if this is in the table already
bool found = false;
foreach (String s in ObjectFileNames)
{
if (s.CompareTo(lcname) == 0)
{
found = true;
break;
}
}
// if we didn't find it, we can use the current name
if (!found)
break;
// this name collides with a name already in the table;
// add a numeric suffix to the base name and try again
fname = obj.Name + i;
}
// add the lower-case name to the file list, so that we'll find
// any collisions with future objects added to the table
ObjectFileNames.Add(lcname);
// remember the mixed-case name as the object filename
obj.FileName = fname;
}
//=====================================================================
/// <summary>
/// Performs various operations that can't be done until all the data
/// has been parsed from the source files.
/// </summary>
public void PostProcess ()
{
this.Classes.Sort();
this.Files.Sort();
this.Macros.Sort();
this.Templates.Sort();
this.GlobalFunctions.Sort();
this.GlobalObjects.Sort();
this.GrammarProds.Sort();
this.Messages.Sort();
foreach (Modification mod in this.Modifications)
{
ObjectOrClass cd = this.FindObjectOrClass(mod.Name);
if (cd != null)
{
// add the 'modify' source to the base object's source list
cd.Modifications.Add(mod.Source);
// add the 'modify' object to the base object's mod list
cd.ModificationMods.Add(mod);
// merge the methods and properties into the base object
cd.MergeModification(mod);
// the 'modify' object's documentation goes in the same
// file as the base object
mod.FileName = cd.FileName;
}
// else throw new Exception("modification of undefined class or object: " + mod.Name);
// PROBLEM: the preceding line triggers because we don't expand macros
}
foreach (ClassDef c in this.Classes)
{
c.LinkBaseClasses(this);
c.Methods.Sort();
c.Properties.Sort();
c.GlobalObjects.Sort();
// note: do NOT sort sub-classes; order matters!
}
foreach (ObjectDef o in this.GlobalObjects)
{
o.LinkBaseClasses(this);
o.Methods.Sort();
o.Properties.Sort();
// note: do NOT sort sub-classes; order matters!
}
foreach (SourceFile f in this.Files)
f.PostProcess(this);
foreach (ClassDef c in this.Classes)
c.CheckForOverridden();
foreach (ObjectDef o in this.GlobalObjects)
o.CheckForOverridden();
// collect all the enums from the enum groups
foreach (EnumGroup g in this.EnumGroups)
foreach (EnumDef e in g.Enums)
this.Enums.Add(e);
this.Enums.Sort();
}
//=====================================================================
/// <summary>
/// Returns the class with the given name, or null if not found.
/// </summary>
public ClassDef FindClass (String name)
{
foreach (ClassDef c in this.Classes)
if (c.Name == name)
return c;
return null;
}
//=====================================================================
/// <summary>
/// Returns the GrammarProd with the given name, or null if not found.
/// </summary>
public GrammarProd FindGrammarProd (String name)
{
// search for it
foreach (GrammarProd g in this.GrammarProds)
{
if (g.Name == name)
return g;
}
// didn't find it
return null;
}
//=====================================================================
/// <summary>
/// Returns the file with the given name, or null if not found.
/// </summary>
public SourceFile FindFile (String shortName)
{
foreach (SourceFile s in this.Files)
if (s.ShortName == shortName)
return s;
return null;
}
//=====================================================================
/// <summary>
/// Returns the class or object with the given name, or null if not found.
/// </summary>
public ObjectOrClass FindObjectOrClass (String name)
{
foreach (ClassDef c in this.Classes)
if (c.Name == name)
return c;
foreach (ObjectDef o in this.GlobalObjects)
if (o.Name == name)
return o;
return null;
}
//=====================================================================
/// <summary>
/// Dumps the symbol table to the named file.
/// </summary>
public void Dump (String fileName)
{
StreamWriter sw = new StreamWriter(fileName);
this.Dump(sw);
sw.Close();
}
//=====================================================================
/// <summary>
/// Dumps the symbol table to the given stream.
/// </summary>
/// <param name="sw"></param>
public void Dump (StreamWriter sw)
{
foreach (ClassDef cd in this.Classes)
cd.Dump(sw);
}
}
//#########################################################################
/// <summary>
/// Describes the location of a symbol in a source file.
/// </summary>
public class SourceLoc
{
/// <summary>
/// The name of the source file.
/// </summary>
public String Name;
/// <summary>
/// The line number in the source file.
/// </summary>
public int Line;
//=====================================================================
/// <summary>
/// Constructor
/// </summary>
/// <param name="name">file name</param>
/// <param name="line">line number</param>
public SourceLoc (String name, int line)
{
this.Name = name;
this.Line = line;
}
}
//#########################################################################
/// <summary>
/// Base class for everything we extract from a source file.
/// </summary>
public class Symbol : IComparable
{
/// <summary>
/// The name of the symbol.
/// </summary>
public String Name;
/// <summary>
/// The comment immediately preceding the symbol's definition.
/// </summary>
public String Description;
/// <summary>
/// Where the symbol was found.
/// </summary>
public SourceLoc Source;
//=====================================================================
/// <summary>
/// Constructor.
/// </summary>
/// <param name="file">the source file where the symbol was found</param>
/// <param name="line">the line where the symbol was found</param>
protected Symbol (String file, int line)
{
this.Source = new SourceLoc(file, line);
}
//=====================================================================
/// <summary>
/// Constructor.
/// </summary>
/// <param name="file">the source file where the symbol was found</param>
/// <param name="line">the line where the symbol was found</param>
public Symbol (String name, String descr, String file, int line)
: this(file, line)
{
this.Name = name;
this.Description = descr;
}
//=====================================================================
public override String ToString () { return this.Name; }
//=====================================================================
/// <summary>
/// For sorting; required by the IComparable interface.
/// </summary>
public int CompareTo (object that)
{
// compare the names
int d = this.Name.ToLower().CompareTo(
((Symbol) that).Name.ToLower());
// if the names are the same sort by source file
if (d == 0)
d = this.Source.Name.ToLower().CompareTo(
((Symbol) that).Source.Name.ToLower());
// if the names and source file are the same, sort by source line
if (d == 0)
d = this.Source.Line - ((Symbol) that).Source.Line;
// return the result
return d;
}
//=====================================================================
/// <summary>
/// Dumps the symbol to the given stream.
/// </summary>
public virtual void Dump (StreamWriter sw)
{
sw.WriteLine("symbol " + this.Name + " // " + this.Description);
}
}
//########################################################################
/// <summary>
/// For storing information about DMsg and BMsg message declarations
/// </summary>
public class Message : Symbol
{
public String type;
public String text;
public Message(String file, int line)
: base(file, line)
{
}
}
//#########################################################################
/// <summary>
/// For temporarily storing "modify" statements.
/// </summary>
public class Modification : Symbol
{
/// <summary>
/// The base filename for the symbol. This is normally just the
/// object name; however, symbol names are case sensitive, but
/// some file systems aren't, so we need to use different filenames
/// when symbol names differ only in case.
/// </summary>
public String FileName;
/// <summary>
/// The object's methods (Method).
/// </summary>
public ArrayList Methods = new ArrayList();
/// <summary>
/// The object's properties (PropertyDef).
/// </summary>
public ArrayList Properties = new ArrayList();
//=====================================================================
/// <summary>
/// Constructor.
/// </summary>
/// <param name="file">the source file where the object was found</param>
/// <param name="line">the line where the object was found</param>
public Modification (String file, int line)
: base (file, line)
{
}
//=====================================================================
/// <summary>
/// Returns the method with the given name, or null if not found.
/// </summary>
public MethodDef FindMethod (String name)
{
foreach (MethodDef m in this.Methods)
if (m.Name == name)
return m;
return null;
}
//=====================================================================
/// <summary>
/// Returns the property with the given name, or null if not found.
/// </summary>
public PropertyDef FindProperty (String name)
{
foreach (PropertyDef p in this.Properties)
if (p.Name == name)
return p;
return null;
}
//=====================================================================
}
//#########################################################################
/// <summary>
/// For GrammarProd objects. A GrammarProd object is implicitly
/// defined by a 'grammar' statement, but only implicitly. The
/// 'grammar' statement explicitly defines a match-object class,
/// and the properties and methods defined in the 'grammar' are
/// attached to the match-object class. However, the statement
/// also defines or adds to a GrammarProd object with the root
/// (untagged) name of the production, and adds the token-list
/// rules it defines to the alternative list for the GrammarProd
/// object.
/// </summary>
public class GrammarProd : Modification
{
/// <summary>
/// The associated match-object classes (ClassDef)
/// </summary>
public ArrayList MatchObjects = new ArrayList();
//=====================================================================
/// <summary>
/// Constructor.
/// </summary>
/// <param name="file">the source file where the object was found</param>
/// <param name="line">the line where the object was found</param>
public GrammarProd (String file, int line)
: base (file, line)
{
}
}
//#########################################################################
/// <summary>
/// Base class for TADS3 objects and classes..
/// </summary>
public abstract class ObjectOrClass : Modification
{
/// <summary>
/// The object's base classes (ClassDef).
/// </summary>
public ArrayList BaseClasses = new ArrayList();
/// <summary>
/// Places where this class or object was modified (SourceLoc).
/// </summary>
public ArrayList Modifications = new ArrayList();
/// <summary>
/// The actual modifier statements
/// </summary>
public ArrayList ModificationMods = new ArrayList();
//=====================================================================
/// <summary>
/// Constructor.
/// </summary>
/// <param name="file">the source file where the object was found</param>
/// <param name="line">the line where the object was found</param>
protected ObjectOrClass (String file, int line)
: base (file, line)
{
}
//=====================================================================
/// <summary>
/// Looks for overridden properties and methods.
/// </summary>
public void CheckForOverridden ()
{
foreach (MethodDef m in this.Methods)
m.CheckForOverridden(this);
foreach (PropertyDef p in this.Properties)
p.CheckForOverridden(this);
}
//=====================================================================
/// <summary>
/// Merges the given modification into the class.
/// </summary>
public void MergeModification (Modification mod)
{
// if (mod.Description != "")
// this.Description += "\r\n" + mod.Description;
foreach (MethodDef modMethod in mod.Methods)
{
MethodDef origMethod = this.FindMethod(modMethod.Name);
if (origMethod == null)
this.Methods.Add(modMethod);
else
{
origMethod.Modifications.Add(modMethod.Source);
origMethod.ModificationMods.Add(modMethod);
// if (modMethod.Description != "")
// origMethod.Description += "\r\n" + modMethod.Description;
}
}
foreach (PropertyDef modProp in mod.Properties)
{
PropertyDef origProp = this.FindProperty(modProp.Name);
if (origProp == null)
this.Properties.Add(modProp);
else
{
origProp.Modifications.Add(modProp.Source);
origProp.ModificationMods.Add(modProp);
}
}
}
//=====================================================================
}
//#########################################################################
/// <summary>
/// Represents a TADS3 global object.
/// </summary>
public class ObjectDef : ObjectOrClass
{
/// <summary>
/// Is this a transient object?
/// </summary>
public bool IsTransient = false;
/// <summary>
/// Does this object represent an action?
/// </summary>
public bool isAction = false;
//=====================================================================
/// <summary>
/// Constructor.
/// </summary>
/// <param name="file">the source file where the object was found</param>
/// <param name="line">the line where the object was found</param>
public ObjectDef (String file, int line)
: base (file, line)
{
}
//=====================================================================
/// <summary>
/// Populates the lists of global objects in this class's base classes.
/// </summary>
public void LinkBaseClasses (SymbolTable st)
{
for (int i = 0; i < this.BaseClasses.Count; i++)
{
String name = this.BaseClasses[i] as string;
if (name == null)
continue;
ObjectOrClass oc = st.FindObjectOrClass(name);
if (oc == null)
continue;
this.BaseClasses[i] = oc;
if (oc is ClassDef)
{
ClassDef c = (ClassDef)oc;
if (!c.GlobalObjects.Contains(this))
c.GlobalObjects.Add(this);
}
}
}
//=====================================================================
/// <summary>
/// Dumps the class to the given stream.
/// </summary>
public override void Dump (StreamWriter sw)
{
sw.Write("object " + this.Name + " :");
foreach (object o in this.BaseClasses)
sw.Write(" " + o.ToString());
sw.WriteLine(" // " + this.Description);
foreach (PropertyDef p in this.Properties)
p.Dump(sw);
foreach (MethodDef m in this.Methods)
m.Dump(sw);
}
}
//#########################################################################
/// <summary>
/// Represents a TADS3 class.
/// </summary>
public class ClassDef : ObjectOrClass
{
/// <summary>
/// The class's subclasses (ClassDef).
/// </summary>
public ArrayList SubClasses = new ArrayList();
/// <summary>
/// Global objects that are of this class (ObjectDef)..
/// </summary>
public ArrayList GlobalObjects = new ArrayList();
/// <summary>
/// Was the class declared as "intrinsic"?
/// </summary>
public bool IsIntrinsic = false;
/// <summary>
/// Was the class declared as "grammar"?
/// </summary>
public bool IsGrammar = false;
/// <summary>
/// For a "grammar" class, the rule defining the grammar
/// </summary>
public String GrammarRule = null;
/// <summary>
/// For a "grammar" class, the associated GrammarProd object
/// </summary>
public GrammarProd GrammarProdObj = null;
/// <summary>
/// Was the class declared using a Define.*Action() macro?
/// </summary>
public bool IsAction = false;
/// <summary>
/// The original definition, if defined via a VerbRule() or
/// DefineXAction macro.
/// </summary>
public String OrigDef = null;
//=====================================================================
/// <summary>
/// Constructor.
/// </summary>
/// <param name="file">the source file where the class was found</param>
/// <param name="line">the line where the class was found</param>
public ClassDef (String file, int line)
: base (file, line)
{
}
//=====================================================================
/// <summary>
/// Populates the lists of subclasses in this class's base classes.
/// </summary>
public void LinkBaseClasses (SymbolTable st)
{
for (int i = 0; i < this.BaseClasses.Count; i++)
{
String name = this.BaseClasses[i] as string;
if (name == null)
continue;
ObjectOrClass oc = st.FindObjectOrClass(name);
if (oc == null)
continue;
this.BaseClasses[i] = oc;
if (oc is ClassDef)
{
ClassDef c = (ClassDef)oc;
if (!c.SubClasses.Contains(this))
c.SubClasses.Add(this);
}
}
}
//=====================================================================
/// <summary>
/// Dumps the class to the given stream.
/// </summary>
public override void Dump (StreamWriter sw)
{
sw.Write("class " + this.Name + " :");
foreach (object o in this.BaseClasses)
sw.Write(" " + o.ToString());
sw.WriteLine(" // " + this.Description);
foreach (PropertyDef p in this.Properties)
p.Dump(sw);
foreach (MethodDef m in this.Methods)
m.Dump(sw);
}
}
//#########################################################################
/// <summary>
/// Represents a single global function (subroutine).
/// </summary>
public class FunctionDef : Symbol
{
/// <summary>
/// The parameter names, in the order in which they were defined.
/// Each element in the array is a String.
/// </summary>
public ArrayList Parameters = new ArrayList();
//=====================================================================
/// <summary>
/// Constructor.
/// </summary>
/// <param name="file">the source file where the symbol was found</param>
/// <param name="line">the line where the symbol was found</param>
public FunctionDef (String file, int line)
: base (file, line)
{
}
//=====================================================================
/// <summary>
/// Dumps the method to the given stream.
/// </summary>
public override void Dump (StreamWriter sw)
{
sw.Write("function " + this.Name + " (");
foreach (String s in this.Parameters)
sw.Write(" " + s);
sw.WriteLine(" ) // " + this.Description);
}
}
//#########################################################################
/// <summary>
/// Represents a single method in a class.
/// </summary>
public class MethodDef : FunctionDef
{
/// <summary>
/// Does this method override a method in a base class?
/// </summary>
public bool Overridden = false;
/// <summary>
/// The class to which this method belongs.
/// </summary>
public Modification ClassOrObject;
/// <summary>
/// Places where this class was modified (SourceLoc).
/// </summary>
public ArrayList Modifications = new ArrayList();
/// <summary>
/// Actual statements containing modifications (MethodDef)
/// </summary>
public ArrayList ModificationMods = new ArrayList();
/// <summary>
/// Is this an interface property definition only (a '//' line)?
/// </summary>
public bool IsIfcOnly = false;
//=====================================================================
/// <summary>
/// Constructor.
/// </summary>
/// <param name="file">the source file where the symbol was found</param>
/// <param name="line">the line where the symbol was found</param>
public MethodDef (String file, int line)
: base (file, line)
{
}
//=====================================================================
/// <summary>
/// Checks for overridden methods.
/// </summary>
public void CheckForOverridden (ObjectOrClass baseClass)
{
foreach (object o in baseClass.BaseClasses)
{
if ((o is ClassDef) && (this._CheckForOverridden((ClassDef) o)))
{
this.Overridden = true;
return;
}
}
}
//=====================================================================
/// <summary>
/// Checks for overridden methods.
/// </summary>
private bool _CheckForOverridden (ObjectOrClass baseClass)
{
foreach (MethodDef m in baseClass.Methods)
if (m.Name == this.Name)
return true;
foreach (object o in baseClass.BaseClasses)
{
if (o is ClassDef)
if (this._CheckForOverridden((ClassDef) o))
return true;
}
return false;
}
//=====================================================================
/// <summary>
/// Dumps the method to the given stream.
/// </summary>
public override void Dump (StreamWriter sw)
{
sw.Write("\tmethod " + this.Name + " (");
foreach (String s in this.Parameters)
sw.Write(" " + s);
sw.WriteLine(" ) // " + this.Description);
}
}
//#########################################################################
/// <summary>
/// Represents a single property within a class.
/// </summary>
public class PropertyDef : Symbol
{
/// <summary>
/// Does this property override a property in a base class?
/// </summary>
public bool Overridden = false;
/// <summary>
/// The class or object to which this property belongs.
/// </summary>
public Modification ClassOrObject;
/// <summary>
/// Places where this property was modified (SourceLoc).
/// </summary>
public ArrayList Modifications = new ArrayList();
/// <summary>
/// Actual statements containing modifications (MethodDef)
/// </summary>
public ArrayList ModificationMods = new ArrayList();
/// <summary>
/// Is this an interface property definition only (a '//' line)?
/// </summary>
public bool IsIfcOnly = false;
//=====================================================================
/// <summary>
/// Constructor.
/// </summary>
/// <param name="name">the name of the property</param>
/// <param name="desc">the comment immediately preceding the property</param>
/// <param name="cl">the class or object to which the property belongs</param>
/// <param name="file">the source file where the property was found</param>
/// <param name="line">the line where the property was found</param>
public PropertyDef (String name, String desc, Modification cl, String file, int line)
: base (file, line)
{
this.Name = name;
this.Description = desc;
this.ClassOrObject = cl;
}
//=====================================================================
/// <summary>
/// Checks for overridden properties.
/// </summary>
public void CheckForOverridden (ObjectOrClass baseClass)
{
foreach (object o in baseClass.BaseClasses)
{
if ((o is ClassDef) && (this._CheckForOverridden((ClassDef) o)))
{
this.Overridden = true;
return;
}
}
}
//=====================================================================
/// <summary>
/// Checks for overridden properties.
/// </summary>
private bool _CheckForOverridden (ObjectOrClass baseClass)
{
foreach (PropertyDef p in baseClass.Properties)
if (p.Name == this.Name)
return true;
foreach (object o in baseClass.BaseClasses)
{
if (o is ClassDef)
if (this._CheckForOverridden((ClassDef) o))
return true;
}
return false;
}
//=====================================================================
/// <summary>
/// Dumps this property to the given stream.
/// </summary>
public override void Dump (StreamWriter sw)
{
sw.WriteLine("\tproperty " + this.Name + " // " + this.Description);
}
}
//#########################################################################
/// <summary>
/// Represents a TADS3 macro.
/// </summary>