Mercurial > projects > dil
annotate src/dil/lexer/IdTable.d @ 820:1d06b4aed7cf
Revised code in the first pass.
Added code to handle anonymous unions and structs. Hope the idea will work.
Added type to class Aggregate and isAnonymous to some other Symbol classes.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Fri, 14 Mar 2008 15:42:08 +0100 |
parents | 372fa4fbbb1d |
children |
rev | line source |
---|---|
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
1 /++ |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
2 Author: Aziz Köksal |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
3 License: GPL3 |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
4 +/ |
601
9f96fd51cb41
Moved dil.IdTable to dil.lexer.IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
600
diff
changeset
|
5 module dil.lexer.IdTable; |
597
4d50267f59c9
Moved dil.TokensEnum to dil.lexer.TokensEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
549
diff
changeset
|
6 |
4d50267f59c9
Moved dil.TokensEnum to dil.lexer.TokensEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
549
diff
changeset
|
7 import dil.lexer.TokensEnum; |
603
fc351756cc84
Moved dil.IdentsGenerator to dil.lexer.IdentsGenerator.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
602
diff
changeset
|
8 import dil.lexer.IdentsGenerator; |
599
c4cdea3a65ba
Moved dil.Keywords to dil.lexer.Keywords.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
597
diff
changeset
|
9 import dil.lexer.Keywords; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
10 import common; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
11 |
600
041eae272362
Moved dil.Identifier to dil.lexer.Identifier.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
599
diff
changeset
|
12 public import dil.lexer.Identifier; |
602
c2e35c83c394
Moved dil.IdentsEnum to dil.lexer.IdentsEnum.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
601
diff
changeset
|
13 public import dil.lexer.IdentsEnum; |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
14 |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
15 /// A namespace for the predefined identifiers. |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
16 struct Ident |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
17 { |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
18 const static |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
19 { |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
20 mixin(generateIdentMembers()); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
21 } |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
22 |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
23 static Identifier*[] allIds() |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
24 { |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
25 return __allIds; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
26 } |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
27 } |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
28 |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
29 /// Global table for hoarding and retrieving identifiers. |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
30 struct IdTable |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
31 { |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
32 static: |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
33 /// A set of common, predefined identifiers for fast lookups. |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
34 private Identifier*[string] staticTable; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
35 /// A table that grows with every newly found, unique identifier. |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
36 private Identifier*[string] growingTable; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
37 |
786
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
38 /// Loads keywords and predefined identifiers into the static table. |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
39 static this() |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
40 { |
797
cf2ad5df025c
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
786
diff
changeset
|
41 foreach (ref k; g_reservedIds) |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
42 staticTable[k.str] = &k; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
43 foreach (id; Ident.allIds()) |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
44 staticTable[id.str] = id; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
45 staticTable.rehash; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
46 } |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
47 |
786
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
48 /// Looks up idString in both tables. |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
49 Identifier* lookup(string idString) |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
50 { |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
51 auto id = inStatic(idString); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
52 if (id) |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
53 return id; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
54 return inGrowing(idString); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
55 } |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
56 |
786
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
57 /// Looks up idString in the static table. |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
58 Identifier* inStatic(string idString) |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
59 { |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
60 auto id = idString in staticTable; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
61 return id ? *id : null; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
62 } |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
63 |
549
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
64 alias Identifier* function(string idString) LookupFunction; |
786
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
65 /// Looks up idString in the growing table. |
549
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
66 LookupFunction inGrowing = &_inGrowing_unsafe; // Default to unsafe function. |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
67 |
786
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
68 /// Sets the thread safety mode of the growing table. |
549
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
69 void setThreadsafe(bool b) |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
70 { |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
71 if (b) |
786
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
72 inGrowing = &_inGrowing_safe; |
549
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
73 else |
786
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
74 inGrowing = &_inGrowing_unsafe; |
549
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
75 } |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
76 |
786
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
77 /// Returns true if access to the growing table is thread-safe. |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
78 bool isThreadsafe() |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
79 { |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
80 return inGrowing is &_inGrowing_safe; |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
81 } |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
82 |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
83 /// Looks up idString in the table. |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
84 /// |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
85 /// Adds idString to the table if not found. |
549
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
86 private Identifier* _inGrowing_unsafe(string idString) |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
87 out(id) |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
88 { assert(id !is null); } |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
89 body |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
90 { |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
91 auto id = idString in growingTable; |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
92 if (id) |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
93 return *id; |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
94 auto newID = Identifier(idString, TOK.Identifier); |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
95 growingTable[idString] = newID; |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
96 return newID; |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
97 } |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
98 |
786
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
99 /// Looks up idString in the table. |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
100 /// |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
101 /// Adds idString to the table if not found. |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
102 /// Access to the data structure is synchronized. |
549
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
103 private Identifier* _inGrowing_safe(string idString) |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
104 { |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
105 synchronized |
549
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
106 return _inGrowing_unsafe(idString); |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
107 } |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
108 |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
109 /+ |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
110 Identifier* addIdentifiers(char[][] idStrings) |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
111 { |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
112 auto ids = new Identifier*[idStrings.length]; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
113 foreach (i, idString; idStrings) |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
114 { |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
115 Identifier** id = idString in tabulatedIds; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
116 if (!id) |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
117 { |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
118 auto newID = Identifier(TOK.Identifier, idString); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
119 tabulatedIds[idString] = newID; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
120 id = &newID; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
121 } |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
122 ids[i] = *id; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
123 } |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
124 } |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
125 +/ |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
603
diff
changeset
|
126 |
786
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
127 static uint anonCount; /// Counter for anonymous identifiers. |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
128 |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
129 /// Generates an anonymous identifier. |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
130 /// |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
131 /// Concatenates prefix with anonCount. |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
132 /// The identifier is not inserted into the table. |
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
133 Identifier* genAnonymousID(string prefix) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
603
diff
changeset
|
134 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
603
diff
changeset
|
135 ++anonCount; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
603
diff
changeset
|
136 auto x = anonCount; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
603
diff
changeset
|
137 // Convert count to a string and append it to str. |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
707
diff
changeset
|
138 char[] num; |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
603
diff
changeset
|
139 do |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
707
diff
changeset
|
140 num = cast(char)('0' + (x % 10)) ~ num; |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
603
diff
changeset
|
141 while (x /= 10) |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
707
diff
changeset
|
142 return Identifier(prefix ~ num, TOK.Identifier); |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
603
diff
changeset
|
143 } |
707
efa5fcb9aa14
Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
144 |
786
3b34f6a95a27
Added and revised documenation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
145 /// Generates an identifier for an anonymous enum. |
707
efa5fcb9aa14
Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
146 Identifier* genAnonEnumID() |
efa5fcb9aa14
Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
147 { |
efa5fcb9aa14
Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
148 return genAnonymousID("__anonenum"); |
efa5fcb9aa14
Added semantic code related to enums.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
149 } |
818
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
806
diff
changeset
|
150 |
820
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
151 /// Generates an identifier for an anonymous class. |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
152 Identifier* genAnonClassID() |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
153 { |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
154 return genAnonymousID("__anonclass"); |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
155 } |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
156 |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
157 /// Generates an identifier for an anonymous struct. |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
158 Identifier* genAnonStructID() |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
159 { |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
160 return genAnonymousID("__anonstruct"); |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
161 } |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
162 |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
163 /// Generates an identifier for an anonymous union. |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
164 Identifier* genAnonUnionID() |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
165 { |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
166 return genAnonymousID("__anonunion"); |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
167 } |
1d06b4aed7cf
Revised code in the first pass.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
818
diff
changeset
|
168 |
818
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
806
diff
changeset
|
169 /// Generates an identifier for a module which has got no valid name. |
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
806
diff
changeset
|
170 Identifier* genModuleID() |
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
806
diff
changeset
|
171 { |
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
806
diff
changeset
|
172 return genAnonymousID("__module"); |
372fa4fbbb1d
Added error messages and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
806
diff
changeset
|
173 } |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
174 } |
549
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
175 |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
176 unittest |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
177 { |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
178 // TODO: write benchmark. |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
179 // Single table |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
180 |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
181 // Single table. synchronized |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
182 |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
183 // Two tables. |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
184 |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
185 // Two tables. synchronized |
9c45b245b554
Added methods to IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
186 } |