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