Mercurial > projects > dil
annotate trunk/src/dil/Parser.d @ 501:949a53332c66
Fixed parsing of AutoDeclarations.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sun, 09 Dec 2007 23:27:40 +0100 |
parents | 5a607597dc22 |
children | 4e14cd1b24da |
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; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
17 import common; |
65 | 18 |
71 | 19 private alias TOK T; |
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 |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
40 this(char[] srcText, string filePath, InformationManager infoMan = null) |
71 | 41 { |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
42 lx = new Lexer(srcText, filePath); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
43 } |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
44 |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
45 protected void init() |
206 | 46 { |
47 nT(); | |
318 | 48 prevToken = token; |
206 | 49 } |
50 | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
51 void nT() |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
52 { |
318 | 53 prevToken = token; |
132 | 54 do |
55 { | |
56 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
|
57 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
|
58 } while (token.isWhitespace) // Skip whitespace |
71 | 59 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
60 |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
61 /++ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
62 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
|
63 +/ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
64 Declarations start() |
102 | 65 { |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
66 init(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
67 auto begin = token; |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
68 auto decls = new Declarations; |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
69 if (token.type == T.Module) |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
70 decls ~= parseModuleDeclaration(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
71 decls.addOptChildren(parseDeclarationDefinitions()); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
72 set(decls, begin); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
73 return decls; |
102 | 74 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
75 |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
76 /++ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
77 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
|
78 +/ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
79 Expression start2() |
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 init(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
82 return parseExpression(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
83 } |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
84 |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
85 uint trying; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
86 uint errorCount; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
87 |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
88 /++ |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
89 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
|
90 the state of the lexer and parser are restored. |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
91 +/ |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
92 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
|
93 { |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
94 auto oldToken = this.token; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
95 auto oldPrevToken = this.prevToken; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
96 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
|
97 |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
98 ++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
|
99 auto result = parseMethod(); |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
100 --trying; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
101 // Check if an error occurred. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
102 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
|
103 { |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
104 // Restore members. |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
105 token = oldToken; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
106 prevToken = oldPrevToken; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
107 lx.token = oldToken; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
108 errorCount = oldCount; |
214 | 109 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
|
110 } |
214 | 111 else |
112 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
|
113 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
|
114 } |
105 | 115 |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
116 /++ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
117 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
|
118 +/ |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
119 Class set(Class)(Class node, Token* begin) |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
120 { |
318 | 121 node.setTokens(begin, this.prevToken); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
122 return node; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
123 } |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
124 |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
125 /++ |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
126 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
|
127 +/ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
128 bool isNodeSet(Node node) |
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 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
|
131 } |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
132 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
133 TOK peekNext() |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
134 { |
239
7911f6a92e6e
- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents:
238
diff
changeset
|
135 Token* next = token; |
296 | 136 do |
137 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
|
138 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
|
139 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
|
140 } |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
141 |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
142 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
|
143 { |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
144 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
|
145 do |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
146 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
|
147 while (next.isWhitespace) // Skip whitespace |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
148 return next.type; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
149 } |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
150 |
102 | 151 /++++++++++++++++++++++++++++++ |
152 + Declaration parsing methods + | |
153 ++++++++++++++++++++++++++++++/ | |
154 | |
368 | 155 Declaration parseModuleDeclaration() |
156 { | |
157 auto begin = token; | |
158 ModuleFQN moduleFQN; | |
159 do | |
160 { | |
161 nT(); | |
162 moduleFQN ~= requireId(); | |
163 } while (token.type == T.Dot) | |
164 require(T.Semicolon); | |
165 return set(new ModuleDeclaration(moduleFQN), begin); | |
166 } | |
167 | |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
168 /++ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
169 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
|
170 DeclDefs: |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
171 DeclDef |
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 +/ |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
174 Declaration[] parseDeclarationDefinitions() |
102 | 175 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
176 Declaration[] decls; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
177 while (token.type != T.EOF) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
178 decls ~= parseDeclarationDefinition(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
179 return decls; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
180 } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
181 |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
182 /++ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
183 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
|
184 DeclDefsBlock: |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
185 { } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
186 { DeclDefs } |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
187 +/ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
188 Declarations parseDeclarationDefinitionsBody() |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
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 // Save attributes. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
191 auto linkageType = this.linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
192 auto protection = this.protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
193 auto storageClass = this.storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
194 // Clear attributes. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
195 this.linkageType = LinkageType.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
196 this.protection = Protection.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
197 this.storageClass = StorageClass.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
198 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
199 // Parse body. |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
200 auto begin = token; |
305 | 201 auto decls = new Declarations; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
202 require(T.LBrace); |
122 | 203 while (token.type != T.RBrace && token.type != T.EOF) |
161 | 204 decls ~= parseDeclarationDefinition(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
205 require(T.RBrace); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
206 set(decls, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
207 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
208 // Restore original values. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
209 this.linkageType = linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
210 this.protection = protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
211 this.storageClass = storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
212 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
213 return decls; |
102 | 214 } |
215 | |
110 | 216 Declaration parseDeclarationDefinition() |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
217 out(decl) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
218 { assert(isNodeSet(decl)); } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
219 body |
102 | 220 { |
262 | 221 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
|
222 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
|
223 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
|
224 { |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
225 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
|
226 T.Pragma, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
227 // Protection attributes |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
228 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
|
229 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
|
230 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
|
231 T.Protected, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
232 T.Public: |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
233 decl = parseAttributeSpecifier(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
234 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
235 // Storage classes |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
236 case T.Extern, |
203
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
237 T.Deprecated, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
238 T.Override, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
239 T.Abstract, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
240 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
|
241 //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
|
242 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
|
243 T.Const, |
269 | 244 //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
|
245 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
|
246 T.Scope: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
247 case_StaticAttribute: |
269 | 248 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
|
249 return parseStorageAttribute(); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
250 case T.Alias: |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
251 nT(); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
252 // TODO: parse StorageClasses? |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
253 decl = new AliasDeclaration(parseVariableOrFunction()); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
254 break; |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
255 case T.Typedef: |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
256 nT(); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
257 // TODO: parse StorageClasses? |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
258 decl = new TypedefDeclaration(parseVariableOrFunction()); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
259 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
|
260 case T.Static: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
261 switch (peekNext()) |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
262 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
263 case T.Import: |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
264 goto case_Import; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
265 case T.This: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
266 decl = parseStaticConstructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
267 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
268 case T.Tilde: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
269 decl = parseStaticDestructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
270 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
271 case T.If: |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
272 decl = parseStaticIfDeclaration(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
273 break; |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
274 case T.Assert: |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
275 decl = parseStaticAssertDeclaration(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
276 break; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
277 default: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
278 goto case_StaticAttribute; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
279 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
280 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
|
281 case T.Import: |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
282 case_Import: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
283 decl = parseImportDeclaration(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
284 imports ~= CastTo!(ImportDeclaration)(decl); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
285 // 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
|
286 decl.setProtection(this.protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
287 return set(decl, begin); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
288 case T.Enum: |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
289 decl = parseEnumDeclaration(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
290 break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
291 case T.Class: |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
292 decl = parseClassDeclaration(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
293 break; |
112 | 294 case T.Interface: |
295 decl = parseInterfaceDeclaration(); | |
296 break; | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
297 case T.Struct, T.Union: |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
298 decl = parseAggregateDeclaration(); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
299 break; |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
300 case T.This: |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
301 decl = parseConstructorDeclaration(); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
302 break; |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
303 case T.Tilde: |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
304 decl = parseDestructorDeclaration(); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
305 break; |
120 | 306 case T.Invariant: |
269 | 307 version(D2) |
308 { | |
309 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
|
310 if (peekAfter(next) == T.LParen) |
269 | 311 { |
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.RParen) |
269 | 313 goto case_Declaration; |
314 } | |
315 else | |
316 goto case_InvariantAttribute; | |
317 } | |
120 | 318 decl = parseInvariantDeclaration(); |
319 break; | |
121 | 320 case T.Unittest: |
321 decl = parseUnittestDeclaration(); | |
322 break; | |
122 | 323 case T.Debug: |
324 decl = parseDebugDeclaration(); | |
140 | 325 break; |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
326 case T.Version: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
327 decl = parseVersionDeclaration(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
328 break; |
140 | 329 case T.Template: |
330 decl = parseTemplateDeclaration(); | |
331 break; | |
141 | 332 case T.New: |
333 decl = parseNewDeclaration(); | |
334 break; | |
335 case T.Delete: | |
336 decl = parseDeleteDeclaration(); | |
337 break; | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
338 case T.Mixin: |
256 | 339 decl = parseMixin!(MixinDeclaration)(); |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
340 break; |
129 | 341 case T.Semicolon: |
342 nT(); | |
343 decl = new EmptyDeclaration(); | |
344 break; | |
192 | 345 // Declaration |
346 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
|
347 // IntegralType |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
348 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
|
349 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
|
350 T.Int, T.Uint, T.Long, T.Ulong, |
192 | 351 T.Float, T.Double, T.Real, |
352 T.Ifloat, T.Idouble, T.Ireal, | |
353 T.Cfloat, T.Cdouble, T.Creal, T.Void: | |
269 | 354 case_Declaration: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
355 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
|
356 /+case T.Module: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
357 // 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
|
358 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
|
359 default: |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
360 decl = new IllegalDeclaration(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
361 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
362 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
363 nT(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
364 while (!token.isDeclDefStart && |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
365 token.type != T.RBrace && |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
366 token.type != T.EOF) |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
367 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
|
368 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
|
369 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
370 decl.setProtection(this.protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
371 decl.setStorageClass(this.storageClass); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
372 assert(!isNodeSet(decl)); |
262 | 373 set(decl, begin); |
129 | 374 return decl; |
102 | 375 } |
376 | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
377 /++ |
122 | 378 DeclarationsBlock: |
379 : DeclDefs | |
380 { } | |
381 { DeclDefs } | |
382 DeclDef | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
383 +/ |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
384 Declaration parseDeclarationsBlock(bool noColon = false) |
122 | 385 { |
305 | 386 Declaration d; |
122 | 387 switch (token.type) |
388 { | |
389 case T.LBrace: | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
390 nT(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
391 auto begin = token; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
392 auto decls = new Declarations; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
393 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
|
394 decls ~= parseDeclarationDefinition(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
395 require(T.RBrace); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
396 d = set(decls, begin); |
122 | 397 break; |
398 case T.Colon: | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
399 if (noColon == true) |
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
400 goto default; |
122 | 401 nT(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
402 auto begin = token; |
305 | 403 auto decls = new Declarations; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
404 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
|
405 decls ~= parseDeclarationDefinition(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
406 d = set(decls, begin); |
122 | 407 break; |
408 default: | |
305 | 409 d = parseDeclarationDefinition(); |
122 | 410 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
411 assert(isNodeSet(d)); |
305 | 412 return d; |
122 | 413 } |
414 | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
415 Declaration parseDeclarationsBlockNoColon() |
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
416 { |
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
417 return parseDeclarationsBlock(true); |
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 |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
420 /++ |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
421 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
|
422 Params: |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
423 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
|
424 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
|
425 +/ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
426 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
|
427 Protection protection = Protection.None, |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
428 LinkageType linkType = LinkageType.None, |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
429 bool testAutoDeclaration = false, |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
430 bool optionalParameterList = true) |
192 | 431 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
432 auto begin = token; |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
433 Type type; |
262 | 434 Token* ident; |
192 | 435 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
436 // Check for AutoDeclaration: StorageClasses Identifier = |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
437 if (testAutoDeclaration && |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
438 token.type == T.Identifier && |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
439 peekNext() == T.Assign) |
192 | 440 { |
262 | 441 ident = token; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
442 nT(); |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
443 } |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
444 else |
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 type = parseType(); |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
447 if (token.type == T.LParen) |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
448 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
449 // 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
|
450 // 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
|
451 // Example: |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
452 // void foo() { |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
453 // // 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
|
454 // some_type (*p_func)(int); |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
455 // // 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
|
456 // 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
|
457 // } |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
458 // // 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
|
459 // something(*p); |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
460 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
|
461 } |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
462 else |
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 ident = requireId(); |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
465 // Type FunctionName ( ParameterList ) FunctionBody |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
466 if (token.type == T.LParen) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
467 { |
415
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
468 // It's a function declaration |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
469 TemplateParameters tparams; |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
470 if (tokenAfterParenIs(T.LParen)) |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
471 { |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
472 // ( TemplateParameterList ) ( ParameterList ) |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
473 tparams = parseTemplateParameterList(); |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
474 } |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
475 |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
476 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
|
477 version(D2) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
478 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
479 switch (token.type) |
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 case T.Const: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
482 stc |= StorageClass.Const; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
483 nT(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
484 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
485 case T.Invariant: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
486 stc |= StorageClass.Invariant; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
487 nT(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
488 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
489 default: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
490 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
491 } |
415
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
492 // ReturnType FunctionName ( ParameterList ) |
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
493 auto funcBody = parseFunctionBody(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
494 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
|
495 d.setStorageClass(stc); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
496 d.setLinkageType(linkType); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
497 d.setProtection(protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
498 return set(d, begin); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
499 } |
415
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
500 type = parseDeclaratorSuffix(type); |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
501 } |
192 | 502 } |
503 | |
504 // It's a variable declaration. | |
262 | 505 Token*[] idents = [ident]; |
194 | 506 Expression[] values; |
199
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
507 goto LenterLoop; // We've already parsed an identifier. Jump to if statement and check for initializer. |
194 | 508 while (token.type == T.Comma) |
509 { | |
222
4f31e4671e06
- Fix: nT() wasn't called in while loop to skip T.Comma.
aziz
parents:
220
diff
changeset
|
510 nT(); |
262 | 511 idents ~= requireId(); |
194 | 512 LenterLoop: |
513 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
|
514 nT(), (values ~= parseInitializer()); |
199
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
515 else |
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
516 values ~= null; |
194 | 517 } |
518 require(T.Semicolon); | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
519 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
|
520 d.setStorageClass(stc); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
521 d.setLinkageType(linkType); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
522 d.setProtection(protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
523 return set(d, begin); |
194 | 524 } |
192 | 525 |
194 | 526 Expression parseInitializer() |
527 { | |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
528 if (token.type == T.Void) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
529 { |
266 | 530 auto begin = token; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
531 auto next = peekNext(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
532 if (next == T.Comma || next == T.Semicolon) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
533 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
534 nT(); |
266 | 535 return set(new VoidInitializer(), begin); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
536 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
537 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
538 return parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
539 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
540 |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
541 Expression parseNonVoidInitializer() |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
542 { |
266 | 543 auto begin = token; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
544 Expression init; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
545 switch (token.type) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
546 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
547 case T.LBracket: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
548 // ArrayInitializer: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
549 // [ ] |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
550 // [ ArrayMemberInitializations ] |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
551 Expression[] keys; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
552 Expression[] values; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
553 |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
554 nT(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
555 while (token.type != T.RBracket) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
556 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
557 auto e = parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
558 if (token.type == T.Colon) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
559 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
560 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
561 keys ~= e; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
562 values ~= parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
563 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
564 else |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
565 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
566 keys ~= null; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
567 values ~= e; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
568 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
569 |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
570 if (token.type != T.Comma) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
571 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
572 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
573 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
574 require(T.RBracket); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
575 init = new ArrayInitializer(keys, values); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
576 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
577 case T.LBrace: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
578 // StructInitializer: |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
579 // { } |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
580 // { StructMemberInitializers } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
581 Expression parseStructInitializer() |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
582 { |
263 | 583 Token*[] idents; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
584 Expression[] values; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
585 |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
586 nT(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
587 while (token.type != T.RBrace) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
588 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
589 if (token.type == T.Identifier) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
590 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
591 // 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
|
592 if (peekNext() == T.Colon) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
593 { |
263 | 594 idents ~= token; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
595 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
596 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
597 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
598 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
599 // NonVoidInitializer |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
600 values ~= parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
601 |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
602 if (token.type != T.Comma) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
603 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
604 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
605 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
606 require(T.RBrace); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
607 return new StructInitializer(idents, values); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
608 } |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
609 |
214 | 610 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
611 auto si = try_(&parseStructInitializer, success); |
214 | 612 if (success) |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
613 { |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
614 init = si; |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
615 break; |
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
616 } |
216 | 617 assert(token.type == T.LBrace); |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
618 //goto default; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
619 default: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
620 init = parseAssignExpression(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
621 } |
266 | 622 set(init, begin); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
623 return init; |
192 | 624 } |
625 | |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
626 FunctionBody parseFunctionBody() |
192 | 627 { |
268 | 628 auto begin = token; |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
629 auto func = new FunctionBody; |
192 | 630 while (1) |
631 { | |
632 switch (token.type) | |
633 { | |
634 case T.LBrace: | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
635 func.funcBody = parseStatements(); |
192 | 636 break; |
637 case T.Semicolon: | |
638 nT(); | |
639 break; | |
640 case T.In: | |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
641 if (func.inBody) |
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
642 error(MID.InContract); |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
643 nT(); |
192 | 644 func.inBody = parseStatements(); |
645 continue; | |
646 case T.Out: | |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
647 if (func.outBody) |
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
648 error(MID.OutContract); |
192 | 649 nT(); |
650 if (token.type == T.LParen) | |
651 { | |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
652 nT(); |
264 | 653 func.outIdent = requireId(); |
192 | 654 require(T.RParen); |
655 } | |
656 func.outBody = parseStatements(); | |
657 continue; | |
658 case T.Body: | |
659 nT(); | |
660 goto case T.LBrace; | |
661 default: | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
662 error(MID.ExpectedButFound, "FunctionBody", token.srcText); |
192 | 663 } |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
664 break; // Exit loop. |
192 | 665 } |
268 | 666 set(func, begin); |
299
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
298
diff
changeset
|
667 func.finishConstruction(); |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
668 return func; |
192 | 669 } |
670 | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
671 LinkageType parseLinkageType() |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
672 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
673 LinkageType linkageType; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
674 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
|
675 return linkageType; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
676 |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
677 nT(); // Skip ( |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
678 if (token.type == T.RParen) |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
679 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
680 nT(); |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
681 error(MID.MissingLinkageType); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
682 return linkageType; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
683 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
684 |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
685 auto ident = requireId(); |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
686 |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
687 switch (ident ? ident.identifier : null) |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
688 { |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
689 case "C": |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
690 if (token.type == T.PlusPlus) |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
691 { |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
692 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
693 linkageType = LinkageType.Cpp; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
694 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
695 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
696 linkageType = LinkageType.C; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
697 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
698 case "D": |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
699 linkageType = LinkageType.D; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
700 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
701 case "Windows": |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
702 linkageType = LinkageType.Windows; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
703 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
704 case "Pascal": |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
705 linkageType = LinkageType.Pascal; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
706 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
707 case "System": |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
708 linkageType = LinkageType.System; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
709 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
710 default: |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
711 error(MID.UnrecognizedLinkageType, token.srcText); |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
712 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
713 require(T.RParen); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
714 return linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
715 } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
716 |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
717 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
|
718 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
719 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
|
720 prev_lt = lt; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
721 else |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
722 // TODO: create new msg RedundantLinkageType. |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
723 error(begin, "redundant linkage type: " ~ Token.textSpan(begin, this.prevToken)); |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
724 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
725 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
726 Declaration parseStorageAttribute() |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
727 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
728 StorageClass stc, stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
729 LinkageType prev_linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
730 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
731 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
|
732 // Nested function. |
305 | 733 Declaration parse() |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
734 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
735 Declaration decl; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
736 auto begin = token; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
737 switch (token.type) |
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 case T.Extern: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
740 if (peekNext() != T.LParen) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
741 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
742 stc_tmp = StorageClass.Extern; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
743 goto Lcommon; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
744 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
745 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
746 nT(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
747 auto linkageType = parseLinkageType(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
748 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
|
749 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
750 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
|
751 this.linkageType = linkageType; // Set. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
752 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
|
753 set(decl, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
754 this.linkageType = saved; // Restore. |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
755 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
756 case T.Override: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
757 stc_tmp = StorageClass.Override; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
758 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
759 case T.Deprecated: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
760 stc_tmp = StorageClass.Deprecated; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
761 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
762 case T.Abstract: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
763 stc_tmp = StorageClass.Abstract; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
764 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
765 case T.Synchronized: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
766 stc_tmp = StorageClass.Synchronized; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
767 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
768 case T.Static: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
769 stc_tmp = StorageClass.Static; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
770 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
771 case T.Final: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
772 stc_tmp = StorageClass.Final; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
773 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
774 case T.Const: |
269 | 775 version(D2) |
776 { | |
777 if (peekNext() == T.LParen) | |
778 goto case_Declaration; | |
779 } | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
780 stc_tmp = StorageClass.Const; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
781 goto Lcommon; |
269 | 782 version(D2) |
783 { | |
784 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
|
785 auto next = token; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
786 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
|
787 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
788 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
|
789 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
|
790 decl = parseDeclarationDefinition(); // invariant ( ) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
791 decl.setStorageClass(stc); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
792 break; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
793 } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
794 // invariant as StorageClass. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
795 stc_tmp = StorageClass.Invariant; |
269 | 796 goto Lcommon; |
797 } | |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
798 case T.Auto: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
799 stc_tmp = StorageClass.Auto; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
800 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
801 case T.Scope: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
802 stc_tmp = StorageClass.Scope; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
803 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
804 Lcommon: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
805 // Issue error if redundant. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
806 if (stc & stc_tmp) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
807 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
|
808 else |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
809 stc |= stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
810 |
269 | 811 auto tok = token.type; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
812 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
813 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
|
814 set(decl, begin); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
815 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
816 case T.Identifier: |
269 | 817 case_Declaration: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
818 // 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
|
819 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
|
820 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
821 default: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
822 this.storageClass = stc; // Set. |
305 | 823 decl = parseDeclarationsBlock(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
824 this.storageClass = saved_storageClass; // Reset. |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
825 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
826 assert(isNodeSet(decl)); |
305 | 827 return decl; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
828 } |
305 | 829 return parse(); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
830 } |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
831 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
832 uint parseAlignAttribute() |
260 | 833 { |
834 assert(token.type == T.Align); | |
835 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
|
836 uint size = DEFAULT_ALIGN_SIZE; // Global default. |
260 | 837 if (token.type == T.LParen) |
838 { | |
839 nT(); | |
840 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
|
841 (size = token.int_), nT(); |
260 | 842 else |
843 expected(T.Int32); | |
844 require(T.RParen); | |
845 } | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
846 return size; |
260 | 847 } |
848 | |
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
|
849 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
|
850 { |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
851 Declaration decl; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
852 |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
853 switch (token.type) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
854 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
855 case T.Align: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
856 uint alignSize = parseAlignAttribute(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
857 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
|
858 this.alignSize = alignSize; // Set. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
859 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
|
860 this.alignSize = saved; // Restore. |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
861 break; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
862 case T.Pragma: |
147 | 863 // Pragma: |
864 // pragma ( Identifier ) | |
865 // pragma ( Identifier , ExpressionList ) | |
866 nT(); | |
245 | 867 Token* ident; |
147 | 868 Expression[] args; |
305 | 869 Declaration decls; |
147 | 870 |
871 require(T.LParen); | |
245 | 872 ident = requireId(); |
147 | 873 |
874 if (token.type == T.Comma) | |
244
829fdb2e2915
- Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents:
243
diff
changeset
|
875 { |
829fdb2e2915
- Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents:
243
diff
changeset
|
876 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
877 args = parseExpressionList(); |
244
829fdb2e2915
- Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents:
243
diff
changeset
|
878 } |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
879 require(T.RParen); |
147 | 880 |
881 if (token.type == T.Semicolon) | |
313
1c1adededd8f
- Fix: assign new EmptyDeclaration to decls when parsing PragmaStatement.
aziz
parents:
312
diff
changeset
|
882 { |
147 | 883 nT(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
884 // TODO: call set()? |
313
1c1adededd8f
- Fix: assign new EmptyDeclaration to decls when parsing PragmaStatement.
aziz
parents:
312
diff
changeset
|
885 decls = new EmptyDeclaration(); |
1c1adededd8f
- Fix: assign new EmptyDeclaration to decls when parsing PragmaStatement.
aziz
parents:
312
diff
changeset
|
886 } |
147 | 887 else |
888 decls = parseDeclarationsBlock(); | |
889 | |
890 decl = new PragmaDeclaration(ident, args, decls); | |
891 break; | |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
892 default: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
893 // Protection attributes |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
894 Protection prot; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
895 switch (token.type) |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
896 { |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
897 case T.Private: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
898 prot = Protection.Private; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
899 case T.Package: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
900 prot = Protection.Package; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
901 case T.Protected: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
902 prot = Protection.Protected; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
903 case T.Public: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
904 prot = Protection.Public; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
905 case T.Export: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
906 prot = Protection.Export; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
907 default: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
908 assert(0); |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
909 } |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
910 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
911 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
|
912 this.protection = prot; // Set. |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
913 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
|
914 this.protection = saved; // Restore. |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
915 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
916 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
|
917 } |
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
|
918 |
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
|
919 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
|
920 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
921 assert(token.type == T.Import || token.type == T.Static); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
922 |
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
|
923 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
|
924 |
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
|
925 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
|
926 { |
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 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
|
928 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
|
929 } |
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 |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
931 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
|
932 |
364 | 933 ModuleFQN[] moduleFQNs; |
263 | 934 Token*[] moduleAliases; |
935 Token*[] bindNames; | |
936 Token*[] bindAliases; | |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
937 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
938 nT(); // Skip import keyword. |
298 | 939 while (1) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
940 { |
364 | 941 ModuleFQN moduleFQN; |
263 | 942 Token* moduleAlias; |
943 | |
944 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
|
945 |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
946 // AliasName = ModuleName |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
947 if (token.type == T.Assign) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
948 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
949 nT(); |
364 | 950 moduleFQN ~= requireId(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
951 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
952 else // import Identifier [^=] |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
953 { |
364 | 954 moduleFQN ~= moduleAlias; |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
955 moduleAlias = null; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
956 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
957 |
298 | 958 // Identifier(.Identifier)* |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
959 while (token.type == T.Dot) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
960 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
961 nT(); |
364 | 962 moduleFQN ~= requireId(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
963 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
964 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
965 // Push identifiers. |
364 | 966 moduleFQNs ~= moduleFQN; |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
967 moduleAliases ~= moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
968 |
298 | 969 if (token.type != T.Comma) |
970 break; | |
971 nT(); | |
972 } | |
973 | |
974 if (token.type == T.Colon) | |
975 { | |
976 // BindAlias = BindName(, BindAlias = BindName)*; | |
977 // BindName(, BindName)*; | |
978 Token* bindName, bindAlias; | |
320
0ce14640eb04
- Fix in parseImportDeclaration(): rewrote while loop and removed a call to nT().
aziz
parents:
319
diff
changeset
|
979 do |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
980 { |
298 | 981 nT(); |
982 bindAlias = requireId(); | |
983 | |
984 if (token.type == T.Assign) | |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
985 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
986 nT(); |
298 | 987 bindName = requireId(); |
988 } | |
989 else | |
990 { | |
991 bindName = bindAlias; | |
992 bindAlias = null; | |
993 } | |
994 | |
995 // Push identifiers. | |
996 bindNames ~= bindName; | |
997 bindAliases ~= bindAlias; | |
320
0ce14640eb04
- Fix in parseImportDeclaration(): rewrote while loop and removed a call to nT().
aziz
parents:
319
diff
changeset
|
998 } while (token.type == T.Comma) |
298 | 999 } |
1000 | |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
1001 require(T.Semicolon); |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
1002 |
366 | 1003 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
|
1004 } |
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
|
1005 |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1006 Declaration parseEnumDeclaration() |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1007 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1008 assert(token.type == T.Enum); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1009 |
264 | 1010 Token* enumName; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1011 Type baseType; |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1012 EnumMember[] members; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
1013 bool hasBody; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1014 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1015 nT(); // Skip enum keyword. |
231 | 1016 |
1017 if (token.type == T.Identifier) | |
1018 { | |
264 | 1019 enumName = token; |
231 | 1020 nT(); |
1021 } | |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1022 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1023 if (token.type == T.Colon) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1024 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1025 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1026 baseType = parseBasicType(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1027 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1028 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1029 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
|
1030 { |
264 | 1031 if (enumName is null) |
231 | 1032 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
|
1033 nT(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1034 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1035 else if (token.type == T.LBrace) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1036 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
1037 hasBody = true; |
398
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1038 nT(); // Skip { |
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1039 while (token.type != T.RBrace) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1040 { |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1041 auto begin = token; |
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1042 auto memberName = requireId(); |
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1043 Expression value; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1044 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1045 if (token.type == T.Assign) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1046 { |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1047 nT(); |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1048 value = parseAssignExpression(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1049 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1050 else |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1051 value = null; |
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1052 |
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1053 members ~= set(new EnumMember(memberName, value), begin); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1054 |
398
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1055 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
|
1056 break; |
398
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1057 nT(); // Skip , |
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1058 } |
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1059 require(T.RBrace); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1060 } |
231 | 1061 else |
1062 error(MID.ExpectedButFound, "enum declaration", token.srcText); | |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1063 |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1064 return new EnumDeclaration(enumName, baseType, members, hasBody); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1065 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1066 |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1067 Declaration parseClassDeclaration() |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1068 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1069 assert(token.type == T.Class); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1070 |
264 | 1071 Token* className; |
258 | 1072 TemplateParameters tparams; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1073 BaseClass[] bases; |
305 | 1074 Declarations decls; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1075 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1076 nT(); // Skip class keyword. |
264 | 1077 className = requireId(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1078 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1079 if (token.type == T.LParen) |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
1080 tparams = parseTemplateParameterList(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1081 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1082 if (token.type == T.Colon) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1083 bases = parseBaseClasses(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1084 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1085 if (token.type == T.Semicolon) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1086 { |
405
e2529923a0cb
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
404
diff
changeset
|
1087 if (bases.length != 0) |
e2529923a0cb
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
404
diff
changeset
|
1088 error(MID.BaseClassInForwardDeclaration); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1089 nT(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1090 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1091 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
|
1092 decls = parseDeclarationDefinitionsBody(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1093 else |
124 | 1094 expected(T.LBrace); // TODO: better error msg |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1095 |
494
9a7ca8c56e59
Refactored a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
493
diff
changeset
|
1096 return new ClassDeclaration(className, tparams, bases, decls); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1097 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1098 |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1099 BaseClass[] parseBaseClasses(bool colonLeadsOff = true) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1100 { |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1101 if (colonLeadsOff) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1102 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1103 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
|
1104 nT(); // Skip colon |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1105 } |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1106 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1107 BaseClass[] bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1108 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1109 while (1) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1110 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1111 Protection prot = Protection.Public; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1112 switch (token.type) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1113 { |
204 | 1114 case T.Identifier, T.Dot, T.Typeof: goto LparseBasicType; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1115 case T.Private: prot = Protection.Private; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1116 case T.Protected: prot = Protection.Protected; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1117 case T.Package: prot = Protection.Package; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1118 case T.Public: /*prot = Protection.Public;*/ break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1119 default: |
405
e2529923a0cb
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
404
diff
changeset
|
1120 error(MID.ExpectedBaseClasses, token.srcText); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1121 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1122 } |
158
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1123 nT(); // Skip protection attribute. |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1124 LparseBasicType: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1125 auto begin = token; |
158
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1126 auto type = parseBasicType(); |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1127 //if (type.tid != TID.DotList) |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1128 // 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
|
1129 bases ~= set(new BaseClass(prot, type), begin); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1130 if (token.type != T.Comma) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1131 break; |
396
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
1132 nT(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1133 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1134 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1135 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1136 |
112 | 1137 Declaration parseInterfaceDeclaration() |
1138 { | |
1139 assert(token.type == T.Interface); | |
1140 | |
264 | 1141 Token* name; |
258 | 1142 TemplateParameters tparams; |
112 | 1143 BaseClass[] bases; |
305 | 1144 Declarations decls; |
112 | 1145 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1146 nT(); // Skip interface keyword. |
264 | 1147 name = requireId(); |
112 | 1148 |
1149 if (token.type == T.LParen) | |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
1150 tparams = parseTemplateParameterList(); |
112 | 1151 |
1152 if (token.type == T.Colon) | |
1153 bases = parseBaseClasses(); | |
1154 | |
1155 if (token.type == T.Semicolon) | |
1156 { | |
405
e2529923a0cb
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
404
diff
changeset
|
1157 if (bases.length != 0) |
e2529923a0cb
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
404
diff
changeset
|
1158 error(MID.BaseClassInForwardDeclaration); |
112 | 1159 nT(); |
1160 } | |
1161 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
|
1162 decls = parseDeclarationDefinitionsBody(); |
112 | 1163 else |
124 | 1164 expected(T.LBrace); // TODO: better error msg |
112 | 1165 |
494
9a7ca8c56e59
Refactored a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
493
diff
changeset
|
1166 return new InterfaceDeclaration(name, tparams, bases, decls); |
112 | 1167 } |
1168 | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1169 Declaration parseAggregateDeclaration() |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1170 { |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1171 assert(token.type == T.Struct || token.type == T.Union); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1172 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1173 TOK tok = token.type; |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1174 |
264 | 1175 Token* name; |
258 | 1176 TemplateParameters tparams; |
305 | 1177 Declarations decls; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1178 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1179 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
|
1180 // name is optional. |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1181 if (token.type == T.Identifier) |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1182 { |
264 | 1183 name = token; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1184 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1185 if (token.type == T.LParen) |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
1186 tparams = parseTemplateParameterList(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1187 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1188 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1189 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
|
1190 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1191 //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
|
1192 // TODO: error: forward declarations must have a name. |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1193 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1194 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1195 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
|
1196 decls = parseDeclarationDefinitionsBody(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1197 else |
124 | 1198 expected(T.LBrace); // TODO: better error msg |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1199 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1200 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
|
1201 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1202 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
|
1203 d.setAlignSize(this.alignSize); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1204 return d; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1205 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1206 else |
494
9a7ca8c56e59
Refactored a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
493
diff
changeset
|
1207 return new UnionDeclaration(name, tparams, decls); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1208 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1209 |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1210 Declaration parseConstructorDeclaration() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1211 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1212 assert(token.type == T.This); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1213 nT(); // Skip 'this' keyword. |
143 | 1214 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1215 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1216 return new ConstructorDeclaration(parameters, funcBody); |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1217 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1218 |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1219 Declaration parseDestructorDeclaration() |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1220 { |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1221 assert(token.type == T.Tilde); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1222 nT(); // Skip ~ |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1223 require(T.This); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1224 require(T.LParen); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1225 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1226 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1227 return new DestructorDeclaration(funcBody); |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1228 } |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1229 |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1230 Declaration parseStaticConstructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1231 { |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1232 assert(token.type == T.Static); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1233 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1234 nT(); // Skip 'this' keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1235 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1236 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1237 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1238 return new StaticConstructorDeclaration(funcBody); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1239 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1240 |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1241 Declaration parseStaticDestructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1242 { |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1243 assert(token.type == T.Static); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1244 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1245 nT(); // Skip ~ |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1246 require(T.This); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1247 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1248 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1249 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1250 return new StaticDestructorDeclaration(funcBody); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1251 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1252 |
120 | 1253 Declaration parseInvariantDeclaration() |
1254 { | |
1255 assert(token.type == T.Invariant); | |
1256 nT(); // Skip invariant keyword. | |
1257 // Optional () for getting ready porting to D 2.0 | |
1258 if (token.type == T.LParen) | |
122 | 1259 requireNext(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1260 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1261 return new InvariantDeclaration(funcBody); |
120 | 1262 } |
1263 | |
121 | 1264 Declaration parseUnittestDeclaration() |
1265 { | |
1266 assert(token.type == T.Unittest); | |
1267 | |
122 | 1268 nT(); // Skip unittest keyword. |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1269 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1270 return new UnittestDeclaration(funcBody); |
121 | 1271 } |
1272 | |
122 | 1273 Declaration parseDebugDeclaration() |
1274 { | |
1275 assert(token.type == T.Debug); | |
1276 | |
1277 nT(); // Skip debug keyword. | |
1278 | |
264 | 1279 Token* spec; // debug = Integer ; |
1280 // debug = Identifier ; | |
1281 Token* cond; // debug ( Integer ) | |
1282 // debug ( Identifier ) | |
305 | 1283 Declaration decls, elseDecls; |
122 | 1284 |
264 | 1285 void parseIdentOrInt(ref Token* tok) |
122 | 1286 { |
1287 nT(); | |
264 | 1288 if (token.type == T.Int32 || |
1289 token.type == T.Identifier) | |
1290 { | |
1291 tok = token; | |
1292 nT(); | |
1293 } | |
122 | 1294 else |
124 | 1295 expected(T.Identifier); // TODO: better error msg |
123 | 1296 } |
1297 | |
1298 if (token.type == T.Assign) | |
1299 { | |
264 | 1300 parseIdentOrInt(spec); |
122 | 1301 require(T.Semicolon); |
1302 } | |
1303 else | |
1304 { | |
123 | 1305 // Condition: |
1306 // Integer | |
1307 // Identifier | |
1308 // ( Condition ) | |
122 | 1309 if (token.type == T.LParen) |
1310 { | |
264 | 1311 parseIdentOrInt(cond); |
122 | 1312 require(T.RParen); |
1313 } | |
1314 | |
123 | 1315 // debug DeclarationsBlock |
1316 // debug ( Condition ) DeclarationsBlock | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1317 decls = parseDeclarationsBlockNoColon(); |
123 | 1318 |
1319 // else DeclarationsBlock | |
264 | 1320 if (token.type == T.Else) |
122 | 1321 { |
123 | 1322 nT(); |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1323 elseDecls = parseDeclarationsBlockNoColon(); |
123 | 1324 } |
1325 } | |
1326 | |
264 | 1327 return new DebugDeclaration(spec, cond, decls, elseDecls); |
123 | 1328 } |
1329 | |
1330 Declaration parseVersionDeclaration() | |
1331 { | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
1332 assert(token.type == T.Version); |
123 | 1333 |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
1334 nT(); // Skip version keyword. |
123 | 1335 |
264 | 1336 Token* spec; // version = Integer ; |
1337 // version = Identifier ; | |
1338 Token* cond; // version ( Integer ) | |
1339 // version ( Identifier ) | |
305 | 1340 Declaration decls, elseDecls; |
122 | 1341 |
264 | 1342 void parseIdentOrInt(ref Token* tok) |
123 | 1343 { |
264 | 1344 if (token.type == T.Int32 || |
1345 token.type == T.Identifier) | |
1346 { | |
1347 tok = token; | |
1348 nT(); | |
1349 } | |
123 | 1350 else |
124 | 1351 expected(T.Identifier); // TODO: better error msg |
123 | 1352 } |
1353 | |
1354 if (token.type == T.Assign) | |
1355 { | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1356 nT(); |
264 | 1357 parseIdentOrInt(spec); |
123 | 1358 require(T.Semicolon); |
1359 } | |
1360 else | |
1361 { | |
1362 // Condition: | |
1363 // Integer | |
1364 // Identifier | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
1365 |
123 | 1366 // ( Condition ) |
1367 require(T.LParen); | |
264 | 1368 parseIdentOrInt(cond); |
123 | 1369 require(T.RParen); |
1370 | |
1371 // version ( Condition ) DeclarationsBlock | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1372 decls = parseDeclarationsBlockNoColon(); |
123 | 1373 |
1374 // else DeclarationsBlock | |
1375 if (token.type == T.Else) | |
1376 { | |
1377 nT(); | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1378 elseDecls = parseDeclarationsBlockNoColon(); |
122 | 1379 } |
1380 } | |
1381 | |
264 | 1382 return new VersionDeclaration(spec, cond, decls, elseDecls); |
122 | 1383 } |
1384 | |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1385 Declaration parseStaticIfDeclaration() |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1386 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1387 assert(token.type == T.Static); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1388 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1389 nT(); // Skip static keyword. |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1390 nT(); // Skip if keyword. |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1391 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1392 Expression condition; |
305 | 1393 Declaration ifDecls, elseDecls; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1394 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1395 require(T.LParen); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1396 condition = parseAssignExpression(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1397 require(T.RParen); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1398 |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1399 ifDecls = parseDeclarationsBlockNoColon(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1400 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1401 if (token.type == T.Else) |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1402 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1403 nT(); |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1404 elseDecls = parseDeclarationsBlockNoColon(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1405 } |
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 return new StaticIfDeclaration(condition, ifDecls, elseDecls); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1408 } |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1409 |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1410 Declaration parseStaticAssertDeclaration() |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1411 { |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1412 assert(token.type == T.Static); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1413 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1414 nT(); // Skip static keyword. |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1415 nT(); // Skip assert keyword. |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1416 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1417 Expression condition, message; |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1418 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1419 require(T.LParen); |
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 condition = parseAssignExpression(); |
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 if (token.type == T.Comma) |
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 nT(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1426 message = parseAssignExpression(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1427 } |
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 require(T.RParen); |
128 | 1430 require(T.Semicolon); |
127
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 return new StaticAssertDeclaration(condition, message); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1433 } |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1434 |
140 | 1435 Declaration parseTemplateDeclaration() |
1436 { | |
1437 assert(token.type == T.Template); | |
1438 nT(); // Skip template keyword. | |
265 | 1439 auto templateName = requireId(); |
143 | 1440 auto templateParams = parseTemplateParameterList(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1441 auto decls = parseDeclarationDefinitionsBody(); |
140 | 1442 return new TemplateDeclaration(templateName, templateParams, decls); |
1443 } | |
1444 | |
141 | 1445 Declaration parseNewDeclaration() |
1446 { | |
1447 assert(token.type == T.New); | |
1448 nT(); // Skip new keyword. | |
143 | 1449 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1450 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1451 return new NewDeclaration(parameters, funcBody); |
141 | 1452 } |
1453 | |
1454 Declaration parseDeleteDeclaration() | |
1455 { | |
1456 assert(token.type == T.Delete); | |
1457 nT(); // Skip delete keyword. | |
143 | 1458 auto parameters = parseParameterList(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1459 // 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
|
1460 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1461 return new DeleteDeclaration(parameters, funcBody); |
141 | 1462 } |
1463 | |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1464 Type parseTypeofType() |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1465 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1466 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
|
1467 Type type; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1468 requireNext(T.LParen); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1469 switch (token.type) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1470 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1471 version(D2) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1472 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1473 case T.Return: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1474 nT(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1475 type = new TypeofType(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1476 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1477 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1478 default: |
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(parseExpression()); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1480 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1481 require(T.RParen); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1482 return type; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1483 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1484 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1485 /+ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1486 DotListExpression: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1487 . DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1488 DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1489 Typeof |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1490 Typeof . DotListItems |
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 DotListItem |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1493 DotListItem . DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1494 DotListItem: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1495 Identifier |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1496 TemplateInstance |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1497 NewExpression |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1498 TemplateInstance: |
233 | 1499 Identifier !( TemplateArguments ) |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1500 +/ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1501 DotListExpression parseDotListExpression() |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1502 { |
233 | 1503 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
|
1504 auto begin = token; |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1505 Expression[] identList; |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1506 if (token.type == T.Dot) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1507 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1508 nT(); |
488
cfb3805768b6
Added DotExpression and DotType.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
486
diff
changeset
|
1509 identList ~= set(new DotExpression(), begin); |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1510 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1511 else if (token.type == T.Typeof) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1512 { |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1513 auto type = parseTypeofType(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1514 set(type, begin); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1515 identList ~= set(new TypeofExpression(type), begin); |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1516 if (token.type != T.Dot) |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1517 goto Lreturn; |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1518 nT(); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1519 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1520 |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1521 while (1) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1522 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1523 begin = token; |
252
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1524 auto ident = requireId(); |
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1525 Expression e; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1526 if (token.type == T.Not && peekNext() == T.LParen) // Identifier !( TemplateArguments ) |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1527 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1528 nT(); // Skip !. |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1529 e = set(new TemplateInstanceExpression(ident, parseTemplateArguments()), begin); |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1530 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1531 else // Identifier |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1532 e = set(new IdentifierExpression(ident), begin); |
252
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1533 |
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1534 identList ~= e; |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1535 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1536 LnewExpressionLoop: |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1537 if (token.type != T.Dot) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1538 break; |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1539 nT(); // Skip dot. |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1540 |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1541 if (token.type == T.New) |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1542 { |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1543 identList ~= parseNewExpression(); |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1544 goto LnewExpressionLoop; |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1545 } |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1546 } |
233 | 1547 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1548 Lreturn: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1549 return new DotListExpression(identList); |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1550 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1551 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1552 /+ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1553 DotListType: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1554 . TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1555 TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1556 Typeof |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1557 Typeof . TypeItems |
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 TypeItem |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1560 TypeItem . TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1561 TypeItem: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1562 Identifier |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1563 TemplateInstance |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1564 TemplateInstance: |
233 | 1565 Identifier !( TemplateArguments ) |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1566 +/ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1567 DotListType parseDotListType() |
153 | 1568 { |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1569 auto begin = token; |
153 | 1570 Type[] identList; |
1571 if (token.type == T.Dot) | |
1572 { | |
1573 nT(); | |
488
cfb3805768b6
Added DotExpression and DotType.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
486
diff
changeset
|
1574 identList ~= set(new DotType(), begin); |
153 | 1575 } |
1576 else if (token.type == T.Typeof) | |
1577 { | |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1578 identList ~= set(parseTypeofType(), begin); |
153 | 1579 if (token.type != T.Dot) |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1580 goto Lreturn; |
153 | 1581 nT(); |
1582 } | |
1583 | |
1584 while (1) | |
1585 { | |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1586 begin = token; |
264 | 1587 auto ident = requireId(); |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1588 // 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
|
1589 if (token.type == T.Not/+ && peekNext() == T.LParen+/) // Identifier !( TemplateArguments ) |
153 | 1590 { |
1591 nT(); // Skip !. | |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1592 identList ~= set(new TemplateInstanceType(ident, parseTemplateArguments()), begin); |
153 | 1593 } |
1594 else // Identifier | |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1595 identList ~= set(new IdentifierType(ident), begin); |
153 | 1596 |
1597 if (token.type != T.Dot) | |
1598 break; | |
1599 nT(); | |
1600 } | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1601 Lreturn: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1602 return new DotListType(identList); |
153 | 1603 } |
1604 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1605 /* |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1606 TemplateMixin: |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1607 mixin ( AssignExpression ) ; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1608 mixin TemplateIdentifier ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1609 mixin TemplateIdentifier MixinIdentifier ; |
233 | 1610 mixin TemplateIdentifier !( TemplateArguments ) ; |
1611 mixin TemplateIdentifier !( TemplateArguments ) MixinIdentifier ; | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1612 */ |
256 | 1613 Class parseMixin(Class)() |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1614 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1615 assert(token.type == T.Mixin); |
256 | 1616 auto begin = token; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1617 nT(); // Skip mixin keyword. |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1618 |
256 | 1619 static if (is(Class == MixinDeclaration)) |
301
caef255a2801
- Fix in some ctors: adding only non-null members to this.children.
aziz
parents:
299
diff
changeset
|
1620 { |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1621 if (token.type == T.LParen) |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1622 { |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1623 // TODO: What about mixin(...).ident;? |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1624 nT(); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1625 auto e = parseAssignExpression(); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1626 require(T.RParen); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1627 require(T.Semicolon); |
262 | 1628 return new MixinDeclaration(e); |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1629 } |
301
caef255a2801
- Fix in some ctors: adding only non-null members to this.children.
aziz
parents:
299
diff
changeset
|
1630 } |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1631 |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1632 Expression[] templateIdent; |
252
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1633 Token* mixinIdent; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1634 |
159 | 1635 // This code is similar to parseDotListType(). |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1636 if (token.type == T.Dot) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1637 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1638 nT(); |
488
cfb3805768b6
Added DotExpression and DotType.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
486
diff
changeset
|
1639 templateIdent ~= set(new DotExpression(), begin); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1640 } |
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 while (1) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1643 { |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1644 begin = token; |
252
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1645 auto ident = requireId(); |
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1646 Expression e; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1647 if (token.type == T.Not) // Identifier !( TemplateArguments ) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1648 { |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1649 // 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
|
1650 nT(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1651 e = set(new TemplateInstanceExpression(ident, parseTemplateArguments()), begin); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1652 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1653 else // Identifier |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1654 e = set(new IdentifierExpression(ident), begin); |
252
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1655 |
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1656 templateIdent ~= e; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1657 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1658 if (token.type != T.Dot) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1659 break; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1660 nT(); |
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 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1663 if (token.type == T.Identifier) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1664 { |
252
788398655d24
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
251
diff
changeset
|
1665 mixinIdent = token; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1666 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1667 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1668 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1669 require(T.Semicolon); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1670 |
262 | 1671 return new Class(templateIdent, mixinIdent); |
150
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 |
102 | 1674 /+++++++++++++++++++++++++++++ |
161 | 1675 + Statement parsing methods + |
1676 +++++++++++++++++++++++++++++/ | |
1677 | |
1678 Statements parseStatements() | |
1679 { | |
262 | 1680 auto begin = token; |
318 | 1681 require(T.LBrace); |
162 | 1682 auto statements = new Statements(); |
161 | 1683 while (token.type != T.RBrace && token.type != T.EOF) |
1684 statements ~= parseStatement(); | |
318 | 1685 require(T.RBrace); |
262 | 1686 return set(statements, begin); |
161 | 1687 } |
1688 | |
1689 Statement parseStatement() | |
1690 { | |
261 | 1691 auto begin = token; |
161 | 1692 Statement s; |
188 | 1693 Declaration d; |
161 | 1694 switch (token.type) |
1695 { | |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1696 case T.Align: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1697 uint size = parseAlignAttribute(); |
260 | 1698 // 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
|
1699 StructDeclaration structDecl; |
260 | 1700 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
|
1701 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1702 auto begin2 = token; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1703 structDecl = CastTo!(StructDeclaration)(parseAggregateDeclaration()); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1704 structDecl.setAlignSize(size); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1705 set(structDecl, begin2); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1706 } |
260 | 1707 else |
1708 expected(T.Struct); | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1709 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1710 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
|
1711 goto LreturnDeclarationStatement; |
201 | 1712 /+ Not applicable for statements. |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1713 // T.Private, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1714 // T.Package, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1715 // T.Protected, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1716 // T.Public, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1717 // T.Export, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1718 // T.Deprecated, |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1719 // T.Override, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1720 // T.Abstract, |
201 | 1721 +/ |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1722 case T.Extern, |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1723 T.Final, |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1724 T.Const, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1725 T.Auto: |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1726 //T.Scope |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1727 //T.Static |
201 | 1728 case_parseAttribute: |
1729 s = parseAttributeStatement(); | |
261 | 1730 return s; |
161 | 1731 case T.Identifier: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1732 if (peekNext() == T.Colon) |
161 | 1733 { |
264 | 1734 auto ident = token; |
161 | 1735 nT(); // Skip Identifier |
1736 nT(); // Skip : | |
234 | 1737 s = new LabeledStatement(ident, parseNoScopeOrEmptyStatement()); |
161 | 1738 break; |
1739 } | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1740 goto case T.Dot; |
201 | 1741 case T.Dot, T.Typeof: |
214 | 1742 bool success; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1743 d = try_(delegate { |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1744 return parseVariableOrFunction(StorageClass.None, |
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1745 Protection.None, |
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1746 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
|
1747 }, success |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1748 ); |
214 | 1749 if (success) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1750 goto LreturnDeclarationStatement; // Declaration |
201 | 1751 else |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1752 goto case_parseExpressionStatement; // Expression |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1753 // IntegralType |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1754 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
|
1755 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
|
1756 T.Int, T.Uint, T.Long, T.Ulong, |
201 | 1757 T.Float, T.Double, T.Real, |
1758 T.Ifloat, T.Idouble, T.Ireal, | |
1759 T.Cfloat, T.Cdouble, T.Creal, T.Void: | |
1760 case_parseDeclaration: | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1761 d = parseVariableOrFunction(); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1762 goto LreturnDeclarationStatement; |
162 | 1763 case T.If: |
1764 s = parseIfStatement(); | |
1765 break; | |
164 | 1766 case T.While: |
1767 s = parseWhileStatement(); | |
1768 break; | |
165 | 1769 case T.Do: |
1770 s = parseDoWhileStatement(); | |
1771 break; | |
216 | 1772 case T.For: |
1773 s = parseForStatement(); | |
1774 break; | |
169 | 1775 case T.Foreach, T.Foreach_reverse: |
1776 s = parseForeachStatement(); | |
1777 break; | |
170 | 1778 case T.Switch: |
1779 s = parseSwitchStatement(); | |
1780 break; | |
171 | 1781 case T.Case: |
1782 s = parseCaseStatement(); | |
1783 break; | |
172 | 1784 case T.Default: |
1785 s = parseDefaultStatement(); | |
1786 break; | |
173 | 1787 case T.Continue: |
1788 s = parseContinueStatement(); | |
1789 break; | |
174 | 1790 case T.Break: |
1791 s = parseBreakStatement(); | |
1792 break; | |
175 | 1793 case T.Return: |
1794 s = parseReturnStatement(); | |
1795 break; | |
176 | 1796 case T.Goto: |
1797 s = parseGotoStatement(); | |
1798 break; | |
177 | 1799 case T.With: |
1800 s = parseWithStatement(); | |
1801 break; | |
178 | 1802 case T.Synchronized: |
1803 s = parseSynchronizedStatement(); | |
1804 break; | |
179 | 1805 case T.Try: |
1806 s = parseTryStatement(); | |
1807 break; | |
180 | 1808 case T.Throw: |
1809 s = parseThrowStatement(); | |
1810 break; | |
181 | 1811 case T.Scope: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1812 if (peekNext() != T.LParen) |
201 | 1813 goto case_parseAttribute; |
181 | 1814 s = parseScopeGuardStatement(); |
1815 break; | |
182 | 1816 case T.Volatile: |
1817 s = parseVolatileStatement(); | |
1818 break; | |
183 | 1819 case T.Asm: |
1820 s = parseAsmStatement(); | |
1821 break; | |
184 | 1822 case T.Pragma: |
1823 s = parsePragmaStatement(); | |
1824 break; | |
185 | 1825 case T.Mixin: |
246
52f4aa097865
- Fix: parse mixin as expression instead of statement when next token is T.LParen.
aziz
parents:
245
diff
changeset
|
1826 if (peekNext() == T.LParen) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1827 goto case_parseExpressionStatement; // Parse as expression. |
256 | 1828 s = parseMixin!(MixinStatement)(); |
185 | 1829 break; |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1830 case T.Static: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1831 switch (peekNext()) |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1832 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1833 case T.If: |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1834 s = parseStaticIfStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1835 break; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1836 case T.Assert: |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1837 s = parseStaticAssertStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1838 break; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1839 default: |
201 | 1840 goto case_parseAttribute; |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1841 } |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1842 break; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1843 case T.Debug: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1844 s = parseDebugStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1845 break; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1846 case T.Version: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1847 s = parseVersionStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1848 break; |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1849 // DeclDef |
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1850 case T.Alias, T.Typedef: |
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1851 d = parseDeclarationDefinition(); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1852 goto LreturnDeclarationStatement; |
188 | 1853 case T.Enum: |
1854 d = parseEnumDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1855 goto LreturnDeclarationStatement; |
188 | 1856 case T.Class: |
1857 d = parseClassDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1858 goto LreturnDeclarationStatement; |
188 | 1859 case T.Interface: |
1860 d = parseInterfaceDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1861 goto LreturnDeclarationStatement; |
188 | 1862 case T.Struct, T.Union: |
1863 d = parseAggregateDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1864 // goto LreturnDeclarationStatement; |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1865 LreturnDeclarationStatement: |
261 | 1866 set(d, begin); |
188 | 1867 s = new DeclarationStatement(d); |
1868 break; | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1869 case T.LBrace: |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1870 s = parseScopeStatement(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1871 break; |
216 | 1872 case T.Semicolon: |
231 | 1873 nT(); |
216 | 1874 s = new EmptyStatement(); |
1875 break; | |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1876 /+ |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1877 Parse ExpressionStatement: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1878 +/ |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1879 // 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
|
1880 // 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
|
1881 case T.This: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1882 case T.Super: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1883 case T.Null: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1884 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
|
1885 // case T.Dollar: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1886 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
|
1887 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
|
1888 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
|
1889 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
|
1890 case T.String: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1891 case T.LBracket: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1892 // case T.LBrace: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1893 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
|
1894 case T.Assert: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1895 // case T.Mixin: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1896 case T.Import: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1897 case T.Typeid: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1898 case T.Is: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1899 case T.LParen: |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1900 /+ // IntegralType |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1901 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
|
1902 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
|
1903 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
|
1904 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
|
1905 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
|
1906 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
|
1907 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
|
1908 // 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
|
1909 case T.AndBinary, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1910 T.PlusPlus, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1911 T.MinusMinus, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1912 T.Mul, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1913 T.Minus, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1914 T.Plus, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1915 T.Not, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1916 T.Tilde, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1917 T.New, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1918 T.Delete, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1919 T.Cast: |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1920 case_parseExpressionStatement: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1921 s = new ExpressionStatement(parseExpression()); |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1922 require(T.Semicolon); |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1923 break; |
161 | 1924 default: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1925 if (token.isSpecialToken) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1926 goto case_parseExpressionStatement; |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1927 |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1928 if (token.type != T.Dollar) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1929 // 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
|
1930 assert(delegate bool(){ |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1931 bool success; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1932 auto expression = try_(&parseExpression, success); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1933 return success; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1934 }() == 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
|
1935 ); |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1936 |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1937 // 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
|
1938 s = new IllegalStatement(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1939 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1940 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1941 nT(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1942 while (!token.isStatementStart && |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1943 token.type != T.RBrace && |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1944 token.type != T.EOF) |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1945 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
|
1946 error(begin, "illegal Statement found: " ~ text); |
161 | 1947 } |
205 | 1948 assert(s !is null); |
261 | 1949 set(s, begin); |
161 | 1950 return s; |
1951 } | |
1952 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1953 /++ |
162 | 1954 ScopeStatement: |
219 | 1955 NoScopeStatement |
162 | 1956 +/ |
164 | 1957 Statement parseScopeStatement() |
162 | 1958 { |
219 | 1959 return new ScopeStatement(parseNoScopeStatement()); |
162 | 1960 } |
1961 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1962 /++ |
166 | 1963 NoScopeStatement: |
1964 NonEmptyStatement | |
1965 BlockStatement | |
1966 BlockStatement: | |
1967 { } | |
1968 { StatementList } | |
1969 +/ | |
1970 Statement parseNoScopeStatement() | |
1971 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1972 auto begin = token; |
166 | 1973 Statement s; |
1974 if (token.type == T.LBrace) | |
1975 { | |
1976 nT(); | |
1977 auto ss = new Statements(); | |
1978 while (token.type != T.RBrace && token.type != T.EOF) | |
1979 ss ~= parseStatement(); | |
1980 require(T.RBrace); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1981 s = set(ss, begin); |
166 | 1982 } |
219 | 1983 else if (token.type == T.Semicolon) |
1984 { | |
1985 error(MID.ExpectedButFound, "non-empty statement", ";"); | |
1986 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1987 s = set(new EmptyStatement(), begin); |
219 | 1988 } |
166 | 1989 else |
1990 s = parseStatement(); | |
1991 return s; | |
1992 } | |
1993 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1994 /++ |
234 | 1995 NoScopeOrEmptyStatement: |
1996 ; | |
1997 NoScopeStatement | |
1998 +/ | |
1999 Statement parseNoScopeOrEmptyStatement() | |
2000 { | |
2001 if (token.type == T.Semicolon) | |
312 | 2002 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2003 auto begin = token; |
234 | 2004 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2005 return set(new EmptyStatement(), begin); |
312 | 2006 } |
234 | 2007 else |
2008 return parseNoScopeStatement(); | |
2009 } | |
2010 | |
201 | 2011 Statement parseAttributeStatement() |
2012 { | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2013 StorageClass stc, stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2014 LinkageType prev_linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2015 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2016 // Nested function. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2017 Declaration parse() |
201 | 2018 { |
261 | 2019 auto begin = token; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2020 Declaration d; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2021 switch (token.type) |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2022 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2023 case T.Extern: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2024 if (peekNext() != T.LParen) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2025 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2026 stc_tmp = StorageClass.Extern; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2027 goto Lcommon; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2028 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2029 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2030 nT(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2031 auto linkageType = parseLinkageType(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2032 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
|
2033 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2034 d = new LinkageDeclaration(linkageType, parse()); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2035 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2036 case T.Static: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2037 stc_tmp = StorageClass.Static; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2038 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2039 case T.Final: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2040 stc_tmp = StorageClass.Final; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2041 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2042 case T.Const: |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2043 version(D2) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2044 { |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2045 if (peekNext() == T.LParen) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2046 goto case_Declaration; |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2047 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2048 stc_tmp = StorageClass.Const; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2049 goto Lcommon; |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2050 version(D2) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2051 { |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2052 case T.Invariant: // D 2.0 |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2053 if (peekNext() == T.LParen) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2054 goto case_Declaration; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2055 stc_tmp = StorageClass.Invariant; |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2056 goto Lcommon; |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2057 } |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2058 case T.Auto: |
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.Auto; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2060 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2061 case T.Scope: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2062 stc_tmp = StorageClass.Scope; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2063 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2064 Lcommon: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2065 // Issue error if redundant. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2066 if (stc & stc_tmp) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2067 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
|
2068 else |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2069 stc |= stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2070 |
269 | 2071 auto tok = token.type; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2072 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2073 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
|
2074 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
|
2075 // 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
|
2076 //case T.Class: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2077 default: |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
2078 case_Declaration: |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
2079 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
|
2080 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2081 return set(d, begin); |
201 | 2082 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2083 return new DeclarationStatement(parse()); |
201 | 2084 } |
2085 | |
162 | 2086 Statement parseIfStatement() |
2087 { | |
2088 assert(token.type == T.If); | |
2089 nT(); | |
2090 | |
283 | 2091 Statement variable; |
162 | 2092 Expression condition; |
2093 Statement ifBody, elseBody; | |
2094 | |
2095 require(T.LParen); | |
283 | 2096 |
2097 Token* ident; | |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2098 auto begin = token; // For start of AutoDeclaration or normal Declaration. |
162 | 2099 // auto Identifier = Expression |
2100 if (token.type == T.Auto) | |
2101 { | |
2102 nT(); | |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
2103 ident = requireId(); |
162 | 2104 require(T.Assign); |
283 | 2105 auto init = parseExpression(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2106 auto v = new VariableDeclaration(null, [ident], [init]); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2107 set(v, ident); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2108 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
|
2109 set(d, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
2110 variable = new DeclarationStatement(d); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2111 set(variable, begin); |
162 | 2112 } |
2113 else | |
2114 { | |
2115 // Declarator = Expression | |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
2116 Type parseDeclaratorAssign() |
162 | 2117 { |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
2118 auto type = parseDeclarator(ident); |
162 | 2119 require(T.Assign); |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
2120 return type; |
162 | 2121 } |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
2122 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
2123 auto type = try_(&parseDeclaratorAssign, success); |
283 | 2124 if (success) |
163
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
2125 { |
283 | 2126 auto init = parseExpression(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2127 auto v = new VariableDeclaration(type, [ident], [init]); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2128 set(v, begin); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2129 variable = new DeclarationStatement(v); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
2130 set(variable, begin); |
163
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
2131 } |
283 | 2132 else |
2133 condition = parseExpression(); | |
162 | 2134 } |
2135 require(T.RParen); | |
164 | 2136 ifBody = parseScopeStatement(); |
162 | 2137 if (token.type == T.Else) |
2138 { | |
2139 nT(); | |
164 | 2140 elseBody = parseScopeStatement(); |
162 | 2141 } |
283 | 2142 return new IfStatement(variable, condition, ifBody, elseBody); |
162 | 2143 } |
2144 | |
164 | 2145 Statement parseWhileStatement() |
2146 { | |
2147 assert(token.type == T.While); | |
2148 nT(); | |
166 | 2149 require(T.LParen); |
164 | 2150 auto condition = parseExpression(); |
166 | 2151 require(T.RParen); |
164 | 2152 return new WhileStatement(condition, parseScopeStatement()); |
2153 } | |
2154 | |
165 | 2155 Statement parseDoWhileStatement() |
2156 { | |
2157 assert(token.type == T.Do); | |
2158 nT(); | |
2159 auto doBody = parseScopeStatement(); | |
2160 require(T.While); | |
166 | 2161 require(T.LParen); |
165 | 2162 auto condition = parseExpression(); |
166 | 2163 require(T.RParen); |
2164 return new DoWhileStatement(condition, doBody); | |
2165 } | |
2166 | |
2167 Statement parseForStatement() | |
2168 { | |
2169 assert(token.type == T.For); | |
2170 nT(); | |
165 | 2171 require(T.LParen); |
166 | 2172 |
2173 Statement init, forBody; | |
2174 Expression condition, increment; | |
2175 | |
2176 if (token.type != T.Semicolon) | |
2177 init = parseNoScopeStatement(); | |
230
8f1790d16753
- Fix: added missing call to parseDeclaratorSuffx() in parseDeclaration.
aziz
parents:
229
diff
changeset
|
2178 else |
8f1790d16753
- Fix: added missing call to parseDeclaratorSuffx() in parseDeclaration.
aziz
parents:
229
diff
changeset
|
2179 nT(); // Skip ; |
166 | 2180 if (token.type != T.Semicolon) |
2181 condition = parseExpression(); | |
168 | 2182 require(T.Semicolon); |
166 | 2183 if (token.type != T.RParen) |
2184 increment = parseExpression(); | |
168 | 2185 require(T.RParen); |
167 | 2186 forBody = parseScopeStatement(); |
166 | 2187 return new ForStatement(init, condition, increment, forBody); |
165 | 2188 } |
2189 | |
169 | 2190 Statement parseForeachStatement() |
2191 { | |
2192 assert(token.type == T.Foreach || token.type == T.Foreach_reverse); | |
2193 TOK tok = token.type; | |
2194 nT(); | |
2195 | |
257 | 2196 auto params = new Parameters; |
269 | 2197 Expression e; // Aggregate or LwrExpression |
169 | 2198 |
2199 require(T.LParen); | |
2200 while (1) | |
2201 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2202 auto paramBegin = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2203 Token* stcTok; |
169 | 2204 Type type; |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
2205 Token* ident; |
169 | 2206 |
2207 switch (token.type) | |
2208 { | |
236
e961d1b957c3
- Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents:
235
diff
changeset
|
2209 case T.Ref, T.Inout: |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2210 stcTok = token; |
169 | 2211 nT(); |
236
e961d1b957c3
- Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents:
235
diff
changeset
|
2212 // fall through |
169 | 2213 case T.Identifier: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2214 auto next = peekNext(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2215 if (next == T.Comma || next == T.Semicolon || next == T.RParen) |
169 | 2216 { |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
2217 ident = token; |
169 | 2218 nT(); |
2219 break; | |
2220 } | |
2221 // fall through | |
2222 default: | |
2223 type = parseDeclarator(ident); | |
2224 } | |
2225 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2226 params ~= set(new Parameter(stcTok, type, ident, null), paramBegin); |
169 | 2227 |
2228 if (token.type != T.Comma) | |
2229 break; | |
2230 nT(); | |
2231 } | |
2232 require(T.Semicolon); | |
269 | 2233 e = parseExpression(); |
2234 version(D2) | |
2235 { //Foreach (ForeachType; LwrExpression .. UprExpression ) ScopeStatement | |
2236 if (token.type == T.Slice) | |
2237 { | |
2238 // if (params.length != 1) | |
2239 // error(MID.XYZ); // TODO: issue error msg | |
2240 nT(); | |
2241 auto upper = parseExpression(); | |
2242 require(T.RParen); | |
2243 auto forBody = parseScopeStatement(); | |
2244 return new ForeachRangeStatement(tok, params, e, upper, forBody); | |
2245 } | |
2246 } | |
2247 // Foreach (ForeachTypeList; Aggregate) ScopeStatement | |
169 | 2248 require(T.RParen); |
2249 auto forBody = parseScopeStatement(); | |
269 | 2250 return new ForeachStatement(tok, params, e, forBody); |
169 | 2251 } |
2252 | |
170 | 2253 Statement parseSwitchStatement() |
2254 { | |
2255 assert(token.type == T.Switch); | |
2256 nT(); | |
2257 | |
2258 require(T.LParen); | |
2259 auto condition = parseExpression(); | |
2260 require(T.RParen); | |
2261 auto switchBody = parseScopeStatement(); | |
2262 return new SwitchStatement(condition, switchBody); | |
2263 } | |
2264 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2265 /++ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2266 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
|
2267 a default or case statement. |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2268 +/ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2269 Statement parseCaseOrDefaultBody() |
220 | 2270 { |
2271 // 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
|
2272 auto begin = token; |
224 | 2273 auto s = new Statements(); |
2274 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
|
2275 token.type != T.Default && |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2276 token.type != T.RBrace && |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2277 token.type != T.EOF) |
224 | 2278 s ~= parseStatement(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2279 return set(new ScopeStatement(s), begin); |
220 | 2280 } |
2281 | |
171 | 2282 Statement parseCaseStatement() |
2283 { | |
2284 assert(token.type == T.Case); | |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
2285 nT(); |
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
2286 auto values = parseExpressionList(); |
171 | 2287 require(T.Colon); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2288 auto caseBody = parseCaseOrDefaultBody(); |
171 | 2289 return new CaseStatement(values, caseBody); |
2290 } | |
2291 | |
172 | 2292 Statement parseDefaultStatement() |
2293 { | |
2294 assert(token.type == T.Default); | |
2295 nT(); | |
2296 require(T.Colon); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2297 auto defaultBody = parseCaseOrDefaultBody(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2298 return new DefaultStatement(defaultBody); |
172 | 2299 } |
2300 | |
173 | 2301 Statement parseContinueStatement() |
2302 { | |
2303 assert(token.type == T.Continue); | |
2304 nT(); | |
264 | 2305 Token* ident; |
173 | 2306 if (token.type == T.Identifier) |
2307 { | |
264 | 2308 ident = token; |
173 | 2309 nT(); |
2310 } | |
2311 require(T.Semicolon); | |
2312 return new ContinueStatement(ident); | |
2313 } | |
2314 | |
174 | 2315 Statement parseBreakStatement() |
2316 { | |
2317 assert(token.type == T.Break); | |
2318 nT(); | |
264 | 2319 Token* ident; |
174 | 2320 if (token.type == T.Identifier) |
2321 { | |
264 | 2322 ident = token; |
174 | 2323 nT(); |
2324 } | |
2325 require(T.Semicolon); | |
2326 return new BreakStatement(ident); | |
2327 } | |
2328 | |
175 | 2329 Statement parseReturnStatement() |
2330 { | |
2331 assert(token.type == T.Return); | |
2332 nT(); | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2333 Expression expr; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2334 if (token.type != T.Semicolon) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2335 expr = parseExpression(); |
175 | 2336 require(T.Semicolon); |
2337 return new ReturnStatement(expr); | |
2338 } | |
2339 | |
176 | 2340 Statement parseGotoStatement() |
2341 { | |
2342 assert(token.type == T.Goto); | |
2343 nT(); | |
264 | 2344 Token* ident; |
176 | 2345 Expression caseExpr; |
2346 switch (token.type) | |
2347 { | |
2348 case T.Case: | |
2349 nT(); | |
2350 if (token.type == T.Semicolon) | |
2351 break; | |
2352 caseExpr = parseExpression(); | |
2353 break; | |
2354 case T.Default: | |
2355 nT(); | |
2356 break; | |
2357 default: | |
264 | 2358 ident = requireId(); |
176 | 2359 } |
2360 require(T.Semicolon); | |
2361 return new GotoStatement(ident, caseExpr); | |
2362 } | |
2363 | |
177 | 2364 Statement parseWithStatement() |
2365 { | |
2366 assert(token.type == T.With); | |
2367 nT(); | |
2368 require(T.LParen); | |
2369 auto expr = parseExpression(); | |
2370 require(T.RParen); | |
2371 return new WithStatement(expr, parseScopeStatement()); | |
2372 } | |
2373 | |
178 | 2374 Statement parseSynchronizedStatement() |
2375 { | |
2376 assert(token.type == T.Synchronized); | |
2377 nT(); | |
2378 Expression expr; | |
2379 | |
2380 if (token.type == T.LParen) | |
2381 { | |
2382 nT(); | |
2383 expr = parseExpression(); | |
2384 require(T.RParen); | |
2385 } | |
2386 return new SynchronizedStatement(expr, parseScopeStatement()); | |
2387 } | |
2388 | |
179 | 2389 Statement parseTryStatement() |
2390 { | |
2391 assert(token.type == T.Try); | |
2392 nT(); | |
2393 | |
2394 auto tryBody = parseScopeStatement(); | |
2395 CatchBody[] catchBodies; | |
2396 FinallyBody finBody; | |
2397 | |
2398 while (token.type == T.Catch) | |
2399 { | |
2400 nT(); | |
2401 Parameter param; | |
2402 if (token.type == T.LParen) | |
2403 { | |
229 | 2404 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2405 auto begin = token; |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
2406 Token* ident; |
369 | 2407 auto type = parseDeclarator(ident, true); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2408 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
|
2409 set(param, begin); |
179 | 2410 require(T.RParen); |
2411 } | |
2412 catchBodies ~= new CatchBody(param, parseNoScopeStatement()); | |
2413 if (param is null) | |
2414 break; // This is a LastCatch | |
2415 } | |
2416 | |
2417 if (token.type == T.Finally) | |
2418 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2419 auto begin = token; |
179 | 2420 nT(); |
2421 finBody = new FinallyBody(parseNoScopeStatement()); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2422 set(finBody, begin); |
179 | 2423 } |
2424 | |
396
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
2425 if (catchBodies.length == 0 && finBody is null) |
179 | 2426 { |
2427 // TODO: issue error msg. | |
2428 } | |
2429 | |
2430 return new TryStatement(tryBody, catchBodies, finBody); | |
2431 } | |
2432 | |
180 | 2433 Statement parseThrowStatement() |
2434 { | |
2435 assert(token.type == T.Throw); | |
2436 nT(); | |
2437 auto expr = parseExpression(); | |
2438 require(T.Semicolon); | |
2439 return new ThrowStatement(expr); | |
2440 } | |
2441 | |
181 | 2442 Statement parseScopeGuardStatement() |
2443 { | |
2444 assert(token.type == T.Scope); | |
2445 nT(); | |
2446 assert(token.type == T.LParen); | |
2447 nT(); | |
2448 | |
264 | 2449 Token* condition = requireId(); |
2450 if (condition) | |
2451 switch (condition.identifier) | |
181 | 2452 { |
2453 case "exit": | |
2454 case "success": | |
2455 case "failure": | |
2456 break; | |
2457 default: | |
2458 // TODO: issue error msg. | |
2459 } | |
2460 require(T.RParen); | |
2461 Statement scopeBody; | |
2462 if (token.type == T.LBrace) | |
2463 scopeBody = parseScopeStatement(); | |
2464 else | |
2465 scopeBody = parseNoScopeStatement(); | |
2466 return new ScopeGuardStatement(condition, scopeBody); | |
2467 } | |
2468 | |
182 | 2469 Statement parseVolatileStatement() |
2470 { | |
2471 assert(token.type == T.Volatile); | |
2472 nT(); | |
2473 Statement volatileBody; | |
2474 if (token.type == T.Semicolon) | |
2475 nT(); | |
2476 else if (token.type == T.LBrace) | |
2477 volatileBody = parseScopeStatement(); | |
2478 else | |
219 | 2479 volatileBody = parseStatement(); |
182 | 2480 return new VolatileStatement(volatileBody); |
2481 } | |
2482 | |
184 | 2483 Statement parsePragmaStatement() |
2484 { | |
2485 assert(token.type == T.Pragma); | |
2486 nT(); | |
2487 | |
245 | 2488 Token* ident; |
184 | 2489 Expression[] args; |
2490 Statement pragmaBody; | |
2491 | |
2492 require(T.LParen); | |
245 | 2493 ident = requireId(); |
184 | 2494 |
2495 if (token.type == T.Comma) | |
244
829fdb2e2915
- Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents:
243
diff
changeset
|
2496 { |
829fdb2e2915
- Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents:
243
diff
changeset
|
2497 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2498 args = parseExpressionList(); |
244
829fdb2e2915
- Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents:
243
diff
changeset
|
2499 } |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2500 require(T.RParen); |
184 | 2501 |
234 | 2502 pragmaBody = parseNoScopeOrEmptyStatement(); |
184 | 2503 |
2504 return new PragmaStatement(ident, args, pragmaBody); | |
2505 } | |
2506 | |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2507 Statement parseStaticIfStatement() |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2508 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2509 assert(token.type == T.Static); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2510 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2511 assert(token.type == T.If); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2512 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2513 Expression condition; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2514 Statement ifBody, elseBody; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2515 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2516 require(T.LParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2517 condition = parseExpression(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2518 require(T.RParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2519 ifBody = parseNoScopeStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2520 if (token.type == T.Else) |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2521 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2522 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2523 elseBody = parseNoScopeStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2524 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2525 return new StaticIfStatement(condition, ifBody, elseBody); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2526 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2527 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2528 Statement parseStaticAssertStatement() |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2529 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2530 assert(token.type == T.Static); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2531 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2532 assert(token.type == T.Assert); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2533 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2534 Expression condition, message; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2535 require(T.LParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2536 condition = parseAssignExpression(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2537 if (token.type == T.Comma) |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2538 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2539 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2540 message = parseAssignExpression(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2541 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2542 require(T.RParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2543 require(T.Semicolon); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2544 return new StaticAssertStatement(condition, message); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2545 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2546 |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2547 Statement parseDebugStatement() |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2548 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2549 assert(token.type == T.Debug); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2550 nT(); // Skip debug keyword. |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2551 |
264 | 2552 Token* cond; // debug ( Integer ) |
2553 // debug ( Identifier ) | |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2554 Statement debugBody, elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2555 |
264 | 2556 void parseIdentOrInt(ref Token* tok) |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2557 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2558 nT(); |
264 | 2559 if (token.type == T.Int32 || |
2560 token.type == T.Identifier) | |
2561 { | |
2562 tok = token; | |
2563 nT(); | |
2564 } | |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2565 else |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2566 expected(T.Identifier); // TODO: better error msg |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2567 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2568 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2569 // if (token.type == T.Assign) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2570 // { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2571 // parseIdentOrInt(identSpec, levelSpec); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2572 // require(T.Semicolon); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2573 // } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2574 // else |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2575 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2576 // Condition: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2577 // Integer |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2578 // Identifier |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2579 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2580 // ( Condition ) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2581 if (token.type == T.LParen) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2582 { |
264 | 2583 parseIdentOrInt(cond); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2584 require(T.RParen); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2585 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2586 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2587 // debug Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2588 // debug ( Condition ) Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2589 debugBody = parseNoScopeStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2590 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2591 // else Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2592 if (token.type == T.Else) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2593 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2594 // debug without condition and else body makes no sense |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2595 //if (levelCond == -1 && identCond.length == 0) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2596 // TODO: issue error msg |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2597 nT(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2598 elseBody = parseNoScopeStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2599 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2600 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2601 |
264 | 2602 return new DebugStatement(cond, debugBody, elseBody); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2603 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2604 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2605 Statement parseVersionStatement() |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2606 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2607 assert(token.type == T.Version); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2608 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2609 nT(); // Skip version keyword. |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2610 |
264 | 2611 Token* cond; // version ( Integer ) |
2612 // version ( Identifier ) | |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2613 Statement versionBody, elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2614 |
264 | 2615 void parseIdentOrInt(ref Token* tok) |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2616 { |
264 | 2617 if (token.type == T.Int32 || |
2618 token.type == T.Identifier) | |
2619 { | |
2620 tok = token; | |
2621 nT(); | |
2622 } | |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2623 else |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2624 expected(T.Identifier); // TODO: better error msg |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2625 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2626 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2627 // if (token.type == T.Assign) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2628 // { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2629 // parseIdentOrInt(identSpec, levelSpec); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2630 // require(T.Semicolon); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2631 // } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2632 // else |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2633 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2634 // Condition: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2635 // Integer |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2636 // Identifier |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2637 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2638 // ( Condition ) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2639 require(T.LParen); |
264 | 2640 parseIdentOrInt(cond); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2641 require(T.RParen); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2642 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2643 // version ( Condition ) Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2644 versionBody = parseNoScopeStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2645 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2646 // else Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2647 if (token.type == T.Else) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2648 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2649 nT(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2650 elseBody = parseNoScopeStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2651 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2652 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2653 |
264 | 2654 return new VersionStatement(cond, versionBody, elseBody); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2655 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2656 |
161 | 2657 /+++++++++++++++++++++++++++++ |
183 | 2658 + Assembler parsing methods + |
2659 +++++++++++++++++++++++++++++/ | |
2660 | |
2661 Statement parseAsmStatement() | |
2662 { | |
2663 assert(token.type == T.Asm); | |
285 | 2664 nT(); // Skip asm keyword. |
2665 require(T.LBrace); | |
2666 auto ss = new Statements; | |
2667 while (token.type != T.RBrace && token.type != T.EOF) | |
2668 ss ~= parseAsmInstruction(); | |
2669 require(T.RBrace); | |
2670 return new AsmStatement(ss); | |
2671 } | |
2672 | |
2673 Statement parseAsmInstruction() | |
2674 { | |
2675 auto begin = token; | |
2676 Statement s; | |
374 | 2677 typeof(token) ident; |
285 | 2678 switch (token.type) |
2679 { | |
374 | 2680 // Keywords that are valid opcodes. |
2681 case T.In, T.Int, T.Out: | |
2682 ident = token; | |
2683 nT(); | |
2684 goto LOpcode; | |
285 | 2685 case T.Identifier: |
374 | 2686 ident = token; |
2687 nT(); // Skip Identifier | |
2688 if (token.type == T.Colon) | |
285 | 2689 { |
2690 // Identifier : AsmInstruction | |
2691 nT(); // Skip : | |
2692 s = new LabeledStatement(ident, parseAsmInstruction()); | |
2693 break; | |
2694 } | |
2695 | |
374 | 2696 LOpcode: |
285 | 2697 // Opcode ; |
2698 // Opcode Operands ; | |
2699 // Opcode | |
2700 // Identifier | |
2701 Expression[] es; | |
374 | 2702 if (token.type != T.Semicolon) |
285 | 2703 { |
2704 while (1) | |
2705 { | |
2706 es ~= parseAsmExpression(); | |
2707 if (token.type != T.Comma) | |
2708 break; | |
2709 nT(); | |
2710 } | |
2711 } | |
2712 require(T.Semicolon); | |
2713 s = new AsmInstruction(ident, es); | |
2714 break; | |
374 | 2715 case T.Align: |
2716 nT(); | |
2717 auto number = token; | |
2718 switch (token.type) | |
2719 { | |
2720 case T.Int32, T.Int64, T.Uint32, T.Uint64: | |
2721 number = token; nT(); break; | |
2722 default: | |
2723 if (token.type != T.Semicolon) | |
2724 nT(); | |
2725 number = null; | |
2726 // TODO: report error: number expected after asm align statement. | |
2727 error(MID.ExpectedButFound, "integer", token.srcText); | |
2728 } | |
2729 require(T.Semicolon); | |
2730 s = new AsmAlignStatement(number); | |
2731 break; | |
285 | 2732 case T.Semicolon: |
2733 s = new EmptyStatement(); | |
2734 nT(); | |
2735 break; | |
2736 default: | |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2737 s = new IllegalAsmInstruction(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2738 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2739 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2740 nT(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2741 while (!token.isAsmInstructionStart && |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2742 token.type != T.RBrace && |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2743 token.type != T.EOF) |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2744 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
|
2745 error(begin, "illegal AsmInstruction found: " ~ text); |
285 | 2746 } |
2747 set(s, begin); | |
2748 return s; | |
2749 } | |
2750 | |
2751 Expression parseAsmExpression() | |
2752 { | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2753 auto begin = token; |
374 | 2754 auto e = parseAsmOrOrExpression(); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2755 if (token.type == T.Question) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2756 { |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
2757 auto tok = token; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2758 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2759 auto iftrue = parseAsmExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2760 require(T.Colon); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2761 auto iffalse = parseAsmExpression(); |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
2762 e = new CondExpression(e, iftrue, iffalse, tok); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2763 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2764 } |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2765 // TODO: create AsmExpression that contains e? |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2766 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2767 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2768 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2769 Expression parseAsmOrOrExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2770 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2771 alias parseAsmAndAndExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2772 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2773 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2774 while (token.type == T.OrLogical) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2775 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2776 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2777 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2778 e = new OrOrExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2779 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2780 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2781 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2782 } |
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 Expression parseAsmAndAndExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2785 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2786 alias parseAsmOrExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2787 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2788 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2789 while (token.type == T.AndLogical) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2790 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2791 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2792 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2793 e = new AndAndExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2794 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2795 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2796 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2797 } |
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 Expression parseAsmOrExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2800 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2801 alias parseAsmXorExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2802 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2803 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2804 while (token.type == T.OrBinary) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2805 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2806 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2807 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2808 e = new OrExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2809 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2810 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2811 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2812 } |
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 Expression parseAsmXorExpression() |
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 alias parseAsmAndExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2817 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2818 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2819 while (token.type == T.Xor) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2820 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2821 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2822 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2823 e = new XorExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2824 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2825 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2826 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2827 } |
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 Expression parseAsmAndExpression() |
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 alias parseAsmCmpExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2832 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2833 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2834 while (token.type == T.AndBinary) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2835 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2836 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2837 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2838 e = new AndExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2839 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2840 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2841 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2842 } |
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 Expression parseAsmCmpExpression() |
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 alias parseAsmShiftExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2847 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2848 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2849 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2850 auto operator = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2851 switch (operator.type) |
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 case T.Equal, T.NotEqual: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2854 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2855 e = new EqualExpression(e, parseNext(), operator); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2856 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2857 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2858 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2859 e = new RelExpression(e, parseNext(), operator); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2860 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2861 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2862 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2863 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2864 set(e, begin); |
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 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2868 Expression parseAsmShiftExpression() |
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 alias parseAsmAddExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2871 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2872 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2873 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2874 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2875 auto operator = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2876 switch (operator.type) |
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 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
|
2879 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
|
2880 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
|
2881 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2882 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2883 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2884 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2885 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2886 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2887 } |
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 Expression parseAsmAddExpression() |
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 alias parseAsmMulExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2892 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2893 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2894 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2895 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2896 auto operator = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2897 switch (operator.type) |
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 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
|
2900 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
|
2901 // Not allowed in asm |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2902 //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
|
2903 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2904 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2905 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2906 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2907 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2908 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2909 } |
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 Expression parseAsmMulExpression() |
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 alias parseAsmPostExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2914 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2915 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2916 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2917 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2918 auto operator = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2919 switch (operator.type) |
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 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
|
2922 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
|
2923 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
|
2924 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2925 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2926 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2927 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2928 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2929 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2930 } |
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 Expression parseAsmPostExpression() |
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 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2935 auto e = parseAsmUnaryExpression(); |
374 | 2936 while (token.type == T.LBracket) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2937 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2938 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2939 e = parseAsmExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2940 e = new AsmPostBracketExpression(e); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2941 require(T.RBracket); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2942 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2943 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2944 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2945 } |
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 Expression parseAsmUnaryExpression() |
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 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2950 Expression e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2951 switch (token.type) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2952 { |
374 | 2953 case T.Byte, T.Short, T.Int, |
2954 T.Float, T.Double, T.Real: | |
2955 goto LAsmTypePrefix; | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2956 case T.Identifier: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2957 switch (token.identifier) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2958 { |
374 | 2959 case "near", "far", /*"byte", "short", "int",*/ |
396
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
2960 "word", "dword", "qword"/*, "float", "double", "real"*/: |
374 | 2961 LAsmTypePrefix: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2962 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2963 if (token.type == T.Identifier && token.identifier == "ptr") |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2964 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2965 else |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2966 error(MID.ExpectedButFound, "ptr", token.srcText); |
374 | 2967 e = new AsmTypeExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2968 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2969 case "offset": |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2970 nT(); |
374 | 2971 e = new AsmOffsetExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2972 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2973 case "seg": |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2974 nT(); |
374 | 2975 e = new AsmSegExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2976 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2977 default: |
374 | 2978 goto LparseAsmPrimaryExpression; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2979 } |
374 | 2980 break; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2981 case T.Minus: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2982 case T.Plus: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2983 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2984 e = new SignExpression(parseAsmUnaryExpression()); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2985 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2986 case T.Not: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2987 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2988 e = new NotExpression(parseAsmUnaryExpression()); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2989 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2990 case T.Tilde: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2991 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2992 e = new CompExpression(parseAsmUnaryExpression()); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2993 default: |
374 | 2994 LparseAsmPrimaryExpression: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2995 e = parseAsmPrimaryExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2996 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2997 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2998 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2999 return e; |
183 | 3000 } |
3001 | |
285 | 3002 Expression parseAsmPrimaryExpression() |
3003 { | |
3004 auto begin = token; | |
3005 Expression e; | |
3006 switch (token.type) | |
3007 { | |
3008 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
|
3009 e = new IntExpression(token.type, token.ulong_); |
285 | 3010 nT(); |
3011 break; | |
3012 case T.Float32, T.Float64, T.Float80, | |
3013 T.Imaginary32, T.Imaginary64, T.Imaginary80: | |
399
ff1d11c27061
Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
398
diff
changeset
|
3014 e = new RealExpression(token.type, token.real_); |
285 | 3015 nT(); |
3016 break; | |
3017 case T.Dollar: | |
3018 e = new DollarExpression(); | |
3019 nT(); | |
3020 break; | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3021 case T.LBracket: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3022 // [ AsmExpression ] |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3023 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3024 e = parseAsmExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3025 require(T.RBracket); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3026 e = new AsmBracketExpression(e); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
3027 break; |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3028 case T.Identifier: |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3029 switch (token.identifier) |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3030 { |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3031 // __LOCAL_SIZE |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3032 case "__LOCAL_SIZE": |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3033 e = new AsmLocalSizeExpression(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3034 nT(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3035 break; |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3036 // Register |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3037 case "ST": |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3038 auto register = token; |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3039 nT(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3040 // (1) - (7) |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3041 Token* number; |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3042 if (token.type == T.LParen) |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3043 { |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3044 nT(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3045 if (token.type == T.Int32) |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3046 { |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3047 number = token; |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3048 nT(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3049 } |
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; |
417
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3056 case "FS": |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3057 auto register = token; |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3058 nT(); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3059 // TODO: is the colon-number part optional? |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3060 Token* number; |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3061 if (token.type == T.Colon) |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3062 { |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3063 // :0, :4, :8 |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3064 nT(); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3065 switch (token.srcText) |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3066 { |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3067 case "0", "4", "8": |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3068 number = token; |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3069 nT(); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3070 break; |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3071 default: |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3072 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
|
3073 } |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3074 } |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3075 e = new AsmRegisterExpression(register, number); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3076 break; |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3077 case "AL", "AH", "AX", "EAX", |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3078 "BL", "BH", "BX", "EBX", |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3079 "CL", "CH", "CX", "ECX", |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3080 "DL", "DH", "DX", "EDX", |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3081 "BP", "EBP", |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3082 "SP", "ESP", |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3083 "DI", "EDI", |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3084 "SI", "ESI", |
417
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
3085 "ES", "CS", "SS", "DS", "GS", |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3086 "CR0", "CR2", "CR3", "CR4", |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3087 "DR0", "DR1", "DR2", "DR3", "DR6", "DR7", |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3088 "TR3", "TR4", "TR5", "TR6", "TR7", |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3089 "MM0", "MM1", "MM2", "MM3", "MM4", "MM5", "MM6", "MM7", |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3090 "XMM0", "XMM1", "XMM2", "XMM3", "XMM4", "XMM5", "XMM6", "XMM7": |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3091 e = new AsmRegisterExpression(token); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3092 nT(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3093 break; |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3094 default: |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3095 // DotIdentifier |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3096 Expression[] identList; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3097 while (1) |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3098 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3099 auto begin2 = token; |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3100 auto ident = requireId(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3101 e = new IdentifierExpression(ident); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3102 set(e, begin2); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3103 identList ~= e; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3104 if (token.type != T.Dot) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3105 break; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3106 nT(); // Skip dot. |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3107 } |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3108 e = new DotListExpression(identList); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3109 } |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
3110 break; |
285 | 3111 default: |
3112 error(MID.ExpectedButFound, "Expression", token.srcText); | |
3113 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
|
3114 if (!trying) |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3115 { |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3116 // 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
|
3117 begin = lx.insertEmptyTokenBefore(token); |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3118 prevToken = begin; |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3119 } |
285 | 3120 } |
3121 set(e, begin); | |
3122 return e; | |
3123 } | |
3124 | |
183 | 3125 /+++++++++++++++++++++++++++++ |
102 | 3126 + Expression parsing methods + |
3127 +++++++++++++++++++++++++++++/ | |
3128 | |
72 | 3129 Expression parseExpression() |
3130 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3131 auto begin = token; |
72 | 3132 auto e = parseAssignExpression(); |
122 | 3133 while (token.type == T.Comma) |
235 | 3134 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3135 auto comma = token; |
235 | 3136 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3137 e = new CommaExpression(e, parseAssignExpression(), comma); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3138 set(e, begin); |
235 | 3139 } |
72 | 3140 return e; |
3141 } | |
3142 | |
71 | 3143 Expression parseAssignExpression() |
3144 { | |
319
83f1f9a4f248
- Removed assigment to 'begin' from loop. Initializing 'begin' at decl point.
aziz
parents:
318
diff
changeset
|
3145 auto begin = token; |
71 | 3146 auto e = parseCondExpression(); |
72 | 3147 while (1) |
71 | 3148 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3149 switch (token.type) |
72 | 3150 { |
3151 case T.Assign: | |
3152 nT(); e = new AssignExpression(e, parseAssignExpression()); | |
3153 break; | |
3154 case T.LShiftAssign: | |
3155 nT(); e = new LShiftAssignExpression(e, parseAssignExpression()); | |
3156 break; | |
3157 case T.RShiftAssign: | |
3158 nT(); e = new RShiftAssignExpression(e, parseAssignExpression()); | |
3159 break; | |
3160 case T.URShiftAssign: | |
3161 nT(); e = new URShiftAssignExpression(e, parseAssignExpression()); | |
3162 break; | |
3163 case T.OrAssign: | |
3164 nT(); e = new OrAssignExpression(e, parseAssignExpression()); | |
3165 break; | |
3166 case T.AndAssign: | |
3167 nT(); e = new AndAssignExpression(e, parseAssignExpression()); | |
3168 break; | |
3169 case T.PlusAssign: | |
3170 nT(); e = new PlusAssignExpression(e, parseAssignExpression()); | |
3171 break; | |
3172 case T.MinusAssign: | |
3173 nT(); e = new MinusAssignExpression(e, parseAssignExpression()); | |
3174 break; | |
3175 case T.DivAssign: | |
3176 nT(); e = new DivAssignExpression(e, parseAssignExpression()); | |
3177 break; | |
3178 case T.MulAssign: | |
3179 nT(); e = new MulAssignExpression(e, parseAssignExpression()); | |
3180 break; | |
3181 case T.ModAssign: | |
3182 nT(); e = new ModAssignExpression(e, parseAssignExpression()); | |
3183 break; | |
3184 case T.XorAssign: | |
3185 nT(); e = new XorAssignExpression(e, parseAssignExpression()); | |
3186 break; | |
3187 case T.CatAssign: | |
3188 nT(); e = new CatAssignExpression(e, parseAssignExpression()); | |
3189 break; | |
3190 default: | |
218 | 3191 return e; |
72 | 3192 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3193 set(e, begin); |
71 | 3194 } |
3195 return e; | |
3196 } | |
72 | 3197 |
71 | 3198 Expression parseCondExpression() |
3199 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3200 auto begin = token; |
72 | 3201 auto e = parseOrOrExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3202 if (token.type == T.Question) |
72 | 3203 { |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
3204 auto tok = token; |
72 | 3205 nT(); |
3206 auto iftrue = parseExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3207 require(T.Colon); |
72 | 3208 auto iffalse = parseCondExpression(); |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
3209 e = new CondExpression(e, iftrue, iffalse, tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3210 set(e, begin); |
72 | 3211 } |
3212 return e; | |
3213 } | |
3214 | |
3215 Expression parseOrOrExpression() | |
3216 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3217 alias parseAndAndExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3218 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3219 auto e = parseNext(); |
223 | 3220 while (token.type == T.OrLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3221 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3222 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3223 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3224 e = new OrOrExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3225 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3226 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3227 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3228 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3229 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3230 Expression parseAndAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3231 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3232 alias parseOrExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3233 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3234 auto e = parseNext(); |
223 | 3235 while (token.type == T.AndLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3236 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3237 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3238 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3239 e = new AndAndExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3240 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3241 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3242 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3243 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3244 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3245 Expression parseOrExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3246 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3247 alias parseXorExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3248 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3249 auto e = parseNext(); |
223 | 3250 while (token.type == T.OrBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3251 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3252 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3253 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3254 e = new OrExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3255 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3256 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3257 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3258 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3259 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3260 Expression parseXorExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3261 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3262 alias parseAndExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3263 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3264 auto e = parseNext(); |
223 | 3265 while (token.type == T.Xor) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3266 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3267 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3268 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3269 e = new XorExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3270 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3271 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3272 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3273 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3274 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3275 Expression parseAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3276 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3277 alias parseCmpExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3278 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3279 auto e = parseNext(); |
223 | 3280 while (token.type == T.AndBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3281 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3282 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3283 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
3284 e = new AndExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3285 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3286 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3287 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3288 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3289 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3290 Expression parseCmpExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
3291 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3292 alias parseShiftExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3293 auto begin = token; |
74 | 3294 auto e = parseShiftExpression(); |
3295 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3296 auto operator = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3297 switch (operator.type) |
74 | 3298 { |
3299 case T.Equal, T.NotEqual: | |
3300 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3301 e = new EqualExpression(e, parseNext(), operator); |
74 | 3302 break; |
3303 case T.Not: | |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
3304 if (peekNext() != T.Is) |
74 | 3305 break; |
3306 nT(); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3307 // fall through |
225 | 3308 case T.Is: |
74 | 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 IdentityExpression(e, parseNext(), operator); |
74 | 3311 break; |
3312 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater, | |
3313 T.Unordered, T.UorE, T.UorG, T.UorGorE, | |
3314 T.UorL, T.UorLorE, T.LorEorG, T.LorG: | |
3315 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3316 e = new RelExpression(e, parseNext(), operator); |
74 | 3317 break; |
3318 case T.In: | |
3319 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3320 e = new InExpression(e, parseNext(), operator); |
74 | 3321 break; |
3322 default: | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3323 return e; |
74 | 3324 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3325 set(e, begin); |
74 | 3326 return e; |
3327 } | |
3328 | |
3329 Expression parseShiftExpression() | |
3330 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3331 alias parseAddExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3332 auto begin = token; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3333 auto e = parseNext(); |
75 | 3334 while (1) |
3335 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3336 auto operator = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3337 switch (operator.type) |
75 | 3338 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3339 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
|
3340 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
|
3341 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
|
3342 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3343 return e; |
75 | 3344 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3345 set(e, begin); |
75 | 3346 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3347 assert(0); |
75 | 3348 } |
3349 | |
3350 Expression parseAddExpression() | |
3351 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3352 alias parseMulExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3353 auto begin = token; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3354 auto e = parseNext(); |
76 | 3355 while (1) |
3356 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3357 auto operator = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3358 switch (operator.type) |
76 | 3359 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3360 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
|
3361 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
|
3362 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
|
3363 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3364 return e; |
76 | 3365 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3366 set(e, begin); |
76 | 3367 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3368 assert(0); |
76 | 3369 } |
3370 | |
3371 Expression parseMulExpression() | |
3372 { | |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3373 alias parsePostExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3374 auto begin = token; |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3375 auto e = parseNext(); |
77 | 3376 while (1) |
3377 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3378 auto operator = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3379 switch (operator.type) |
77 | 3380 { |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3381 case T.Mul: nT(); e = new MulExpression(e, parseNext(), operator); break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3382 case T.Div: nT(); e = new DivExpression(e, parseNext(), operator); break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3383 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
|
3384 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3385 return e; |
77 | 3386 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3387 set(e, begin); |
77 | 3388 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
3389 assert(0); |
71 | 3390 } |
3391 | |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3392 Expression parsePostExpression() |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3393 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3394 auto begin = token; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3395 auto e = parseUnaryExpression(); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3396 while (1) |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3397 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3398 switch (token.type) |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3399 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3400 case T.Dot: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3401 e = new PostDotListExpression(e, parseDotListExpression()); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3402 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3403 case T.PlusPlus: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3404 e = new PostIncrExpression(e); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3405 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3406 case T.MinusMinus: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3407 e = new PostDecrExpression(e); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3408 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3409 case T.LParen: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3410 e = new CallExpression(e, parseArguments()); |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3411 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3412 case T.LBracket: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3413 // parse Slice- and IndexExpression |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3414 nT(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
3415 // [] is a SliceExpression |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3416 if (token.type == T.RBracket) |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3417 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3418 e = new SliceExpression(e, null, null); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3419 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3420 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3421 |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3422 Expression[] es = [parseAssignExpression()]; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3423 |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
3424 // [ AssignExpression .. AssignExpression ] |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3425 if (token.type == T.Slice) |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3426 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3427 nT(); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3428 e = new SliceExpression(e, es[0], parseAssignExpression()); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3429 require(T.RBracket); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3430 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3431 } |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3432 |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
3433 // [ ExpressionList ] |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3434 if (token.type == T.Comma) |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3435 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3436 nT(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3437 es ~= parseExpressionList(); |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3438 } |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3439 require(T.RBracket); |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3440 |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3441 e = new IndexExpression(e, es); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3442 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3443 default: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3444 return e; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3445 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3446 nT(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
3447 Lset: // Jumped here to skip nT(). |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3448 set(e, begin); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3449 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3450 assert(0); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3451 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3452 |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3453 Expression parseUnaryExpression() |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3454 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3455 auto begin = token; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3456 Expression e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3457 switch (token.type) |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3458 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3459 case T.AndBinary: |
257 | 3460 nT(); |
243 | 3461 e = new AddressExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3462 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3463 case T.PlusPlus: |
257 | 3464 nT(); |
243 | 3465 e = new PreIncrExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3466 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3467 case T.MinusMinus: |
257 | 3468 nT(); |
243 | 3469 e = new PreDecrExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3470 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3471 case T.Mul: |
257 | 3472 nT(); |
243 | 3473 e = new DerefExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3474 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3475 case T.Minus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3476 case T.Plus: |
257 | 3477 nT(); |
243 | 3478 e = new SignExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3479 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3480 case T.Not: |
257 | 3481 nT(); |
243 | 3482 e = new NotExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3483 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3484 case T.Tilde: |
257 | 3485 nT(); |
243 | 3486 e = new CompExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3487 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3488 case T.New: |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3489 e = parseNewExpression(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3490 return e; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3491 case T.Delete: |
257 | 3492 nT(); |
243 | 3493 e = new DeleteExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3494 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3495 case T.Cast: |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3496 requireNext(T.LParen); |
269 | 3497 Type type; |
3498 switch (token.type) | |
3499 { | |
3500 version(D2) | |
3501 { | |
3502 auto begin2 = token; | |
3503 case T.Const: | |
3504 type = new ConstType(null); | |
3505 goto case_break; | |
3506 case T.Invariant: | |
3507 type = new InvariantType(null); | |
3508 case_break: | |
3509 nT(); | |
3510 set(type, begin2); | |
3511 break; | |
3512 } | |
3513 default: | |
3514 type = parseType(); | |
3515 } | |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3516 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3517 e = new CastExpression(parseUnaryExpression(), type); |
257 | 3518 break; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3519 case T.LParen: |
102 | 3520 // ( Type ) . Identifier |
225 | 3521 Type parseType_() |
3522 { | |
3523 nT(); | |
3524 auto type = parseType(); | |
3525 require(T.RParen); | |
233 | 3526 require(T.Dot); |
225 | 3527 return type; |
3528 } | |
3529 bool success; | |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
3530 auto type = try_(&parseType_, success); |
225 | 3531 if (success) |
3532 { | |
243 | 3533 auto ident = requireId(); |
225 | 3534 e = new TypeDotIdExpression(type, ident); |
257 | 3535 break; |
225 | 3536 } |
3537 goto default; | |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3538 default: |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3539 e = parsePrimaryExpression(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3540 return e; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3541 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3542 assert(e !is null); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3543 set(e, begin); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3544 return e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3545 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3546 |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
3547 Expression parsePrimaryExpression() |
78
f043759fb59a
- Added code to parseUnaryExpression(); not fully implemented.
aziz
parents:
77
diff
changeset
|
3548 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3549 auto begin = token; |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3550 Expression e; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3551 switch (token.type) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3552 { |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3553 case T.Identifier, T.Dot, T.Typeof: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3554 e = parseDotListExpression(); |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3555 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3556 case T.This: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3557 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3558 e = new ThisExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3559 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3560 case T.Super: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3561 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3562 e = new SuperExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3563 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3564 case T.Null: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3565 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3566 e = new NullExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3567 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3568 case T.True, T.False: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3569 nT(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3570 e = new BoolExpression(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3571 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3572 case T.Dollar: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3573 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3574 e = new DollarExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3575 break; |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3576 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
|
3577 e = new IntExpression(token.type, token.ulong_); |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3578 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3579 break; |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3580 case T.Float32, T.Float64, T.Float80, |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3581 T.Imaginary32, T.Imaginary64, T.Imaginary80: |
399
ff1d11c27061
Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
398
diff
changeset
|
3582 e = new RealExpression(token.type, token.real_); |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3583 nT(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3584 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3585 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
|
3586 e = new CharExpression(token); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3587 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3588 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3589 case T.String: |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
3590 Token*[] stringLiterals; |
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
3591 do |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3592 { |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
3593 stringLiterals ~= token; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3594 nT(); |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
3595 } while (token.type == T.String) |
399
ff1d11c27061
Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
398
diff
changeset
|
3596 e = new StringExpression(stringLiterals); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3597 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3598 case T.LBracket: |
85 | 3599 Expression[] values; |
3600 | |
3601 nT(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3602 if (token.type != T.RBracket) |
85 | 3603 { |
3604 e = parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3605 if (token.type == T.Colon) |
85 | 3606 goto LparseAssocArray; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3607 if (token.type == T.Comma) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3608 { |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3609 nT(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3610 values = [e] ~ parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3611 } |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3612 require(T.RBracket); |
85 | 3613 } |
271
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3614 else |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3615 nT(); |
85 | 3616 |
3617 e = new ArrayLiteralExpression(values); | |
3618 break; | |
3619 | |
3620 LparseAssocArray: | |
3621 Expression[] keys; | |
3622 | |
3623 keys ~= e; | |
3624 nT(); // Skip colon. | |
271
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3625 goto LenterLoop; |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3626 |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3627 while (1) |
88 | 3628 { |
271
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3629 keys ~= parseAssignExpression(); |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3630 require(T.Colon); |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3631 LenterLoop: |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3632 values ~= parseAssignExpression(); |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3633 if (token.type != T.Comma) |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3634 break; |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3635 nT(); |
88 | 3636 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3637 require(T.RBracket); |
399
ff1d11c27061
Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
398
diff
changeset
|
3638 e = new AArrayLiteralExpression(keys, values); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3639 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3640 case T.LBrace: |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
3641 // DelegateLiteral := { Statements } |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3642 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3643 e = new FunctionLiteralExpression(funcBody); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3644 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3645 case T.Function, T.Delegate: |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
3646 // FunctionLiteral := (function|delegate) Type? '(' ArgumentList ')' '{' Statements '}' |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3647 nT(); // Skip function|delegate token. |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3648 Type returnType; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3649 Parameters parameters; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3650 if (token.type != T.LBrace) |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3651 { |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3652 if (token.type != T.LParen) // Optional return type |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3653 returnType = parseType(); |
143 | 3654 parameters = parseParameterList(); |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3655 } |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3656 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3657 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
|
3658 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3659 case T.Assert: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3660 Expression msg; |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3661 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3662 e = parseAssignExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3663 if (token.type == T.Comma) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3664 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3665 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3666 msg = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3667 } |
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 AssertExpression(e, msg); |
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.Mixin: |
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 MixinExpression(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.Import: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3678 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3679 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3680 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3681 e = new ImportExpression(e); |
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.Typeid: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3684 requireNext(T.LParen); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3685 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3686 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3687 e = new TypeidExpression(type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3688 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3689 case T.Is: |
100 | 3690 requireNext(T.LParen); |
3691 | |
248 | 3692 Type type, specType; |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
3693 Token* ident; // optional Identifier |
248 | 3694 Token* opTok, specTok; |
100 | 3695 |
3696 type = parseDeclarator(ident, true); | |
3697 | |
3698 switch (token.type) | |
3699 { | |
3700 case T.Colon, T.Equal: | |
248 | 3701 opTok = token; |
100 | 3702 nT(); |
3703 switch (token.type) | |
3704 { | |
3705 case T.Typedef, | |
3706 T.Struct, | |
3707 T.Union, | |
3708 T.Class, | |
3709 T.Interface, | |
3710 T.Enum, | |
3711 T.Function, | |
3712 T.Delegate, | |
3713 T.Super, | |
3714 T.Return: | |
493
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3715 case_Const_Invariant: |
248 | 3716 specTok = token; |
102 | 3717 nT(); |
100 | 3718 break; |
493
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3719 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
|
3720 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
|
3721 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
|
3722 // Fall through. It's a type. |
100 | 3723 default: |
248 | 3724 specType = parseType(); |
100 | 3725 } |
3726 default: | |
3727 } | |
377 | 3728 |
3729 TemplateParameters tparams; | |
3730 version(D2) | |
3731 { | |
3732 // is ( Type Identifier : TypeSpecialization , TemplateParameterList ) | |
3733 // is ( Type Identifier == TypeSpecialization , TemplateParameterList ) | |
3734 if (ident && specType && token.type == T.Comma) | |
3735 tparams = parseTemplateParameterList2(); | |
3736 } | |
102 | 3737 require(T.RParen); |
377 | 3738 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
|
3739 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3740 case T.LParen: |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3741 if (tokenAfterParenIs(T.LBrace)) |
130 | 3742 { |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3743 auto parameters = parseParameterList(); |
143 | 3744 // ( ParameterList ) FunctionBody |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3745 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3746 e = new FunctionLiteralExpression(null, parameters, funcBody); |
130 | 3747 } |
3748 else | |
3749 { | |
131 | 3750 // ( Expression ) |
130 | 3751 nT(); |
3752 e = parseExpression(); | |
3753 require(T.RParen); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3754 // TODO: create ParenExpression? |
130 | 3755 } |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3756 break; |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3757 // IntegralType . Identifier |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
3758 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
|
3759 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
|
3760 T.Int, T.Uint, T.Long, T.Ulong, |
94 | 3761 T.Float, T.Double, T.Real, |
3762 T.Ifloat, T.Idouble, T.Ireal, | |
192 | 3763 T.Cfloat, T.Cdouble, T.Creal, T.Void: |
280 | 3764 auto type = new IntegralType(token.type); |
247 | 3765 nT(); |
3766 set(type, begin); | |
3767 require(T.Dot); | |
243 | 3768 auto ident = requireId(); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3769 |
94 | 3770 e = new TypeDotIdExpression(type, ident); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3771 break; |
269 | 3772 version(D2) |
3773 { | |
3774 case T.Traits: | |
3775 nT(); | |
3776 require(T.LParen); | |
3777 auto id = requireId(); | |
3778 TemplateArguments args; | |
3779 if (token.type == T.Comma) | |
3780 args = parseTemplateArguments2(); | |
3781 else | |
3782 require(T.RParen); | |
3783 e = new TraitsExpression(id, args); | |
3784 break; | |
3785 } | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3786 default: |
343
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3787 if (token.isSpecialToken) |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3788 { |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3789 e = new SpecialTokenExpression(token); |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3790 nT(); |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3791 break; |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3792 } |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3793 |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3794 error(MID.ExpectedButFound, "Expression", token.srcText); |
136
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
3795 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
|
3796 if (!trying) |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3797 { |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3798 // 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
|
3799 begin = lx.insertEmptyTokenBefore(token); |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3800 prevToken = begin; |
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3801 } |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3802 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3803 set(e, begin); |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3804 return e; |
77 | 3805 } |
3806 | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3807 Expression parseNewExpression(/*Expression e*/) |
81 | 3808 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3809 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
|
3810 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
|
3811 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
|
3812 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3813 Expression[] newArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3814 Expression[] ctorArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3815 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3816 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
|
3817 newArguments = parseArguments(); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3818 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3819 // NewAnonClassExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3820 // 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
|
3821 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
|
3822 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3823 nT(); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3824 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
|
3825 ctorArguments = parseArguments(); |
144
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 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
|
3828 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
3829 auto decls = parseDeclarationDefinitionsBody(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3830 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
|
3831 } |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3832 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3833 // NewExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3834 // NewArguments Type [ AssignExpression ] |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3835 // NewArguments Type ( ArgumentList ) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3836 // NewArguments Type |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3837 auto type = parseType(); |
302
d04a79e795a2
- Fix in parseNewExpression(): removed check for type id.
aziz
parents:
301
diff
changeset
|
3838 |
d04a79e795a2
- Fix in parseNewExpression(): removed check for type id.
aziz
parents:
301
diff
changeset
|
3839 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
|
3840 ctorArguments = parseArguments(); |
302
d04a79e795a2
- Fix in parseNewExpression(): removed check for type id.
aziz
parents:
301
diff
changeset
|
3841 |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3842 return set(new NewExpression(/*e, */newArguments, type, ctorArguments), begin); |
81 | 3843 } |
3844 | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3845 Type parseType() |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3846 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3847 return parseBasicType2(parseBasicType()); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3848 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3849 |
94 | 3850 Type parseBasicType() |
3851 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3852 auto begin = token; |
94 | 3853 Type t; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3854 // IdentifierType tident; |
94 | 3855 |
3856 switch (token.type) | |
3857 { | |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
3858 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
|
3859 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
|
3860 T.Int, T.Uint, T.Long, T.Ulong, |
94 | 3861 T.Float, T.Double, T.Real, |
3862 T.Ifloat, T.Idouble, T.Ireal, | |
192 | 3863 T.Cfloat, T.Cdouble, T.Creal, T.Void: |
280 | 3864 t = new IntegralType(token.type); |
94 | 3865 nT(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3866 set(t, begin); |
94 | 3867 break; |
153 | 3868 case T.Identifier, T.Typeof, T.Dot: |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3869 t = parseDotListType(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
3870 assert(!isNodeSet(t)); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
3871 set(t, begin); |
153 | 3872 break; |
269 | 3873 version(D2) |
3874 { | |
3875 case T.Const: | |
3876 // const ( Type ) | |
3877 nT(); | |
3878 require(T.LParen); | |
3879 t = parseType(); | |
3880 require(T.RParen); | |
3881 t = new ConstType(t); | |
3882 set(t, begin); | |
3883 break; | |
3884 case T.Invariant: | |
3885 // invariant ( Type ) | |
3886 nT(); | |
3887 require(T.LParen); | |
3888 t = parseType(); | |
3889 require(T.RParen); | |
3890 t = new InvariantType(t); | |
3891 set(t, begin); | |
3892 break; | |
369 | 3893 } // version(D2) |
94 | 3894 default: |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3895 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
|
3896 t = new UndefinedType(); |
259
8118da6fee44
- Moved nT() below statement where an attribute class is constructed.
aziz
parents:
258
diff
changeset
|
3897 nT(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3898 set(t, begin); |
94 | 3899 } |
3900 return t; | |
3901 } | |
3902 | |
95 | 3903 Type parseBasicType2(Type t) |
3904 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3905 typeof(token) begin; |
95 | 3906 while (1) |
3907 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3908 begin = token; |
95 | 3909 switch (token.type) |
3910 { | |
3911 case T.Mul: | |
3912 t = new PointerType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3913 nT(); |
95 | 3914 break; |
3915 case T.LBracket: | |
106 | 3916 t = parseArrayType(t); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3917 continue; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3918 case T.Function, T.Delegate: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3919 TOK tok = token.type; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3920 nT(); |
143 | 3921 auto parameters = parseParameterList(); |
135 | 3922 if (tok == T.Function) |
291
c0e857931ff6
- Changed FunctionType and DelegateType. Both receive return type and parameters.
aziz
parents:
290
diff
changeset
|
3923 t = new FunctionType(t, parameters); |
135 | 3924 else |
291
c0e857931ff6
- Changed FunctionType and DelegateType. Both receive return type and parameters.
aziz
parents:
290
diff
changeset
|
3925 t = new DelegateType(t, parameters); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3926 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3927 default: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3928 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3929 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3930 set(t, begin); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3931 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3932 assert(0); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3933 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3934 |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3935 bool tokenAfterParenIs(TOK tok) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3936 { |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3937 // 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
|
3938 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
|
3939 Token* next = token; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3940 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
|
3941 Loop: |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3942 while (1) |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3943 { |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3944 lx.peek(next); |
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3945 switch (next.type) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3946 { |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3947 case T.RParen: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3948 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
|
3949 { // 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
|
3950 do |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3951 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
|
3952 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
|
3953 break Loop; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3954 } |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3955 break; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3956 case T.LParen: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3957 ++level; |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3958 break; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3959 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
|
3960 break Loop; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3961 default: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3962 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3963 } |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3964 return next.type == tok; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3965 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3966 |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3967 Type parseDeclaratorSuffix(Type t) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3968 { |
192 | 3969 switch (token.type) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3970 { |
192 | 3971 case T.LBracket: |
3972 // Type Identifier ArrayType | |
3973 // ArrayType := [] or [Type] or [Expression..Expression] | |
3974 do | |
106 | 3975 t = parseArrayType(t); |
192 | 3976 while (token.type == T.LBracket) |
3977 break; | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3978 /+ // parsed in parseDeclaration() |
192 | 3979 case T.LParen: |
258 | 3980 TemplateParameters tparams; |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3981 if (tokenAfterParenIs(T.LParen)) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3982 { |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3983 // ( TemplateParameterList ) ( ParameterList ) |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3984 tparams = parseTemplateParameterList(); |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3985 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3986 |
192 | 3987 auto params = parseParameterList(); |
3988 // ReturnType FunctionName ( ParameterList ) | |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3989 t = new FunctionType(t, params, tparams); |
192 | 3990 break; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3991 +/ |
192 | 3992 default: |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3993 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3994 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3995 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3996 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3997 |
106 | 3998 Type parseArrayType(Type t) |
3999 { | |
4000 assert(token.type == T.LBracket); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4001 auto begin = token; |
106 | 4002 nT(); |
4003 if (token.type == T.RBracket) | |
4004 { | |
4005 t = new ArrayType(t); | |
4006 nT(); | |
4007 } | |
4008 else | |
4009 { | |
214 | 4010 bool success; |
369 | 4011 Type parseAAType() |
4012 { | |
4013 auto type = parseType(); | |
4014 require(T.RBracket); | |
4015 return type; | |
4016 } | |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
4017 auto assocType = try_(&parseAAType, success); |
214 | 4018 if (success) |
106 | 4019 t = new ArrayType(t, assocType); |
4020 else | |
4021 { | |
4022 Expression e = parseExpression(), e2; | |
4023 if (token.type == T.Slice) | |
4024 { | |
4025 nT(); | |
4026 e2 = parseExpression(); | |
4027 } | |
4028 t = new ArrayType(t, e, e2); | |
369 | 4029 require(T.RBracket); |
106 | 4030 } |
4031 } | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4032 set(t, begin); |
106 | 4033 return t; |
4034 } | |
4035 | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4036 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
|
4037 { |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4038 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
|
4039 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
|
4040 auto begin = token; |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4041 nT(); // Skip ( |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4042 type = parseBasicType2(type); |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4043 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
|
4044 { |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4045 // Can be nested. |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4046 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
|
4047 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4048 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
|
4049 { |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4050 // 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
|
4051 ident = token; |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4052 nT(); |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4053 type = parseDeclaratorSuffix(type); |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4054 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4055 require(T.RParen); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4056 |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4057 Parameters params; |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4058 if (optionalParamList) |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4059 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
|
4060 else |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4061 params = parseParameterList(); |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4062 |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4063 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
|
4064 return type; |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4065 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4066 |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
4067 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
|
4068 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
4069 auto t = parseType(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
4070 |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4071 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
|
4072 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
4073 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
|
4074 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4075 else if (token.type == T.Identifier) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
4076 { |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
4077 ident = token; |
95 | 4078 nT(); |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
4079 t = parseDeclaratorSuffix(t); |
95 | 4080 } |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4081 |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
4082 if (ident is null && !identOptional) |
124 | 4083 expected(T.Identifier); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
4084 |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
4085 return t; |
95 | 4086 } |
4087 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4088 /++ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4089 Parse a list of AssignExpressions. |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4090 ExpressionList: |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4091 AssignExpression |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4092 AssignExpression , ExpressionList |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4093 +/ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4094 Expression[] parseExpressionList() |
138 | 4095 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4096 Expression[] expressions; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4097 while (1) |
138 | 4098 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4099 expressions ~= parseAssignExpression(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4100 if (token.type != T.Comma) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4101 break; |
138 | 4102 nT(); |
4103 } | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4104 return expressions; |
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 |
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 Arguments: |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4109 ( ) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4110 ( ExpressionList ) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4111 +/ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4112 Expression[] parseArguments() |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4113 { |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4114 assert(token.type == T.LParen); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4115 nT(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4116 Expression[] args; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4117 if (token.type != TOK.RParen) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4118 args = parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
4119 require(TOK.RParen); |
139 | 4120 return args; |
138 | 4121 } |
4122 | |
143 | 4123 Parameters parseParameterList() |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
4124 out(params) |
96 | 4125 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
4126 if (params.length > 1) |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
4127 foreach (param; params.items[0..$-1]) |
96 | 4128 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
4129 if (param.isVariadic()) |
96 | 4130 assert(0, "variadic arguments can only appear at the end of the parameter list."); |
4131 } | |
4132 } | |
4133 body | |
95 | 4134 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4135 auto begin = token; |
95 | 4136 require(T.LParen); |
4137 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4138 auto params = new Parameters(); |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4139 |
95 | 4140 if (token.type == T.RParen) |
4141 { | |
4142 nT(); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4143 return set(params, begin); |
95 | 4144 } |
4145 | |
4146 while (1) | |
4147 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4148 auto paramBegin = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4149 Token* stcTok; |
269 | 4150 StorageClass stc, tmp; |
4151 | |
4152 if (token.type == T.Ellipses) | |
4153 { | |
4154 nT(); | |
4155 params ~= set(new Parameter(null, null, null, null), paramBegin); | |
4156 break; // Exit loop. | |
4157 } | |
4158 | |
4159 Lstc_loop: | |
95 | 4160 switch (token.type) |
4161 { | |
269 | 4162 version(D2) |
4163 { | |
4164 case T.Invariant: // D2.0 | |
4165 if (peekNext() == T.LParen) | |
4166 goto default; | |
4167 tmp = StorageClass.Invariant; | |
4168 goto Lcommon; | |
4169 case T.Const: // D2.0 | |
4170 if (peekNext() == T.LParen) | |
4171 goto default; | |
4172 tmp = StorageClass.Const; | |
4173 goto Lcommon; | |
4174 case T.Final: // D2.0 | |
4175 tmp = StorageClass.Final; | |
4176 goto Lcommon; | |
4177 case T.Scope: // D2.0 | |
4178 tmp = StorageClass.Scope; | |
4179 goto Lcommon; | |
4180 case T.Static: // D2.0 | |
4181 tmp = StorageClass.Static; | |
4182 goto Lcommon; | |
4183 case T.In: | |
4184 tmp = StorageClass.In; | |
4185 goto Lcommon; | |
4186 case T.Out: | |
282 | 4187 tmp = StorageClass.Out; |
269 | 4188 goto Lcommon; |
4189 case T.Inout, T.Ref: | |
4190 tmp = StorageClass.Ref; | |
4191 goto Lcommon; | |
4192 case T.Lazy: | |
4193 tmp = StorageClass.Lazy; | |
4194 goto Lcommon; | |
4195 Lcommon: | |
4196 if (stc & tmp) | |
4197 error(MID.RedundantStorageClass, token.srcText); | |
4198 else | |
4199 stc |= tmp; | |
4200 nT(); | |
4201 goto Lstc_loop; | |
4202 } | |
4203 else // else body of version(D2) | |
4204 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4205 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
|
4206 stcTok = token; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4207 nT(); |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4208 goto default; |
269 | 4209 } |
95 | 4210 default: |
269 | 4211 version(D2) |
4212 { | |
4213 if (stc != StorageClass.None) | |
4214 stcTok = begin; | |
4215 } | |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
4216 Token* ident; |
130 | 4217 auto type = parseDeclarator(ident, true); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
4218 |
95 | 4219 Expression assignExpr; |
4220 if (token.type == T.Assign) | |
4221 { | |
4222 nT(); | |
4223 assignExpr = parseAssignExpression(); | |
4224 } | |
4225 | |
4226 if (token.type == T.Ellipses) | |
4227 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4228 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
|
4229 p.stc |= StorageClass.Variadic; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4230 params ~= p; |
95 | 4231 nT(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4232 break; // Exit loop. |
95 | 4233 } |
4234 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4235 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
|
4236 |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4237 if (token.type != T.Comma) |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4238 break; // Exit loop. |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4239 nT(); |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4240 continue; |
95 | 4241 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4242 break; // Exit loop. |
95 | 4243 } |
4244 require(T.RParen); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
4245 return set(params, begin); |
95 | 4246 } |
4247 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
4248 TemplateArguments parseTemplateArguments() |
139 | 4249 { |
376 | 4250 TemplateArguments targs; |
139 | 4251 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
|
4252 if (token.type != T.RParen) |
376 | 4253 targs = parseTemplateArguments_(); |
139 | 4254 require(T.RParen); |
376 | 4255 return targs; |
139 | 4256 } |
376 | 4257 |
269 | 4258 version(D2) |
4259 { | |
4260 TemplateArguments parseTemplateArguments2() | |
4261 { | |
4262 assert(token.type == T.Comma); | |
4263 nT(); | |
376 | 4264 TemplateArguments targs; |
269 | 4265 if (token.type != T.RParen) |
376 | 4266 targs = parseTemplateArguments_(); |
269 | 4267 else |
4268 error(MID.ExpectedButFound, "Type/Expression", ")"); | |
4269 require(T.RParen); | |
376 | 4270 return targs; |
269 | 4271 } |
4272 } // version(D2) | |
376 | 4273 |
4274 TemplateArguments parseTemplateArguments_() | |
4275 { | |
4276 auto begin = token; | |
4277 auto targs = new TemplateArguments; | |
4278 while (1) | |
4279 { | |
379
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4280 Type parseType_() |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4281 { |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4282 auto type = parseType(); |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4283 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
|
4284 return type; |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4285 ++errorCount; // Cause try_() to fail. |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4286 return null; |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
4287 } |
376 | 4288 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
4289 auto typeArgument = try_(&parseType_, success); |
376 | 4290 if (success) |
4291 // TemplateArgument: | |
4292 // Type | |
4293 // Symbol | |
4294 targs ~= typeArgument; | |
4295 else | |
4296 // TemplateArgument: | |
4297 // AssignExpression | |
4298 targs ~= parseAssignExpression(); | |
4299 if (token.type != T.Comma) | |
4300 break; // Exit loop. | |
4301 nT(); | |
4302 } | |
4303 set(targs, begin); | |
4304 return targs; | |
4305 } | |
4306 | |
258 | 4307 TemplateParameters parseTemplateParameterList() |
137 | 4308 { |
377 | 4309 TemplateParameters tparams; |
4310 require(T.LParen); | |
4311 if (token.type != T.RParen) | |
4312 tparams = parseTemplateParameterList_(); | |
4313 require(T.RParen); | |
4314 return tparams; | |
4315 } | |
4316 | |
4317 version(D2) | |
4318 { | |
4319 TemplateParameters parseTemplateParameterList2() | |
4320 { | |
4321 assert(token.type == T.Comma); | |
4322 nT(); | |
4323 TemplateParameters tparams; | |
4324 if (token.type != T.RParen) | |
4325 tparams = parseTemplateParameterList_(); | |
4326 else | |
4327 error(MID.ExpectedButFound, "Type/Expression", ")"); | |
4328 return tparams; | |
4329 } | |
4330 } // version(D2) | |
4331 | |
4332 TemplateParameters parseTemplateParameterList_() | |
4333 { | |
258 | 4334 auto begin = token; |
295
75b47c71a34c
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
293
diff
changeset
|
4335 auto tparams = new TemplateParameters; |
75b47c71a34c
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
293
diff
changeset
|
4336 |
137 | 4337 while (1) |
4338 { | |
258 | 4339 auto paramBegin = token; |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4340 TemplateParameter tp; |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
4341 Token* ident; |
137 | 4342 Type specType, defType; |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4343 |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4344 void parseSpecAndOrDefaultType() |
137 | 4345 { |
4346 // : SpecializationType | |
4347 if (token.type == T.Colon) | |
4348 { | |
4349 nT(); | |
4350 specType = parseType(); | |
4351 } | |
4352 // = DefaultType | |
4353 if (token.type == T.Assign) | |
4354 { | |
4355 nT(); | |
4356 defType = parseType(); | |
4357 } | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4358 } |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4359 |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4360 switch (token.type) |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4361 { |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4362 case T.Alias: |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4363 // TemplateAliasParameter: |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4364 // alias Identifier |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4365 nT(); // Skip alias keyword. |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4366 ident = requireId(); |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4367 parseSpecAndOrDefaultType(); |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4368 tp = new TemplateAliasParameter(ident, specType, defType); |
137 | 4369 break; |
4370 case T.Identifier: | |
253
4279b638c63e
- Changed some string types to Token*. Adapted parser accordingly.
aziz
parents:
252
diff
changeset
|
4371 ident = token; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
4372 switch (peekNext()) |
137 | 4373 { |
4374 case T.Ellipses: | |
4375 // TemplateTupleParameter: | |
4376 // Identifier ... | |
4377 nT(); // Skip Identifier. | |
4378 nT(); // Skip Ellipses. | |
341
3ac651ea83fb
- Fix: created TemplateAliasParameter instead of TemplateTypeParameter.
aziz
parents:
340
diff
changeset
|
4379 if (token.type == T.Comma) |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
4380 error(MID.TemplateTupleParameter); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4381 tp = new TemplateTupleParameter(ident); |
137 | 4382 break; |
4383 case T.Comma, T.RParen, T.Colon, T.Assign: | |
4384 // TemplateTypeParameter: | |
4385 // Identifier | |
4386 nT(); // Skip Identifier. | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4387 parseSpecAndOrDefaultType(); |
341
3ac651ea83fb
- Fix: created TemplateAliasParameter instead of TemplateTypeParameter.
aziz
parents:
340
diff
changeset
|
4388 tp = new TemplateTypeParameter(ident, specType, defType); |
137 | 4389 break; |
4390 default: | |
4391 // TemplateValueParameter: | |
4392 // Declarator | |
4393 ident = null; | |
4394 goto LTemplateValueParameter; | |
4395 } | |
4396 break; | |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4397 version(D2) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4398 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4399 case T.This: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4400 // TemplateThisParameter |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4401 // this TemplateTypeParameter |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4402 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
|
4403 ident = requireId(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4404 parseSpecAndOrDefaultType(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4405 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
|
4406 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4407 } |
137 | 4408 default: |
4409 LTemplateValueParameter: | |
4410 // TemplateValueParameter: | |
4411 // Declarator | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4412 Expression specValue, defValue; |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4413 auto valueType = parseDeclarator(ident); |
137 | 4414 // : SpecializationValue |
4415 if (token.type == T.Colon) | |
4416 { | |
4417 nT(); | |
4418 specValue = parseCondExpression(); | |
4419 } | |
4420 // = DefaultValue | |
4421 if (token.type == T.Assign) | |
4422 { | |
4423 nT(); | |
4424 defValue = parseCondExpression(); | |
4425 } | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4426 tp = new TemplateValueParameter(valueType, ident, specValue, defValue); |
137 | 4427 } |
4428 | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4429 // Push template parameter. |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4430 tparams ~= set(tp, paramBegin); |
137 | 4431 |
4432 if (token.type != T.Comma) | |
4433 break; | |
4434 nT(); | |
4435 } | |
258 | 4436 set(tparams, begin); |
137 | 4437 return tparams; |
4438 } | |
4439 | |
124 | 4440 void expected(TOK tok) |
86
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) |
327 | 4443 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
|
4444 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4445 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4446 void require(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4447 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
4448 if (token.type == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4449 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4450 else |
327 | 4451 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
|
4452 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4453 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4454 void requireNext(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4455 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4456 nT(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4457 require(tok); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4458 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4459 |
243 | 4460 Token* requireId() |
4461 { | |
4462 if (token.type == T.Identifier) | |
4463 { | |
4464 auto id = token; | |
4465 nT(); | |
4466 return id; | |
4467 } | |
4468 else | |
4469 error(MID.ExpectedButFound, "Identifier", token.srcText); | |
4470 return null; | |
4471 } | |
4472 | |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4473 /// 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
|
4474 void error(Token* token, char[] formatMsg, ...) |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4475 { |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4476 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
|
4477 } |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4478 |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
4479 void error(MID mid, ...) |
71 | 4480 { |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4481 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
|
4482 } |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4483 |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4484 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
|
4485 { |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4486 if (trying) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4487 { |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4488 ++errorCount; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4489 return; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4490 } |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4491 auto location = token.getLocation(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4492 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
|
4493 errors ~= new Information(InfoType.Parser, mid, location, msg); |
71 | 4494 } |
65 | 4495 } |