Mercurial > projects > dil
annotate trunk/src/dil/Parser.d @ 502:4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Rearranged members of struct Identifier and added new member ID identID.
Moved idTableLookup to module dil.IdTable.
Renamed module TokenIDs to TokensEnum.
Added member Identifier* ident to struct Token.
Changed string switchtes in Parser to integer switches using enum ID.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Tue, 11 Dec 2007 14:19:30 +0100 |
parents | 949a53332c66 |
children | 9076c4cea2a4 |
rev | line source |
---|---|
0 | 1 /++ |
2 Author: Aziz Köksal | |
249 | 3 License: GPL3 |
0 | 4 +/ |
326 | 5 module dil.Parser; |
327 | 6 import dil.Lexer; |
7 import dil.SyntaxTree; | |
8 import dil.Token; | |
9 import dil.Messages; | |
10 import dil.Information; | |
11 import dil.Declarations; | |
12 import dil.Statements; | |
13 import dil.Expressions; | |
14 import dil.Types; | |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
15 import dil.Enums; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
16 import dil.CompilerInfo; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
17 import dil.IdentsEnum; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
18 import dil.IdTable; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
19 import common; |
65 | 20 |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
21 /++ |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
22 The Parser produces an abstract syntax tree (AST) by analyzing |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
23 the tokens of the provided source code. |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
24 +/ |
65 | 25 class Parser |
26 { | |
71 | 27 Lexer lx; |
318 | 28 Token* token; /// Current non-whitespace token. |
29 Token* prevToken; /// Previous non-whitespace token. | |
71 | 30 |
31 Information[] errors; | |
32 | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
33 ImportDeclaration[] imports; /// ImportDeclarations in the source text. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
34 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
35 LinkageType linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
36 Protection protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
37 StorageClass storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
38 uint alignSize = DEFAULT_ALIGN_SIZE; |
364 | 39 |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
40 private alias TOK T; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
41 |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
42 this(char[] srcText, string filePath, InformationManager infoMan = null) |
71 | 43 { |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
44 lx = new Lexer(srcText, filePath); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
45 } |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
46 |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
47 protected void init() |
206 | 48 { |
49 nT(); | |
318 | 50 prevToken = token; |
206 | 51 } |
52 | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
53 void nT() |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
54 { |
318 | 55 prevToken = token; |
132 | 56 do |
57 { | |
58 lx.nextToken(); | |
239
7911f6a92e6e
- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents:
238
diff
changeset
|
59 token = lx.token; |
314
ebd21bbf296e
- Added Whitespace, Sheband and Hashline to enum TOK. TOK.Whitespace is a flag and tokens that are considered whitespace are flagged as such.
aziz
parents:
313
diff
changeset
|
60 } while (token.isWhitespace) // Skip whitespace |
71 | 61 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
62 |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
63 /++ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
64 Start the parser and return the parsed Declarations. |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
65 +/ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
66 Declarations start() |
102 | 67 { |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
68 init(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
69 auto begin = token; |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
70 auto decls = new Declarations; |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
71 if (token.type == T.Module) |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
72 decls ~= parseModuleDeclaration(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
73 decls.addOptChildren(parseDeclarationDefinitions()); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
74 set(decls, begin); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
75 return decls; |
102 | 76 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
77 |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
78 /++ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
79 Start the parser and return the parsed Expression. |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
80 +/ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
81 Expression start2() |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
82 { |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
83 init(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
84 return parseExpression(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
85 } |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
86 |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
87 uint trying; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
88 uint errorCount; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
89 |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
90 /++ |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
91 This method executes the delegate parseMethod and when an error occurred |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
92 the state of the lexer and parser are restored. |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
93 +/ |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
94 ReturnType try_(ReturnType)(ReturnType delegate() parseMethod, out bool success) |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
95 { |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
96 auto oldToken = this.token; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
97 auto oldPrevToken = this.prevToken; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
98 auto oldCount = this.errorCount; |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
99 |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
100 ++trying; |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
101 auto result = parseMethod(); |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
102 --trying; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
103 // Check if an error occurred. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
104 if (errorCount != oldCount) |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
105 { |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
106 // Restore members. |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
107 token = oldToken; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
108 prevToken = oldPrevToken; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
109 lx.token = oldToken; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
110 errorCount = oldCount; |
214 | 111 success = false; |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
112 } |
214 | 113 else |
114 success = true; | |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
115 return result; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
116 } |
105 | 117 |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
118 /++ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
119 Sets the begin and end tokens of an AST node. |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
120 +/ |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
121 Class set(Class)(Class node, Token* begin) |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
122 { |
318 | 123 node.setTokens(begin, this.prevToken); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
124 return node; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
125 } |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
126 |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
127 /++ |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
128 Returns true if set() has been called on a node. |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
129 +/ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
130 bool isNodeSet(Node node) |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
131 { |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
132 return node.begin !is null && node.end !is null; |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
133 } |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
134 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
135 TOK peekNext() |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
136 { |
239
7911f6a92e6e
- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents:
238
diff
changeset
|
137 Token* next = token; |
296 | 138 do |
139 lx.peek(next); | |
314
ebd21bbf296e
- Added Whitespace, Sheband and Hashline to enum TOK. TOK.Whitespace is a flag and tokens that are considered whitespace are flagged as such.
aziz
parents:
313
diff
changeset
|
140 while (next.isWhitespace) // Skip whitespace |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
141 return next.type; |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
142 } |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
143 |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
144 TOK peekAfter(ref Token* next) |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
145 { |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
146 assert(next !is null); |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
147 do |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
148 lx.peek(next); |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
149 while (next.isWhitespace) // Skip whitespace |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
150 return next.type; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
151 } |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
152 |
102 | 153 /++++++++++++++++++++++++++++++ |
154 + Declaration parsing methods + | |
155 ++++++++++++++++++++++++++++++/ | |
156 | |
368 | 157 Declaration parseModuleDeclaration() |
158 { | |
159 auto begin = token; | |
160 ModuleFQN moduleFQN; | |
161 do | |
162 { | |
163 nT(); | |
164 moduleFQN ~= requireId(); | |
165 } while (token.type == T.Dot) | |
166 require(T.Semicolon); | |
167 return set(new ModuleDeclaration(moduleFQN), begin); | |
168 } | |
169 | |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
170 /++ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
171 Parse DeclarationDefinitions until the end of file is hit. |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
172 DeclDefs: |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
173 DeclDef |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
174 DeclDefs |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
175 +/ |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
176 Declaration[] parseDeclarationDefinitions() |
102 | 177 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
178 Declaration[] decls; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
179 while (token.type != T.EOF) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
180 decls ~= parseDeclarationDefinition(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
181 return decls; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
182 } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
183 |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
184 /++ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
185 Parse the body of a template, class, interface, struct or union. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
186 DeclDefsBlock: |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
187 { } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
188 { DeclDefs } |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
189 +/ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
190 Declarations parseDeclarationDefinitionsBody() |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
191 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
192 // Save attributes. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
193 auto linkageType = this.linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
194 auto protection = this.protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
195 auto storageClass = this.storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
196 // Clear attributes. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
197 this.linkageType = LinkageType.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
198 this.protection = Protection.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
199 this.storageClass = StorageClass.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
200 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
201 // Parse body. |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
202 auto begin = token; |
305 | 203 auto decls = new Declarations; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
204 require(T.LBrace); |
122 | 205 while (token.type != T.RBrace && token.type != T.EOF) |
161 | 206 decls ~= parseDeclarationDefinition(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
207 require(T.RBrace); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
208 set(decls, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
209 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
210 // Restore original values. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
211 this.linkageType = linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
212 this.protection = protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
213 this.storageClass = storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
214 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
215 return decls; |
102 | 216 } |
217 | |
110 | 218 Declaration parseDeclarationDefinition() |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
219 out(decl) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
220 { assert(isNodeSet(decl)); } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
221 body |
102 | 222 { |
262 | 223 auto begin = token; |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
224 Declaration decl; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
225 switch (token.type) |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
226 { |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
227 case T.Align, |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
228 T.Pragma, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
229 // Protection attributes |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
230 T.Export, |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
231 T.Private, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
232 T.Package, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
233 T.Protected, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
234 T.Public: |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
235 decl = parseAttributeSpecifier(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
236 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
237 // Storage classes |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
238 case T.Extern, |
203
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
239 T.Deprecated, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
240 T.Override, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
241 T.Abstract, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
242 T.Synchronized, |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
243 //T.Static, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
244 T.Final, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
245 T.Const, |
269 | 246 //T.Invariant, // D 2.0 |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
247 T.Auto, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
248 T.Scope: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
249 case_StaticAttribute: |
269 | 250 case_InvariantAttribute: // D 2.0 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
251 return parseStorageAttribute(); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
252 case T.Alias: |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
253 nT(); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
254 // TODO: parse StorageClasses? |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
255 decl = new AliasDeclaration(parseVariableOrFunction()); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
256 break; |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
257 case T.Typedef: |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
258 nT(); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
259 // TODO: parse StorageClasses? |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
260 decl = new TypedefDeclaration(parseVariableOrFunction()); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
261 break; |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
262 case T.Static: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
263 switch (peekNext()) |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
264 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
265 case T.Import: |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
266 goto case_Import; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
267 case T.This: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
268 decl = parseStaticConstructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
269 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
270 case T.Tilde: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
271 decl = parseStaticDestructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
272 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
273 case T.If: |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
274 decl = parseStaticIfDeclaration(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
275 break; |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
276 case T.Assert: |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
277 decl = parseStaticAssertDeclaration(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
278 break; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
279 default: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
280 goto case_StaticAttribute; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
281 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
282 break; |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
283 case T.Import: |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
284 case_Import: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
285 decl = parseImportDeclaration(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
286 imports ~= CastTo!(ImportDeclaration)(decl); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
287 // Handle specially. StorageClass mustn't be set. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
288 decl.setProtection(this.protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
289 return set(decl, begin); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
290 case T.Enum: |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
291 decl = parseEnumDeclaration(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
292 break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
293 case T.Class: |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
294 decl = parseClassDeclaration(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
295 break; |
112 | 296 case T.Interface: |
297 decl = parseInterfaceDeclaration(); | |
298 break; | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
299 case T.Struct, T.Union: |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
300 decl = parseAggregateDeclaration(); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
301 break; |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
302 case T.This: |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
303 decl = parseConstructorDeclaration(); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
304 break; |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
305 case T.Tilde: |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
306 decl = parseDestructorDeclaration(); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
307 break; |
120 | 308 case T.Invariant: |
269 | 309 version(D2) |
310 { | |
311 auto next = token; | |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
312 if (peekAfter(next) == T.LParen) |
269 | 313 { |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
314 if (peekAfter(next) != T.RParen) |
269 | 315 goto case_Declaration; |
316 } | |
317 else | |
318 goto case_InvariantAttribute; | |
319 } | |
120 | 320 decl = parseInvariantDeclaration(); |
321 break; | |
121 | 322 case T.Unittest: |
323 decl = parseUnittestDeclaration(); | |
324 break; | |
122 | 325 case T.Debug: |
326 decl = parseDebugDeclaration(); | |
140 | 327 break; |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
328 case T.Version: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
329 decl = parseVersionDeclaration(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
330 break; |
140 | 331 case T.Template: |
332 decl = parseTemplateDeclaration(); | |
333 break; | |
141 | 334 case T.New: |
335 decl = parseNewDeclaration(); | |
336 break; | |
337 case T.Delete: | |
338 decl = parseDeleteDeclaration(); | |
339 break; | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
340 case T.Mixin: |
256 | 341 decl = parseMixin!(MixinDeclaration)(); |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
342 break; |
129 | 343 case T.Semicolon: |
344 nT(); | |
345 decl = new EmptyDeclaration(); | |
346 break; | |
192 | 347 // Declaration |
348 case T.Identifier, T.Dot, T.Typeof: | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
349 // IntegralType |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
350 case T.Char, T.Wchar, T.Dchar, T.Bool, |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
351 T.Byte, T.Ubyte, T.Short, T.Ushort, |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
352 T.Int, T.Uint, T.Long, T.Ulong, |
192 | 353 T.Float, T.Double, T.Real, |
354 T.Ifloat, T.Idouble, T.Ireal, | |
355 T.Cfloat, T.Cdouble, T.Creal, T.Void: | |
269 | 356 case_Declaration: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
357 return parseVariableOrFunction(this.storageClass, this.protection, this.linkageType); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
358 /+case T.Module: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
359 // TODO: Error: module is optional and can appear only once at the top of the source file. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
360 break;+/ |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
361 default: |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
362 decl = new IllegalDeclaration(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
363 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
364 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
365 nT(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
366 while (!token.isDeclDefStart && |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
367 token.type != T.RBrace && |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
368 token.type != T.EOF) |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
369 auto text = Token.textSpan(begin, this.prevToken); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
370 error(begin, "illegal Declaration found: " ~ text); |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
371 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
372 decl.setProtection(this.protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
373 decl.setStorageClass(this.storageClass); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
374 assert(!isNodeSet(decl)); |
262 | 375 set(decl, begin); |
129 | 376 return decl; |
102 | 377 } |
378 | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
379 /++ |
122 | 380 DeclarationsBlock: |
381 : DeclDefs | |
382 { } | |
383 { DeclDefs } | |
384 DeclDef | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
385 +/ |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
386 Declaration parseDeclarationsBlock(bool noColon = false) |
122 | 387 { |
305 | 388 Declaration d; |
122 | 389 switch (token.type) |
390 { | |
391 case T.LBrace: | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
392 nT(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
393 auto begin = token; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
394 auto decls = new Declarations; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
395 while (token.type != T.RBrace && token.type != T.EOF) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
396 decls ~= parseDeclarationDefinition(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
397 require(T.RBrace); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
398 d = set(decls, begin); |
122 | 399 break; |
400 case T.Colon: | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
401 if (noColon == true) |
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
402 goto default; |
122 | 403 nT(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
404 auto begin = token; |
305 | 405 auto decls = new Declarations; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
406 while (token.type != T.RBrace && token.type != T.EOF) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
407 decls ~= parseDeclarationDefinition(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
408 d = set(decls, begin); |
122 | 409 break; |
410 default: | |
305 | 411 d = parseDeclarationDefinition(); |
122 | 412 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
413 assert(isNodeSet(d)); |
305 | 414 return d; |
122 | 415 } |
416 | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
417 Declaration parseDeclarationsBlockNoColon() |
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
418 { |
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
419 return parseDeclarationsBlock(true); |
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
420 } |
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
421 |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
422 /++ |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
423 Parses either a VariableDeclaration or a FunctionDeclaration. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
424 Params: |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
425 stc = the previously parsed storage classes |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
426 optionalParameterList = a hint for how to parse C-style function pointers |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
427 +/ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
428 Declaration parseVariableOrFunction(StorageClass stc = StorageClass.None, |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
429 Protection protection = Protection.None, |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
430 LinkageType linkType = LinkageType.None, |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
431 bool testAutoDeclaration = false, |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
432 bool optionalParameterList = true) |
192 | 433 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
434 auto begin = token; |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
435 Type type; |
262 | 436 Token* ident; |
192 | 437 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
438 // Check for AutoDeclaration: StorageClasses Identifier = |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
439 if (testAutoDeclaration && |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
440 token.type == T.Identifier && |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
441 peekNext() == T.Assign) |
192 | 442 { |
262 | 443 ident = token; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
444 nT(); |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
445 } |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
446 else |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
447 { |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
448 type = parseType(); |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
449 if (token.type == T.LParen) |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
450 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
451 // C-style function pointers make the grammar ambiguous. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
452 // We have to treat them specially at function scope. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
453 // Example: |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
454 // void foo() { |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
455 // // A pointer to a function taking an integer and returning 'some_type'. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
456 // some_type (*p_func)(int); |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
457 // // In the following case precedence is given to a CallExpression. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
458 // something(*p); // 'something' may be a function/method or an object having opCall overloaded. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
459 // } |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
460 // // A pointer to a function taking no parameters and returning 'something'. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
461 // something(*p); |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
462 type = parseCFunctionPointerType(type, ident, optionalParameterList); |
415
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
463 } |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
464 else |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
465 { |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
466 ident = requireId(); |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
467 // Type FunctionName ( ParameterList ) FunctionBody |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
468 if (token.type == T.LParen) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
469 { |
415
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
470 // It's a function declaration |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
471 TemplateParameters tparams; |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
472 if (tokenAfterParenIs(T.LParen)) |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
473 { |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
474 // ( TemplateParameterList ) ( ParameterList ) |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
475 tparams = parseTemplateParameterList(); |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
476 } |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
477 |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
478 auto params = parseParameterList(); |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
479 version(D2) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
480 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
481 switch (token.type) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
482 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
483 case T.Const: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
484 stc |= StorageClass.Const; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
485 nT(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
486 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
487 case T.Invariant: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
488 stc |= StorageClass.Invariant; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
489 nT(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
490 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
491 default: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
492 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
493 } |
415
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
494 // ReturnType FunctionName ( ParameterList ) |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
495 auto funcBody = parseFunctionBody(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
496 auto d = new FunctionDeclaration(type, ident, tparams, params, funcBody); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
497 d.setStorageClass(stc); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
498 d.setLinkageType(linkType); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
499 d.setProtection(protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
500 return set(d, begin); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
501 } |
415
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
502 type = parseDeclaratorSuffix(type); |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
503 } |
192 | 504 } |
505 | |
506 // It's a variable declaration. | |
262 | 507 Token*[] idents = [ident]; |
194 | 508 Expression[] values; |
199
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
509 goto LenterLoop; // We've already parsed an identifier. Jump to if statement and check for initializer. |
194 | 510 while (token.type == T.Comma) |
511 { | |
222
4f31e4671e06
- Fix: nT() wasn't called in while loop to skip T.Comma.
aziz
parents:
220
diff
changeset
|
512 nT(); |
262 | 513 idents ~= requireId(); |
194 | 514 LenterLoop: |
515 if (token.type == T.Assign) | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
516 nT(), (values ~= parseInitializer()); |
199
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
517 else |
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
518 values ~= null; |
194 | 519 } |
520 require(T.Semicolon); | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
521 auto d = new VariableDeclaration(type, idents, values); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
522 d.setStorageClass(stc); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
523 d.setLinkageType(linkType); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
524 d.setProtection(protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
525 return set(d, begin); |
194 | 526 } |
192 | 527 |
194 | 528 Expression parseInitializer() |
529 { | |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
530 if (token.type == T.Void) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
531 { |
266 | 532 auto begin = token; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
533 auto next = peekNext(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
534 if (next == T.Comma || next == T.Semicolon) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
535 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
536 nT(); |
266 | 537 return set(new VoidInitializer(), begin); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
538 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
539 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
540 return parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
541 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
542 |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
543 Expression parseNonVoidInitializer() |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
544 { |
266 | 545 auto begin = token; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
546 Expression init; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
547 switch (token.type) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
548 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
549 case T.LBracket: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
550 // ArrayInitializer: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
551 // [ ] |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
552 // [ ArrayMemberInitializations ] |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
553 Expression[] keys; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
554 Expression[] values; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
555 |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
556 nT(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
557 while (token.type != T.RBracket) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
558 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
559 auto e = parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
560 if (token.type == T.Colon) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
561 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
562 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
563 keys ~= e; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
564 values ~= parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
565 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
566 else |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
567 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
568 keys ~= null; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
569 values ~= e; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
570 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
571 |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
572 if (token.type != T.Comma) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
573 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
574 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
575 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
576 require(T.RBracket); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
577 init = new ArrayInitializer(keys, values); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
578 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
579 case T.LBrace: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
580 // StructInitializer: |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
581 // { } |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
582 // { StructMemberInitializers } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
583 Expression parseStructInitializer() |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
584 { |
263 | 585 Token*[] idents; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
586 Expression[] values; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
587 |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
588 nT(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
589 while (token.type != T.RBrace) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
590 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
591 if (token.type == T.Identifier) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
592 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
593 // Peek for colon to see if this is a member identifier. |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
594 if (peekNext() == T.Colon) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
595 { |
263 | 596 idents ~= token; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
597 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
598 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
599 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
600 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
601 // NonVoidInitializer |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
602 values ~= parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
603 |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
604 if (token.type != T.Comma) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
605 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
606 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
607 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
608 require(T.RBrace); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
609 return new StructInitializer(idents, values); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
610 } |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
611 |
214 | 612 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
613 auto si = try_(&parseStructInitializer, success); |
214 | 614 if (success) |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
615 { |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
616 init = si; |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
617 break; |
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
618 } |
216 | 619 assert(token.type == T.LBrace); |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
620 //goto default; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
621 default: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
622 init = parseAssignExpression(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
623 } |
266 | 624 set(init, begin); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
625 return init; |
192 | 626 } |
627 | |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
628 FunctionBody parseFunctionBody() |
192 | 629 { |
268 | 630 auto begin = token; |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
631 auto func = new FunctionBody; |
192 | 632 while (1) |
633 { | |
634 switch (token.type) | |
635 { | |
636 case T.LBrace: | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
637 func.funcBody = parseStatements(); |
192 | 638 break; |
639 case T.Semicolon: | |
640 nT(); | |
641 break; | |
642 case T.In: | |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
643 if (func.inBody) |
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
644 error(MID.InContract); |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
645 nT(); |
192 | 646 func.inBody = parseStatements(); |
647 continue; | |
648 case T.Out: | |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
649 if (func.outBody) |
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
650 error(MID.OutContract); |
192 | 651 nT(); |
652 if (token.type == T.LParen) | |
653 { | |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
654 nT(); |
264 | 655 func.outIdent = requireId(); |
192 | 656 require(T.RParen); |
657 } | |
658 func.outBody = parseStatements(); | |
659 continue; | |
660 case T.Body: | |
661 nT(); | |
662 goto case T.LBrace; | |
663 default: | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
664 error(MID.ExpectedButFound, "FunctionBody", token.srcText); |
192 | 665 } |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
666 break; // Exit loop. |
192 | 667 } |
268 | 668 set(func, begin); |
299
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
298
diff
changeset
|
669 func.finishConstruction(); |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
670 return func; |
192 | 671 } |
672 | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
673 LinkageType parseLinkageType() |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
674 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
675 LinkageType linkageType; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
676 if (token.type != T.LParen) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
677 return linkageType; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
678 |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
679 nT(); // Skip ( |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
680 if (token.type == T.RParen) |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
681 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
682 nT(); |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
683 error(MID.MissingLinkageType); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
684 return linkageType; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
685 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
686 |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
687 auto identTok = requireId(); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
688 |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
689 ID identID = identTok ? identTok.ident.identID : ID.Null; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
690 |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
691 switch (identID) |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
692 { |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
693 case ID.C: |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
694 if (token.type == T.PlusPlus) |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
695 { |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
696 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
697 linkageType = LinkageType.Cpp; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
698 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
699 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
700 linkageType = LinkageType.C; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
701 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
702 case ID.D: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
703 linkageType = LinkageType.D; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
704 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
705 case ID.Windows: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
706 linkageType = LinkageType.Windows; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
707 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
708 case ID.Pascal: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
709 linkageType = LinkageType.Pascal; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
710 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
711 case ID.System: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
712 linkageType = LinkageType.System; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
713 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
714 default: |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
715 error(MID.UnrecognizedLinkageType, token.srcText); |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
716 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
717 require(T.RParen); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
718 return linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
719 } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
720 |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
721 void checkLinkageType(ref LinkageType prev_lt, LinkageType lt, Token* begin) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
722 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
723 if (prev_lt == LinkageType.None) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
724 prev_lt = lt; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
725 else |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
726 // TODO: create new msg RedundantLinkageType. |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
727 error(begin, "redundant linkage type: " ~ Token.textSpan(begin, this.prevToken)); |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
728 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
729 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
730 Declaration parseStorageAttribute() |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
731 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
732 StorageClass stc, stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
733 LinkageType prev_linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
734 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
735 auto saved_storageClass = this.storageClass; // Save. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
736 // Nested function. |
305 | 737 Declaration parse() |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
738 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
739 Declaration decl; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
740 auto begin = token; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
741 switch (token.type) |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
742 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
743 case T.Extern: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
744 if (peekNext() != T.LParen) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
745 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
746 stc_tmp = StorageClass.Extern; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
747 goto Lcommon; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
748 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
749 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
750 nT(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
751 auto linkageType = parseLinkageType(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
752 checkLinkageType(prev_linkageType, linkageType, begin); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
753 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
754 auto saved = this.linkageType; // Save. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
755 this.linkageType = linkageType; // Set. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
756 decl = new LinkageDeclaration(linkageType, parse()); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
757 set(decl, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
758 this.linkageType = saved; // Restore. |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
759 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
760 case T.Override: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
761 stc_tmp = StorageClass.Override; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
762 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
763 case T.Deprecated: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
764 stc_tmp = StorageClass.Deprecated; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
765 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
766 case T.Abstract: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
767 stc_tmp = StorageClass.Abstract; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
768 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
769 case T.Synchronized: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
770 stc_tmp = StorageClass.Synchronized; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
771 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
772 case T.Static: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
773 stc_tmp = StorageClass.Static; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
774 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
775 case T.Final: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
776 stc_tmp = StorageClass.Final; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
777 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
778 case T.Const: |
269 | 779 version(D2) |
780 { | |
781 if (peekNext() == T.LParen) | |
782 goto case_Declaration; | |
783 } | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
784 stc_tmp = StorageClass.Const; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
785 goto Lcommon; |
269 | 786 version(D2) |
787 { | |
788 case T.Invariant: // D 2.0 | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
789 auto next = token; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
790 if (peekAfter(next) == T.LParen) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
791 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
792 if (peekAfter(next) != T.RParen) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
793 goto case_Declaration; // invariant ( Type ) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
794 decl = parseDeclarationDefinition(); // invariant ( ) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
795 decl.setStorageClass(stc); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
796 break; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
797 } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
798 // invariant as StorageClass. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
799 stc_tmp = StorageClass.Invariant; |
269 | 800 goto Lcommon; |
801 } | |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
802 case T.Auto: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
803 stc_tmp = StorageClass.Auto; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
804 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
805 case T.Scope: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
806 stc_tmp = StorageClass.Scope; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
807 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
808 Lcommon: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
809 // Issue error if redundant. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
810 if (stc & stc_tmp) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
811 error(MID.RedundantStorageClass, token.srcText); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
812 else |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
813 stc |= stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
814 |
269 | 815 auto tok = token.type; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
816 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
817 decl = new StorageClassDeclaration(stc_tmp, tok, parse()); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
818 set(decl, begin); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
819 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
820 case T.Identifier: |
269 | 821 case_Declaration: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
822 // This could be a normal Declaration or an AutoDeclaration |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
823 decl = parseVariableOrFunction(stc, this.protection, prev_linkageType, true); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
824 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
825 default: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
826 this.storageClass = stc; // Set. |
305 | 827 decl = parseDeclarationsBlock(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
828 this.storageClass = saved_storageClass; // Reset. |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
829 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
830 assert(isNodeSet(decl)); |
305 | 831 return decl; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
832 } |
305 | 833 return parse(); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
834 } |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
835 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
836 uint parseAlignAttribute() |
260 | 837 { |
838 assert(token.type == T.Align); | |
839 nT(); // Skip align keyword. | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
840 uint size = DEFAULT_ALIGN_SIZE; // Global default. |
260 | 841 if (token.type == T.LParen) |
842 { | |
843 nT(); | |
844 if (token.type == T.Int32) | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
845 (size = token.int_), nT(); |
260 | 846 else |
847 expected(T.Int32); | |
848 require(T.RParen); | |
849 } | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
850 return size; |
260 | 851 } |
852 | |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
853 Declaration parseAttributeSpecifier() |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
854 { |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
855 Declaration decl; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
856 |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
857 switch (token.type) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
858 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
859 case T.Align: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
860 uint alignSize = parseAlignAttribute(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
861 auto saved = this.alignSize; // Save. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
862 this.alignSize = alignSize; // Set. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
863 decl = new AlignDeclaration(alignSize, parseDeclarationsBlock()); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
864 this.alignSize = saved; // Restore. |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
865 break; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
866 case T.Pragma: |
147 | 867 // Pragma: |
868 // pragma ( Identifier ) | |
869 // pragma ( Identifier , ExpressionList ) | |
870 nT(); | |
245 | 871 Token* ident; |
147 | 872 Expression[] args; |
305 | 873 Declaration decls; |
147 | 874 |
875 require(T.LParen); | |
245 | 876 ident = requireId(); |
147 | 877 |
878 if (token.type == T.Comma) | |
244
829fdb2e2915
- Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents:
243
diff
changeset
|
879 { |
829fdb2e2915
- Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents:
243
diff
changeset
|
880 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
881 args = parseExpressionList(); |
244
829fdb2e2915
- Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents:
243
diff
changeset
|
882 } |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
883 require(T.RParen); |
147 | 884 |
885 if (token.type == T.Semicolon) | |
313
1c1adededd8f
- Fix: assign new EmptyDeclaration to decls when parsing PragmaStatement.
aziz
parents:
312
diff
changeset
|
886 { |
147 | 887 nT(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
888 // TODO: call set()? |
313
1c1adededd8f
- Fix: assign new EmptyDeclaration to decls when parsing PragmaStatement.
aziz
parents:
312
diff
changeset
|
889 decls = new EmptyDeclaration(); |
1c1adededd8f
- Fix: assign new EmptyDeclaration to decls when parsing PragmaStatement.
aziz
parents:
312
diff
changeset
|
890 } |
147 | 891 else |
892 decls = parseDeclarationsBlock(); | |
893 | |
894 decl = new PragmaDeclaration(ident, args, decls); | |
895 break; | |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
896 default: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
897 // Protection attributes |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
898 Protection prot; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
899 switch (token.type) |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
900 { |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
901 case T.Private: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
902 prot = Protection.Private; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
903 case T.Package: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
904 prot = Protection.Package; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
905 case T.Protected: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
906 prot = Protection.Protected; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
907 case T.Public: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
908 prot = Protection.Public; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
909 case T.Export: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
910 prot = Protection.Export; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
911 default: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
912 assert(0); |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
913 } |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
914 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
915 auto saved = this.protection; // Save. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
916 this.protection = prot; // Set. |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
917 decl = new ProtectionDeclaration(prot, parseDeclarationsBlock()); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
918 this.protection = saved; // Restore. |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
919 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
920 return decl; |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
921 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
922 |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
923 Declaration parseImportDeclaration() |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
924 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
925 assert(token.type == T.Import || token.type == T.Static); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
926 |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
927 bool isStatic; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
928 |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
929 if (token.type == T.Static) |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
930 { |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
931 isStatic = true; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
932 nT(); |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
933 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
934 |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
935 assert(token.type == T.Import); |
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
936 |
364 | 937 ModuleFQN[] moduleFQNs; |
263 | 938 Token*[] moduleAliases; |
939 Token*[] bindNames; | |
940 Token*[] bindAliases; | |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
941 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
942 nT(); // Skip import keyword. |
298 | 943 while (1) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
944 { |
364 | 945 ModuleFQN moduleFQN; |
263 | 946 Token* moduleAlias; |
947 | |
948 moduleAlias = requireId(); | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
949 |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
950 // AliasName = ModuleName |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
951 if (token.type == T.Assign) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
952 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
953 nT(); |
364 | 954 moduleFQN ~= requireId(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
955 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
956 else // import Identifier [^=] |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
957 { |
364 | 958 moduleFQN ~= moduleAlias; |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
959 moduleAlias = null; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
960 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
961 |
298 | 962 // Identifier(.Identifier)* |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
963 while (token.type == T.Dot) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
964 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
965 nT(); |
364 | 966 moduleFQN ~= requireId(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
967 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
968 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
969 // Push identifiers. |
364 | 970 moduleFQNs ~= moduleFQN; |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
971 moduleAliases ~= moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
972 |
298 | 973 if (token.type != T.Comma) |
974 break; | |
975 nT(); | |
976 } | |
977 | |
978 if (token.type == T.Colon) | |
979 { | |
980 // BindAlias = BindName(, BindAlias = BindName)*; | |
981 // BindName(, BindName)*; | |
982 Token* bindName, bindAlias; | |
320
0ce14640eb04
- Fix in parseImportDeclaration(): rewrote while loop and removed a call to nT().
aziz
parents:
319
diff
changeset
|
983 do |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
984 { |
298 | 985 nT(); |
986 bindAlias = requireId(); | |
987 | |
988 if (token.type == T.Assign) | |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
989 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
990 nT(); |
298 | 991 bindName = requireId(); |
992 } | |
993 else | |
994 { | |
995 bindName = bindAlias; | |
996 bindAlias = null; | |
997 } | |
998 | |
999 // Push identifiers. | |
1000 bindNames ~= bindName; | |
1001 bindAliases ~= bindAlias; | |
320
0ce14640eb04
- Fix in parseImportDeclaration(): rewrote while loop and removed a call to nT().
aziz
parents:
319
diff
changeset
|
1002 } while (token.type == T.Comma) |
298 | 1003 } |
1004 | |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
1005 require(T.Semicolon); |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
1006 |
366 | 1007 return new ImportDeclaration(moduleFQNs, moduleAliases, bindNames, bindAliases, isStatic); |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
1008 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
1009 |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1010 Declaration parseEnumDeclaration() |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1011 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1012 assert(token.type == T.Enum); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1013 |
264 | 1014 Token* enumName; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1015 Type baseType; |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1016 EnumMember[] members; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
1017 bool hasBody; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1018 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1019 nT(); // Skip enum keyword. |
231 | 1020 |
1021 if (token.type == T.Identifier) | |
1022 { | |
264 | 1023 enumName = token; |
231 | 1024 nT(); |
1025 } | |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1026 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1027 if (token.type == T.Colon) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1028 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1029 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1030 baseType = parseBasicType(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1031 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1032 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1033 if (token.type == T.Semicolon) |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1034 { |
264 | 1035 if (enumName is null) |
231 | 1036 expected(T.Identifier); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1037 nT(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1038 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1039 else if (token.type == T.LBrace) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1040 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
1041 hasBody = true; |
398
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1042 nT(); // Skip { |
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1043 while (token.type != T.RBrace) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1044 { |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1045 auto begin = token; |
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1046 auto memberName = requireId(); |
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1047 Expression value; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1048 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1049 if (token.type == T.Assign) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1050 { |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1051 nT(); |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1052 value = parseAssignExpression(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1053 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1054 else |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1055 value = null; |
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1056 |
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1057 members ~= set(new EnumMember(memberName, value), begin); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1058 |
398
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1059 if (token.type != T.Comma) |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1060 break; |
398
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1061 nT(); // Skip , |
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1062 } |
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1063 require(T.RBrace); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1064 } |
231 | 1065 else |
1066 error(MID.ExpectedButFound, "enum declaration", token.srcText); | |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1067 |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1068 return new EnumDeclaration(enumName, baseType, members, hasBody); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1069 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1070 |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1071 Declaration parseClassDeclaration() |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1072 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1073 assert(token.type == T.Class); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1074 |
264 | 1075 Token* className; |
258 | 1076 TemplateParameters tparams; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1077 BaseClass[] bases; |
305 | 1078 Declarations decls; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1079 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1080 nT(); // Skip class keyword. |
264 | 1081 className = requireId(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1082 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1083 if (token.type == T.LParen) |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
1084 tparams = parseTemplateParameterList(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1085 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1086 if (token.type == T.Colon) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1087 bases = parseBaseClasses(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1088 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1089 if (token.type == T.Semicolon) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1090 { |
405
e2529923a0cb
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
404
diff
changeset
|
1091 if (bases.length != 0) |
e2529923a0cb
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
404
diff
changeset
|
1092 error(MID.BaseClassInForwardDeclaration); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1093 nT(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1094 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1095 else if (token.type == T.LBrace) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1096 decls = parseDeclarationDefinitionsBody(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1097 else |
124 | 1098 expected(T.LBrace); // TODO: better error msg |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1099 |
494
9a7ca8c56e59
Refactored a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
493
diff
changeset
|
1100 return new ClassDeclaration(className, tparams, bases, decls); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1101 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1102 |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1103 BaseClass[] parseBaseClasses(bool colonLeadsOff = true) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1104 { |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1105 if (colonLeadsOff) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1106 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1107 assert(token.type == T.Colon); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1108 nT(); // Skip colon |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1109 } |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1110 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1111 BaseClass[] bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1112 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1113 while (1) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1114 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1115 Protection prot = Protection.Public; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1116 switch (token.type) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1117 { |
204 | 1118 case T.Identifier, T.Dot, T.Typeof: goto LparseBasicType; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1119 case T.Private: prot = Protection.Private; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1120 case T.Protected: prot = Protection.Protected; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1121 case T.Package: prot = Protection.Package; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1122 case T.Public: /*prot = Protection.Public;*/ break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1123 default: |
405
e2529923a0cb
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
404
diff
changeset
|
1124 error(MID.ExpectedBaseClasses, token.srcText); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1125 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1126 } |
158
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1127 nT(); // Skip protection attribute. |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1128 LparseBasicType: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1129 auto begin = token; |
158
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1130 auto type = parseBasicType(); |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1131 //if (type.tid != TID.DotList) |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1132 // TODO: issue error msg. base classes can only be one or more identifiers or template instances separated by dots. |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1133 bases ~= set(new BaseClass(prot, type), begin); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1134 if (token.type != T.Comma) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1135 break; |
396
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
1136 nT(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1137 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1138 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1139 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1140 |
112 | 1141 Declaration parseInterfaceDeclaration() |
1142 { | |
1143 assert(token.type == T.Interface); | |
1144 | |
264 | 1145 Token* name; |
258 | 1146 TemplateParameters tparams; |
112 | 1147 BaseClass[] bases; |
305 | 1148 Declarations decls; |
112 | 1149 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1150 nT(); // Skip interface keyword. |
264 | 1151 name = requireId(); |
112 | 1152 |
1153 if (token.type == T.LParen) | |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
1154 tparams = parseTemplateParameterList(); |
112 | 1155 |
1156 if (token.type == T.Colon) | |
1157 bases = parseBaseClasses(); | |
1158 | |
1159 if (token.type == T.Semicolon) | |
1160 { | |
405
e2529923a0cb
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
404
diff
changeset
|
1161 if (bases.length != 0) |
e2529923a0cb
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
404
diff
changeset
|
1162 error(MID.BaseClassInForwardDeclaration); |
112 | 1163 nT(); |
1164 } | |
1165 else if (token.type == T.LBrace) | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1166 decls = parseDeclarationDefinitionsBody(); |
112 | 1167 else |
124 | 1168 expected(T.LBrace); // TODO: better error msg |
112 | 1169 |
494
9a7ca8c56e59
Refactored a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
493
diff
changeset
|
1170 return new InterfaceDeclaration(name, tparams, bases, decls); |
112 | 1171 } |
1172 | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1173 Declaration parseAggregateDeclaration() |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1174 { |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1175 assert(token.type == T.Struct || token.type == T.Union); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1176 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1177 TOK tok = token.type; |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1178 |
264 | 1179 Token* name; |
258 | 1180 TemplateParameters tparams; |
305 | 1181 Declarations decls; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1182 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1183 nT(); // Skip struct or union keyword. |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1184 // name is optional. |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1185 if (token.type == T.Identifier) |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1186 { |
264 | 1187 name = token; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1188 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1189 if (token.type == T.LParen) |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
1190 tparams = parseTemplateParameterList(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1191 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1192 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1193 if (token.type == T.Semicolon) |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1194 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1195 //if (name.length == 0) |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1196 // TODO: error: forward declarations must have a name. |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1197 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1198 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1199 else if (token.type == T.LBrace) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1200 decls = parseDeclarationDefinitionsBody(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1201 else |
124 | 1202 expected(T.LBrace); // TODO: better error msg |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1203 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1204 if (tok == T.Struct) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1205 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1206 auto d = new StructDeclaration(name, tparams, decls); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1207 d.setAlignSize(this.alignSize); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1208 return d; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1209 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1210 else |
494
9a7ca8c56e59
Refactored a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
493
diff
changeset
|
1211 return new UnionDeclaration(name, tparams, decls); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1212 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1213 |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1214 Declaration parseConstructorDeclaration() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1215 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1216 assert(token.type == T.This); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1217 nT(); // Skip 'this' keyword. |
143 | 1218 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1219 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1220 return new ConstructorDeclaration(parameters, funcBody); |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1221 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1222 |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1223 Declaration parseDestructorDeclaration() |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1224 { |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1225 assert(token.type == T.Tilde); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1226 nT(); // Skip ~ |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1227 require(T.This); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1228 require(T.LParen); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1229 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1230 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1231 return new DestructorDeclaration(funcBody); |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1232 } |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1233 |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1234 Declaration parseStaticConstructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1235 { |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1236 assert(token.type == T.Static); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1237 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1238 nT(); // Skip 'this' keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1239 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1240 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1241 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1242 return new StaticConstructorDeclaration(funcBody); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1243 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1244 |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1245 Declaration parseStaticDestructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1246 { |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1247 assert(token.type == T.Static); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1248 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1249 nT(); // Skip ~ |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1250 require(T.This); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1251 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1252 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1253 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1254 return new StaticDestructorDeclaration(funcBody); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1255 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1256 |
120 | 1257 Declaration parseInvariantDeclaration() |
1258 { | |
1259 assert(token.type == T.Invariant); | |
1260 nT(); // Skip invariant keyword. | |
1261 // Optional () for getting ready porting to D 2.0 | |
1262 if (token.type == T.LParen) | |
122 | 1263 requireNext(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1264 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1265 return new InvariantDeclaration(funcBody); |
120 | 1266 } |
1267 | |
121 | 1268 Declaration parseUnittestDeclaration() |
1269 { | |
1270 assert(token.type == T.Unittest); | |
1271 | |
122 | 1272 nT(); // Skip unittest keyword. |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1273 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1274 return new UnittestDeclaration(funcBody); |
121 | 1275 } |
1276 | |
122 | 1277 Declaration parseDebugDeclaration() |
1278 { | |
1279 assert(token.type == T.Debug); | |
1280 | |
1281 nT(); // Skip debug keyword. | |
1282 | |
264 | 1283 Token* spec; // debug = Integer ; |
1284 // debug = Identifier ; | |
1285 Token* cond; // debug ( Integer ) | |
1286 // debug ( Identifier ) | |
305 | 1287 Declaration decls, elseDecls; |
122 | 1288 |
264 | 1289 void parseIdentOrInt(ref Token* tok) |
122 | 1290 { |
1291 nT(); | |
264 | 1292 if (token.type == T.Int32 || |
1293 token.type == T.Identifier) | |
1294 { | |
1295 tok = token; | |
1296 nT(); | |
1297 } | |
122 | 1298 else |
124 | 1299 expected(T.Identifier); // TODO: better error msg |
123 | 1300 } |
1301 | |
1302 if (token.type == T.Assign) | |
1303 { | |
264 | 1304 parseIdentOrInt(spec); |
122 | 1305 require(T.Semicolon); |
1306 } | |
1307 else | |
1308 { | |
123 | 1309 // Condition: |
1310 // Integer | |
1311 // Identifier | |
1312 // ( Condition ) | |
122 | 1313 if (token.type == T.LParen) |
1314 { | |
264 | 1315 parseIdentOrInt(cond); |
122 | 1316 require(T.RParen); |
1317 } | |
1318 | |
123 | 1319 // debug DeclarationsBlock |
1320 // debug ( Condition ) DeclarationsBlock | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1321 decls = parseDeclarationsBlockNoColon(); |
123 | 1322 |
1323 // else DeclarationsBlock | |
264 | 1324 if (token.type == T.Else) |
122 | 1325 { |
123 | 1326 nT(); |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1327 elseDecls = parseDeclarationsBlockNoColon(); |
123 | 1328 } |
1329 } | |
1330 | |
264 | 1331 return new DebugDeclaration(spec, cond, decls, elseDecls); |
123 | 1332 } |
1333 | |
1334 Declaration parseVersionDeclaration() | |
1335 { | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
1336 assert(token.type == T.Version); |
123 | 1337 |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
1338 nT(); // Skip version keyword. |
123 | 1339 |
264 | 1340 Token* spec; // version = Integer ; |
1341 // version = Identifier ; | |
1342 Token* cond; // version ( Integer ) | |
1343 // version ( Identifier ) | |
305 | 1344 Declaration decls, elseDecls; |
122 | 1345 |
264 | 1346 void parseIdentOrInt(ref Token* tok) |
123 | 1347 { |
264 | 1348 if (token.type == T.Int32 || |
1349 token.type == T.Identifier) | |
1350 { | |
1351 tok = token; | |
1352 nT(); | |
1353 } | |
123 | 1354 else |
124 | 1355 expected(T.Identifier); // TODO: better error msg |
123 | 1356 } |
1357 | |
1358 if (token.type == T.Assign) | |
1359 { | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1360 nT(); |
264 | 1361 parseIdentOrInt(spec); |
123 | 1362 require(T.Semicolon); |
1363 } | |
1364 else | |
1365 { | |
1366 // Condition: | |
1367 // Integer | |
1368 // Identifier | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
1369 |
123 | 1370 // ( Condition ) |
1371 require(T.LParen); | |
264 | 1372 parseIdentOrInt(cond); |
123 | 1373 require(T.RParen); |
1374 | |
1375 // version ( Condition ) DeclarationsBlock | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1376 decls = parseDeclarationsBlockNoColon(); |
123 | 1377 |
1378 // else DeclarationsBlock | |
1379 if (token.type == T.Else) | |
1380 { | |
1381 nT(); | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1382 elseDecls = parseDeclarationsBlockNoColon(); |
122 | 1383 } |
1384 } | |
1385 | |
264 | 1386 return new VersionDeclaration(spec, cond, decls, elseDecls); |
122 | 1387 } |
1388 | |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1389 Declaration parseStaticIfDeclaration() |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1390 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1391 assert(token.type == T.Static); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1392 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1393 nT(); // Skip static keyword. |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1394 nT(); // Skip if keyword. |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1395 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1396 Expression condition; |
305 | 1397 Declaration ifDecls, elseDecls; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1398 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1399 require(T.LParen); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1400 condition = parseAssignExpression(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1401 require(T.RParen); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1402 |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1403 ifDecls = parseDeclarationsBlockNoColon(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1404 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1405 if (token.type == T.Else) |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1406 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1407 nT(); |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1408 elseDecls = parseDeclarationsBlockNoColon(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1409 } |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1410 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1411 return new StaticIfDeclaration(condition, ifDecls, elseDecls); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1412 } |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1413 |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1414 Declaration parseStaticAssertDeclaration() |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1415 { |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1416 assert(token.type == T.Static); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1417 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1418 nT(); // Skip static keyword. |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1419 nT(); // Skip assert keyword. |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1420 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1421 Expression condition, message; |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1422 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1423 require(T.LParen); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1424 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1425 condition = parseAssignExpression(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1426 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1427 if (token.type == T.Comma) |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1428 { |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1429 nT(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1430 message = parseAssignExpression(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1431 } |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1432 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1433 require(T.RParen); |
128 | 1434 require(T.Semicolon); |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1435 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1436 return new StaticAssertDeclaration(condition, message); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1437 } |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1438 |
140 | 1439 Declaration parseTemplateDeclaration() |
1440 { | |
1441 assert(token.type == T.Template); | |
1442 nT(); // Skip template keyword. | |
265 | 1443 auto templateName = requireId(); |
143 | 1444 auto templateParams = parseTemplateParameterList(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1445 auto decls = parseDeclarationDefinitionsBody(); |
140 | 1446 return new TemplateDeclaration(templateName, templateParams, decls); |
1447 } | |
1448 | |
141 | 1449 Declaration parseNewDeclaration() |
1450 { | |
1451 assert(token.type == T.New); | |
1452 nT(); // Skip new keyword. | |
143 | 1453 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1454 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1455 return new NewDeclaration(parameters, funcBody); |
141 | 1456 } |
1457 | |
1458 Declaration parseDeleteDeclaration() | |
1459 { | |
1460 assert(token.type == T.Delete); | |
1461 nT(); // Skip delete keyword. | |
143 | 1462 auto parameters = parseParameterList(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1463 // TODO: only one parameter of type void* allowed. Check in parsing or semantic phase? |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1464 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1465 return new DeleteDeclaration(parameters, funcBody); |
141 | 1466 } |
1467 | |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1468 Type parseTypeofType() |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1469 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1470 assert(token.type == T.Typeof); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1471 Type type; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1472 requireNext(T.LParen); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1473 switch (token.type) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1474 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1475 version(D2) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1476 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1477 case T.Return: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1478 nT(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1479 type = new TypeofType(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1480 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1481 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1482 default: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1483 type = new TypeofType(parseExpression()); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1484 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1485 require(T.RParen); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1486 return type; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1487 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1488 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1489 /+ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1490 DotListExpression: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1491 . DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1492 DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1493 Typeof |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1494 Typeof . DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1495 DotListItems: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1496 DotListItem |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1497 DotListItem . DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1498 DotListItem: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1499 Identifier |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1500 TemplateInstance |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1501 NewExpression |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1502 TemplateInstance: |
233 | 1503 Identifier !( TemplateArguments ) |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1504 +/ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1505 DotListExpression parseDotListExpression() |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1506 { |
233 | 1507 assert(token.type == T.Identifier || token.type == T.Dot || token.type == T.Typeof); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1508 auto begin = token; |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1509 Expression[] identList; |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1510 if (token.type == T.Dot) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1511 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1512 nT(); |
488
cfb3805768b6
Added DotExpression and DotType.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
486
diff
changeset
|
1513 identList ~= set(new DotExpression(), begin); |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1514 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1515 else if (token.type == T.Typeof) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1516 { |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1517 auto type = parseTypeofType(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1518 set(type, begin); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1519 identList ~= set(new TypeofExpression(type), begin); |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1520 if (token.type != T.Dot) |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1521 goto Lreturn; |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1522 nT(); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1523 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1524 |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1525 while (1) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1526 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1527 begin = token; |
252
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1528 auto ident = requireId(); |
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1529 Expression e; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1530 if (token.type == T.Not && peekNext() == T.LParen) // Identifier !( TemplateArguments ) |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1531 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1532 nT(); // Skip !. |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1533 e = set(new TemplateInstanceExpression(ident, parseTemplateArguments()), begin); |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1534 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1535 else // Identifier |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1536 e = set(new IdentifierExpression(ident), begin); |
252
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1537 |
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1538 identList ~= e; |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1539 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1540 LnewExpressionLoop: |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1541 if (token.type != T.Dot) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1542 break; |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1543 nT(); // Skip dot. |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1544 |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1545 if (token.type == T.New) |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1546 { |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1547 identList ~= parseNewExpression(); |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1548 goto LnewExpressionLoop; |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1549 } |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1550 } |
233 | 1551 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1552 Lreturn: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1553 return new DotListExpression(identList); |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1554 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1555 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1556 /+ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1557 DotListType: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1558 . TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1559 TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1560 Typeof |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1561 Typeof . TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1562 TypeItems: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1563 TypeItem |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1564 TypeItem . TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1565 TypeItem: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1566 Identifier |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1567 TemplateInstance |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1568 TemplateInstance: |
233 | 1569 Identifier !( TemplateArguments ) |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1570 +/ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1571 DotListType parseDotListType() |
153 | 1572 { |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1573 auto begin = token; |
153 | 1574 Type[] identList; |
1575 if (token.type == T.Dot) | |
1576 { | |
1577 nT(); | |
488
cfb3805768b6
Added DotExpression and DotType.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
486
diff
changeset
|
1578 identList ~= set(new DotType(), begin); |
153 | 1579 } |
1580 else if (token.type == T.Typeof) | |
1581 { | |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1582 identList ~= set(parseTypeofType(), begin); |
153 | 1583 if (token.type != T.Dot) |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1584 goto Lreturn; |
153 | 1585 nT(); |
1586 } | |
1587 | |
1588 while (1) | |
1589 { | |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1590 begin = token; |
264 | 1591 auto ident = requireId(); |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1592 // NB.: Currently Types can't be followed by "!=" so we don't need to peek for "(" when parsing TemplateInstances. |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1593 if (token.type == T.Not/+ && peekNext() == T.LParen+/) // Identifier !( TemplateArguments ) |
153 | 1594 { |
1595 nT(); // Skip !. | |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1596 identList ~= set(new TemplateInstanceType(ident, parseTemplateArguments()), begin); |
153 | 1597 } |
1598 else // Identifier | |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1599 identList ~= set(new IdentifierType(ident), begin); |
153 | 1600 |
1601 if (token.type != T.Dot) | |
1602 break; | |
1603 nT(); | |
1604 } | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1605 Lreturn: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1606 return new DotListType(identList); |
153 | 1607 } |
1608 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1609 /* |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1610 TemplateMixin: |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1611 mixin ( AssignExpression ) ; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1612 mixin TemplateIdentifier ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1613 mixin TemplateIdentifier MixinIdentifier ; |
233 | 1614 mixin TemplateIdentifier !( TemplateArguments ) ; |
1615 mixin TemplateIdentifier !( TemplateArguments ) MixinIdentifier ; | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1616 */ |
256 | 1617 Class parseMixin(Class)() |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1618 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1619 assert(token.type == T.Mixin); |
256 | 1620 auto begin = token; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1621 nT(); // Skip mixin keyword. |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1622 |
256 | 1623 static if (is(Class == MixinDeclaration)) |
301
caef255a2801
- Fix in some ctors: adding only non-null members to this.children.
aziz
parents:
299
diff
changeset
|
1624 { |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1625 if (token.type == T.LParen) |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1626 { |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1627 // TODO: What about mixin(...).ident;? |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1628 nT(); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1629 auto e = parseAssignExpression(); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1630 require(T.RParen); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1631 require(T.Semicolon); |
262 | 1632 return new MixinDeclaration(e); |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1633 } |
301
caef255a2801
- Fix in some ctors: adding only non-null members to this.children.
aziz
parents:
299
diff
changeset
|
1634 } |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1635 |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1636 Expression[] templateIdent; |
252
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1637 Token* mixinIdent; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1638 |
159 | 1639 // This code is similar to parseDotListType(). |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1640 if (token.type == T.Dot) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1641 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1642 nT(); |
488
cfb3805768b6
Added DotExpression and DotType.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
486
diff
changeset
|
1643 templateIdent ~= set(new DotExpression(), begin); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1644 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1645 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1646 while (1) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1647 { |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1648 begin = token; |
252
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1649 auto ident = requireId(); |
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1650 Expression e; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1651 if (token.type == T.Not) // Identifier !( TemplateArguments ) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1652 { |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1653 // No need to peek for T.LParen. This must be a template instance. |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1654 nT(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1655 e = set(new TemplateInstanceExpression(ident, parseTemplateArguments()), begin); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1656 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1657 else // Identifier |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1658 e = set(new IdentifierExpression(ident), begin); |
252
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1659 |
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1660 templateIdent ~= e; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1661 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1662 if (token.type != T.Dot) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1663 break; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1664 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1665 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1666 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1667 if (token.type == T.Identifier) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1668 { |
252
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1669 mixinIdent = token; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1670 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1671 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1672 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1673 require(T.Semicolon); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1674 |
262 | 1675 return new Class(templateIdent, mixinIdent); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1676 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1677 |
102 | 1678 /+++++++++++++++++++++++++++++ |
161 | 1679 + Statement parsing methods + |
1680 +++++++++++++++++++++++++++++/ | |
1681 | |
1682 Statements parseStatements() | |
1683 { | |
262 | 1684 auto begin = token; |
318 | 1685 require(T.LBrace); |
162 | 1686 auto statements = new Statements(); |
161 | 1687 while (token.type != T.RBrace && token.type != T.EOF) |
1688 statements ~= parseStatement(); | |
318 | 1689 require(T.RBrace); |
262 | 1690 return set(statements, begin); |
161 | 1691 } |
1692 | |
1693 Statement parseStatement() | |
1694 { | |
261 | 1695 auto begin = token; |
161 | 1696 Statement s; |
188 | 1697 Declaration d; |
161 | 1698 switch (token.type) |
1699 { | |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1700 case T.Align: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1701 uint size = parseAlignAttribute(); |
260 | 1702 // Restrict align attribute to structs in parsing phase. |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1703 StructDeclaration structDecl; |
260 | 1704 if (token.type == T.Struct) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1705 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1706 auto begin2 = token; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1707 structDecl = CastTo!(StructDeclaration)(parseAggregateDeclaration()); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1708 structDecl.setAlignSize(size); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1709 set(structDecl, begin2); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1710 } |
260 | 1711 else |
1712 expected(T.Struct); | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1713 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1714 d = new AlignDeclaration(size, structDecl ? cast(Declaration)structDecl : new Declarations); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1715 goto LreturnDeclarationStatement; |
201 | 1716 /+ Not applicable for statements. |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1717 // T.Private, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1718 // T.Package, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1719 // T.Protected, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1720 // T.Public, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1721 // T.Export, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1722 // T.Deprecated, |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1723 // T.Override, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1724 // T.Abstract, |
201 | 1725 +/ |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1726 case T.Extern, |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1727 T.Final, |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1728 T.Const, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1729 T.Auto: |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1730 //T.Scope |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1731 //T.Static |
201 | 1732 case_parseAttribute: |
1733 s = parseAttributeStatement(); | |
261 | 1734 return s; |
161 | 1735 case T.Identifier: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1736 if (peekNext() == T.Colon) |
161 | 1737 { |
264 | 1738 auto ident = token; |
161 | 1739 nT(); // Skip Identifier |
1740 nT(); // Skip : | |
234 | 1741 s = new LabeledStatement(ident, parseNoScopeOrEmptyStatement()); |
161 | 1742 break; |
1743 } | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1744 goto case T.Dot; |
201 | 1745 case T.Dot, T.Typeof: |
214 | 1746 bool success; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1747 d = try_(delegate { |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1748 return parseVariableOrFunction(StorageClass.None, |
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1749 Protection.None, |
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1750 LinkageType.None, false, false); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1751 }, success |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1752 ); |
214 | 1753 if (success) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1754 goto LreturnDeclarationStatement; // Declaration |
201 | 1755 else |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1756 goto case_parseExpressionStatement; // Expression |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1757 // IntegralType |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1758 case T.Char, T.Wchar, T.Dchar, T.Bool, |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1759 T.Byte, T.Ubyte, T.Short, T.Ushort, |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1760 T.Int, T.Uint, T.Long, T.Ulong, |
201 | 1761 T.Float, T.Double, T.Real, |
1762 T.Ifloat, T.Idouble, T.Ireal, | |
1763 T.Cfloat, T.Cdouble, T.Creal, T.Void: | |
1764 case_parseDeclaration: | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1765 d = parseVariableOrFunction(); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1766 goto LreturnDeclarationStatement; |
162 | 1767 case T.If: |
1768 s = parseIfStatement(); | |
1769 break; | |
164 | 1770 case T.While: |
1771 s = parseWhileStatement(); | |
1772 break; | |
165 | 1773 case T.Do: |
1774 s = parseDoWhileStatement(); | |
1775 break; | |
216 | 1776 case T.For: |
1777 s = parseForStatement(); | |
1778 break; | |
169 | 1779 case T.Foreach, T.Foreach_reverse: |
1780 s = parseForeachStatement(); | |
1781 break; | |
170 | 1782 case T.Switch: |
1783 s = parseSwitchStatement(); | |
1784 break; | |
171 | 1785 case T.Case: |
1786 s = parseCaseStatement(); | |
1787 break; | |
172 | 1788 case T.Default: |
1789 s = parseDefaultStatement(); | |
1790 break; | |
173 | 1791 case T.Continue: |
1792 s = parseContinueStatement(); | |
1793 break; | |
174 | 1794 case T.Break: |
1795 s = parseBreakStatement(); | |
1796 break; | |
175 | 1797 case T.Return: |
1798 s = parseReturnStatement(); | |
1799 break; | |
176 | 1800 case T.Goto: |
1801 s = parseGotoStatement(); | |
1802 break; | |
177 | 1803 case T.With: |
1804 s = parseWithStatement(); | |
1805 break; | |
178 | 1806 case T.Synchronized: |
1807 s = parseSynchronizedStatement(); | |
1808 break; | |
179 | 1809 case T.Try: |
1810 s = parseTryStatement(); | |
1811 break; | |
180 | 1812 case T.Throw: |
1813 s = parseThrowStatement(); | |
1814 break; | |
181 | 1815 case T.Scope: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1816 if (peekNext() != T.LParen) |
201 | 1817 goto case_parseAttribute; |
181 | 1818 s = parseScopeGuardStatement(); |
1819 break; | |
182 | 1820 case T.Volatile: |
1821 s = parseVolatileStatement(); | |
1822 break; | |
183 | 1823 case T.Asm: |
1824 s = parseAsmStatement(); | |
1825 break; | |
184 | 1826 case T.Pragma: |
1827 s = parsePragmaStatement(); | |
1828 break; | |
185 | 1829 case T.Mixin: |
246
52f4aa097865
- Fix: parse mixin as expression instead of statement when next token is T.LParen.
aziz
parents:
245
diff
changeset
|
1830 if (peekNext() == T.LParen) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1831 goto case_parseExpressionStatement; // Parse as expression. |
256 | 1832 s = parseMixin!(MixinStatement)(); |
185 | 1833 break; |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1834 case T.Static: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1835 switch (peekNext()) |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1836 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1837 case T.If: |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1838 s = parseStaticIfStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1839 break; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1840 case T.Assert: |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1841 s = parseStaticAssertStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1842 break; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1843 default: |
201 | 1844 goto case_parseAttribute; |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1845 } |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1846 break; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1847 case T.Debug: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1848 s = parseDebugStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1849 break; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1850 case T.Version: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1851 s = parseVersionStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1852 break; |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1853 // DeclDef |
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1854 case T.Alias, T.Typedef: |
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1855 d = parseDeclarationDefinition(); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1856 goto LreturnDeclarationStatement; |
188 | 1857 case T.Enum: |
1858 d = parseEnumDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1859 goto LreturnDeclarationStatement; |
188 | 1860 case T.Class: |
1861 d = parseClassDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1862 goto LreturnDeclarationStatement; |
188 | 1863 case T.Interface: |
1864 d = parseInterfaceDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1865 goto LreturnDeclarationStatement; |
188 | 1866 case T.Struct, T.Union: |
1867 d = parseAggregateDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1868 // goto LreturnDeclarationStatement; |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1869 LreturnDeclarationStatement: |
261 | 1870 set(d, begin); |
188 | 1871 s = new DeclarationStatement(d); |
1872 break; | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1873 case T.LBrace: |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1874 s = parseScopeStatement(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1875 break; |
216 | 1876 case T.Semicolon: |
231 | 1877 nT(); |
216 | 1878 s = new EmptyStatement(); |
1879 break; | |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1880 /+ |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1881 Parse ExpressionStatement: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1882 +/ |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1883 // Tokens that start a PrimaryExpression. |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1884 // case T.Identifier, T.Dot, T.Typeof: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1885 case T.This: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1886 case T.Super: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1887 case T.Null: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1888 case T.True, T.False: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1889 // case T.Dollar: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1890 case T.Int32, T.Int64, T.Uint32, T.Uint64: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1891 case T.Float32, T.Float64, T.Float80, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1892 T.Imaginary32, T.Imaginary64, T.Imaginary80: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1893 case T.CharLiteral, T.WCharLiteral, T.DCharLiteral: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1894 case T.String: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1895 case T.LBracket: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1896 // case T.LBrace: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1897 case T.Function, T.Delegate: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1898 case T.Assert: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1899 // case T.Mixin: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1900 case T.Import: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1901 case T.Typeid: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1902 case T.Is: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1903 case T.LParen: |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1904 /+ // IntegralType |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1905 case T.Char, T.Wchar, T.Dchar, T.Bool, |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1906 T.Byte, T.Ubyte, T.Short, T.Ushort, |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1907 T.Int, T.Uint, T.Long, T.Ulong, |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1908 T.Float, T.Double, T.Real, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1909 T.Ifloat, T.Idouble, T.Ireal, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1910 T.Cfloat, T.Cdouble, T.Creal, T.Void:+/ |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1911 case T.Traits: // D2.0 |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1912 // Tokens that can start a UnaryExpression: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1913 case T.AndBinary, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1914 T.PlusPlus, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1915 T.MinusMinus, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1916 T.Mul, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1917 T.Minus, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1918 T.Plus, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1919 T.Not, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1920 T.Tilde, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1921 T.New, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1922 T.Delete, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1923 T.Cast: |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1924 case_parseExpressionStatement: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1925 s = new ExpressionStatement(parseExpression()); |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1926 require(T.Semicolon); |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1927 break; |
161 | 1928 default: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1929 if (token.isSpecialToken) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1930 goto case_parseExpressionStatement; |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1931 |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1932 if (token.type != T.Dollar) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1933 // Assert that this isn't a valid expression. |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1934 assert(delegate bool(){ |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1935 bool success; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1936 auto expression = try_(&parseExpression, success); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1937 return success; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1938 }() == false, "Didn't expect valid expression." |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1939 ); |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1940 |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1941 // Report error: it's an illegal statement. |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1942 s = new IllegalStatement(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1943 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1944 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1945 nT(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1946 while (!token.isStatementStart && |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1947 token.type != T.RBrace && |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1948 token.type != T.EOF) |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1949 auto text = Token.textSpan(begin, this.prevToken); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1950 error(begin, "illegal Statement found: " ~ text); |
161 | 1951 } |
205 | 1952 assert(s !is null); |
261 | 1953 set(s, begin); |
161 | 1954 return s; |
1955 } | |
1956 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1957 /++ |
162 | 1958 ScopeStatement: |
219 | 1959 NoScopeStatement |
162 | 1960 +/ |
164 | 1961 Statement parseScopeStatement() |
162 | 1962 { |
219 | 1963 return new ScopeStatement(parseNoScopeStatement()); |
162 | 1964 } |
1965 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1966 /++ |
166 | 1967 NoScopeStatement: |
1968 NonEmptyStatement | |
1969 BlockStatement | |
1970 BlockStatement: | |
1971 { } | |
1972 { StatementList } | |
1973 +/ | |
1974 Statement parseNoScopeStatement() | |
1975 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1976 auto begin = token; |
166 | 1977 Statement s; |
1978 if (token.type == T.LBrace) | |
1979 { | |
1980 nT(); | |
1981 auto ss = new Statements(); | |
1982 while (token.type != T.RBrace && token.type != T.EOF) | |
1983 ss ~= parseStatement(); | |
1984 require(T.RBrace); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1985 s = set(ss, begin); |
166 | 1986 } |
219 | 1987 else if (token.type == T.Semicolon) |
1988 { | |
1989 error(MID.ExpectedButFound, "non-empty statement", ";"); | |
1990 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1991 s = set(new EmptyStatement(), begin); |
219 | 1992 } |
166 | 1993 else |
1994 s = parseStatement(); | |
1995 return s; | |
1996 } | |
1997 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1998 /++ |
234 | 1999 NoScopeOrEmptyStatement: |
2000 ; | |
2001 NoScopeStatement | |
2002 +/ | |
2003 Statement parseNoScopeOrEmptyStatement() | |
2004 { | |
2005 if (token.type == T.Semicolon) | |
312 | 2006 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2007 auto begin = token; |
234 | 2008 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2009 return set(new EmptyStatement(), begin); |
312 | 2010 } |
234 | 2011 else |
2012 return parseNoScopeStatement(); | |
2013 } | |
2014 | |
201 | 2015 Statement parseAttributeStatement() |
2016 { | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2017 StorageClass stc, stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2018 LinkageType prev_linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2019 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2020 // Nested function. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2021 Declaration parse() |
201 | 2022 { |
261 | 2023 auto begin = token; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2024 Declaration d; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2025 switch (token.type) |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2026 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2027 case T.Extern: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2028 if (peekNext() != T.LParen) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2029 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2030 stc_tmp = StorageClass.Extern; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2031 goto Lcommon; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2032 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2033 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2034 nT(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2035 auto linkageType = parseLinkageType(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2036 checkLinkageType(prev_linkageType, linkageType, begin); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2037 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2038 d = new LinkageDeclaration(linkageType, parse()); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2039 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2040 case T.Static: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2041 stc_tmp = StorageClass.Static; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2042 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2043 case T.Final: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2044 stc_tmp = StorageClass.Final; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2045 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2046 case T.Const: |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2047 version(D2) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2048 { |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2049 if (peekNext() == T.LParen) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2050 goto case_Declaration; |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2051 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2052 stc_tmp = StorageClass.Const; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2053 goto Lcommon; |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2054 version(D2) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2055 { |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2056 case T.Invariant: // D 2.0 |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2057 if (peekNext() == T.LParen) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2058 goto case_Declaration; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2059 stc_tmp = StorageClass.Invariant; |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2060 goto Lcommon; |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2061 } |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2062 case T.Auto: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2063 stc_tmp = StorageClass.Auto; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2064 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2065 case T.Scope: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2066 stc_tmp = StorageClass.Scope; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2067 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2068 Lcommon: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2069 // Issue error if redundant. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2070 if (stc & stc_tmp) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2071 error(MID.RedundantStorageClass, token.srcText); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2072 else |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2073 stc |= stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2074 |
269 | 2075 auto tok = token.type; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2076 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2077 d = new StorageClassDeclaration(stc_tmp, tok, parse()); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2078 break; |
239
7911f6a92e6e
- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents:
238
diff
changeset
|
2079 // TODO: allow "scope class", "abstract scope class" in function bodies? |
7911f6a92e6e
- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents:
238
diff
changeset
|
2080 //case T.Class: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2081 default: |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2082 case_Declaration: |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
2083 return parseVariableOrFunction(stc, Protection.None, prev_linkageType, true); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2084 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2085 return set(d, begin); |
201 | 2086 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2087 return new DeclarationStatement(parse()); |
201 | 2088 } |
2089 | |
162 | 2090 Statement parseIfStatement() |
2091 { | |
2092 assert(token.type == T.If); | |
2093 nT(); | |
2094 | |
283 | 2095 Statement variable; |
162 | 2096 Expression condition; |
2097 Statement ifBody, elseBody; | |
2098 | |
2099 require(T.LParen); | |
283 | 2100 |
2101 Token* ident; | |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2102 auto begin = token; // For start of AutoDeclaration or normal Declaration. |
162 | 2103 // auto Identifier = Expression |
2104 if (token.type == T.Auto) | |
2105 { | |
2106 nT(); | |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
2107 ident = requireId(); |
162 | 2108 require(T.Assign); |
283 | 2109 auto init = parseExpression(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2110 auto v = new VariableDeclaration(null, [ident], [init]); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2111 set(v, ident); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2112 auto d = new StorageClassDeclaration(StorageClass.Auto, T.Auto, v); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2113 set(d, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2114 variable = new DeclarationStatement(d); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2115 set(variable, begin); |
162 | 2116 } |
2117 else | |
2118 { | |
2119 // Declarator = Expression | |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
2120 Type parseDeclaratorAssign() |
162 | 2121 { |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
2122 auto type = parseDeclarator(ident); |
162 | 2123 require(T.Assign); |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
2124 return type; |
162 | 2125 } |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
2126 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
2127 auto type = try_(&parseDeclaratorAssign, success); |
283 | 2128 if (success) |
163
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
2129 { |
283 | 2130 auto init = parseExpression(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2131 auto v = new VariableDeclaration(type, [ident], [init]); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2132 set(v, begin); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2133 variable = new DeclarationStatement(v); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2134 set(variable, begin); |
163
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
2135 } |
283 | 2136 else |
2137 condition = parseExpression(); | |
162 | 2138 } |
2139 require(T.RParen); | |
164 | 2140 ifBody = parseScopeStatement(); |
162 | 2141 if (token.type == T.Else) |
2142 { | |
2143 nT(); | |
164 | 2144 elseBody = parseScopeStatement(); |
162 | 2145 } |
283 | 2146 return new IfStatement(variable, condition, ifBody, elseBody); |
162 | 2147 } |
2148 | |
164 | 2149 Statement parseWhileStatement() |
2150 { | |
2151 assert(token.type == T.While); | |
2152 nT(); | |
166 | 2153 require(T.LParen); |
164 | 2154 auto condition = parseExpression(); |
166 | 2155 require(T.RParen); |
164 | 2156 return new WhileStatement(condition, parseScopeStatement()); |
2157 } | |
2158 | |
165 | 2159 Statement parseDoWhileStatement() |
2160 { | |
2161 assert(token.type == T.Do); | |
2162 nT(); | |
2163 auto doBody = parseScopeStatement(); | |
2164 require(T.While); | |
166 | 2165 require(T.LParen); |
165 | 2166 auto condition = parseExpression(); |
166 | 2167 require(T.RParen); |
2168 return new DoWhileStatement(condition, doBody); | |
2169 } | |
2170 | |
2171 Statement parseForStatement() | |
2172 { | |
2173 assert(token.type == T.For); | |
2174 nT(); | |
165 | 2175 require(T.LParen); |
166 | 2176 |
2177 Statement init, forBody; | |
2178 Expression condition, increment; | |
2179 | |
2180 if (token.type != T.Semicolon) | |
2181 init = parseNoScopeStatement(); | |
230
8f1790d16753
- Fix: added missing call to parseDeclaratorSuffx() in parseDeclaration.
aziz
parents:
229
diff
changeset
|
2182 else |
8f1790d16753
- Fix: added missing call to parseDeclaratorSuffx() in parseDeclaration.
aziz
parents:
229
diff
changeset
|
2183 nT(); // Skip ; |
166 | 2184 if (token.type != T.Semicolon) |
2185 condition = parseExpression(); | |
168 | 2186 require(T.Semicolon); |
166 | 2187 if (token.type != T.RParen) |
2188 increment = parseExpression(); | |
168 | 2189 require(T.RParen); |
167 | 2190 forBody = parseScopeStatement(); |
166 | 2191 return new ForStatement(init, condition, increment, forBody); |
165 | 2192 } |
2193 | |
169 | 2194 Statement parseForeachStatement() |
2195 { | |
2196 assert(token.type == T.Foreach || token.type == T.Foreach_reverse); | |
2197 TOK tok = token.type; | |
2198 nT(); | |
2199 | |
257 | 2200 auto params = new Parameters; |
269 | 2201 Expression e; // Aggregate or LwrExpression |
169 | 2202 |
2203 require(T.LParen); | |
2204 while (1) | |
2205 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2206 auto paramBegin = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2207 Token* stcTok; |
169 | 2208 Type type; |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
2209 Token* ident; |
169 | 2210 |
2211 switch (token.type) | |
2212 { | |
236
e961d1b957c3
- Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents:
235
diff
changeset
|
2213 case T.Ref, T.Inout: |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2214 stcTok = token; |
169 | 2215 nT(); |
236
e961d1b957c3
- Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents:
235
diff
changeset
|
2216 // fall through |
169 | 2217 case T.Identifier: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2218 auto next = peekNext(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2219 if (next == T.Comma || next == T.Semicolon || next == T.RParen) |
169 | 2220 { |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
2221 ident = token; |
169 | 2222 nT(); |
2223 break; | |
2224 } | |
2225 // fall through | |
2226 default: | |
2227 type = parseDeclarator(ident); | |
2228 } | |
2229 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2230 params ~= set(new Parameter(stcTok, type, ident, null), paramBegin); |
169 | 2231 |
2232 if (token.type != T.Comma) | |
2233 break; | |
2234 nT(); | |
2235 } | |
2236 require(T.Semicolon); | |
269 | 2237 e = parseExpression(); |
2238 version(D2) | |
2239 { //Foreach (ForeachType; LwrExpression .. UprExpression ) ScopeStatement | |
2240 if (token.type == T.Slice) | |
2241 { | |
2242 // if (params.length != 1) | |
2243 // error(MID.XYZ); // TODO: issue error msg | |
2244 nT(); | |
2245 auto upper = parseExpression(); | |
2246 require(T.RParen); | |
2247 auto forBody = parseScopeStatement(); | |
2248 return new ForeachRangeStatement(tok, params, e, upper, forBody); | |
2249 } | |
2250 } | |
2251 // Foreach (ForeachTypeList; Aggregate) ScopeStatement | |
169 | 2252 require(T.RParen); |
2253 auto forBody = parseScopeStatement(); | |
269 | 2254 return new ForeachStatement(tok, params, e, forBody); |
169 | 2255 } |
2256 | |
170 | 2257 Statement parseSwitchStatement() |
2258 { | |
2259 assert(token.type == T.Switch); | |
2260 nT(); | |
2261 | |
2262 require(T.LParen); | |
2263 auto condition = parseExpression(); | |
2264 require(T.RParen); | |
2265 auto switchBody = parseScopeStatement(); | |
2266 return new SwitchStatement(condition, switchBody); | |
2267 } | |
2268 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2269 /++ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2270 Helper function for parsing the body of |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2271 a default or case statement. |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2272 +/ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2273 Statement parseCaseOrDefaultBody() |
220 | 2274 { |
2275 // This function is similar to parseNoScopeStatement() | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2276 auto begin = token; |
224 | 2277 auto s = new Statements(); |
2278 while (token.type != T.Case && | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2279 token.type != T.Default && |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2280 token.type != T.RBrace && |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2281 token.type != T.EOF) |
224 | 2282 s ~= parseStatement(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2283 return set(new ScopeStatement(s), begin); |
220 | 2284 } |
2285 | |
171 | 2286 Statement parseCaseStatement() |
2287 { | |
2288 assert(token.type == T.Case); | |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
2289 nT(); |
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
2290 auto values = parseExpressionList(); |
171 | 2291 require(T.Colon); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2292 auto caseBody = parseCaseOrDefaultBody(); |
171 | 2293 return new CaseStatement(values, caseBody); |
2294 } | |
2295 | |
172 | 2296 Statement parseDefaultStatement() |
2297 { | |
2298 assert(token.type == T.Default); | |
2299 nT(); | |
2300 require(T.Colon); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2301 auto defaultBody = parseCaseOrDefaultBody(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2302 return new DefaultStatement(defaultBody); |
172 | 2303 } |
2304 | |
173 | 2305 Statement parseContinueStatement() |
2306 { | |
2307 assert(token.type == T.Continue); | |
2308 nT(); | |
264 | 2309 Token* ident; |
173 | 2310 if (token.type == T.Identifier) |
2311 { | |
264 | 2312 ident = token; |
173 | 2313 nT(); |
2314 } | |
2315 require(T.Semicolon); | |
2316 return new ContinueStatement(ident); | |
2317 } | |
2318 | |
174 | 2319 Statement parseBreakStatement() |
2320 { | |
2321 assert(token.type == T.Break); | |
2322 nT(); | |
264 | 2323 Token* ident; |
174 | 2324 if (token.type == T.Identifier) |
2325 { | |
264 | 2326 ident = token; |
174 | 2327 nT(); |
2328 } | |
2329 require(T.Semicolon); | |
2330 return new BreakStatement(ident); | |
2331 } | |
2332 | |
175 | 2333 Statement parseReturnStatement() |
2334 { | |
2335 assert(token.type == T.Return); | |
2336 nT(); | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2337 Expression expr; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2338 if (token.type != T.Semicolon) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2339 expr = parseExpression(); |
175 | 2340 require(T.Semicolon); |
2341 return new ReturnStatement(expr); | |
2342 } | |
2343 | |
176 | 2344 Statement parseGotoStatement() |
2345 { | |
2346 assert(token.type == T.Goto); | |
2347 nT(); | |
264 | 2348 Token* ident; |
176 | 2349 Expression caseExpr; |
2350 switch (token.type) | |
2351 { | |
2352 case T.Case: | |
2353 nT(); | |
2354 if (token.type == T.Semicolon) | |
2355 break; | |
2356 caseExpr = parseExpression(); | |
2357 break; | |
2358 case T.Default: | |
2359 nT(); | |
2360 break; | |
2361 default: | |
264 | 2362 ident = requireId(); |
176 | 2363 } |
2364 require(T.Semicolon); | |
2365 return new GotoStatement(ident, caseExpr); | |
2366 } | |
2367 | |
177 | 2368 Statement parseWithStatement() |
2369 { | |
2370 assert(token.type == T.With); | |
2371 nT(); | |
2372 require(T.LParen); | |
2373 auto expr = parseExpression(); | |
2374 require(T.RParen); | |
2375 return new WithStatement(expr, parseScopeStatement()); | |
2376 } | |
2377 | |
178 | 2378 Statement parseSynchronizedStatement() |
2379 { | |
2380 assert(token.type == T.Synchronized); | |
2381 nT(); | |
2382 Expression expr; | |
2383 | |
2384 if (token.type == T.LParen) | |
2385 { | |
2386 nT(); | |
2387 expr = parseExpression(); | |
2388 require(T.RParen); | |
2389 } | |
2390 return new SynchronizedStatement(expr, parseScopeStatement()); | |
2391 } | |
2392 | |
179 | 2393 Statement parseTryStatement() |
2394 { | |
2395 assert(token.type == T.Try); | |
2396 nT(); | |
2397 | |
2398 auto tryBody = parseScopeStatement(); | |
2399 CatchBody[] catchBodies; | |
2400 FinallyBody finBody; | |
2401 | |
2402 while (token.type == T.Catch) | |
2403 { | |
2404 nT(); | |
2405 Parameter param; | |
2406 if (token.type == T.LParen) | |
2407 { | |
229 | 2408 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2409 auto begin = token; |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
2410 Token* ident; |
369 | 2411 auto type = parseDeclarator(ident, true); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2412 param = new Parameter(null, type, ident, null); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2413 set(param, begin); |
179 | 2414 require(T.RParen); |
2415 } | |
2416 catchBodies ~= new CatchBody(param, parseNoScopeStatement()); | |
2417 if (param is null) | |
2418 break; // This is a LastCatch | |
2419 } | |
2420 | |
2421 if (token.type == T.Finally) | |
2422 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2423 auto begin = token; |
179 | 2424 nT(); |
2425 finBody = new FinallyBody(parseNoScopeStatement()); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2426 set(finBody, begin); |
179 | 2427 } |
2428 | |
396
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
2429 if (catchBodies.length == 0 && finBody is null) |
179 | 2430 { |
2431 // TODO: issue error msg. | |
2432 } | |
2433 | |
2434 return new TryStatement(tryBody, catchBodies, finBody); | |
2435 } | |
2436 | |
180 | 2437 Statement parseThrowStatement() |
2438 { | |
2439 assert(token.type == T.Throw); | |
2440 nT(); | |
2441 auto expr = parseExpression(); | |
2442 require(T.Semicolon); | |
2443 return new ThrowStatement(expr); | |
2444 } | |
2445 | |
181 | 2446 Statement parseScopeGuardStatement() |
2447 { | |
2448 assert(token.type == T.Scope); | |
2449 nT(); | |
2450 assert(token.type == T.LParen); | |
2451 nT(); | |
2452 | |
264 | 2453 Token* condition = requireId(); |
2454 if (condition) | |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2455 switch (condition.ident.identID) |
181 | 2456 { |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2457 case ID.exit, ID.success, ID.failure: |
181 | 2458 break; |
2459 default: | |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2460 // TODO: create MID.InvalidScopeIdentifier |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2461 error(condition, "'exit', 'success', 'failure' are valid scope identifiers, but not '{}';", condition.srcText); |
181 | 2462 } |
2463 require(T.RParen); | |
2464 Statement scopeBody; | |
2465 if (token.type == T.LBrace) | |
2466 scopeBody = parseScopeStatement(); | |
2467 else | |
2468 scopeBody = parseNoScopeStatement(); | |
2469 return new ScopeGuardStatement(condition, scopeBody); | |
2470 } | |
2471 | |
182 | 2472 Statement parseVolatileStatement() |
2473 { | |
2474 assert(token.type == T.Volatile); | |
2475 nT(); | |
2476 Statement volatileBody; | |
2477 if (token.type == T.Semicolon) | |
2478 nT(); | |
2479 else if (token.type == T.LBrace) | |
2480 volatileBody = parseScopeStatement(); | |
2481 else | |
219 | 2482 volatileBody = parseStatement(); |
182 | 2483 return new VolatileStatement(volatileBody); |
2484 } | |
2485 | |
184 | 2486 Statement parsePragmaStatement() |
2487 { | |
2488 assert(token.type == T.Pragma); | |
2489 nT(); | |
2490 | |
245 | 2491 Token* ident; |
184 | 2492 Expression[] args; |
2493 Statement pragmaBody; | |
2494 | |
2495 require(T.LParen); | |
245 | 2496 ident = requireId(); |
184 | 2497 |
2498 if (token.type == T.Comma) | |
244
829fdb2e2915
- Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents:
243
diff
changeset
|
2499 { |
829fdb2e2915
- Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents:
243
diff
changeset
|
2500 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2501 args = parseExpressionList(); |
244
829fdb2e2915
- Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents:
243
diff
changeset
|
2502 } |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2503 require(T.RParen); |
184 | 2504 |
234 | 2505 pragmaBody = parseNoScopeOrEmptyStatement(); |
184 | 2506 |
2507 return new PragmaStatement(ident, args, pragmaBody); | |
2508 } | |
2509 | |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2510 Statement parseStaticIfStatement() |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2511 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2512 assert(token.type == T.Static); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2513 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2514 assert(token.type == T.If); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2515 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2516 Expression condition; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2517 Statement ifBody, elseBody; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2518 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2519 require(T.LParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2520 condition = parseExpression(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2521 require(T.RParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2522 ifBody = parseNoScopeStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2523 if (token.type == T.Else) |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2524 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2525 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2526 elseBody = parseNoScopeStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2527 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2528 return new StaticIfStatement(condition, ifBody, elseBody); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2529 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2530 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2531 Statement parseStaticAssertStatement() |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2532 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2533 assert(token.type == T.Static); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2534 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2535 assert(token.type == T.Assert); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2536 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2537 Expression condition, message; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2538 require(T.LParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2539 condition = parseAssignExpression(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2540 if (token.type == T.Comma) |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2541 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2542 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2543 message = parseAssignExpression(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2544 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2545 require(T.RParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2546 require(T.Semicolon); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2547 return new StaticAssertStatement(condition, message); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2548 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2549 |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2550 Statement parseDebugStatement() |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2551 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2552 assert(token.type == T.Debug); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2553 nT(); // Skip debug keyword. |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2554 |
264 | 2555 Token* cond; // debug ( Integer ) |
2556 // debug ( Identifier ) | |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2557 Statement debugBody, elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2558 |
264 | 2559 void parseIdentOrInt(ref Token* tok) |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2560 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2561 nT(); |
264 | 2562 if (token.type == T.Int32 || |
2563 token.type == T.Identifier) | |
2564 { | |
2565 tok = token; | |
2566 nT(); | |
2567 } | |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2568 else |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2569 expected(T.Identifier); // TODO: better error msg |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2570 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2571 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2572 // if (token.type == T.Assign) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2573 // { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2574 // parseIdentOrInt(identSpec, levelSpec); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2575 // require(T.Semicolon); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2576 // } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2577 // else |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2578 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2579 // Condition: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2580 // Integer |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2581 // Identifier |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2582 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2583 // ( Condition ) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2584 if (token.type == T.LParen) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2585 { |
264 | 2586 parseIdentOrInt(cond); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2587 require(T.RParen); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2588 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2589 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2590 // debug Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2591 // debug ( Condition ) Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2592 debugBody = parseNoScopeStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2593 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2594 // else Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2595 if (token.type == T.Else) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2596 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2597 // debug without condition and else body makes no sense |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2598 //if (levelCond == -1 && identCond.length == 0) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2599 // TODO: issue error msg |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2600 nT(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2601 elseBody = parseNoScopeStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2602 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2603 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2604 |
264 | 2605 return new DebugStatement(cond, debugBody, elseBody); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2606 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2607 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2608 Statement parseVersionStatement() |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2609 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2610 assert(token.type == T.Version); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2611 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2612 nT(); // Skip version keyword. |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2613 |
264 | 2614 Token* cond; // version ( Integer ) |
2615 // version ( Identifier ) | |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2616 Statement versionBody, elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2617 |
264 | 2618 void parseIdentOrInt(ref Token* tok) |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2619 { |
264 | 2620 if (token.type == T.Int32 || |
2621 token.type == T.Identifier) | |
2622 { | |
2623 tok = token; | |
2624 nT(); | |
2625 } | |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2626 else |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2627 expected(T.Identifier); // TODO: better error msg |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2628 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2629 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2630 // if (token.type == T.Assign) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2631 // { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2632 // parseIdentOrInt(identSpec, levelSpec); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2633 // require(T.Semicolon); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2634 // } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2635 // else |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2636 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2637 // Condition: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2638 // Integer |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2639 // Identifier |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2640 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2641 // ( Condition ) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2642 require(T.LParen); |
264 | 2643 parseIdentOrInt(cond); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2644 require(T.RParen); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2645 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2646 // version ( Condition ) Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2647 versionBody = parseNoScopeStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2648 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2649 // else Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2650 if (token.type == T.Else) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2651 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2652 nT(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2653 elseBody = parseNoScopeStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2654 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2655 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2656 |
264 | 2657 return new VersionStatement(cond, versionBody, elseBody); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2658 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2659 |
161 | 2660 /+++++++++++++++++++++++++++++ |
183 | 2661 + Assembler parsing methods + |
2662 +++++++++++++++++++++++++++++/ | |
2663 | |
2664 Statement parseAsmStatement() | |
2665 { | |
2666 assert(token.type == T.Asm); | |
285 | 2667 nT(); // Skip asm keyword. |
2668 require(T.LBrace); | |
2669 auto ss = new Statements; | |
2670 while (token.type != T.RBrace && token.type != T.EOF) | |
2671 ss ~= parseAsmInstruction(); | |
2672 require(T.RBrace); | |
2673 return new AsmStatement(ss); | |
2674 } | |
2675 | |
2676 Statement parseAsmInstruction() | |
2677 { | |
2678 auto begin = token; | |
2679 Statement s; | |
374 | 2680 typeof(token) ident; |
285 | 2681 switch (token.type) |
2682 { | |
374 | 2683 // Keywords that are valid opcodes. |
2684 case T.In, T.Int, T.Out: | |
2685 ident = token; | |
2686 nT(); | |
2687 goto LOpcode; | |
285 | 2688 case T.Identifier: |
374 | 2689 ident = token; |
2690 nT(); // Skip Identifier | |
2691 if (token.type == T.Colon) | |
285 | 2692 { |
2693 // Identifier : AsmInstruction | |
2694 nT(); // Skip : | |
2695 s = new LabeledStatement(ident, parseAsmInstruction()); | |
2696 break; | |
2697 } | |
2698 | |
374 | 2699 LOpcode: |
285 | 2700 // Opcode ; |
2701 // Opcode Operands ; | |
2702 // Opcode | |
2703 // Identifier | |
2704 Expression[] es; | |
374 | 2705 if (token.type != T.Semicolon) |
285 | 2706 { |
2707 while (1) | |
2708 { | |
2709 es ~= parseAsmExpression(); | |
2710 if (token.type != T.Comma) | |
2711 break; | |
2712 nT(); | |
2713 } | |
2714 } | |
2715 require(T.Semicolon); | |
2716 s = new AsmInstruction(ident, es); | |
2717 break; | |
374 | 2718 case T.Align: |
2719 nT(); | |
2720 auto number = token; | |
2721 switch (token.type) | |
2722 { | |
2723 case T.Int32, T.Int64, T.Uint32, T.Uint64: | |
2724 number = token; nT(); break; | |
2725 default: | |
2726 if (token.type != T.Semicolon) | |
2727 nT(); | |
2728 number = null; | |
2729 // TODO: report error: number expected after asm align statement. | |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2730 error(token, "expected an integer after align, not '{}'", token.srcText); |
374 | 2731 } |
2732 require(T.Semicolon); | |
2733 s = new AsmAlignStatement(number); | |
2734 break; | |
285 | 2735 case T.Semicolon: |
2736 s = new EmptyStatement(); | |
2737 nT(); | |
2738 break; | |
2739 default: | |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2740 s = new IllegalAsmInstruction(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2741 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2742 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2743 nT(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2744 while (!token.isAsmInstructionStart && |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2745 token.type != T.RBrace && |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2746 token.type != T.EOF) |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2747 auto text = Token.textSpan(begin, this.prevToken); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2748 error(begin, "illegal AsmInstruction found: " ~ text); |
285 | 2749 } |
2750 set(s, begin); | |
2751 return s; | |
2752 } | |
2753 | |
2754 Expression parseAsmExpression() | |
2755 { | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2756 auto begin = token; |
374 | 2757 auto e = parseAsmOrOrExpression(); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2758 if (token.type == T.Question) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2759 { |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
2760 auto tok = token; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2761 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2762 auto iftrue = parseAsmExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2763 require(T.Colon); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2764 auto iffalse = parseAsmExpression(); |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
2765 e = new CondExpression(e, iftrue, iffalse, tok); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2766 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2767 } |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2768 // TODO: create AsmExpression that contains e? |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2769 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2770 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2771 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2772 Expression parseAsmOrOrExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2773 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2774 alias parseAsmAndAndExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2775 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2776 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2777 while (token.type == T.OrLogical) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2778 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2779 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2780 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2781 e = new OrOrExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2782 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2783 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2784 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2785 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2786 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2787 Expression parseAsmAndAndExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2788 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2789 alias parseAsmOrExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2790 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2791 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2792 while (token.type == T.AndLogical) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2793 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2794 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2795 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2796 e = new AndAndExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2797 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2798 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2799 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2800 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2801 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2802 Expression parseAsmOrExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2803 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2804 alias parseAsmXorExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2805 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2806 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2807 while (token.type == T.OrBinary) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2808 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2809 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2810 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2811 e = new OrExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2812 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2813 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2814 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2815 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2816 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2817 Expression parseAsmXorExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2818 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2819 alias parseAsmAndExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2820 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2821 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2822 while (token.type == T.Xor) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2823 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2824 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2825 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2826 e = new XorExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2827 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2828 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2829 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2830 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2831 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2832 Expression parseAsmAndExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2833 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2834 alias parseAsmCmpExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2835 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2836 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2837 while (token.type == T.AndBinary) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2838 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2839 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2840 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2841 e = new AndExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2842 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2843 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2844 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2845 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2846 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2847 Expression parseAsmCmpExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2848 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2849 alias parseAsmShiftExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2850 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2851 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2852 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2853 auto operator = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2854 switch (operator.type) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2855 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2856 case T.Equal, T.NotEqual: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2857 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2858 e = new EqualExpression(e, parseNext(), operator); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2859 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2860 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2861 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2862 e = new RelExpression(e, parseNext(), operator); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2863 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2864 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2865 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2866 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2867 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2868 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2869 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2870 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2871 Expression parseAsmShiftExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2872 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2873 alias parseAsmAddExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2874 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2875 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2876 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2877 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2878 auto operator = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2879 switch (operator.type) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2880 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2881 case T.LShift: nT(); e = new LShiftExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2882 case T.RShift: nT(); e = new RShiftExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2883 case T.URShift: nT(); e = new URShiftExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2884 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2885 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2886 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2887 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2888 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2889 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2890 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2891 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2892 Expression parseAsmAddExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2893 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2894 alias parseAsmMulExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2895 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2896 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2897 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2898 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2899 auto operator = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2900 switch (operator.type) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2901 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2902 case T.Plus: nT(); e = new PlusExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2903 case T.Minus: nT(); e = new MinusExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2904 // Not allowed in asm |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2905 //case T.Tilde: nT(); e = new CatExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2906 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2907 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2908 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2909 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2910 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2911 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2912 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2913 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2914 Expression parseAsmMulExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2915 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2916 alias parseAsmPostExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2917 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2918 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2919 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2920 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2921 auto operator = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2922 switch (operator.type) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2923 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2924 case T.Mul: nT(); e = new MulExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2925 case T.Div: nT(); e = new DivExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2926 case T.Mod: nT(); e = new ModExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2927 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2928 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2929 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2930 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2931 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2932 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2933 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2934 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2935 Expression parseAsmPostExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2936 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2937 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2938 auto e = parseAsmUnaryExpression(); |
374 | 2939 while (token.type == T.LBracket) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2940 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2941 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2942 e = parseAsmExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2943 e = new AsmPostBracketExpression(e); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2944 require(T.RBracket); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2945 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2946 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2947 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2948 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2949 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2950 Expression parseAsmUnaryExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2951 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2952 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2953 Expression e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2954 switch (token.type) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2955 { |
374 | 2956 case T.Byte, T.Short, T.Int, |
2957 T.Float, T.Double, T.Real: | |
2958 goto LAsmTypePrefix; | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2959 case T.Identifier: |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2960 switch (token.ident.identID) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2961 { |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2962 case ID.near, ID.far,/* "byte", "short", "int",*/ |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2963 ID.word, ID.dword, ID.qword/*, "float", "double", "real"*/: |
374 | 2964 LAsmTypePrefix: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2965 nT(); |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2966 if (token.type == T.Identifier && token.ident is Ident.ptr) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2967 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2968 else |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2969 error(MID.ExpectedButFound, "ptr", token.srcText); |
374 | 2970 e = new AsmTypeExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2971 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2972 case ID.offset: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2973 nT(); |
374 | 2974 e = new AsmOffsetExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2975 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2976 case ID.seg: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2977 nT(); |
374 | 2978 e = new AsmSegExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2979 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2980 default: |
374 | 2981 goto LparseAsmPrimaryExpression; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2982 } |
374 | 2983 break; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2984 case T.Minus: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2985 case T.Plus: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2986 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2987 e = new SignExpression(parseAsmUnaryExpression()); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2988 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2989 case T.Not: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2990 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2991 e = new NotExpression(parseAsmUnaryExpression()); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2992 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2993 case T.Tilde: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2994 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2995 e = new CompExpression(parseAsmUnaryExpression()); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2996 default: |
374 | 2997 LparseAsmPrimaryExpression: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2998 e = parseAsmPrimaryExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2999 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3000 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3001 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3002 return e; |
183 | 3003 } |
3004 | |
285 | 3005 Expression parseAsmPrimaryExpression() |
3006 { | |
3007 auto begin = token; | |
3008 Expression e; | |
3009 switch (token.type) | |
3010 { | |
3011 case T.Int32, T.Int64, T.Uint32, T.Uint64: | |
399
ff1d11c27061
Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
398
diff
changeset
|
3012 e = new IntExpression(token.type, token.ulong_); |
285 | 3013 nT(); |
3014 break; | |
3015 case T.Float32, T.Float64, T.Float80, | |
3016 T.Imaginary32, T.Imaginary64, T.Imaginary80: | |
399
ff1d11c27061
Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
398
diff
changeset
|
3017 e = new RealExpression(token.type, token.real_); |
285 | 3018 nT(); |
3019 break; | |
3020 case T.Dollar: | |
3021 e = new DollarExpression(); | |
3022 nT(); | |
3023 break; | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3024 case T.LBracket: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3025 // [ AsmExpression ] |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3026 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3027 e = parseAsmExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3028 require(T.RBracket); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3029 e = new AsmBracketExpression(e); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3030 break; |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3031 case T.Identifier: |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3032 auto register = token.ident; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3033 switch (register.identID) |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3034 { |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3035 // __LOCAL_SIZE |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3036 case ID.__LOCAL_SIZE: |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3037 nT(); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3038 e = new AsmLocalSizeExpression(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3039 break; |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3040 // Register |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3041 case ID.ST: |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3042 nT(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3043 // (1) - (7) |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3044 int number = -1; |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3045 if (token.type == T.LParen) |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3046 { |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3047 nT(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3048 if (token.type == T.Int32) |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3049 (number = token.int_), nT(); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3050 else |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3051 expected(T.Int32); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3052 require(T.RParen); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3053 } |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3054 e = new AsmRegisterExpression(register, number); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3055 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3056 case ID.FS: |
417
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3057 nT(); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3058 // TODO: is the colon-number part optional? |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3059 int number = -1; |
417
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3060 if (token.type == T.Colon) |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3061 { |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3062 // :0, :4, :8 |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3063 nT(); |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3064 if (token.type == T.Int32) |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3065 (number = token.int_), nT(); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3066 if (number != 0 && number != 4 && number != 8) |
417
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3067 error(MID.ExpectedButFound, "0, 4 or 8", token.srcText); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3068 } |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3069 e = new AsmRegisterExpression(register, number); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3070 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3071 case ID.AL, ID.AH, ID.AX, ID.EAX, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3072 ID.BL, ID.BH, ID.BX, ID.EBX, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3073 ID.CL, ID.CH, ID.CX, ID.ECX, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3074 ID.DL, ID.DH, ID.DX, ID.EDX, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3075 ID.BP, ID.EBP, ID.SP, ID.ESP, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3076 ID.DI, ID.EDI, ID.SI, ID.ESI, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3077 ID.ES, ID.CS, ID.SS, ID.DS, ID.GS, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3078 ID.CR0, ID.CR2, ID.CR3, ID.CR4, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3079 ID.DR0, ID.DR1, ID.DR2, ID.DR3, ID.DR6, ID.DR7, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3080 ID.TR3, ID.TR4, ID.TR5, ID.TR6, ID.TR7, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3081 ID.MM0, ID.MM1, ID.MM2, ID.MM3, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3082 ID.MM4, ID.MM5, ID.MM6, ID.MM7, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3083 ID.XMM0, ID.XMM1, ID.XMM2, ID.XMM3, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3084 ID.XMM4, ID.XMM5, ID.XMM6, ID.XMM7: |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3085 nT(); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3086 e = new AsmRegisterExpression(register); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3087 break; |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3088 default: |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3089 // DotIdentifier |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3090 Expression[] identList; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3091 while (1) |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3092 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3093 auto begin2 = token; |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3094 auto ident = requireId(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3095 e = new IdentifierExpression(ident); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3096 set(e, begin2); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3097 identList ~= e; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3098 if (token.type != T.Dot) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3099 break; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3100 nT(); // Skip dot. |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3101 } |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3102 e = new DotListExpression(identList); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3103 } |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3104 break; |
285 | 3105 default: |
3106 error(MID.ExpectedButFound, "Expression", token.srcText); | |
3107 e = new EmptyExpression(); | |
414
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3108 if (!trying) |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3109 { |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3110 // Insert a dummy token and don't consume current one. |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3111 begin = lx.insertEmptyTokenBefore(token); |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3112 this.prevToken = begin; |
414
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3113 } |
285 | 3114 } |
3115 set(e, begin); | |
3116 return e; | |
3117 } | |
3118 | |
183 | 3119 /+++++++++++++++++++++++++++++ |
102 | 3120 + Expression parsing methods + |
3121 +++++++++++++++++++++++++++++/ | |
3122 | |
72 | 3123 Expression parseExpression() |
3124 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3125 auto begin = token; |
72 | 3126 auto e = parseAssignExpression(); |
122 | 3127 while (token.type == T.Comma) |
235 | 3128 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3129 auto comma = token; |
235 | 3130 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3131 e = new CommaExpression(e, parseAssignExpression(), comma); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3132 set(e, begin); |
235 | 3133 } |
72 | 3134 return e; |
3135 } | |
3136 | |
71 | 3137 Expression parseAssignExpression() |
3138 { | |
319
83f1f9a4f248
- Removed assigment to 'begin' from loop. Initializing 'begin' at decl point.
aziz
parents:
318
diff
changeset
|
3139 auto begin = token; |
71 | 3140 auto e = parseCondExpression(); |
72 | 3141 while (1) |
71 | 3142 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3143 switch (token.type) |
72 | 3144 { |
3145 case T.Assign: | |
3146 nT(); e = new AssignExpression(e, parseAssignExpression()); | |
3147 break; | |
3148 case T.LShiftAssign: | |
3149 nT(); e = new LShiftAssignExpression(e, parseAssignExpression()); | |
3150 break; | |
3151 case T.RShiftAssign: | |
3152 nT(); e = new RShiftAssignExpression(e, parseAssignExpression()); | |
3153 break; | |
3154 case T.URShiftAssign: | |
3155 nT(); e = new URShiftAssignExpression(e, parseAssignExpression()); | |
3156 break; | |
3157 case T.OrAssign: | |
3158 nT(); e = new OrAssignExpression(e, parseAssignExpression()); | |
3159 break; | |
3160 case T.AndAssign: | |
3161 nT(); e = new AndAssignExpression(e, parseAssignExpression()); | |
3162 break; | |
3163 case T.PlusAssign: | |
3164 nT(); e = new PlusAssignExpression(e, parseAssignExpression()); | |
3165 break; | |
3166 case T.MinusAssign: | |
3167 nT(); e = new MinusAssignExpression(e, parseAssignExpression()); | |
3168 break; | |
3169 case T.DivAssign: | |
3170 nT(); e = new DivAssignExpression(e, parseAssignExpression()); | |
3171 break; | |
3172 case T.MulAssign: | |
3173 nT(); e = new MulAssignExpression(e, parseAssignExpression()); | |
3174 break; | |
3175 case T.ModAssign: | |
3176 nT(); e = new ModAssignExpression(e, parseAssignExpression()); | |
3177 break; | |
3178 case T.XorAssign: | |
3179 nT(); e = new XorAssignExpression(e, parseAssignExpression()); | |
3180 break; | |
3181 case T.CatAssign: | |
3182 nT(); e = new CatAssignExpression(e, parseAssignExpression()); | |
3183 break; | |
3184 default: | |
218 | 3185 return e; |
72 | 3186 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3187 set(e, begin); |
71 | 3188 } |
3189 return e; | |
3190 } | |
72 | 3191 |
71 | 3192 Expression parseCondExpression() |
3193 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3194 auto begin = token; |
72 | 3195 auto e = parseOrOrExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3196 if (token.type == T.Question) |
72 | 3197 { |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
3198 auto tok = token; |
72 | 3199 nT(); |
3200 auto iftrue = parseExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3201 require(T.Colon); |
72 | 3202 auto iffalse = parseCondExpression(); |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
3203 e = new CondExpression(e, iftrue, iffalse, tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3204 set(e, begin); |
72 | 3205 } |
3206 return e; | |
3207 } | |
3208 | |
3209 Expression parseOrOrExpression() | |
3210 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3211 alias parseAndAndExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3212 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3213 auto e = parseNext(); |
223 | 3214 while (token.type == T.OrLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3215 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3216 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3217 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3218 e = new OrOrExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3219 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3220 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3221 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3222 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3223 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3224 Expression parseAndAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3225 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3226 alias parseOrExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3227 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3228 auto e = parseNext(); |
223 | 3229 while (token.type == T.AndLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3230 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3231 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3232 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3233 e = new AndAndExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3234 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3235 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3236 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3237 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3238 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3239 Expression parseOrExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3240 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3241 alias parseXorExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3242 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3243 auto e = parseNext(); |
223 | 3244 while (token.type == T.OrBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3245 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3246 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3247 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3248 e = new OrExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3249 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3250 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3251 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3252 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3253 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3254 Expression parseXorExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3255 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3256 alias parseAndExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3257 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3258 auto e = parseNext(); |
223 | 3259 while (token.type == T.Xor) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3260 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3261 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3262 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3263 e = new XorExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3264 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3265 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3266 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3267 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3268 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3269 Expression parseAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3270 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3271 alias parseCmpExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3272 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3273 auto e = parseNext(); |
223 | 3274 while (token.type == T.AndBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3275 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3276 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3277 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3278 e = new AndExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3279 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3280 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3281 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3282 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3283 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3284 Expression parseCmpExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3285 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3286 alias parseShiftExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3287 auto begin = token; |
74 | 3288 auto e = parseShiftExpression(); |
3289 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3290 auto operator = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3291 switch (operator.type) |
74 | 3292 { |
3293 case T.Equal, T.NotEqual: | |
3294 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3295 e = new EqualExpression(e, parseNext(), operator); |
74 | 3296 break; |
3297 case T.Not: | |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
3298 if (peekNext() != T.Is) |
74 | 3299 break; |
3300 nT(); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3301 // fall through |
225 | 3302 case T.Is: |
74 | 3303 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3304 e = new IdentityExpression(e, parseNext(), operator); |
74 | 3305 break; |
3306 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater, | |
3307 T.Unordered, T.UorE, T.UorG, T.UorGorE, | |
3308 T.UorL, T.UorLorE, T.LorEorG, T.LorG: | |
3309 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3310 e = new RelExpression(e, parseNext(), operator); |
74 | 3311 break; |
3312 case T.In: | |
3313 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3314 e = new InExpression(e, parseNext(), operator); |
74 | 3315 break; |
3316 default: | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3317 return e; |
74 | 3318 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3319 set(e, begin); |
74 | 3320 return e; |
3321 } | |
3322 | |
3323 Expression parseShiftExpression() | |
3324 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3325 alias parseAddExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3326 auto begin = token; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3327 auto e = parseNext(); |
75 | 3328 while (1) |
3329 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3330 auto operator = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3331 switch (operator.type) |
75 | 3332 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3333 case T.LShift: nT(); e = new LShiftExpression(e, parseNext(), operator); break; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3334 case T.RShift: nT(); e = new RShiftExpression(e, parseNext(), operator); break; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3335 case T.URShift: nT(); e = new URShiftExpression(e, parseNext(), operator); break; |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3336 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3337 return e; |
75 | 3338 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3339 set(e, begin); |
75 | 3340 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3341 assert(0); |
75 | 3342 } |
3343 | |
3344 Expression parseAddExpression() | |
3345 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3346 alias parseMulExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3347 auto begin = token; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3348 auto e = parseNext(); |
76 | 3349 while (1) |
3350 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3351 auto operator = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3352 switch (operator.type) |
76 | 3353 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3354 case T.Plus: nT(); e = new PlusExpression(e, parseNext(), operator); break; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3355 case T.Minus: nT(); e = new MinusExpression(e, parseNext(), operator); break; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3356 case T.Tilde: nT(); e = new CatExpression(e, parseNext(), operator); break; |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3357 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3358 return e; |
76 | 3359 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3360 set(e, begin); |
76 | 3361 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3362 assert(0); |
76 | 3363 } |
3364 | |
3365 Expression parseMulExpression() | |
3366 { | |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3367 alias parsePostExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3368 auto begin = token; |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3369 auto e = parseNext(); |
77 | 3370 while (1) |
3371 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3372 auto operator = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3373 switch (operator.type) |
77 | 3374 { |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3375 case T.Mul: nT(); e = new MulExpression(e, parseNext(), operator); break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3376 case T.Div: nT(); e = new DivExpression(e, parseNext(), operator); break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3377 case T.Mod: nT(); e = new ModExpression(e, parseNext(), operator); break; |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3378 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3379 return e; |
77 | 3380 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3381 set(e, begin); |
77 | 3382 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3383 assert(0); |
71 | 3384 } |
3385 | |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3386 Expression parsePostExpression() |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3387 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3388 auto begin = token; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3389 auto e = parseUnaryExpression(); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3390 while (1) |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3391 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3392 switch (token.type) |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3393 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3394 case T.Dot: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3395 e = new PostDotListExpression(e, parseDotListExpression()); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3396 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3397 case T.PlusPlus: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3398 e = new PostIncrExpression(e); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3399 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3400 case T.MinusMinus: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3401 e = new PostDecrExpression(e); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3402 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3403 case T.LParen: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3404 e = new CallExpression(e, parseArguments()); |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3405 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3406 case T.LBracket: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3407 // parse Slice- and IndexExpression |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3408 nT(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
3409 // [] is a SliceExpression |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3410 if (token.type == T.RBracket) |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3411 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3412 e = new SliceExpression(e, null, null); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3413 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3414 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3415 |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3416 Expression[] es = [parseAssignExpression()]; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3417 |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
3418 // [ AssignExpression .. AssignExpression ] |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3419 if (token.type == T.Slice) |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3420 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3421 nT(); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3422 e = new SliceExpression(e, es[0], parseAssignExpression()); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3423 require(T.RBracket); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3424 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3425 } |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3426 |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
3427 // [ ExpressionList ] |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3428 if (token.type == T.Comma) |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3429 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3430 nT(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3431 es ~= parseExpressionList(); |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3432 } |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3433 require(T.RBracket); |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3434 |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3435 e = new IndexExpression(e, es); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3436 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3437 default: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3438 return e; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3439 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3440 nT(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
3441 Lset: // Jumped here to skip nT(). |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3442 set(e, begin); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3443 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3444 assert(0); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3445 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3446 |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3447 Expression parseUnaryExpression() |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3448 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3449 auto begin = token; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3450 Expression e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3451 switch (token.type) |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3452 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3453 case T.AndBinary: |
257 | 3454 nT(); |
243 | 3455 e = new AddressExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3456 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3457 case T.PlusPlus: |
257 | 3458 nT(); |
243 | 3459 e = new PreIncrExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3460 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3461 case T.MinusMinus: |
257 | 3462 nT(); |
243 | 3463 e = new PreDecrExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3464 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3465 case T.Mul: |
257 | 3466 nT(); |
243 | 3467 e = new DerefExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3468 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3469 case T.Minus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3470 case T.Plus: |
257 | 3471 nT(); |
243 | 3472 e = new SignExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3473 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3474 case T.Not: |
257 | 3475 nT(); |
243 | 3476 e = new NotExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3477 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3478 case T.Tilde: |
257 | 3479 nT(); |
243 | 3480 e = new CompExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3481 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3482 case T.New: |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3483 e = parseNewExpression(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3484 return e; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3485 case T.Delete: |
257 | 3486 nT(); |
243 | 3487 e = new DeleteExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3488 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3489 case T.Cast: |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3490 requireNext(T.LParen); |
269 | 3491 Type type; |
3492 switch (token.type) | |
3493 { | |
3494 version(D2) | |
3495 { | |
3496 auto begin2 = token; | |
3497 case T.Const: | |
3498 type = new ConstType(null); | |
3499 goto case_break; | |
3500 case T.Invariant: | |
3501 type = new InvariantType(null); | |
3502 case_break: | |
3503 nT(); | |
3504 set(type, begin2); | |
3505 break; | |
3506 } | |
3507 default: | |
3508 type = parseType(); | |
3509 } | |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3510 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3511 e = new CastExpression(parseUnaryExpression(), type); |
257 | 3512 break; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3513 case T.LParen: |
102 | 3514 // ( Type ) . Identifier |
225 | 3515 Type parseType_() |
3516 { | |
3517 nT(); | |
3518 auto type = parseType(); | |
3519 require(T.RParen); | |
233 | 3520 require(T.Dot); |
225 | 3521 return type; |
3522 } | |
3523 bool success; | |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
3524 auto type = try_(&parseType_, success); |
225 | 3525 if (success) |
3526 { | |
243 | 3527 auto ident = requireId(); |
225 | 3528 e = new TypeDotIdExpression(type, ident); |
257 | 3529 break; |
225 | 3530 } |
3531 goto default; | |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3532 default: |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3533 e = parsePrimaryExpression(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3534 return e; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3535 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3536 assert(e !is null); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3537 set(e, begin); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3538 return e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3539 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3540 |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
3541 Expression parsePrimaryExpression() |
78
f043759fb59a
- Added code to parseUnaryExpression(); not fully implemented.
aziz
parents:
77
diff
changeset
|
3542 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3543 auto begin = token; |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3544 Expression e; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3545 switch (token.type) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3546 { |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3547 case T.Identifier, T.Dot, T.Typeof: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3548 e = parseDotListExpression(); |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3549 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3550 case T.This: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3551 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3552 e = new ThisExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3553 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3554 case T.Super: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3555 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3556 e = new SuperExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3557 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3558 case T.Null: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3559 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3560 e = new NullExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3561 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3562 case T.True, T.False: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3563 nT(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3564 e = new BoolExpression(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3565 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3566 case T.Dollar: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3567 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3568 e = new DollarExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3569 break; |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3570 case T.Int32, T.Int64, T.Uint32, T.Uint64: |
399
ff1d11c27061
Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
398
diff
changeset
|
3571 e = new IntExpression(token.type, token.ulong_); |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3572 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3573 break; |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3574 case T.Float32, T.Float64, T.Float80, |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3575 T.Imaginary32, T.Imaginary64, T.Imaginary80: |
399
ff1d11c27061
Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
398
diff
changeset
|
3576 e = new RealExpression(token.type, token.real_); |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3577 nT(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3578 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3579 case T.CharLiteral, T.WCharLiteral, T.DCharLiteral: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3580 e = new CharExpression(token); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3581 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3582 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3583 case T.String: |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
3584 Token*[] stringLiterals; |
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
3585 do |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3586 { |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
3587 stringLiterals ~= token; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3588 nT(); |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
3589 } while (token.type == T.String) |
399
ff1d11c27061
Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
398
diff
changeset
|
3590 e = new StringExpression(stringLiterals); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3591 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3592 case T.LBracket: |
85 | 3593 Expression[] values; |
3594 | |
3595 nT(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3596 if (token.type != T.RBracket) |
85 | 3597 { |
3598 e = parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3599 if (token.type == T.Colon) |
85 | 3600 goto LparseAssocArray; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3601 if (token.type == T.Comma) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3602 { |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3603 nT(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3604 values = [e] ~ parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3605 } |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3606 require(T.RBracket); |
85 | 3607 } |
271
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3608 else |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3609 nT(); |
85 | 3610 |
3611 e = new ArrayLiteralExpression(values); | |
3612 break; | |
3613 | |
3614 LparseAssocArray: | |
3615 Expression[] keys; | |
3616 | |
3617 keys ~= e; | |
3618 nT(); // Skip colon. | |
271
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3619 goto LenterLoop; |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3620 |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3621 while (1) |
88 | 3622 { |
271
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3623 keys ~= parseAssignExpression(); |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3624 require(T.Colon); |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3625 LenterLoop: |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3626 values ~= parseAssignExpression(); |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3627 if (token.type != T.Comma) |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3628 break; |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3629 nT(); |
88 | 3630 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3631 require(T.RBracket); |
399
ff1d11c27061
Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
398
diff
changeset
|
3632 e = new AArrayLiteralExpression(keys, values); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3633 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3634 case T.LBrace: |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
3635 // DelegateLiteral := { Statements } |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3636 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3637 e = new FunctionLiteralExpression(funcBody); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3638 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3639 case T.Function, T.Delegate: |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
3640 // FunctionLiteral := (function|delegate) Type? '(' ArgumentList ')' '{' Statements '}' |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3641 nT(); // Skip function|delegate token. |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3642 Type returnType; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3643 Parameters parameters; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3644 if (token.type != T.LBrace) |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3645 { |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3646 if (token.type != T.LParen) // Optional return type |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3647 returnType = parseType(); |
143 | 3648 parameters = parseParameterList(); |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3649 } |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3650 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3651 e = new FunctionLiteralExpression(returnType, parameters, funcBody); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3652 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3653 case T.Assert: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3654 Expression msg; |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3655 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3656 e = parseAssignExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3657 if (token.type == T.Comma) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3658 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3659 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3660 msg = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3661 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3662 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3663 e = new AssertExpression(e, msg); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3664 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3665 case T.Mixin: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3666 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3667 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3668 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3669 e = new MixinExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3670 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3671 case T.Import: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3672 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3673 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3674 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3675 e = new ImportExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3676 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3677 case T.Typeid: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3678 requireNext(T.LParen); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3679 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3680 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3681 e = new TypeidExpression(type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3682 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3683 case T.Is: |
100 | 3684 requireNext(T.LParen); |
3685 | |
248 | 3686 Type type, specType; |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
3687 Token* ident; // optional Identifier |
248 | 3688 Token* opTok, specTok; |
100 | 3689 |
3690 type = parseDeclarator(ident, true); | |
3691 | |
3692 switch (token.type) | |
3693 { | |
3694 case T.Colon, T.Equal: | |
248 | 3695 opTok = token; |
100 | 3696 nT(); |
3697 switch (token.type) | |
3698 { | |
3699 case T.Typedef, | |
3700 T.Struct, | |
3701 T.Union, | |
3702 T.Class, | |
3703 T.Interface, | |
3704 T.Enum, | |
3705 T.Function, | |
3706 T.Delegate, | |
3707 T.Super, | |
3708 T.Return: | |
493
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3709 case_Const_Invariant: |
248 | 3710 specTok = token; |
102 | 3711 nT(); |
100 | 3712 break; |
493
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3713 case T.Const, T.Invariant: |
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3714 if (peekNext() != T.LParen) |
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3715 goto case_Const_Invariant; |
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3716 // Fall through. It's a type. |
100 | 3717 default: |
248 | 3718 specType = parseType(); |
100 | 3719 } |
3720 default: | |
3721 } | |
377 | 3722 |
3723 TemplateParameters tparams; | |
3724 version(D2) | |
3725 { | |
3726 // is ( Type Identifier : TypeSpecialization , TemplateParameterList ) | |
3727 // is ( Type Identifier == TypeSpecialization , TemplateParameterList ) | |
3728 if (ident && specType && token.type == T.Comma) | |
3729 tparams = parseTemplateParameterList2(); | |
3730 } | |
102 | 3731 require(T.RParen); |
377 | 3732 e = new IsExpression(type, ident, opTok, specTok, specType, tparams); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3733 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3734 case T.LParen: |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3735 if (tokenAfterParenIs(T.LBrace)) |
130 | 3736 { |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3737 auto parameters = parseParameterList(); |
143 | 3738 // ( ParameterList ) FunctionBody |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3739 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3740 e = new FunctionLiteralExpression(null, parameters, funcBody); |
130 | 3741 } |
3742 else | |
3743 { | |
131 | 3744 // ( Expression ) |
130 | 3745 nT(); |
3746 e = parseExpression(); | |
3747 require(T.RParen); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3748 // TODO: create ParenExpression? |
130 | 3749 } |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3750 break; |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3751 // IntegralType . Identifier |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
3752 case T.Char, T.Wchar, T.Dchar, T.Bool, |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
3753 T.Byte, T.Ubyte, T.Short, T.Ushort, |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
3754 T.Int, T.Uint, T.Long, T.Ulong, |
94 | 3755 T.Float, T.Double, T.Real, |
3756 T.Ifloat, T.Idouble, T.Ireal, | |
192 | 3757 T.Cfloat, T.Cdouble, T.Creal, T.Void: |
280 | 3758 auto type = new IntegralType(token.type); |
247 | 3759 nT(); |
3760 set(type, begin); | |
3761 require(T.Dot); | |
243 | 3762 auto ident = requireId(); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3763 |
94 | 3764 e = new TypeDotIdExpression(type, ident); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3765 break; |
269 | 3766 version(D2) |
3767 { | |
3768 case T.Traits: | |
3769 nT(); | |
3770 require(T.LParen); | |
3771 auto id = requireId(); | |
3772 TemplateArguments args; | |
3773 if (token.type == T.Comma) | |
3774 args = parseTemplateArguments2(); | |
3775 else | |
3776 require(T.RParen); | |
3777 e = new TraitsExpression(id, args); | |
3778 break; | |
3779 } | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3780 default: |
343
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3781 if (token.isSpecialToken) |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3782 { |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3783 e = new SpecialTokenExpression(token); |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3784 nT(); |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3785 break; |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3786 } |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3787 |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3788 error(MID.ExpectedButFound, "Expression", token.srcText); |
136
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
3789 e = new EmptyExpression(); |
414
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3790 if (!trying) |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3791 { |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3792 // Insert a dummy token and don't consume current one. |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3793 begin = lx.insertEmptyTokenBefore(token); |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
3794 this.prevToken = begin; |
414
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3795 } |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3796 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3797 set(e, begin); |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3798 return e; |
77 | 3799 } |
3800 | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3801 Expression parseNewExpression(/*Expression e*/) |
81 | 3802 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3803 auto begin = token; |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3804 assert(token.type == T.New); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3805 nT(); // Skip new keyword. |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3806 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3807 Expression[] newArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3808 Expression[] ctorArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3809 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3810 if (token.type == T.LParen) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3811 newArguments = parseArguments(); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3812 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3813 // NewAnonClassExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3814 // new (ArgumentList)opt class (ArgumentList)opt SuperClassopt InterfaceClassesopt ClassBody |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3815 if (token.type == T.Class) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3816 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3817 nT(); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3818 if (token.type == T.LParen) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3819 ctorArguments = parseArguments(); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3820 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3821 BaseClass[] bases = token.type != T.LBrace ? parseBaseClasses(false) : null ; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3822 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
3823 auto decls = parseDeclarationDefinitionsBody(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3824 return set(new NewAnonClassExpression(/*e, */newArguments, bases, ctorArguments, decls), begin); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3825 } |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3826 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3827 // NewExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3828 // NewArguments Type [ AssignExpression ] |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3829 // NewArguments Type ( ArgumentList ) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3830 // NewArguments Type |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3831 auto type = parseType(); |
302
d04a79e795a2
- Fix in parseNewExpression(): removed check for type id.
aziz
parents:
301
diff
changeset
|
3832 |
d04a79e795a2
- Fix in parseNewExpression(): removed check for type id.
aziz
parents:
301
diff
changeset
|
3833 if (token.type == T.LParen) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3834 ctorArguments = parseArguments(); |
302
d04a79e795a2
- Fix in parseNewExpression(): removed check for type id.
aziz
parents:
301
diff
changeset
|
3835 |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3836 return set(new NewExpression(/*e, */newArguments, type, ctorArguments), begin); |
81 | 3837 } |
3838 | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3839 Type parseType() |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3840 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3841 return parseBasicType2(parseBasicType()); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3842 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3843 |
94 | 3844 Type parseBasicType() |
3845 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3846 auto begin = token; |
94 | 3847 Type t; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3848 // IdentifierType tident; |
94 | 3849 |
3850 switch (token.type) | |
3851 { | |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
3852 case T.Char, T.Wchar, T.Dchar, T.Bool, |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
3853 T.Byte, T.Ubyte, T.Short, T.Ushort, |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
3854 T.Int, T.Uint, T.Long, T.Ulong, |
94 | 3855 T.Float, T.Double, T.Real, |
3856 T.Ifloat, T.Idouble, T.Ireal, | |
192 | 3857 T.Cfloat, T.Cdouble, T.Creal, T.Void: |
280 | 3858 t = new IntegralType(token.type); |
94 | 3859 nT(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3860 set(t, begin); |
94 | 3861 break; |
153 | 3862 case T.Identifier, T.Typeof, T.Dot: |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3863 t = parseDotListType(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
3864 assert(!isNodeSet(t)); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
3865 set(t, begin); |
153 | 3866 break; |
269 | 3867 version(D2) |
3868 { | |
3869 case T.Const: | |
3870 // const ( Type ) | |
3871 nT(); | |
3872 require(T.LParen); | |
3873 t = parseType(); | |
3874 require(T.RParen); | |
3875 t = new ConstType(t); | |
3876 set(t, begin); | |
3877 break; | |
3878 case T.Invariant: | |
3879 // invariant ( Type ) | |
3880 nT(); | |
3881 require(T.LParen); | |
3882 t = parseType(); | |
3883 require(T.RParen); | |
3884 t = new InvariantType(t); | |
3885 set(t, begin); | |
3886 break; | |
369 | 3887 } // version(D2) |
94 | 3888 default: |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3889 error(MID.ExpectedButFound, "BasicType", token.srcText); |
134
a31aa0d6dd5e
- Added class UndefinedType. Returning it in parseBasicType() when no token matched the basic type list.
aziz
parents:
133
diff
changeset
|
3890 t = new UndefinedType(); |
259
8118da6fee44
- Moved nT() below statement where an attribute class is constructed.
aziz
parents:
258
diff
changeset
|
3891 nT(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3892 set(t, begin); |
94 | 3893 } |
3894 return t; | |
3895 } | |
3896 | |
95 | 3897 Type parseBasicType2(Type t) |
3898 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3899 typeof(token) begin; |
95 | 3900 while (1) |
3901 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3902 begin = token; |
95 | 3903 switch (token.type) |
3904 { | |
3905 case T.Mul: | |
3906 t = new PointerType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3907 nT(); |
95 | 3908 break; |
3909 case T.LBracket: | |
106 | 3910 t = parseArrayType(t); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3911 continue; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3912 case T.Function, T.Delegate: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3913 TOK tok = token.type; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3914 nT(); |
143 | 3915 auto parameters = parseParameterList(); |
135 | 3916 if (tok == T.Function) |
291
c0e857931ff6
- Changed FunctionType and DelegateType. Both receive return type and parameters.
aziz
parents:
290
diff
changeset
|
3917 t = new FunctionType(t, parameters); |
135 | 3918 else |
291
c0e857931ff6
- Changed FunctionType and DelegateType. Both receive return type and parameters.
aziz
parents:
290
diff
changeset
|
3919 t = new DelegateType(t, parameters); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3920 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3921 default: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3922 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3923 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3924 set(t, begin); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3925 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3926 assert(0); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3927 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3928 |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3929 bool tokenAfterParenIs(TOK tok) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3930 { |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3931 // We count nested parentheses tokens because template types may appear inside parameter lists; e.g. (int x, Foo!(int) y). |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3932 assert(token.type == T.LParen); |
239
7911f6a92e6e
- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents:
238
diff
changeset
|
3933 Token* next = token; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3934 uint level = 1; |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3935 Loop: |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3936 while (1) |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3937 { |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3938 lx.peek(next); |
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3939 switch (next.type) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3940 { |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3941 case T.RParen: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3942 if (--level == 0) |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3943 { // Last, closing parentheses found. |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3944 do |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3945 lx.peek(next); |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3946 while (next.isWhitespace) |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3947 break Loop; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3948 } |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3949 break; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3950 case T.LParen: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3951 ++level; |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3952 break; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3953 case T.EOF: |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3954 break Loop; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3955 default: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3956 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3957 } |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3958 return next.type == tok; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3959 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3960 |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3961 Type parseDeclaratorSuffix(Type t) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3962 { |
192 | 3963 switch (token.type) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3964 { |
192 | 3965 case T.LBracket: |
3966 // Type Identifier ArrayType | |
3967 // ArrayType := [] or [Type] or [Expression..Expression] | |
3968 do | |
106 | 3969 t = parseArrayType(t); |
192 | 3970 while (token.type == T.LBracket) |
3971 break; | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3972 /+ // parsed in parseDeclaration() |
192 | 3973 case T.LParen: |
258 | 3974 TemplateParameters tparams; |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3975 if (tokenAfterParenIs(T.LParen)) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3976 { |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3977 // ( TemplateParameterList ) ( ParameterList ) |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3978 tparams = parseTemplateParameterList(); |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3979 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3980 |
192 | 3981 auto params = parseParameterList(); |
3982 // ReturnType FunctionName ( ParameterList ) | |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3983 t = new FunctionType(t, params, tparams); |
192 | 3984 break; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3985 +/ |
192 | 3986 default: |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3987 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3988 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3989 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3990 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3991 |
106 | 3992 Type parseArrayType(Type t) |
3993 { | |
3994 assert(token.type == T.LBracket); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3995 auto begin = token; |
106 | 3996 nT(); |
3997 if (token.type == T.RBracket) | |
3998 { | |
3999 t = new ArrayType(t); | |
4000 nT(); | |
4001 } | |
4002 else | |
4003 { | |
214 | 4004 bool success; |
369 | 4005 Type parseAAType() |
4006 { | |
4007 auto type = parseType(); | |
4008 require(T.RBracket); | |
4009 return type; | |
4010 } | |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
4011 auto assocType = try_(&parseAAType, success); |
214 | 4012 if (success) |
106 | 4013 t = new ArrayType(t, assocType); |
4014 else | |
4015 { | |
4016 Expression e = parseExpression(), e2; | |
4017 if (token.type == T.Slice) | |
4018 { | |
4019 nT(); | |
4020 e2 = parseExpression(); | |
4021 } | |
4022 t = new ArrayType(t, e, e2); | |
369 | 4023 require(T.RBracket); |
106 | 4024 } |
4025 } | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4026 set(t, begin); |
106 | 4027 return t; |
4028 } | |
4029 | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4030 Type parseCFunctionPointerType(Type type, ref Token* ident, bool optionalParamList) |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4031 { |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4032 assert(token.type == T.LParen); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4033 assert(type !is null); |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4034 auto begin = token; |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4035 nT(); // Skip ( |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4036 type = parseBasicType2(type); |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4037 if (token.type == T.LParen) |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4038 { |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4039 // Can be nested. |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4040 type = parseCFunctionPointerType(type, ident, true); |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4041 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4042 else if (token.type == T.Identifier) |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4043 { |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4044 // The identifier of the function pointer and the declaration. |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4045 ident = token; |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4046 nT(); |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4047 type = parseDeclaratorSuffix(type); |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4048 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4049 require(T.RParen); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4050 |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4051 Parameters params; |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4052 if (optionalParamList) |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4053 params = token.type == T.LParen ? parseParameterList() : null; |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4054 else |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4055 params = parseParameterList(); |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4056 |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4057 type = set(new CFuncPointerType(type, params), begin); |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4058 return type; |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4059 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4060 |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
4061 Type parseDeclarator(ref Token* ident, bool identOptional = false) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
4062 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
4063 auto t = parseType(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
4064 |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4065 if (token.type == T.LParen) |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4066 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4067 t = parseCFunctionPointerType(t, ident, true); |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4068 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4069 else if (token.type == T.Identifier) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
4070 { |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
4071 ident = token; |
95 | 4072 nT(); |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
4073 t = parseDeclaratorSuffix(t); |
95 | 4074 } |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4075 |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4076 if (ident is null && !identOptional) |
124 | 4077 expected(T.Identifier); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
4078 |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
4079 return t; |
95 | 4080 } |
4081 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4082 /++ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4083 Parse a list of AssignExpressions. |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4084 ExpressionList: |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4085 AssignExpression |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4086 AssignExpression , ExpressionList |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4087 +/ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4088 Expression[] parseExpressionList() |
138 | 4089 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4090 Expression[] expressions; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4091 while (1) |
138 | 4092 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4093 expressions ~= parseAssignExpression(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4094 if (token.type != T.Comma) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4095 break; |
138 | 4096 nT(); |
4097 } | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4098 return expressions; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4099 } |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4100 |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4101 /++ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4102 Arguments: |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4103 ( ) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4104 ( ExpressionList ) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4105 +/ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4106 Expression[] parseArguments() |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4107 { |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4108 assert(token.type == T.LParen); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4109 nT(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4110 Expression[] args; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4111 if (token.type != TOK.RParen) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4112 args = parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4113 require(TOK.RParen); |
139 | 4114 return args; |
138 | 4115 } |
4116 | |
143 | 4117 Parameters parseParameterList() |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
4118 out(params) |
96 | 4119 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
4120 if (params.length > 1) |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
4121 foreach (param; params.items[0..$-1]) |
96 | 4122 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
4123 if (param.isVariadic()) |
96 | 4124 assert(0, "variadic arguments can only appear at the end of the parameter list."); |
4125 } | |
4126 } | |
4127 body | |
95 | 4128 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4129 auto begin = token; |
95 | 4130 require(T.LParen); |
4131 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4132 auto params = new Parameters(); |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4133 |
95 | 4134 if (token.type == T.RParen) |
4135 { | |
4136 nT(); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4137 return set(params, begin); |
95 | 4138 } |
4139 | |
4140 while (1) | |
4141 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4142 auto paramBegin = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4143 Token* stcTok; |
269 | 4144 StorageClass stc, tmp; |
4145 | |
4146 if (token.type == T.Ellipses) | |
4147 { | |
4148 nT(); | |
4149 params ~= set(new Parameter(null, null, null, null), paramBegin); | |
4150 break; // Exit loop. | |
4151 } | |
4152 | |
4153 Lstc_loop: | |
95 | 4154 switch (token.type) |
4155 { | |
269 | 4156 version(D2) |
4157 { | |
4158 case T.Invariant: // D2.0 | |
4159 if (peekNext() == T.LParen) | |
4160 goto default; | |
4161 tmp = StorageClass.Invariant; | |
4162 goto Lcommon; | |
4163 case T.Const: // D2.0 | |
4164 if (peekNext() == T.LParen) | |
4165 goto default; | |
4166 tmp = StorageClass.Const; | |
4167 goto Lcommon; | |
4168 case T.Final: // D2.0 | |
4169 tmp = StorageClass.Final; | |
4170 goto Lcommon; | |
4171 case T.Scope: // D2.0 | |
4172 tmp = StorageClass.Scope; | |
4173 goto Lcommon; | |
4174 case T.Static: // D2.0 | |
4175 tmp = StorageClass.Static; | |
4176 goto Lcommon; | |
4177 case T.In: | |
4178 tmp = StorageClass.In; | |
4179 goto Lcommon; | |
4180 case T.Out: | |
282 | 4181 tmp = StorageClass.Out; |
269 | 4182 goto Lcommon; |
4183 case T.Inout, T.Ref: | |
4184 tmp = StorageClass.Ref; | |
4185 goto Lcommon; | |
4186 case T.Lazy: | |
4187 tmp = StorageClass.Lazy; | |
4188 goto Lcommon; | |
4189 Lcommon: | |
4190 if (stc & tmp) | |
4191 error(MID.RedundantStorageClass, token.srcText); | |
4192 else | |
4193 stc |= tmp; | |
4194 nT(); | |
4195 goto Lstc_loop; | |
4196 } | |
4197 else // else body of version(D2) | |
4198 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4199 case T.In, T.Out, T.Inout, T.Ref, T.Lazy: |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4200 stcTok = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4201 nT(); |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4202 goto default; |
269 | 4203 } |
95 | 4204 default: |
269 | 4205 version(D2) |
4206 { | |
4207 if (stc != StorageClass.None) | |
4208 stcTok = begin; | |
4209 } | |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
4210 Token* ident; |
130 | 4211 auto type = parseDeclarator(ident, true); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
4212 |
95 | 4213 Expression assignExpr; |
4214 if (token.type == T.Assign) | |
4215 { | |
4216 nT(); | |
4217 assignExpr = parseAssignExpression(); | |
4218 } | |
4219 | |
4220 if (token.type == T.Ellipses) | |
4221 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4222 auto p = set(new Parameter(stcTok, type, ident, assignExpr), paramBegin); |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4223 p.stc |= StorageClass.Variadic; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4224 params ~= p; |
95 | 4225 nT(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4226 break; // Exit loop. |
95 | 4227 } |
4228 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4229 params ~= set(new Parameter(stcTok, type, ident, assignExpr), paramBegin); |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4230 |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4231 if (token.type != T.Comma) |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4232 break; // Exit loop. |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4233 nT(); |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4234 continue; |
95 | 4235 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4236 break; // Exit loop. |
95 | 4237 } |
4238 require(T.RParen); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4239 return set(params, begin); |
95 | 4240 } |
4241 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
4242 TemplateArguments parseTemplateArguments() |
139 | 4243 { |
376 | 4244 TemplateArguments targs; |
139 | 4245 require(T.LParen); |
255
7ba0229af908
- Fixed parseTemplateArguments. Removed a return path and put the while loop into an if-statement.
aziz
parents:
254
diff
changeset
|
4246 if (token.type != T.RParen) |
376 | 4247 targs = parseTemplateArguments_(); |
139 | 4248 require(T.RParen); |
376 | 4249 return targs; |
139 | 4250 } |
376 | 4251 |
269 | 4252 version(D2) |
4253 { | |
4254 TemplateArguments parseTemplateArguments2() | |
4255 { | |
4256 assert(token.type == T.Comma); | |
4257 nT(); | |
376 | 4258 TemplateArguments targs; |
269 | 4259 if (token.type != T.RParen) |
376 | 4260 targs = parseTemplateArguments_(); |
269 | 4261 else |
4262 error(MID.ExpectedButFound, "Type/Expression", ")"); | |
4263 require(T.RParen); | |
376 | 4264 return targs; |
269 | 4265 } |
4266 } // version(D2) | |
376 | 4267 |
4268 TemplateArguments parseTemplateArguments_() | |
4269 { | |
4270 auto begin = token; | |
4271 auto targs = new TemplateArguments; | |
4272 while (1) | |
4273 { | |
379
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4274 Type parseType_() |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4275 { |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4276 auto type = parseType(); |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4277 if (token.type == T.Comma || token.type == T.RParen) |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4278 return type; |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4279 ++errorCount; // Cause try_() to fail. |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4280 return null; |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4281 } |
376 | 4282 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
4283 auto typeArgument = try_(&parseType_, success); |
376 | 4284 if (success) |
4285 // TemplateArgument: | |
4286 // Type | |
4287 // Symbol | |
4288 targs ~= typeArgument; | |
4289 else | |
4290 // TemplateArgument: | |
4291 // AssignExpression | |
4292 targs ~= parseAssignExpression(); | |
4293 if (token.type != T.Comma) | |
4294 break; // Exit loop. | |
4295 nT(); | |
4296 } | |
4297 set(targs, begin); | |
4298 return targs; | |
4299 } | |
4300 | |
258 | 4301 TemplateParameters parseTemplateParameterList() |
137 | 4302 { |
377 | 4303 TemplateParameters tparams; |
4304 require(T.LParen); | |
4305 if (token.type != T.RParen) | |
4306 tparams = parseTemplateParameterList_(); | |
4307 require(T.RParen); | |
4308 return tparams; | |
4309 } | |
4310 | |
4311 version(D2) | |
4312 { | |
4313 TemplateParameters parseTemplateParameterList2() | |
4314 { | |
4315 assert(token.type == T.Comma); | |
4316 nT(); | |
4317 TemplateParameters tparams; | |
4318 if (token.type != T.RParen) | |
4319 tparams = parseTemplateParameterList_(); | |
4320 else | |
4321 error(MID.ExpectedButFound, "Type/Expression", ")"); | |
4322 return tparams; | |
4323 } | |
4324 } // version(D2) | |
4325 | |
4326 TemplateParameters parseTemplateParameterList_() | |
4327 { | |
258 | 4328 auto begin = token; |
295
75b47c71a34c
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
293
diff
changeset
|
4329 auto tparams = new TemplateParameters; |
75b47c71a34c
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
293
diff
changeset
|
4330 |
137 | 4331 while (1) |
4332 { | |
258 | 4333 auto paramBegin = token; |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4334 TemplateParameter tp; |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
4335 Token* ident; |
137 | 4336 Type specType, defType; |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4337 |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4338 void parseSpecAndOrDefaultType() |
137 | 4339 { |
4340 // : SpecializationType | |
4341 if (token.type == T.Colon) | |
4342 { | |
4343 nT(); | |
4344 specType = parseType(); | |
4345 } | |
4346 // = DefaultType | |
4347 if (token.type == T.Assign) | |
4348 { | |
4349 nT(); | |
4350 defType = parseType(); | |
4351 } | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4352 } |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4353 |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4354 switch (token.type) |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4355 { |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4356 case T.Alias: |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4357 // TemplateAliasParameter: |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4358 // alias Identifier |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4359 nT(); // Skip alias keyword. |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4360 ident = requireId(); |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4361 parseSpecAndOrDefaultType(); |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4362 tp = new TemplateAliasParameter(ident, specType, defType); |
137 | 4363 break; |
4364 case T.Identifier: | |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
4365 ident = token; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
4366 switch (peekNext()) |
137 | 4367 { |
4368 case T.Ellipses: | |
4369 // TemplateTupleParameter: | |
4370 // Identifier ... | |
4371 nT(); // Skip Identifier. | |
4372 nT(); // Skip Ellipses. | |
341
3ac651ea83fb
- Fix: created TemplateAliasParameter instead of TemplateTypeParameter.
aziz
parents:
340
diff
changeset
|
4373 if (token.type == T.Comma) |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
4374 error(MID.TemplateTupleParameter); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4375 tp = new TemplateTupleParameter(ident); |
137 | 4376 break; |
4377 case T.Comma, T.RParen, T.Colon, T.Assign: | |
4378 // TemplateTypeParameter: | |
4379 // Identifier | |
4380 nT(); // Skip Identifier. | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4381 parseSpecAndOrDefaultType(); |
341
3ac651ea83fb
- Fix: created TemplateAliasParameter instead of TemplateTypeParameter.
aziz
parents:
340
diff
changeset
|
4382 tp = new TemplateTypeParameter(ident, specType, defType); |
137 | 4383 break; |
4384 default: | |
4385 // TemplateValueParameter: | |
4386 // Declarator | |
4387 ident = null; | |
4388 goto LTemplateValueParameter; | |
4389 } | |
4390 break; | |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4391 version(D2) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4392 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4393 case T.This: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4394 // TemplateThisParameter |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4395 // this TemplateTypeParameter |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4396 nT(); // Skip 'this' keyword. |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4397 ident = requireId(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4398 parseSpecAndOrDefaultType(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4399 tp = new TemplateThisParameter(ident, specType, defType); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4400 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4401 } |
137 | 4402 default: |
4403 LTemplateValueParameter: | |
4404 // TemplateValueParameter: | |
4405 // Declarator | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4406 Expression specValue, defValue; |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4407 auto valueType = parseDeclarator(ident); |
137 | 4408 // : SpecializationValue |
4409 if (token.type == T.Colon) | |
4410 { | |
4411 nT(); | |
4412 specValue = parseCondExpression(); | |
4413 } | |
4414 // = DefaultValue | |
4415 if (token.type == T.Assign) | |
4416 { | |
4417 nT(); | |
4418 defValue = parseCondExpression(); | |
4419 } | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4420 tp = new TemplateValueParameter(valueType, ident, specValue, defValue); |
137 | 4421 } |
4422 | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4423 // Push template parameter. |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4424 tparams ~= set(tp, paramBegin); |
137 | 4425 |
4426 if (token.type != T.Comma) | |
4427 break; | |
4428 nT(); | |
4429 } | |
258 | 4430 set(tparams, begin); |
137 | 4431 return tparams; |
4432 } | |
4433 | |
124 | 4434 void expected(TOK tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4435 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
4436 if (token.type != tok) |
327 | 4437 error(MID.ExpectedButFound, Token.toString(tok), token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4438 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4439 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4440 void require(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4441 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
4442 if (token.type == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4443 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4444 else |
327 | 4445 error(MID.ExpectedButFound, Token.toString(tok), token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4446 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4447 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4448 void requireNext(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4449 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4450 nT(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4451 require(tok); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4452 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4453 |
243 | 4454 Token* requireId() |
4455 { | |
4456 if (token.type == T.Identifier) | |
4457 { | |
4458 auto id = token; | |
4459 nT(); | |
4460 return id; | |
4461 } | |
4462 else | |
4463 error(MID.ExpectedButFound, "Identifier", token.srcText); | |
4464 return null; | |
4465 } | |
4466 | |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4467 /// Reports an error that has no message ID yet. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4468 void error(Token* token, char[] formatMsg, ...) |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4469 { |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4470 error_(token, MID.min, formatMsg, _arguments, _argptr); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4471 } |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4472 |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
4473 void error(MID mid, ...) |
71 | 4474 { |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4475 error_(this.token, mid, GetMsg(mid), _arguments, _argptr); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4476 } |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4477 |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4478 void error_(Token* token, MID mid, char[] formatMsg, TypeInfo[] _arguments, void* _argptr) |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4479 { |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4480 if (trying) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4481 { |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4482 ++errorCount; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4483 return; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4484 } |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4485 auto location = token.getLocation(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4486 auto msg = Format(_arguments, _argptr, formatMsg); |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
4487 errors ~= new Information(InfoType.Parser, mid, location, msg); |
71 | 4488 } |
65 | 4489 } |