annotate dmd/Parser.d @ 123:9e39c7de8438

Make dmd test suite compile
author korDen
date Fri, 03 Sep 2010 20:46:58 +0400
parents c77e9f4f1793
children 767a01c2a272
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.Parser;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 110
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.PostBlitDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.FileInitExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.LineInitExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.EnumMember;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.CtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.ShlAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.ShrAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.UshrAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.CatAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.StaticIfCondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TraitsExp;
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
16 import dmd.TemplateMixin;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.BaseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.AssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.TemplateInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.NewExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.ArrayExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.DotTemplateInstanceExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.NewAnonClassExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.InterfaceDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.UnionDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.AnonDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.StructInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.ArrayInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.TemplateAliasParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.TemplateTupleParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.TemplateThisParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.TemplateValueParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.VoidInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.VersionCondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.DebugCondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.PostExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.SliceExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.FuncExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.AssocArrayLiteralExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.ArrayLiteralExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.IsExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.FuncLiteralDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.AssertExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.CompileExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.FileExp;
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
51 import dmd.TemplateMixin;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.TemplateParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.TemplateTypeParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import dmd.TypeidExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.StringExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 import dmd.ScopeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 import dmd.IdentifierExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 import dmd.DollarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 import dmd.ThisExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 import dmd.SuperExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 import dmd.NullExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 import dmd.RealExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 import dmd.TypeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 import dmd.AddrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 import dmd.CastExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 import dmd.PtrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 import dmd.NegExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 import dmd.XorAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 import dmd.OrAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 import dmd.UAddExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 import dmd.NotExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 import dmd.ComExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 import dmd.DeleteExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 import dmd.MulAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 import dmd.ModAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 import dmd.MinAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 import dmd.DivAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 import dmd.AndAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 import dmd.AddAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 import dmd.ModuleDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 import dmd.CaseRangeStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 import dmd.CommaExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 import dmd.XorExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 import dmd.CondExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 import dmd.CmpExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 import dmd.InExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 import dmd.OrOrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 import dmd.OrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 import dmd.AddExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 import dmd.MinExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 import dmd.CatExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 import dmd.AndAndExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 import dmd.EqualExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 import dmd.ShlExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 import dmd.ShrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 import dmd.DivExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 import dmd.MulExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 import dmd.ModExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 import dmd.UshrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 import dmd.IdentityExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 import dmd.AndExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 import dmd.LabelStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 import dmd.StaticAssertStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 import dmd.DeclarationStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 import dmd.ScopeStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 import dmd.PragmaStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 import dmd.WhileStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 import dmd.DoStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 import dmd.ForStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 import dmd.OnScopeStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 import dmd.IfStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 import dmd.SwitchStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 import dmd.CaseStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 import dmd.DefaultStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 import dmd.GotoDefaultStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 import dmd.GotoCaseStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 import dmd.GotoStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 import dmd.SynchronizedStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 import dmd.WithStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 import dmd.Catch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 import dmd.TryCatchStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 import dmd.TryFinallyStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 import dmd.ThrowStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 import dmd.VolatileStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 import dmd.ReturnStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 import dmd.BreakStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 import dmd.ContinueStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 import dmd.AsmStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 import dmd.TypeReturn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 import dmd.TypeTypeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 import dmd.ForeachRangeStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 import dmd.ForeachStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 import dmd.CompileStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 import dmd.CompoundStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 import dmd.ConditionalStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 import dmd.CompoundDeclarationStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 import dmd.Argument;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 import dmd.ParseStatementFlags;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
143 import dmd.TypeNewArray;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 import dmd.TypeNext;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 import dmd.TypeInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 import dmd.TypePointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 import dmd.TypeDArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 import dmd.TypeAArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 import dmd.TypeSlice;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 import dmd.TemplateInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 import dmd.TypeIdentifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 import dmd.TypeDelegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 import dmd.LinkDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 import dmd.TypedefDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 import dmd.AliasDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 import dmd.LINK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 import dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 import dmd.TemplateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 import dmd.StaticAssert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 import dmd.TypeQualified;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 import dmd.Condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 import dmd.PostBlitDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 import dmd.DtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 import dmd.ConditionalDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 import dmd.StaticCtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 import dmd.StaticDtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 import dmd.InvariantDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 import dmd.UnitTestDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 import dmd.NewDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 import dmd.DeleteDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 import dmd.EnumDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 import dmd.Import;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 import dmd.Initializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 import dmd.Token;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 import dmd.ParseStatementFlags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 import dmd.PROT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 import dmd.CompileDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 import dmd.StaticIfDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 import dmd.StorageClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 import dmd.LinkDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 import dmd.ProtDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 import dmd.AlignDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 import dmd.PragmaDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 import dmd.DebugSymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 import dmd.VersionSymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 import dmd.AliasThis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 import core.stdc.string : memcpy;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208
34
544b922227c7 update to work with dmd 2.048
korDen
parents: 24
diff changeset
209 import std.exception;
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
210 import core.memory;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 class Parser : Lexer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 ModuleDeclaration md;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 LINK linkage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 Loc endloc; // set to location of last right curly
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 int inBrackets; // inside [] of array index or slice
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 this(Module module_, ubyte* base, uint length, int doDocComment)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 super(module_, base, 0, length, doDocComment, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 //printf("Parser.Parser()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 linkage = LINK.LINKd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 //nextToken(); // start up the scanner
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
227 Dsymbols parseModule()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
229 typeof(return) decldefs;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 // ModuleDeclation leads off
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 if (token.value == TOK.TOKmodule)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
234 string comment = token.blockComment;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 bool safe = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 error("module (system) identifier expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 Identifier id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 if (id is Id.system)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 safe = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 error("(safe) expected, not %s", id.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 error("Identifier expected following module");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 Array a = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 Identifier id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 while (nextToken() == TOK.TOKdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 if (!a)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 a = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 a.push(cast(void*)id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 { error("Identifier expected following package");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 md = new ModuleDeclaration(a, id, safe);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 if (token.value != TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 error("';' expected following module declaration instead of %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 addComment(mod, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 decldefs = parseDeclDefs(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 if (token.value != TOK.TOKeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 error("unrecognized declaration");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 return decldefs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 while (token.value != TOK.TOKsemicolon && token.value != TOK.TOKeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 nextToken();
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
304 return new Dsymbols();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
307 Dsymbols parseDeclDefs(int once)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 Dsymbol s;
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
310 Dsymbols decldefs;
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
311 Dsymbols a;
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
312 Dsymbols aelse;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 PROT prot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 STC stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 STC storageClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 Condition condition;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
317 string comment;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 //printf("Parser.parseDeclDefs()\n");
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
320 decldefs = new Dsymbols();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 comment = token.blockComment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 storageClass = STC.STCundefined;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 case TOK.TOKenum:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 { /* Determine if this is a manifest constant declaration,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 * or a conventional enum.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 Token *t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 if (t.value == TOK.TOKlcurly || t.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 s = parseEnum();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 else if (t.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 if (t.value == TOK.TOKlcurly || t.value == TOK.TOKcolon ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 t.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 s = parseEnum();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 case TOK.TOKstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 case TOK.TOKunion:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 case TOK.TOKclass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 case TOK.TOKinterface:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 s = parseAggregate();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 case TOK.TOKimport:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 s = parseImport(decldefs, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 case TOK.TOKtemplate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 s = cast(Dsymbol)parseTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 case TOK.TOKmixin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 { Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 { // mixin(string)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 check(TOK.TOKlparen, "mixin");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 Expression e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 check(TOK.TOKsemicolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 s = new CompileDeclaration(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 s = parseMixin();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 case TOK.TOKwchar: case TOK.TOKdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 case TOK.TOKbit: case TOK.TOKbool: case TOK.TOKchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 case TOK.TOKint8: case TOK.TOKuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 case TOK.TOKint16: case TOK.TOKuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 case TOK.TOKint32: case TOK.TOKuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 case TOK.TOKint64: case TOK.TOKuns64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 case TOK.TOKfloat32: case TOK.TOKfloat64: case TOK.TOKfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 case TOK.TOKimaginary32: case TOK.TOKimaginary64: case TOK.TOKimaginary80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 case TOK.TOKcomplex32: case TOK.TOKcomplex64: case TOK.TOKcomplex80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 case TOK.TOKvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 case TOK.TOKalias:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 case TOK.TOKtypedef:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 Ldeclaration:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 a = parseDeclarations(STC.STCundefined);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 decldefs.append(a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 case TOK.TOKthis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 s = parseCtor();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 static if (false) { // dead end, use this(this){} instead
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 case TOK.TOKassign:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 s = parsePostBlit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 case TOK.TOKtilde:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 s = parseDtor();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 { Token *t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 if (t.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 if (peek(t).value == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 // invariant() forms start of class invariant
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 s = parseInvariant();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 // invariant(type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 stc = STC.STCimmutable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 case TOK.TOKunittest:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 s = parseUnitTest();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 case TOK.TOKnew:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 s = parseNew();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 case TOK.TOKdelete:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 s = parseDelete();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 case TOK.TOKrcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 return decldefs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 case TOK.TOKstatic:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 if (token.value == TOK.TOKthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 s = parseStaticCtor();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 else if (token.value == TOK.TOKtilde)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 s = parseStaticDtor();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 else if (token.value == TOK.TOKassert)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 s = parseStaticAssert();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 else if (token.value == TOK.TOKif)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 { condition = parseStaticIfCondition();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 aelse = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 if (token.value == TOK.TOKelse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 aelse = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 s = new StaticIfDeclaration(condition, a, aelse);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 else if (token.value == TOK.TOKimport)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 s = parseImport(decldefs, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 { stc = STC.STCstatic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 goto Lstc2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 stc = STC.STCconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 stc = STC.STCimmutable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 case TOK.TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 stc = STC.STCshared;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 case TOK.TOKfinal: stc = STC.STCfinal; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 case TOK.TOKauto: stc = STC.STCauto; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 case TOK.TOKscope: stc = STC.STCscope; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 case TOK.TOKoverride: stc = STC.STCoverride; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 case TOK.TOKabstract: stc = STC.STCabstract; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 case TOK.TOKsynchronized: stc = STC.STCsynchronized; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 case TOK.TOKdeprecated: stc = STC.STCdeprecated; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 case TOK.TOKnothrow: stc = STC.STCnothrow; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 case TOK.TOKpure: stc = STC.STCpure; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 case TOK.TOKref: stc = STC.STCref; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 case TOK.TOKtls: stc = STC.STCtls; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 case TOK.TOKgshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 stc = STC.STCgshared; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 //case TOK.TOKmanifest: stc = STC.STCmanifest; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 Lstc:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 if (storageClass & stc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 error("redundant storage class %s", Token.toChars(token.value));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 composeStorageClass(storageClass | stc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 Lstc2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 storageClass |= stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 case TOK.TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 // If followed by a (, it is not a storage class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 if (token.value == TOK.TOKconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 stc = STC.STCconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 else if (token.value == TOK.TOKshared)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 stc = STC.STCshared;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 stc = STC.STCimmutable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 case TOK.TOKfinal: stc = STC.STCfinal; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 case TOK.TOKauto: stc = STC.STCauto; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 case TOK.TOKscope: stc = STC.STCscope; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 case TOK.TOKoverride: stc = STC.STCoverride; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 case TOK.TOKabstract: stc = STC.STCabstract; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 case TOK.TOKsynchronized: stc = STC.STCsynchronized; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 case TOK.TOKdeprecated: stc = STC.STCdeprecated; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 case TOK.TOKnothrow: stc = STC.STCnothrow; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 case TOK.TOKpure: stc = STC.STCpure; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 case TOK.TOKref: stc = STC.STCref; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 case TOK.TOKtls: stc = STC.STCtls; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 case TOK.TOKgshared: stc = STC.STCgshared; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 //case TOK.TOKmanifest: stc = STC.STCmanifest; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 /* Look for auto initializers:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 * storage_class identifier = initializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 if (token.value == TOK.TOKidentifier &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 peek(&token).value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 a = parseAutoDeclarations(storageClass, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 decldefs.append(a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 /* Look for return type inference for template functions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 Token *tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 if (token.value == TOK.TOKidentifier &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 (tk = peek(&token)).value == TOK.TOKlparen &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 skipParens(tk, &tk) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 (peek(tk).value == TOK.TOKlparen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 peek(tk).value == TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 a = parseDeclarations(storageClass);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 decldefs.append(a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 s = new StorageClassDeclaration(storageClass, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 case TOK.TOKextern:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 if (peek(&token).value != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 stc = STC.STCextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 LINK linksave = linkage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 linkage = parseLinkage();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 s = new LinkDeclaration(linkage, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 linkage = linksave;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 case TOK.TOKprivate: prot = PROT.PROTprivate; goto Lprot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 case TOK.TOKpackage: prot = PROT.PROTpackage; goto Lprot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 case TOK.TOKprotected: prot = PROT.PROTprotected; goto Lprot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 case TOK.TOKpublic: prot = PROT.PROTpublic; goto Lprot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 case TOK.TOKexport: prot = PROT.PROTexport; goto Lprot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 Lprot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 case TOK.TOKprivate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 case TOK.TOKpackage:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 case TOK.TOKprotected:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 case TOK.TOKpublic:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 case TOK.TOKexport:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 error("redundant protection attribute");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 s = new ProtDeclaration(prot, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 case TOK.TOKalign:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 { uint n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 if (token.value == TOK.TOKint32v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 n = cast(uint)token.uns64value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 { error("integer expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 n = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 n = global.structalign; // default
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 s = new AlignDeclaration(n, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 case TOK.TOKpragma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 { Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 Expressions args = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 { error("pragma(identifier expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 if (token.value == TOK.TOKcomma && peekNext() != TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 args = parseArguments(); // pragma(identifier, args...)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 check(TOK.TOKrparen); // pragma(identifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 a = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 s = new PragmaDeclaration(loc, ident, args, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 case TOK.TOKdebug:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 if (token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 s = new DebugSymbol(loc, token.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 else if (token.value == TOK.TOKint32v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 s = new DebugSymbol(loc, cast(uint)token.uns64value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 { error("identifier or integer expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 if (token.value != TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 error("semicolon expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 condition = parseDebugCondition();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 goto Lcondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 case TOK.TOKversion:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 if (token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 s = new VersionSymbol(loc, token.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 else if (token.value == TOK.TOKint32v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 s = new VersionSymbol(loc, cast(uint)token.uns64value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 { error("identifier or integer expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 if (token.value != TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 error("semicolon expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 condition = parseVersionCondition();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 goto Lcondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 Lcondition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 aelse = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 if (token.value == TOK.TOKelse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 aelse = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 s = new ConditionalDeclaration(condition, a, aelse);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724 case TOK.TOKsemicolon: // empty declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 error("Declaration expected, not '%s'",token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 Lerror:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 while (token.value != TOK.TOKsemicolon && token.value != TOK.TOKeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 if (s)
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
738 { decldefs.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 addComment(s, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 } while (!once);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 return decldefs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 * Parse auto declarations of the form:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 * storageClass ident = init, ident = init, ... ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 * and return the array of them.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749 * Starts with token on the first ident.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 * Ends with scanner past closing ';'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 */
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
752 version (DMDV2)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
753 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
754 Dsymbols parseAutoDeclarations(STC storageClass, const(char)[] comment)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
756 auto a = new Dsymbols;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 Identifier ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 nextToken(); // skip over ident
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 assert(token.value == TOKassign);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 nextToken(); // skip over '='
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 Initializer init = parseInitializer();
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
765 auto v = new VarDeclaration(loc, null, ident, init);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 v.storage_class = storageClass;
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
767 a.push(v);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 if (token.value == TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 addComment(v, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 else if (token.value == TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 if (token.value == TOKidentifier &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 peek(&token).value == TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779 addComment(v, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 error("Identifier expected following comma");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 error("semicolon expected following auto declaration, not '%s'", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 /********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 * Parse declarations after an align, protection, or extern decl.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 */
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
795 Dsymbols parseBlock()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
797 Dsymbols a = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 Dsymbol ss;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 //printf("parseBlock()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 error("declaration expected following attribute, not ';'");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 error("declaration expected following attribute, not EOF");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 a = parseDeclDefs(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 if (token.value != TOK.TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 { /* { */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 error("matching '}' expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 case TOK.TOKcolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 a = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 a = parseDeclDefs(0); // grab declarations up to closing curly bracket
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 a = parseDeclDefs(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 void composeStorageClass(STC stc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 STC u = stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 u &= STC.STCconst | STC.STCimmutable | STC.STCmanifest;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 if (u & (u - 1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 error("conflicting storage class %s", Token.toChars(token.value));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 u = stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 u &= STC.STCgshared | STC.STCshared | STC.STCtls;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 if (u & (u - 1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 error("conflicting storage class %s", Token.toChars(token.value));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 * Parse constraint.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 * Constraint is of the form:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 * if ( ConstraintExpression )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 Expression parseConstraint()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 Expression e = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 if (token.value == TOKif)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 nextToken(); // skip over 'if'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 check(TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 e = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 * Parse a TemplateDeclaration.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 TemplateDeclaration parseTemplateDeclaration()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 TemplateDeclaration tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 TemplateParameters tpl;
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
880 Dsymbols decldefs;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881 Expression constraint = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 if (token.value != TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887 error("TemplateIdentifier expected following template");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 tpl = parseTemplateParameterList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 if (!tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 constraint = parseConstraint();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 if (token.value != TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 error("members of template declaration expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 decldefs = parseDeclDefs(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 if (token.value != TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 error("template member expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 tempdecl = new TemplateDeclaration(loc, id, tpl, constraint, decldefs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 return tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 /******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 * Parse template parameter list.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 * flag 0: parsing "( list )"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 * 1: parsing non-empty "list )"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 TemplateParameters parseTemplateParameterList(int flag = 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 TemplateParameters tpl = new TemplateParameters();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 if (!flag && token.value != TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 error("parenthesized TemplateParameterList expected following TemplateIdentifier");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 // Get array of TemplateParameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 if (flag || token.value != TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 int isvariadic = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 TemplateParameter tp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 Identifier tp_ident = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 Type tp_spectype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 Type tp_valtype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 Type tp_defaulttype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 Expression tp_specvalue = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952 Expression tp_defaultvalue = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 Token* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955 // Get TemplateParameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 // First, look ahead to see if it is a TypeParameter or a ValueParameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 if (token.value == TOKalias)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 // AliasParameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963 Type spectype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 if (isDeclaration(&token, 2, TOKreserved, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 spectype = parseType(&tp_ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 if (token.value != TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 error("identifier expected for template alias parameter");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 tp_ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 Object spec = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 if (token.value == TOKcolon) // : Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 if (isDeclaration(&token, 0, TOKreserved, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 spec = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 spec = parseCondExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 Object def = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 if (token.value == TOKassign) // = Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 if (isDeclaration(&token, 0, TOKreserved, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 def = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 def = parseCondExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 tp = new TemplateAliasParameter(loc, tp_ident, spectype, spec, def);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 else if (t.value == TOKcolon || t.value == TOKassign ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 t.value == TOKcomma || t.value == TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 { // TypeParameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 if (token.value != TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 { error("identifier expected for template type parameter");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 tp_ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 if (token.value == TOKcolon) // : Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 tp_spectype = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 if (token.value == TOKassign) // = Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 tp_defaulttype = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 tp = new TemplateTypeParameter(loc, tp_ident, tp_spectype, tp_defaulttype);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 else if (token.value == TOKidentifier && t.value == TOKdotdotdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 { // ident...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 if (isvariadic)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 error("variadic template parameter must be last");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 isvariadic = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 tp_ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 tp = new TemplateTupleParameter(loc, tp_ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 /// version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 else if (token.value == TOKthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 { // ThisParameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 if (token.value != TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 { error("identifier expected for template this parameter");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 tp_ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 if (token.value == TOKcolon) // : Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 tp_spectype = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 if (token.value == TOKassign) // = Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 tp_defaulttype = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 tp = new TemplateThisParameter(loc, tp_ident, tp_spectype, tp_defaulttype);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 { // ValueParameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 tp_valtype = parseType(&tp_ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 if (!tp_ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 error("identifier expected for template value parameter");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 tp_ident = new Identifier("error", TOKidentifier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 if (token.value == TOKcolon) // : CondExpression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 tp_specvalue = parseCondExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065 if (token.value == TOKassign) // = CondExpression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 tp_defaultvalue = parseDefaultInitExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 tp = new TemplateValueParameter(loc, tp_ident, tp_valtype, tp_specvalue, tp_defaultvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071 }
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1072 tpl.push(tp);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073 if (token.value != TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 return tpl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 }
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1083
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1084 /******************************************
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1085 * Parse template mixin.
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1086 * mixin Foo;
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1087 * mixin Foo!(args);
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1088 * mixin a.b.c!(args).Foo!(args);
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1089 * mixin Foo!(args) identifier;
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1090 * mixin typeof(expr).identifier!(args);
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1091 */
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1092
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 Dsymbol parseMixin()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 {
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1095 TemplateMixin tm;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1096 Identifier id;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1097 Type tqual;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1098 Objects tiargs;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1099 Array idents;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1100
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1101 //printf("parseMixin()\n");
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1102 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1103 tqual = null;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1104 if (token.value == TOKdot)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1105 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1106 id = Id.empty;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1107 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1108 else
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1109 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1110 if (token.value == TOKtypeof)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1111 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1112 tqual = parseTypeof();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1113 check(TOKdot);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1114 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1115 if (token.value != TOKidentifier)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1116 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1117 error("identifier expected, not %s", token.toChars());
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1118 id = Id.empty;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1119 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1120 else
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1121 id = token.ident;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1122 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1123 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1124
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1125 idents = new Array();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1126 while (1)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1127 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1128 tiargs = null;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1129 if (token.value == TOKnot)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1130 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1131 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1132 if (token.value == TOKlparen)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1133 tiargs = parseTemplateArgumentList();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1134 else
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1135 tiargs = parseTemplateArgument();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1136 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1137 if (token.value != TOKdot)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1138 break;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1139 if (tiargs)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1140 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1141 TemplateInstance tempinst = new TemplateInstance(loc, id);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1142 tempinst.tiargs = tiargs;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1143 id = cast(Identifier)tempinst;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1144 tiargs = null;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1145 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1146 idents.push(cast(void*)id);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1147 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1148 if (token.value != TOKidentifier)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1149 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1150 error("identifier expected following '.' instead of '%s'", token.toChars());
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1151 break;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1152 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1153 id = token.ident;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1154 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1155 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1156 idents.push(cast(void*)id);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1157 if (token.value == TOKidentifier)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1158 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1159 id = token.ident;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1160 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1161 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1162 else
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1163 id = null;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1164
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1165 tm = new TemplateMixin(loc, id, tqual, idents, tiargs);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1166 if (token.value != TOKsemicolon)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1167 error("';' expected after mixin");
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1168 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1169 return tm;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1170 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1171
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1172 /******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1173 * Parse template argument list.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1174 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1175 * current token is opening '('
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1176 * Output:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1177 * current token is one after closing ')'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1178 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1179 Objects parseTemplateArgumentList()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1180 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1181 //printf("Parser.parseTemplateArgumentList()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1182 if (token.value != TOKlparen && token.value != TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1183 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1184 error("!(TemplateArgumentList) expected following TemplateIdentifier");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1185 return new Objects();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1186 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1187 return parseTemplateArgumentList2();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1188 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1189
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1190 Objects parseTemplateArgumentList2()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1191 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1192 //printf("Parser.parseTemplateArgumentList2()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1193 Objects tiargs = new Objects();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1194 TOK endtok = TOKrparen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1195 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1196
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1197 // Get TemplateArgumentList
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1198 if (token.value != endtok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1199 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1200 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1201 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1202 // See if it is an Expression or a Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1203 if (isDeclaration(&token, 0, TOKreserved, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1204 { // Template argument is a type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1205 Type ta = parseType();
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
1206 tiargs.push(ta);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1207 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1208 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1209 { // Template argument is an expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1210 Expression ea = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1211
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1212 if (ea.op == TOKfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1214 FuncLiteralDeclaration fd = (cast(FuncExp)ea).fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1215 if (fd.type.ty == Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1216 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1217 TypeFunction tf = cast(TypeFunction)fd.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1218 /* If there are parameters that consist of only an identifier,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1219 * rather than assuming the identifier is a type, as we would
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1220 * for regular function declarations, assume the identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1221 * is the parameter name, and we're building a template with
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1222 * a deduced type.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1223 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1224 TemplateParameters tpl = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1225 for (int i = 0; i < tf.parameters.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1226 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1227 Argument param = cast(Argument)tf.parameters.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1228 if (param.ident is null &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1229 param.type &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1230 param.type.ty == Tident &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1231 (cast(TypeIdentifier)param.type).idents.dim == 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1232 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1233 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1234 /* Switch parameter type to parameter identifier,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1235 * parameterize with template type parameter _T
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1236 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1237 TypeIdentifier pt = cast(TypeIdentifier)param.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1238 param.ident = pt.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1239 Identifier id = Lexer.uniqueId("__T");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 param.type = new TypeIdentifier(pt.loc, id);
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1241 auto tp = new TemplateTypeParameter(fd.loc, id, null, null);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 if (!tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1243 tpl = new TemplateParameters();
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1244 tpl.push(tp);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1245 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1246 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1247
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1248 if (tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1249 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1250 // Wrap a template around function fd
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
1251 auto decldefs = new Dsymbols();
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
1252 decldefs.push(fd);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
1253 auto tempdecl = new TemplateDeclaration(fd.loc, fd.ident, tpl, null, decldefs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1254 tempdecl.literal = 1; // it's a template 'literal'
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
1255 tiargs.push(tempdecl);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1256 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1257 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1258 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1259 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1260
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
1261 tiargs.push(ea);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1262 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1263 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1264 if (token.value != TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1265 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1266 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1267 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1269 check(endtok, "template argument list");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1270 return tiargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1271 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1272
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1273 /*****************************
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1274 * Parse single template argument, to support the syntax:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1275 * foo!arg
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1276 * Input:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1277 * current token is the arg
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1278 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1279 Objects parseTemplateArgument()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1280 {
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1281 //printf("parseTemplateArgument()\n");
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1282 Objects tiargs = new Objects();
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1283 Type ta;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1284 switch (token.value)
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1285 {
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1286 case TOKidentifier:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1287 ta = new TypeIdentifier(loc, token.ident);
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1288 goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1289
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1290 case TOKvoid: ta = Type.tvoid; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1291 case TOKint8: ta = Type.tint8; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1292 case TOKuns8: ta = Type.tuns8; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1293 case TOKint16: ta = Type.tint16; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1294 case TOKuns16: ta = Type.tuns16; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1295 case TOKint32: ta = Type.tint32; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1296 case TOKuns32: ta = Type.tuns32; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1297 case TOKint64: ta = Type.tint64; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1298 case TOKuns64: ta = Type.tuns64; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1299 case TOKfloat32: ta = Type.tfloat32; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1300 case TOKfloat64: ta = Type.tfloat64; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1301 case TOKfloat80: ta = Type.tfloat80; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1302 case TOKimaginary32: ta = Type.timaginary32; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1303 case TOKimaginary64: ta = Type.timaginary64; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1304 case TOKimaginary80: ta = Type.timaginary80; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1305 case TOKcomplex32: ta = Type.tcomplex32; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1306 case TOKcomplex64: ta = Type.tcomplex64; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1307 case TOKcomplex80: ta = Type.tcomplex80; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1308 case TOKbit: ta = Type.tbit; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1309 case TOKbool: ta = Type.tbool; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1310 case TOKchar: ta = Type.tchar; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1311 case TOKwchar: ta = Type.twchar; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1312 case TOKdchar: ta = Type.tdchar; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1313 LabelX:
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
1314 tiargs.push(ta);
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1315 nextToken();
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1316 break;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1317
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1318 case TOKint32v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1319 case TOKuns32v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1320 case TOKint64v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1321 case TOKuns64v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1322 case TOKfloat32v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1323 case TOKfloat64v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1324 case TOKfloat80v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1325 case TOKimaginary32v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1326 case TOKimaginary64v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1327 case TOKimaginary80v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1328 case TOKnull:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1329 case TOKtrue:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1330 case TOKfalse:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1331 case TOKcharv:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1332 case TOKwcharv:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1333 case TOKdcharv:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1334 case TOKstring:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1335 case TOKfile:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1336 case TOKline:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1337 {
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1338 // Template argument is an expression
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1339 Expression ea = parsePrimaryExp();
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
1340 tiargs.push(ea);
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1341 break;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1342 }
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1343
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1344 default:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1345 error("template argument expected following !");
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1346 break;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1347 }
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1348
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1349 if (token.value == TOKnot)
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1350 error("multiple ! arguments are not allowed");
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1351 return tiargs;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1352 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1353
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1354 /**********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1355 * Parse a static assertion.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1356 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1357 StaticAssert parseStaticAssert()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1358 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1359 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1360 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1361 Expression msg = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1362
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1363 //printf("parseStaticAssert()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1364 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1365 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1366 exp = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1367 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1368 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1369 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1370 msg = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1371 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1372
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1373 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1374 check(TOK.TOKsemicolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1375
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1376 return new StaticAssert(loc, exp, msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1377 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1378
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1379 TypeQualified parseTypeof()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1380 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1381 TypeQualified t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1382 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1383
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1384 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1385 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1386 if (token.value == TOK.TOKreturn) // typeof(return)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1387 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1388 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1389 t = new TypeReturn(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1390 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1391 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1392 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1393 Expression exp = parseExpression(); // typeof(expression)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1394 t = new TypeTypeof(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1395 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1396 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1397 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1398 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1399
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1400 /***********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1401 * Parse extern (linkage)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1402 * The parser is on the 'extern' token.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1403 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1404 LINK parseLinkage()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1405 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1406 LINK link = LINK.LINKdefault;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1407 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1408 assert(token.value == TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1409 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1410 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1411 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1412 Identifier id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1413
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1414 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1415 if (id == Id.Windows)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1416 link = LINK.LINKwindows;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1417 else if (id == Id.Pascal)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1418 link = LINK.LINKpascal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1419 else if (id == Id.D)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1420 link = LINK.LINKd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1421 else if (id == Id.C)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1422 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1423 link = LINK.LINKc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1424 if (token.value == TOK.TOKplusplus)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1425 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1426 link = LINK.LINKcpp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1427 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1428 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1429 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1430 else if (id == Id.System)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1431 {
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 110
diff changeset
1432 version (Windows)
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 110
diff changeset
1433 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1434 link = LINK.LINKwindows;
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 110
diff changeset
1435 }
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 110
diff changeset
1436 else
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 110
diff changeset
1437 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1438 link = LINK.LINKc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1439 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1440 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1441 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1442 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1443 error("valid linkage identifiers are D, C, C++, Pascal, Windows, System");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1444 link = LINK.LINKd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1445 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1446 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1447 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1448 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1449 link = LINK.LINKd; // default
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1450 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1451 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1452
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1453 return link;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1454 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1455
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1456
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1457 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1458 * Parse a debug conditional
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1459 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1460 Condition parseDebugCondition()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1461 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1462 Condition c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1463
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1464 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1465 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1466 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1467 uint level = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1468 Identifier id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1469
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1470 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1471 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1472 else if (token.value == TOK.TOKint32v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1473 level = cast(uint)token.uns64value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1474 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1475 error("identifier or integer expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1476
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1477 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1478 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1479
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1480 c = new DebugCondition(mod, level, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1481 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1482 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1483 c = new DebugCondition(mod, 1, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1484
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1485 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1486 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1487
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1488 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1489 * Parse a version conditional
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1490 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1491 Condition parseVersionCondition()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1492 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1493 Condition c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1494 uint level = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1495 Identifier id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1496
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1497 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1498 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1499 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1500 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1501 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1502 else if (token.value == TOK.TOKint32v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1503 level = cast(uint)token.uns64value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1504 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1505 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1506 /* Allow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1507 * version (unittest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1508 * even though unittest is a keyword
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1509 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1510 if (token.value == TOK.TOKunittest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1511 id = Lexer.idPool(Token.toChars(TOK.TOKunittest));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1512 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1513 error("identifier or integer expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1514 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1515 error("identifier or integer expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1516 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1517 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1518 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1519 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1520 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1521 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1522 error("(condition) expected following version");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1523
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1524 c = new VersionCondition(mod, level, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1525
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1526 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1527 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1528
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1529 /***********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1530 * static if (expression)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1531 * body
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1532 * else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1533 * body
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1534 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1535 Condition parseStaticIfCondition()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1536 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1537 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1538 Condition condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1539 Array aif;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1540 Array aelse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1541 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1542
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1543 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1544 if (token.value == TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1545 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1546 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1547 exp = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1548 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1549 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1550 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1551 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1552 error("(expression) expected following static if");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1553 exp = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1554 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1555 condition = new StaticIfCondition(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1556 return condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1557 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1558
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1559 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1560 * Parse a constructor definition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1561 * this(parameters) { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1562 * or postblit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1563 * this(this) { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1564 * or constructor template:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1565 * this(templateparameters)(parameters) { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1566 * Current token is 'this'.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1567 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1568
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1569 Dsymbol parseCtor()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1570 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1571 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1572
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1573 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1574 if (token.value == TOK.TOKlparen && peek(&token).value == TOK.TOKthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1575 { // this(this) { ... }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1576 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1577 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1578 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1579 PostBlitDeclaration f = new PostBlitDeclaration(loc, Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1580 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1581 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1582 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1583
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1584 /* Look ahead to see if:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1585 * this(...)(...)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1586 * which is a constructor template
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1587 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1588 TemplateParameters tpl = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1589 if (token.value == TOK.TOKlparen && peekPastParen(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1590 { tpl = parseTemplateParameterList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1591
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1592 int varargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1593 Arguments arguments = parseParameters(&varargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1594
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1595 Expression constraint = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1596 if (tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1597 constraint = parseConstraint();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1598
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1599 CtorDeclaration f = new CtorDeclaration(loc, Loc(0), arguments, varargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1600 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1601
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1602 // Wrap a template around it
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
1603 auto decldefs = new Dsymbols();
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
1604 decldefs.push(f);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
1605 auto tempdecl = new TemplateDeclaration(loc, f.ident, tpl, constraint, decldefs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1606 return tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1607 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1608
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1609 /* Just a regular constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1610 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1611 int varargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1612 Arguments arguments = parseParameters(&varargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1613 CtorDeclaration f = new CtorDeclaration(loc, Loc(0), arguments, varargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1614 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1615 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1616 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1617
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1618 PostBlitDeclaration parsePostBlit()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1619 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1620 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1621 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1622
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1623 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1624 * Parse a destructor definition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1625 * ~this() { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1626 * Current token is '~'.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1627 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1628 DtorDeclaration parseDtor()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1629 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1630 DtorDeclaration f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1631 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1632
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1633 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1634 check(TOKthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1635 check(TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1636 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1637
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1638 f = new DtorDeclaration(loc, Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1639 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1640 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1641 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1642
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1643 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1644 * Parse a static constructor definition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1645 * static this() { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1646 * Current token is 'this'.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1647 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1648 StaticCtorDeclaration parseStaticCtor()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1649 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1650 StaticCtorDeclaration f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1651 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1652
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1653 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1654 check(TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1655 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1656
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1657 f = new StaticCtorDeclaration(loc, Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1658 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1659 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1660 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1661
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1662 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1663 * Parse a static destructor definition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1664 * static ~this() { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1665 * Current token is '~'.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1666 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1667 StaticDtorDeclaration parseStaticDtor()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1668 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1669 StaticDtorDeclaration f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1670 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1671
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1672 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1673 check(TOKthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1674 check(TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1675 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1676
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1677 f = new StaticDtorDeclaration(loc, Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1678 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1679 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1680 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1681
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1682 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1683 * Parse an invariant definition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1684 * invariant() { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1685 * Current token is 'invariant'.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1686 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1687 InvariantDeclaration parseInvariant()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1688 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1689 InvariantDeclaration f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1690 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1691
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1692 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1693 if (token.value == TOKlparen) // optional ()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1694 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1695 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1696 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1697 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1698
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1699 f = new InvariantDeclaration(loc, Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1700 f.fbody = parseStatement(ParseStatementFlags.PScurly);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1701 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1702 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1703
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1704 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1705 * Parse a unittest definition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1706 * unittest { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1707 * Current token is 'unittest'.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1708 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1709 UnitTestDeclaration parseUnitTest()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1710 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1711 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1712
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1713 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1714
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1715 UnitTestDeclaration f = new UnitTestDeclaration(loc, this.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1716 f.fbody = parseStatement(ParseStatementFlags.PScurly);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1717
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1718 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1719 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1720
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1721 /*****************************************
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1722 * Parse a new definition:
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1723 * new(arguments) { body }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1724 * Current token is 'new'.
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1725 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1726 NewDeclaration parseNew()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1727 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1728 NewDeclaration f;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1729 scope Arguments arguments = new Arguments();
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1730 int varargs;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1731 Loc loc = this.loc;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1732
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1733 nextToken();
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1734 arguments = parseParameters(&varargs);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1735 f = new NewDeclaration(loc, Loc(0), arguments, varargs);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1736 parseContracts(f);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1737 return f;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1738 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1739
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1740 /*****************************************
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1741 * Parse a delete definition:
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1742 * delete(arguments) { body }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1743 * Current token is 'delete'.
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1744 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1745 DeleteDeclaration parseDelete()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1746 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1747 DeleteDeclaration f;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1748 scope Arguments arguments;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1749 int varargs;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1750 Loc loc = this.loc;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1751
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1752 nextToken();
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1753 arguments = parseParameters(&varargs);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1754 if (varargs)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1755 error("... not allowed in delete function parameter list");
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1756 f = new DeleteDeclaration(loc, Loc(0), arguments);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1757 parseContracts(f);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1758 return f;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1759 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1760
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1761 Arguments parseParameters(int* pvarargs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1762 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1763 Arguments arguments = new Arguments();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1764 int varargs = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1765 int hasdefault = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1766
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1767 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1768 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1769 { Type *tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1770 Identifier ai = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1771 Type at;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1772 Argument a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1773 STC storageClass = STC.STCundefined;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1774 STC stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1775 Expression ae;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1776
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1777 for ( ;1; nextToken())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1778 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1779 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1780 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1781 case TOK.TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1782 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1783
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1784 case TOK.TOKdotdotdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1785 varargs = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1786 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1787 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1788
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1789 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1790 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1791 goto Ldefault;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1792 stc = STC.STCconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1793 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1794
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1795 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1796 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1797 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1798 goto Ldefault;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1799 stc = STC.STCimmutable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1800 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1801
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1802 case TOK.TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1803 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1804 goto Ldefault;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1805 stc = STC.STCshared;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1806 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1807
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1808 case TOK.TOKin: stc = STC.STCin; goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1809 case TOK.TOKout: stc = STC.STCout; goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1810 case TOK.TOKinout:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1811 case TOK.TOKref: stc = STC.STCref; goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1812 case TOK.TOKlazy: stc = STC.STClazy; goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1813 case TOK.TOKscope: stc = STC.STCscope; goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1814 case TOK.TOKfinal: stc = STC.STCfinal; goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1815 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1816 if (storageClass & stc ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1817 (storageClass & STC.STCin && stc & (STC.STCconst | STC.STCscope)) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1818 (stc & STC.STCin && storageClass & (STC.STCconst | STC.STCscope))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1819 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1820 error("redundant storage class %s", Token.toChars(token.value));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1821 storageClass |= stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1822 composeStorageClass(storageClass);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1823 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1824
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1825 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1826 case TOK.TOKstatic: stc = STC.STCstatic; goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1827 case TOK.TOKauto: storageClass = STC.STCauto; goto L4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1828 case TOK.TOKalias: storageClass = STC.STCalias; goto L4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1829 L4:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1830 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1831 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1832 { ai = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1833 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1834 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1835 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1836 ai = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1837 at = null; // no type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1838 ae = null; // no default argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1839 if (token.value == TOK.TOKassign) // = defaultArg
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1840 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1841 ae = parseDefaultInitExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1842 hasdefault = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1843 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1844 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1845 { if (hasdefault)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1846 error("default argument expected for alias %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1847 ai ? ai.toChars() : "");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1848 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1849 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1850 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1851
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1852 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1853 Ldefault:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1854 stc = (storageClass & (STC.STCin | STC.STCout | STC.STCref | STC.STClazy));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1855 if (stc & (stc - 1)) // if stc is not a power of 2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1856 error("incompatible parameter storage classes");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1857 if ((storageClass & (STC.STCconst | STC.STCout)) == (STC.STCconst | STC.STCout))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1858 error("out cannot be const");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1859 if ((storageClass & (STC.STCimmutable | STC.STCout)) == (STC.STCimmutable | STC.STCout))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1860 error("out cannot be immutable");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1861 if ((storageClass & STC.STCscope) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1862 (storageClass & (STC.STCref | STC.STCout)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1863 error("scope cannot be ref or out");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1864 at = parseType(&ai);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1865 ae = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1866 if (token.value == TOK.TOKassign) // = defaultArg
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1867 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1868 ae = parseDefaultInitExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1869 hasdefault = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1870 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1871 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1872 { if (hasdefault)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1873 error("default argument expected for %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1874 ai ? ai.toChars() : at.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1875 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1876 if (token.value == TOK.TOKdotdotdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1877 { /* This is:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1878 * at ai ...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1879 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1880
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1881 if (storageClass & (STC.STCout | STC.STCref))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1882 error("variadic argument cannot be out or ref");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1883 varargs = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1884 a = new Argument(storageClass, at, ai, ae);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1885 arguments.push(cast(void*)a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1886 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1887 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1888 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1889 L3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1890 a = new Argument(storageClass, at, ai, ae);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1891 arguments.push(cast(void*)a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1892 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1893 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1894 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1895 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1896 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1897 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1898 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1899 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1900 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1901
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1902 L1: ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1903 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1904 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1905 *pvarargs = varargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1906 return arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1907 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1908
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1909 EnumDeclaration parseEnum()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1910 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1911 EnumDeclaration e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1912 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1913 Type memtype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1914 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1915
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1916 //printf("Parser.parseEnum()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1917 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1918 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1919 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1920 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1921 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1922 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1923 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1924 id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1925
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1926 if (token.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1927 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1928 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1929 memtype = parseBasicType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1930 memtype = parseDeclarator(memtype, null, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1931 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1932 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1933 memtype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1934
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1935 e = new EnumDeclaration(loc, id, memtype);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1936 if (token.value == TOK.TOKsemicolon && id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1937 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1938 else if (token.value == TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1939 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1940 //printf("enum definition\n");
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
1941 e.members = new Dsymbols();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1942 nextToken();
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
1943 string comment = token.blockComment;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1944 while (token.value != TOK.TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1945 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1946 /* Can take the following forms:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1947 * 1. ident
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1948 * 2. ident = value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1949 * 3. type ident = value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1950 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1951
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1952 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1953
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1954 Type type = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1955 Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1956 Token* tp = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1957 if (token.value == TOK.TOKidentifier &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1958 (tp.value == TOK.TOKassign || tp.value == TOK.TOKcomma || tp.value == TOK.TOKrcurly))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1959 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1960 ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1961 type = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1962 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1963 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1964 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1965 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1966 type = parseType(&ident, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1967 if (id || memtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1968 error("type only allowed if anonymous enum and no enum type");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1969 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1970
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1971 Expression value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1972 if (token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1973 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1974 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1975 value = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1976 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1977 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1978 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1979 value = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1980 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1981 error("if type, there must be an initializer");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1982 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1983
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
1984 auto em = new EnumMember(loc, ident, value, type);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
1985 e.members.push(em);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1986
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1987 if (token.value == TOK.TOKrcurly) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1988 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1989 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1990 addComment(em, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1991 comment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1992 check(TOK.TOKcomma);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1993 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1994 addComment(em, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1995 comment = token.blockComment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1996 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1997 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1998 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1999 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2000 error("enum declaration is invalid");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2001
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2002 //printf("-parseEnum() %s\n", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2003 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2004 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2005
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2006 Dsymbol parseAggregate()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2007 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2008 AggregateDeclaration a = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2009 int anon = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2010 TOK tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2011 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2012 TemplateParameters tpl = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2013 Expression constraint = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2014
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2015 //printf("Parser.parseAggregate()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2016 tok = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2017 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2018 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2019 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2020 id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2021 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2022 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2023 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2024 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2025 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2026
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2027 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2028 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2029 // Class template declaration.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2030
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2031 // Gather template parameter list
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2032 tpl = parseTemplateParameterList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2033 constraint = parseConstraint();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2034 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2035 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2036
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2037 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2038 switch (tok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2039 { case TOK.TOKclass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2040 case TOK.TOKinterface:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2041 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2042 if (!id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2043 error("anonymous classes not allowed");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2044
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2045 // Collect base class(es)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2046 BaseClasses baseclasses = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2047 if (token.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2048 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2049 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2050 baseclasses = parseBaseClasses();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2051
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2052 if (token.value != TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2053 error("members expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2054 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2055
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2056 if (tok == TOK.TOKclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2057 a = new ClassDeclaration(loc, id, baseclasses);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2058 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2059 a = new InterfaceDeclaration(loc, id, baseclasses);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2060 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2061 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2062
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2063 case TOK.TOKstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2064 if (id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2065 a = new StructDeclaration(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2066 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2067 anon = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2068 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2069
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2070 case TOK.TOKunion:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2071 if (id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2072 a = new UnionDeclaration(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2073 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2074 anon = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2075 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2076
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2077 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2078 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2079 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2080 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2081 if (a && token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2082 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2083 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2084 else if (token.value == TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2085 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2086 //printf("aggregate definition\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2087 nextToken();
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2088 auto decl = parseDeclDefs(0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2089 if (token.value != TOK.TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2090 error("} expected following member declarations in aggregate");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2091 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2092 if (anon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2093 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2094 /* Anonymous structs/unions are more like attributes.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2095 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2096 return new AnonDeclaration(loc, anon - 1, decl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2097 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2098 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2099 a.members = decl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2101 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2102 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2103 error("{ } expected following aggregate declaration");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2104 a = new StructDeclaration(loc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2105 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2106
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2107 if (tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2108 { // Wrap a template around the aggregate declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2109
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2110 auto decldefs = new Dsymbols();
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2111 decldefs.push(a);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2112 auto tempdecl = new TemplateDeclaration(loc, id, tpl, constraint, decldefs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2113 return tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2114 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2115
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2116 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2118
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2119 BaseClasses parseBaseClasses()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2121 BaseClasses baseclasses = new BaseClasses();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2122
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2123 for (; 1; nextToken())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2125 PROT protection = PROT.PROTpublic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2126 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2127 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2128 case TOK.TOKprivate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2129 protection = PROT.PROTprivate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2130 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2131 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2132 case TOK.TOKpackage:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2133 protection = PROT.PROTpackage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2134 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2135 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2136 case TOK.TOKprotected:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2137 protection = PROT.PROTprotected;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2138 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2139 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2140 case TOK.TOKpublic:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2141 protection = PROT.PROTpublic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2142 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2143 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2144 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2145 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2146 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2147 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2148 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2149 BaseClass b = new BaseClass(parseBasicType(), protection);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2150 baseclasses.push(cast(void*)b);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2151 if (token.value != TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2152 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2153 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2154 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2155 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2156 error("base classes expected instead of %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2157 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2158 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2160 return baseclasses;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2162
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2163 Import parseImport(Dsymbols decldefs, int isstatic)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2164 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2165 Import s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2166 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2167 Identifier aliasid = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2168 Array a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2169 Loc loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2170
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2171 //printf("Parser.parseImport()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2172 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2173 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2174 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2175 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2176 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2177 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2178 error("Identifier expected following import");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2179 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2181
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2182 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2183 a = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2184 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2185 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2186 if (!aliasid && token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2187 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2188 aliasid = id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2189 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2190 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2191 while (token.value == TOK.TOKdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2192 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2193 if (!a)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2194 a = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2195 a.push(cast(void*)id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2196 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2197 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2198 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2199 error("identifier expected following package");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2200 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2201 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2202 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2203 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2204 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2205
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2206 s = new Import(loc, a, id, aliasid, isstatic);
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2207 decldefs.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2208
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2209 /* Look for
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2210 * : alias=name, alias=name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2211 * syntax.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2212 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2213 if (token.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2214 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2215 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2216 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2217 Identifier name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2218
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2219 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2220 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2221 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2222 error("Identifier expected following :");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2223 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2224 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2225 Identifier alias_ = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2226 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2227 if (token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2228 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2229 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2230 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2231 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2232 error("Identifier expected following %s=", alias_.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2233 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2234 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2235 name = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2236 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2237 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2238 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2239 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2240 name = alias_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2241 alias_ = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2242 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2243 s.addAlias(name, alias_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2244 } while (token.value == TOK.TOKcomma);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2245
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2246 break; // no comma-separated imports of this form
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2247 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2248
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2249 aliasid = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2250
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2251 } while (token.value == TOK.TOKcomma);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2252
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2253 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2254 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2255 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2256 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2257 error("';' expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2258 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2259 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2260
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2261 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2262 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2263
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2264 Type parseType(Identifier* pident = null, TemplateParameters* tpl = null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2265 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2266 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2267
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2268 /* Take care of the storage class prefixes that
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2269 * serve as type attributes:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2270 * const shared, shared const, const, invariant, shared
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2271 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2272 if (token.value == TOK.TOKconst && peekNext() == TOK.TOKshared && peekNext2() != TOK.TOKlparen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2273 token.value == TOK.TOKshared && peekNext() == TOK.TOKconst && peekNext2() != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2274 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2275 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2276 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2277 /* shared const type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2278 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2279 t = parseType(pident, tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2280 t = t.makeSharedConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2281 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2282 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2283 else if (token.value == TOK.TOKconst && peekNext() != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2284 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2285 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2286 /* const type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2287 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2288 t = parseType(pident, tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2289 t = t.makeConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2290 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2291 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2292 else if ((token.value == TOK.TOKinvariant || token.value == TOK.TOKimmutable) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2293 peekNext() != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2294 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2295 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2296 /* invariant type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2297 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2298 t = parseType(pident, tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2299 t = t.makeInvariant();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2300 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2301 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2302 else if (token.value == TOK.TOKshared && peekNext() != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2303 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2304 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2305 /* shared type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2306 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2307 t = parseType(pident, tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2308 t = t.makeShared();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2309 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2310 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2311 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2312 t = parseBasicType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2313 t = parseDeclarator(t, pident, tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2314 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2315 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2317 Type parseBasicType()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2318 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2319 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2320 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2321 TypeQualified tid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2322
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2323 //printf("parseBasicType()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2324 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2325 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2326 case TOK.TOKvoid: t = Type.tvoid; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2327 case TOK.TOKint8: t = Type.tint8; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2328 case TOK.TOKuns8: t = Type.tuns8; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2329 case TOK.TOKint16: t = Type.tint16; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2330 case TOK.TOKuns16: t = Type.tuns16; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2331 case TOK.TOKint32: t = Type.tint32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2332 case TOK.TOKuns32: t = Type.tuns32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2333 case TOK.TOKint64: t = Type.tint64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2334 case TOK.TOKuns64: t = Type.tuns64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2335 case TOK.TOKfloat32: t = Type.tfloat32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2336 case TOK.TOKfloat64: t = Type.tfloat64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2337 case TOK.TOKfloat80: t = Type.tfloat80; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2338 case TOK.TOKimaginary32: t = Type.timaginary32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2339 case TOK.TOKimaginary64: t = Type.timaginary64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2340 case TOK.TOKimaginary80: t = Type.timaginary80; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2341 case TOK.TOKcomplex32: t = Type.tcomplex32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2342 case TOK.TOKcomplex64: t = Type.tcomplex64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2343 case TOK.TOKcomplex80: t = Type.tcomplex80; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2344 case TOK.TOKbit: t = Type.tbit; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2345 case TOK.TOKbool: t = Type.tbool; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2346 case TOK.TOKchar: t = Type.tchar; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2347 case TOK.TOKwchar: t = Type.twchar; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2348 case TOK.TOKdchar: t = Type.tdchar; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2349 LabelX:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2350 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2351 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2352
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2353 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2354 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2355 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2356 if (token.value == TOK.TOKnot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2357 { // ident!(template_arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2358 TemplateInstance tempinst = new TemplateInstance(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2359 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2360 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2361 // ident!(template_arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2362 tempinst.tiargs = parseTemplateArgumentList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2363 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2364 // ident!template_argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2365 tempinst.tiargs = parseTemplateArgument();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2366 tid = new TypeInstance(loc, tempinst);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2367 goto Lident2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2368 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2369 Lident:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2370 tid = new TypeIdentifier(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2371 Lident2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2372 while (token.value == TOK.TOKdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2373 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2374 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2375 { error("identifier expected following '.' instead of '%s'", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2376 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2377 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2378 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2379 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2380 if (token.value == TOK.TOKnot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2381 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2382 TemplateInstance tempinst = new TemplateInstance(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2383 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2384 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2385 // ident!(template_arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2386 tempinst.tiargs = parseTemplateArgumentList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2387 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2388 // ident!template_argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2389 tempinst.tiargs = parseTemplateArgument();
56
51605de93870 TupleExp.optimize
korDen
parents: 34
diff changeset
2390 tid.addIdent(tempinst);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2391 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2392 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2393 tid.addIdent(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2394 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2395 t = tid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2396 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2397
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2398 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2399 // Leading . as in .foo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2400 id = Id.empty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2401 goto Lident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2402
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2403 case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2404 // typeof(expression)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2405 tid = parseTypeof();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2406 goto Lident2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2407
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2408 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2409 // const(type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2410 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2411 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2412 t = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2413 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2414 if (t.isShared())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2415 t = t.makeSharedConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2416 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2417 t = t.makeConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2418 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2419
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2420 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2421 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2422 // invariant(type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2423 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2424 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2425 t = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2426 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2427 t = t.makeInvariant();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2428 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2429
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2430 case TOK.TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2431 // shared(type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2432 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2433 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2434 t = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2435 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2436 if (t.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2437 t = t.makeSharedConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2438 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2439 t = t.makeShared();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2440 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2441
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2442 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2443 error("basic type expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2444 t = Type.tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2445 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2446 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2447 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2448 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2449
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2450 Type parseBasicType2(Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2451 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2452 //writef("parseBasicType2()\n");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2453 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2454 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2455 switch (token.value)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2456 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2457 case TOK.TOKmul:
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2458 t = new TypePointer(t);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2459 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2460 continue;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2461
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2462 case TOK.TOKlbracket:
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2463 // Handle []. Make sure things like
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2464 // int[3][1] a;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2465 // is (array[1] of array[3] of int)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2466 nextToken();
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2467 if (token.value == TOK.TOKrbracket)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2468 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2469 t = new TypeDArray(t); // []
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2470 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2471 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2472 else if (token.value == TOKnew && peekNext() == TOKrbracket)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2473 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2474 t = new TypeNewArray(t); // [new]
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2475 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2476 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2477 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2478 else if (isDeclaration(&token, 0, TOK.TOKrbracket, null))
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2479 { // It's an associative array declaration
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2480
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2481 //printf("it's an associative array\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2482 Type index = parseType(); // [ type ]
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2483 t = new TypeAArray(t, index);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2484 check(TOK.TOKrbracket);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2485 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2486 else
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2487 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2488 //printf("it's type[expression]\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2489 inBrackets++;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2490 Expression e = parseExpression(); // [ expression ]
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2491 if (token.value == TOK.TOKslice)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2492 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2493 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2494 Expression e2 = parseExpression(); // [ exp .. exp ]
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2495 t = new TypeSlice(t, e, e2);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2496 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2497 else
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2498 t = new TypeSArray(t,e);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2499 inBrackets--;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2500 check(TOK.TOKrbracket);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2501 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2502 continue;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2503
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2504 case TOK.TOKdelegate:
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2505 case TOK.TOKfunction:
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2506 { // Handle delegate declaration:
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2507 // t delegate(parameter list) nothrow pure
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2508 // t function(parameter list) nothrow pure
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2509 Arguments arguments;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2510 int varargs;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2511 bool ispure = false;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2512 bool isnothrow = false;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2513 TOK save = token.value;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2514
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2515 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2516 arguments = parseParameters(&varargs);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2517 while (1)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2518 { // Postfixes
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2519 if (token.value == TOK.TOKpure)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2520 ispure = true;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2521 else if (token.value == TOK.TOKnothrow)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2522 isnothrow = true;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2523 else
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2524 break;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2525 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2526 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2527 TypeFunction tf = new TypeFunction(arguments, t, varargs, linkage);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2528 tf.ispure = ispure;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2529 tf.isnothrow = isnothrow;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2530 if (save == TOK.TOKdelegate)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2531 t = new TypeDelegate(tf);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2532 else
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2533 t = new TypePointer(tf); // pointer to function
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2534 continue;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2535 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2536
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2537 default:
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2538 return t;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2539 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2540 assert(0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2541 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2542 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2543 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2544 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2545
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2546 Type parseDeclarator(Type t, Identifier* pident, TemplateParameters* tpl = null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2547 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2548 Type ts;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2549
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2550 //printf("parseDeclarator(tpl = %p)\n", tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2551 t = parseBasicType2(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2552
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2553 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2554 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2555
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2556 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2557 if (pident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2558 *pident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2559 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2560 error("unexpected identifer '%s' in declarator", token.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2561 ts = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2562 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2563 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2564
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2565 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2566 /* Parse things with parentheses around the identifier, like:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2567 * int (*ident[3])[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2568 * although the D style would be:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2569 * int[]*[3] ident
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2570 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2571 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2572 ts = parseDeclarator(t, pident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2573 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2574 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2575
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2576 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2577 ts = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2578 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2579 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2580
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2581 // parse DeclaratorSuffixes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2582 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2583 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2584 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2585 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2586 version (CARRAYDECL) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2587 /* Support C style array syntax:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2588 * int ident[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2589 * as opposed to D-style:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2590 * int[] ident
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2591 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2592 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2593 { // This is the old C-style post [] syntax.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2594 TypeNext ta;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2595 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2596 if (token.value == TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2597 { // It's a dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2598 ta = new TypeDArray(t); // []
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2599 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2600 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2601 else if (token.value == TOKnew && peekNext() == TOKrbracket)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2602 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2603 t = new TypeNewArray(t); // [new]
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2604 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2605 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2606 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2607 else if (isDeclaration(&token, 0, TOK.TOKrbracket, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2608 { // It's an associative array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2609
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2610 //printf("it's an associative array\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2611 Type index = parseType(); // [ type ]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2612 check(TOK.TOKrbracket);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2613 ta = new TypeAArray(t, index);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2614 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2615 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2616 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2617 //printf("It's a static array\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2618 Expression e = parseExpression(); // [ expression ]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2619 ta = new TypeSArray(t, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2620 check(TOK.TOKrbracket);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2621 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2622
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2623 /* Insert ta into
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2624 * ts . ... . t
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2625 * so that
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2626 * ts . ... . ta . t
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2627 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2628 Type* pt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2629 for (pt = &ts; *pt !is t; pt = &(cast(TypeNext)*pt).next) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2630 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2631 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2632 *pt = ta;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2633 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2634 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2635 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2636 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2637 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2638 if (tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2639 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2640 /* Look ahead to see if this is (...)(...),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2641 * i.e. a function template declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2642 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2643 if (peekPastParen(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2644 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2645 //printf("function template declaration\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2646
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2647 // Gather template parameter list
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2648 *tpl = parseTemplateParameterList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2649 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2650 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2651
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2652 int varargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2653 Arguments arguments = parseParameters(&varargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2654 Type tf = new TypeFunction(arguments, t, varargs, linkage);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2655
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2656 /* Parse const/invariant/nothrow/pure postfix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2657 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2658 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2659 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2660 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2661 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2662 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2663 if (tf.isShared())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2664 tf = tf.makeSharedConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2665 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2666 tf = tf.makeConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2667 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2668 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2669
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2670 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2671 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2672 tf = tf.makeInvariant();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2673 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2674 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2675
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2676 case TOK.TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2677 if (tf.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2678 tf = tf.makeSharedConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2679 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2680 tf = tf.makeShared();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2681 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2682 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2683
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2684 case TOK.TOKnothrow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2685 (cast(TypeFunction)tf).isnothrow = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2686 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2687 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2688
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2689 case TOK.TOKpure:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2690 (cast(TypeFunction)tf).ispure = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2691 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2692 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2693
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2694 case TOK.TOKat:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2695 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2696 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2697 { error("attribute identifier expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2698 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2699 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2700 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2701 Identifier id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2702 if (id is Id.property)
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
2703 (cast(TypeFunction)tf).isproperty = 1;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2704 else
96
acd69f84627e further work
Trass3r
parents: 84
diff changeset
2705 error("valid attribute identifiers are @property, not @%s", id.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2706 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2707 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2708 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2709 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2710 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2711 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2712 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2713
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2714 /* Insert tf into
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2715 * ts . ... . t
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2716 * so that
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2717 * ts . ... . tf . t
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2718 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2719 Type* pt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2720 for (pt = &ts; *pt !is t; pt = &(cast(TypeNext)*pt).next) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2721 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2722 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2723 *pt = tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2724 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2725 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2726
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2727 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2728 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2729 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2730 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2731 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2732
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2733 return ts;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2734 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2735
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2736 Dsymbols parseDeclarations(STC storage_class)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2737 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2738 STC stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2739 Type ts;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2740 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2741 Type tfirst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2742 Identifier ident;
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2743 Dsymbols a;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2744 TOK tok = TOK.TOKreserved;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2745 string comment = token.blockComment;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2746 LINK link = linkage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2747
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2748 //printf("parseDeclarations() %s\n", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2749 if (storage_class)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2750 { ts = null; // infer type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2751 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2752 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2753
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2754 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2755 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2756 case TOK.TOKalias:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2757 /* Look for:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2758 * alias identifier this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2759 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2760 tok = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2761 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2762 if (token.value == TOK.TOKidentifier && peek(&token).value == TOK.TOKthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2763 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2764 AliasThis s = new AliasThis(this.loc, token.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2765 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2766 check(TOK.TOKthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2767 check(TOK.TOKsemicolon);
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2768 a = new Dsymbols();
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2769 a.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2770 addComment(s, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2771 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2772 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2773 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2774 case TOK.TOKtypedef:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2775 tok = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2776 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2777 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2778 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2779 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2780 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2781
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2782 storage_class = STC.STCundefined;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2783 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2784 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2785 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2786 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2787 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2788 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2789 break; // const as type constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2790 stc = STC.STCconst; // const as storage class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2791 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2792
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2793 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2794 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2795 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2796 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2797 stc = STC.STCimmutable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2798 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2799
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2800 case TOK.TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2801 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2802 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2803 stc = STC.STCshared;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2804 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2805
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2806 case TOK.TOKstatic: stc = STC.STCstatic; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2807 case TOK.TOKfinal: stc = STC.STCfinal; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2808 case TOK.TOKauto: stc = STC.STCauto; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2809 case TOK.TOKscope: stc = STC.STCscope; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2810 case TOK.TOKoverride: stc = STC.STCoverride; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2811 case TOK.TOKabstract: stc = STC.STCabstract; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2812 case TOK.TOKsynchronized: stc = STC.STCsynchronized; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2813 case TOK.TOKdeprecated: stc = STC.STCdeprecated; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2814 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2815 case TOK.TOKnothrow: stc = STC.STCnothrow; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2816 case TOK.TOKpure: stc = STC.STCpure; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2817 case TOK.TOKref: stc = STC.STCref; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2818 case TOK.TOKtls: stc = STC.STCtls; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2819 case TOK.TOKgshared: stc = STC.STCgshared; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2820 case TOK.TOKenum: stc = STC.STCmanifest; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2821 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2822 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2823 if (storage_class & stc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2824 error("redundant storage class '%s'", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2825 storage_class = (storage_class | stc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2826 composeStorageClass(storage_class);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2827 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2828 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2829
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2830 case TOK.TOKextern:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2831 if (peek(&token).value != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2832 { stc = STC.STCextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2833 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2834 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2835
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2836 link = parseLinkage();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2837 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2838
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2839 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2840 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2841 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2842 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2843 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2844
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2845 /* Look for auto initializers:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2846 * storage_class identifier = initializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2847 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2848 if (storage_class &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2849 token.value == TOK.TOKidentifier &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2850 peek(&token).value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2851 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2852 return parseAutoDeclarations(storage_class, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2853 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2854
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2855 if (token.value == TOK.TOKclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2856 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2857 AggregateDeclaration s = cast(AggregateDeclaration)parseAggregate();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2858 s.storage_class |= storage_class;
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2859 a = new Dsymbols();
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2860 a.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2861 addComment(s, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2862 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2863 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2864
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2865 /* Look for return type inference for template functions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2866 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2867 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2868 Token *tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2869 if (storage_class &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2870 token.value == TOK.TOKidentifier &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2871 (tk = peek(&token)).value == TOK.TOKlparen &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2872 skipParens(tk, &tk) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2873 peek(tk).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2874 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2875 ts = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2876 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2877 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2878 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2879 ts = parseBasicType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2880 ts = parseBasicType2(ts);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2881 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2882 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2883
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2884 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2885 tfirst = null;
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2886 a = new Dsymbols();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2887
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2888 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2889 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2890 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2891 TemplateParameters tpl = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2892
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2893 ident = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2894 t = parseDeclarator(ts, &ident, &tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2895 assert(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2896 if (!tfirst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2897 tfirst = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2898 else if (t != tfirst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2899 error("multiple declarations must have the same type, not %s and %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2900 tfirst.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2901 if (!ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2902 error("no identifier for declarator %s", t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2903
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2904 if (tok == TOK.TOKtypedef || tok == TOK.TOKalias)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2905 { Declaration v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2906 Initializer init = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2907
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2908 if (token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2909 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2910 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2911 init = parseInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2912 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2913 if (tok == TOK.TOKtypedef)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2914 v = new TypedefDeclaration(loc, ident, t, init);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2915 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2916 { if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2917 error("alias cannot have initializer");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2918 v = new AliasDeclaration(loc, ident, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2919 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2920 v.storage_class = storage_class;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2921 if (link == linkage)
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2922 a.push(v);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2923 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2924 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2925 auto ax = new Dsymbols();
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2926 ax.push(v);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2927 Dsymbol s = new LinkDeclaration(link, ax);
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2928 a.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2929 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2930 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2931 { case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2932 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2933 addComment(v, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2934 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2935
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2936 case TOK.TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2937 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2938 addComment(v, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2939 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2940
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2941 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2942 error("semicolon expected to close %s declaration", Token.toChars(tok));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2943 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2944 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2945 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2946 else if (t.ty == TY.Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2947 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2948 auto tf = cast(TypeFunction)t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2949 Expression constraint = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2950 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2951 if (Argument.isTPL(tf.parameters))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2952 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2953 if (!tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2954 tpl = new TemplateParameters();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2955 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2956 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2957 FuncDeclaration f =
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2958 new FuncDeclaration(loc, Loc(0), ident, storage_class, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2959 addComment(f, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2960 if (tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2961 constraint = parseConstraint();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2962 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2963 addComment(f, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2964 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2965 if (link == linkage)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2966 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2967 s = f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2968 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2969 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2970 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2971 auto ax = new Dsymbols();
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2972 ax.push(f);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2973 s = new LinkDeclaration(link, ax);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2974 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2975 /* A template parameter list means it's a function template
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2976 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2977 if (tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2978 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2979 // Wrap a template around the function declaration
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2980 auto decldefs = new Dsymbols();
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2981 decldefs.push(s);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2982 auto tempdecl =
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2983 new TemplateDeclaration(loc, s.ident, tpl, constraint, decldefs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2984 s = tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2985 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2986 addComment(s, comment);
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2987 a.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2988 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2989 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2990 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2991 Initializer init = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2992 if (token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2993 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2994 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2995 init = parseInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2996 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2997
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2998 VarDeclaration v = new VarDeclaration(loc, t, ident, init);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2999 v.storage_class = storage_class;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3000 if (link == linkage)
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3001 a.push(v);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3002 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3003 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3004 auto ax = new Dsymbols();
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3005 ax.push(v);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3006 auto s = new LinkDeclaration(link, ax);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3007 a.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3008 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3009 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3010 { case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3011 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3012 addComment(v, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3013 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3014
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3015 case TOK.TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3016 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3017 addComment(v, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3018 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3019
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3020 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3021 error("semicolon expected, not '%s'", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3022 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3023 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3024 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3025 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3026 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3027 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3028 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3029
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3030 void parseContracts(FuncDeclaration f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3031 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3032 Type tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3033 LINK linksave = linkage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3034
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3035 // The following is irrelevant, as it is overridden by sc.linkage in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3036 // TypeFunction.semantic
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3037 linkage = LINK.LINKd; // nested functions have D linkage
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3038 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3039 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3040 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3041 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3042 if (f.frequire || f.fensure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3043 error("missing body { ... } after in or out");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3044 f.fbody = parseStatement(ParseStatementFlags.PSsemi);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3045 f.endloc = endloc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3046 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3047
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3048 case TOK.TOKbody:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3049 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3050 f.fbody = parseStatement(ParseStatementFlags.PScurly);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3051 f.endloc = endloc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3052 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3053
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3054 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3055 if (f.frequire || f.fensure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3056 error("missing body { ... } after in or out");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3057 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3058 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3059
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3060 static if (false) { // Do we want this for function declarations, so we can do:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3061 // int x, y, foo(), z;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3062 case TOK.TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3063 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3064 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3065 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3066
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3067 static if (false) { // Dumped feature
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3068 case TOK.TOKthrow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3069 if (!f.fthrows)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3070 f.fthrows = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3071 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3072 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3073 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3074 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3075 tb = parseBasicType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3076 f.fthrows.push(tb);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3077 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3078 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3079 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3080 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3081 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3082 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3083 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3084 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3085 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3086
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3087 case TOK.TOKin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3088 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3089 if (f.frequire)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3090 error("redundant 'in' statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3091 f.frequire = parseStatement(ParseStatementFlags.PScurly | ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3092 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3093
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3094 case TOK.TOKout:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3095 // parse: out (identifier) { statement }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3096 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3097 if (token.value != TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3098 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3099 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3100 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3101 error("(identifier) following 'out' expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3102 f.outId = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3103 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3104 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3105 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3106 if (f.fensure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3107 error("redundant 'out' statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3108 f.fensure = parseStatement(ParseStatementFlags.PScurly | ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3109 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3111 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3112 error("semicolon expected following function declaration");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3113 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3114 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3115 linkage = linksave;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3118 Statement parseStatement(ParseStatementFlags flags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3119 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3120 Statement s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3121 Token* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3122 Condition condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3123 Statement ifbody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3124 Statement elsebody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3125 bool isfinal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3126 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3127
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3128 //printf("parseStatement()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3130 if (flags & ParseStatementFlags.PScurly && token.value != TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3131 error("statement expected to be { }, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3133 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3134 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3135 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3136 /* A leading identifier can be a declaration, label, or expression.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3137 * The easiest case to check first is label:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3138 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3139 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3140 if (t.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3141 { // It's a label
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3142
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3143 Identifier ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3144 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3145 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3146 s = parseStatement(ParseStatementFlags.PSsemi);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3147 s = new LabelStatement(loc, ident, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3148 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3149 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3150 // fallthrough to TOK.TOKdot
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3151 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3152 case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3153 if (isDeclaration(&token, 2, TOK.TOKreserved, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3154 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3155 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3156 goto Lexp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3157 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3158
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3159 case TOK.TOKassert:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3160 case TOK.TOKthis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3161 case TOK.TOKsuper:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3162 case TOK.TOKint32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3163 case TOK.TOKuns32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3164 case TOK.TOKint64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3165 case TOK.TOKuns64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3166 case TOK.TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3167 case TOK.TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3168 case TOK.TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3169 case TOK.TOKimaginary32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3170 case TOK.TOKimaginary64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3171 case TOK.TOKimaginary80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3172 case TOK.TOKcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3173 case TOK.TOKwcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3174 case TOK.TOKdcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3175 case TOK.TOKnull:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3176 case TOK.TOKtrue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3177 case TOK.TOKfalse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3178 case TOK.TOKstring:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3179 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3180 case TOK.TOKcast:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3181 case TOK.TOKmul:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3182 case TOK.TOKmin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3183 case TOK.TOKadd:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3184 case TOK.TOKplusplus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3185 case TOK.TOKminusminus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3186 case TOK.TOKnew:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3187 case TOK.TOKdelete:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3188 case TOK.TOKdelegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3189 case TOK.TOKfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3190 case TOK.TOKtypeid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3191 case TOK.TOKis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3192 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3193 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3194 case TOK.TOKtraits:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3195 case TOK.TOKfile:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3196 case TOK.TOKline:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3197 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3198 Lexp:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3199 { Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3200
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3201 exp = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3202 check(TOK.TOKsemicolon, "statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3203 s = new ExpStatement(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3204 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3206
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3207 case TOK.TOKstatic:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3208 { // Look ahead to see if it's static assert() or static if()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3209 Token *tt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3210
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3211 tt = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3212 if (tt.value == TOK.TOKassert)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3214 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3215 s = new StaticAssertStatement(parseStaticAssert());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3216 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3217 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3218 if (tt.value == TOK.TOKif)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3219 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3220 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3221 condition = parseStaticIfCondition();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3222 goto Lcondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3223 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3224 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3225 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3226
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3227 case TOK.TOKfinal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3228 if (peekNext() == TOK.TOKswitch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3229 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3230 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3231 isfinal = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3232 goto Lswitch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3233 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3234 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3235
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3236 case TOK.TOKwchar: case TOK.TOKdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3237 case TOK.TOKbit: case TOK.TOKbool: case TOK.TOKchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3238 case TOK.TOKint8: case TOK.TOKuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3239 case TOK.TOKint16: case TOK.TOKuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3240 case TOK.TOKint32: case TOK.TOKuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3241 case TOK.TOKint64: case TOK.TOKuns64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3242 case TOK.TOKfloat32: case TOK.TOKfloat64: case TOK.TOKfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3243 case TOK.TOKimaginary32: case TOK.TOKimaginary64: case TOK.TOKimaginary80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3244 case TOK.TOKcomplex32: case TOK.TOKcomplex64: case TOK.TOKcomplex80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3245 case TOK.TOKvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3246 case TOK.TOKtypedef:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3247 case TOK.TOKalias:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3248 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3249 case TOK.TOKauto:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3250 case TOK.TOKextern:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3251 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3252 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3253 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3254 case TOK.TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3255 case TOK.TOKnothrow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3256 case TOK.TOKpure:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3257 case TOK.TOKtls:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3258 case TOK.TOKgshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3259 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3260 // case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3261 Ldeclaration:
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3262 { Dsymbols a;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3263
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3264 a = parseDeclarations(STC.STCundefined);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3265 if (a.dim > 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3266 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3267 Statements as = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3268 as.reserve(a.dim);
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
3269 foreach(Dsymbol d; a)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3270 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3271 s = new DeclarationStatement(loc, d);
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
3272 as.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3273 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3274 s = new CompoundDeclarationStatement(loc, as);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3276 else if (a.dim == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3277 {
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
3278 auto d = a[0];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3279 s = new DeclarationStatement(loc, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3281 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3282 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3283 if (flags & ParseStatementFlags.PSscope)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3284 s = new ScopeStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3285 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3286 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3287
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3288 case TOK.TOKstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3289 case TOK.TOKunion:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3290 case TOK.TOKclass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3291 case TOK.TOKinterface:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3292 { Dsymbol d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3293
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3294 d = parseAggregate();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3295 s = new DeclarationStatement(loc, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3296 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3297 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3298
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3299 case TOK.TOKenum:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3300 { /* Determine if this is a manifest constant declaration,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3301 * or a conventional enum.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3302 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3303 Dsymbol d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3304 Token* tt = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3305 if (tt.value == TOK.TOKlcurly || tt.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3306 d = parseEnum();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3307 else if (tt.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3308 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3309 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3310 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3311 tt = peek(tt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3312 if (tt.value == TOK.TOKlcurly || tt.value == TOK.TOKcolon ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3313 tt.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3314 d = parseEnum();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3315 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3316 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3317 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3318 s = new DeclarationStatement(loc, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3319 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3320 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3321
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3322 case TOK.TOKmixin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3323 { t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3324 if (t.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3325 { // mixin(string)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3326 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3327 check(TOK.TOKlparen, "mixin");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3328 Expression e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3329 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3330 check(TOK.TOKsemicolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3331 s = new CompileStatement(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3332 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3333 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3334 Dsymbol d = parseMixin();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3335 s = new DeclarationStatement(loc, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3336 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3337 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3338
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3339 case TOK.TOKlcurly:
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
3340 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
3341 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
3342 Statements statements = new Statements();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
3343 while (token.value != TOK.TOKrcurly && token.value != TOKeof)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3344 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
3345 statements.push(parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3346 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3347 endloc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3348 s = new CompoundStatement(loc, statements);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3349 if (flags & (ParseStatementFlags.PSscope | ParseStatementFlags.PScurlyscope))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3350 s = new ScopeStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3351 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3352 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3353 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3354
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3355 case TOK.TOKwhile:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3356 { Expression condition2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3357 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3358
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3359 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3360 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3361 condition2 = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3362 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3363 body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3364 s = new WhileStatement(loc, condition2, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3365 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3366 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3367
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3368 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3369 if (!(flags & ParseStatementFlags.PSsemi))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3370 error("use '{ }' for an empty statement, not a ';'");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3371 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3372 s = new ExpStatement(loc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3373 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3374
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3375 case TOK.TOKdo:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3376 { Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3377 Expression condition2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3378
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3379 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3380 body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3381 check(TOK.TOKwhile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3382 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3383 condition2 = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3384 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3385 s = new DoStatement(loc, body_, condition2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3386 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3387 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3388
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3389 case TOK.TOKfor:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3390 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3391 Statement init;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3392 Expression condition2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3393 Expression increment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3394 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3395
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3396 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3397 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3398 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3399 { init = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3400 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3401 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3402 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3403 { init = parseStatement(cast(ParseStatementFlags)0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3404 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3405 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3406 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3407 condition2 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3408 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3409 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3410 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3411 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3412 condition2 = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3413 check(TOK.TOKsemicolon, "for condition");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3414 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3415 if (token.value == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3416 { increment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3417 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3418 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3419 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3420 { increment = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3421 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3422 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3423 body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3424 s = new ForStatement(loc, init, condition2, increment, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3425 if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3426 s = new ScopeStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3427 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3428 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3429
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3430 case TOK.TOKforeach:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3431 case TOK.TOKforeach_reverse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3432 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3433 TOK op = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3434 Arguments arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3435
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3436 Statement d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3437 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3438 Expression aggr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3439
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3440 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3441 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3442
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3443 arguments = new Arguments();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3444
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3445 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3446 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3447 Type tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3448 Identifier ai = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3449 Type at;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3450 STC storageClass = STC.STCundefined;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3451 Argument a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3452
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3453 if (token.value == TOK.TOKinout || token.value == TOK.TOKref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3454 { storageClass = STC.STCref;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3455 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3456 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3457 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3458 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3459 Token *tt = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3460 if (tt.value == TOK.TOKcomma || tt.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3461 { ai = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3462 at = null; // infer argument type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3463 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3464 goto Larg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3465 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3466 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3467 at = parseType(&ai);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3468 if (!ai)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3469 error("no identifier for declarator %s", at.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3470 Larg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3471 a = new Argument(storageClass, at, ai, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3472 arguments.push(cast(void*)a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3473 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3474 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3475 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3476 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3477 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3478 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3479 check(TOK.TOKsemicolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3480
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3481 aggr = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3482 if (token.value == TOK.TOKslice && arguments.dim == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3483 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3484 Argument a = cast(Argument)arguments.data[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3485 delete arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3486 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3487 Expression upr = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3488 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3489 body_ = parseStatement(cast(ParseStatementFlags)0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3490 s = new ForeachRangeStatement(loc, op, a, aggr, upr, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3491 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3492 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3493 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3494 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3495 body_ = parseStatement(cast(ParseStatementFlags)0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3496 s = new ForeachStatement(loc, op, arguments, aggr, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3497 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3498 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3499 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3500
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3501 case TOK.TOKif:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3502 { Argument arg = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3503 Expression condition2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3504 Statement ifbody2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3505 Statement elsebody2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3506
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3507 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3508 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3509
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3510 if (token.value == TOK.TOKauto)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3511 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3512 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3513 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3514 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3515 Token *tt = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3516 if (tt.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3517 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3518 arg = new Argument(STC.STCundefined, null, token.ident, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3519 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3520 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3521 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3522 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3523 { error("= expected following auto identifier");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3524 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3525 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3526 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3527 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3528 { error("identifier expected following auto");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3529 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3530 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3531 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3532 else if (isDeclaration(&token, 2, TOK.TOKassign, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3533 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3534 Type at;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3535 Identifier ai;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3536
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3537 at = parseType(&ai);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3538 check(TOK.TOKassign);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3539 arg = new Argument(STC.STCundefined, at, ai, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3540 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3541
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3542 // Check for " ident;"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3543 else if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3544 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3545 Token *tt = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3546 if (tt.value == TOK.TOKcomma || tt.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3547 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3548 arg = new Argument(STC.STCundefined, null, token.ident, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3549 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3550 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3551 if (1 || !global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3552 error("if (v; e) is deprecated, use if (auto v = e)");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3553 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3554 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3555
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3556 condition2 = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3557 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3558 ifbody2 = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3559 if (token.value == TOK.TOKelse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3560 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3561 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3562 elsebody2 = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3563 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3564 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3565 elsebody2 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3566 s = new IfStatement(loc, arg, condition2, ifbody2, elsebody2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3567 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3568 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3569
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3570 case TOK.TOKscope:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3571 if (peek(&token).value != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3572 goto Ldeclaration; // scope used as storage class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3573 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3574 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3575 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3576 { error("scope identifier expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3577 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3578 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3579 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3580 { TOK tt = TOK.TOKon_scope_exit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3581 Identifier id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3582
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3583 if (id == Id.exit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3584 tt = TOK.TOKon_scope_exit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3585 else if (id == Id.failure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3586 tt = TOK.TOKon_scope_failure;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3587 else if (id == Id.success)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3588 tt = TOK.TOKon_scope_success;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3589 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3590 error("valid scope identifiers are exit, failure, or success, not %s", id.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3591 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3592 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3593 Statement st = parseStatement(ParseStatementFlags.PScurlyscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3594 s = new OnScopeStatement(loc, tt, st);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3595 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3596 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3597
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3598 case TOK.TOKdebug:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3599 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3600 condition = parseDebugCondition();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3601 goto Lcondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3602
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3603 case TOK.TOKversion:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3604 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3605 condition = parseVersionCondition();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3606 goto Lcondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3607
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3608 Lcondition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3609 ifbody = parseStatement(cast(ParseStatementFlags)0 /*ParseStatementFlags.PSsemi*/);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3610 elsebody = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3611 if (token.value == TOK.TOKelse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3612 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3613 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3614 elsebody = parseStatement(cast(ParseStatementFlags)0 /*ParseStatementFlags.PSsemi*/);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3615 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3616 s = new ConditionalStatement(loc, condition, ifbody, elsebody);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3617 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3618
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3619 case TOK.TOKpragma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3620 { Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3621 Expressions args = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3622 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3623
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3624 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3625 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3626 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3627 { error("pragma(identifier expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3628 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3629 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3630 ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3631 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3632 if (token.value == TOK.TOKcomma && peekNext() != TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3633 args = parseArguments(); // pragma(identifier, args...);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3634 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3635 check(TOK.TOKrparen); // pragma(identifier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3636 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3637 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3638 body_ = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3639 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3640 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3641 body_ = parseStatement(ParseStatementFlags.PSsemi);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3642 s = new PragmaStatement(loc, ident, args, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3643 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3644 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3645
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3646 case TOK.TOKswitch:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3647 isfinal = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3648 goto Lswitch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3649
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3650 Lswitch:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3651 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3652 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3653 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3654 Expression condition2 = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3655 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3656 Statement body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3657 s = new SwitchStatement(loc, condition2, body_, isfinal);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3658 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3659 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3660
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3661 case TOK.TOKcase:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3662 { Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3663 Statements statements;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3664 scope Array cases = new Array(); // array of Expression's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3665 Expression last = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3666
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3667 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3668 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3669 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3670 exp = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3671 cases.push(cast(void*)exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3672 if (token.value != TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3673 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3674 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3675 check(TOK.TOKcolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3676
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3677 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3678 /* case exp: .. case last:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3679 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3680 if (token.value == TOK.TOKslice)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3681 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3682 if (cases.dim > 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3683 error("only one case allowed for start of case range");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3684 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3685 check(TOK.TOKcase);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3686 last = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3687 check(TOK.TOKcolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3688 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3689 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3690
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3691 statements = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3692 while (token.value != TOK.TOKcase &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3693 token.value != TOK.TOKdefault &&
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
3694 token.value != TOKeof &&
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3695 token.value != TOK.TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3696 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
3697 statements.push(parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3698 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3699 s = new CompoundStatement(loc, statements);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3700 s = new ScopeStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3701
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3702 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3703 if (last)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3704 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3705 s = new CaseRangeStatement(loc, exp, last, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3706 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3707 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3708 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3709 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3710 // Keep cases in order by building the case statements backwards
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3711 for (int i = cases.dim; i; i--)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3712 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3713 exp = cast(Expression)cases.data[i - 1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3714 s = new CaseStatement(loc, exp, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3715 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3716 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3717 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3718 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3719
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3720 case TOK.TOKdefault:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3721 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3722 Statements statements;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3723
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3724 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3725 check(TOK.TOKcolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3726
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3727 statements = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3728 while (token.value != TOK.TOKcase &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3729 token.value != TOK.TOKdefault &&
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
3730 token.value != TOKeof &&
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3731 token.value != TOK.TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3732 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
3733 statements.push(parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3734 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3735 s = new CompoundStatement(loc, statements);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3736 s = new ScopeStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3737 s = new DefaultStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3738 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3739 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3740
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3741 case TOK.TOKreturn:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3742 { Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3743
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3744 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3745 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3746 exp = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3747 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3748 exp = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3749 check(TOK.TOKsemicolon, "return statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3750 s = new ReturnStatement(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3751 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3752 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3753
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3754 case TOK.TOKbreak:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3755 { Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3756
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3757 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3758 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3759 { ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3760 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3761 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3762 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3763 ident = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3764 check(TOK.TOKsemicolon, "break statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3765 s = new BreakStatement(loc, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3766 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3767 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3768
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3769 case TOK.TOKcontinue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3770 { Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3771
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3772 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3773 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3774 { ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3775 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3776 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3777 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3778 ident = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3779 check(TOK.TOKsemicolon, "continue statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3780 s = new ContinueStatement(loc, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3781 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3782 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3783
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3784 case TOK.TOKgoto:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3785 { Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3786
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3787 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3788 if (token.value == TOK.TOKdefault)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3789 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3790 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3791 s = new GotoDefaultStatement(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3792 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3793 else if (token.value == TOK.TOKcase)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3794 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3795 Expression exp = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3796
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3797 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3798 if (token.value != TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3799 exp = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3800 s = new GotoCaseStatement(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3801 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3802 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3803 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3804 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3805 { error("Identifier expected following goto");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3806 ident = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3807 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3808 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3809 { ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3810 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3811 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3812 s = new GotoStatement(loc, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3813 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3814 check(TOK.TOKsemicolon, "goto statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3815 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3816 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3817
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3818 case TOK.TOKsynchronized:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3819 { Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3820 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3821
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3822 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3823 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3824 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3825 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3826 exp = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3827 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3828 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3829 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3830 exp = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3831 body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3832 s = new SynchronizedStatement(loc, exp, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3833 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3834 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3835
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3836 case TOK.TOKwith:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3837 { Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3838 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3839
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3840 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3841 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3842 exp = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3843 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3844 body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3845 s = new WithStatement(loc, exp, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3846 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3847 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3848
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3849 case TOK.TOKtry:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3850 { Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3851 Array catches = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3852 Statement finalbody = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3853
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3854 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3855 body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3856 while (token.value == TOK.TOKcatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3857 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3858 Statement handler;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3859 Catch c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3860 Type tt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3861 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3862 Loc loc2 = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3863
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3864 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3865 if (token.value == TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3866 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3867 tt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3868 id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3869 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3870 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3871 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3872 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3873 id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3874 tt = parseType(&id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3875 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3876 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3877 handler = parseStatement(cast(ParseStatementFlags)0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3878 c = new Catch(loc2, tt, id, handler);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3879 if (!catches)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3880 catches = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3881 catches.push(cast(void*)c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3882 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3883
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3884 if (token.value == TOK.TOKfinally)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3885 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3886 finalbody = parseStatement(cast(ParseStatementFlags)0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3887 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3888
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3889 s = body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3890 if (!catches && !finalbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3891 error("catch or finally expected following try");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3892 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3893 { if (catches)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3894 s = new TryCatchStatement(loc, body_, catches);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3895 if (finalbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3896 s = new TryFinallyStatement(loc, s, finalbody);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3897 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3898 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3899 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3900
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3901 case TOK.TOKthrow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3902 { Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3903
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3904 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3905 exp = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3906 check(TOK.TOKsemicolon, "throw statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3907 s = new ThrowStatement(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3908 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3909 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3910
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3911 case TOK.TOKvolatile:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3912 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3913 s = parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3914 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3915 if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3916 error("volatile statements deprecated; used synchronized statements instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3917 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3918 s = new VolatileStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3919 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3920
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3921 case TOK.TOKasm:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3922 { Statements statements;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3923 Identifier label;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3924 Loc labelloc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3925 Token* toklist;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3926 Token** ptoklist;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3927
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3928 // Parse the asm block into a sequence of AsmStatements,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3929 // each AsmStatement is one instruction.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3930 // Separate out labels.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3931 // Defer parsing of AsmStatements until semantic processing.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3932
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3933 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3934 check(TOK.TOKlcurly);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3935 toklist = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3936 ptoklist = &toklist;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3937 label = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3938 statements = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3939 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3940 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3941 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3942 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3943 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3944 if (!toklist)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3945 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3946 // Look ahead to see if it is a label
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3947 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3948 if (t.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3949 { // It's a label
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3950 label = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3951 labelloc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3952 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3953 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3954 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3955 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3956 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3957 goto Ldefault;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3958
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3959 case TOK.TOKrcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3960 if (toklist || label)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3961 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3962 error("asm statements must end in ';'");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3963 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3964 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3965
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3966 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3967 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3968 if (toklist || label)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3969 { // Create AsmStatement from list of tokens we've saved
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3970 s = new AsmStatement(this.loc, toklist);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3971 toklist = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3972 ptoklist = &toklist;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3973 if (label)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3974 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3975 s = new LabelStatement(labelloc, label, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3976 label = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3977 }
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
3978 statements.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3979 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3980 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3981 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3982
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3983 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3984 /* { */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3985 error("matching '}' expected, not end of file");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3986 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3987
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3988 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3989 Ldefault:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3990 *ptoklist = new Token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3991 memcpy(*ptoklist, &token, Token.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3992 ptoklist = &(*ptoklist).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3993 *ptoklist = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3994
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3995 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3996 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3997 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3998 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3999 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4000 s = new CompoundStatement(loc, statements);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4001 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4002 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4003 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4004
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4005 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4006 error("found '%s' instead of statement", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4007 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4008
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4009 Lerror:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4010 while (token.value != TOK.TOKrcurly &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4011 token.value != TOK.TOKsemicolon &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4012 token.value != TOK.TOKeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4013 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4014 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4015 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4016 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4017 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4018 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4019
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4020 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4021 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4022
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4023 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4024 * Parse initializer for variable declaration.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4025 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4026 Initializer parseInitializer()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4027 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4028 StructInitializer is_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4029 ArrayInitializer ia;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4030 ExpInitializer ie;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4031 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4032 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4033 Initializer value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4034 int comma;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4035 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4036 Token* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4037 int braces;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4038 int brackets;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4039
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4040 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4041 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4042 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4043 /* Scan ahead to see if it is a struct initializer or
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4044 * a function literal.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4045 * If it contains a ';', it is a function literal.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4046 * Treat { } as a struct initializer.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4047 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4048 braces = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4049 for (t = peek(&token); 1; t = peek(t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4050 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4051 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4052 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4053 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4054 case TOK.TOKreturn:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4055 goto Lexpression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4056
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4057 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4058 braces++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4059 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4060
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4061 case TOK.TOKrcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4062 if (--braces == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4063 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4064 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4065
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4066 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4067 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4068
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4069 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4070 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4071 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4072 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4073 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4074
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4075 is_ = new StructInitializer(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4076 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4077 comma = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4078 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4079 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4080 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4081 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4082 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4083 if (comma == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4084 error("comma expected separating field initializers");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4085 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4086 if (t.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4087 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4088 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4089 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4090 nextToken(); // skip over ':'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4091 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4092 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4093 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4094 id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4095 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4096 value = parseInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4097 is_.addInit(id, value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4098 comma = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4099 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4101 case TOK.TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4102 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4103 comma = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4104 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4106 case TOK.TOKrcurly: // allow trailing comma's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4107 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4108 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4110 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4111 error("found EOF instead of initializer");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4112 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4114 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4115 value = parseInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4116 is_.addInit(null, value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4117 comma = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4118 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4119 //error("found '%s' instead of field initializer", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4120 //break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4122 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4124 return is_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4126 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4127 /* Scan ahead to see if it is an array initializer or
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4128 * an expression.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4129 * If it ends with a ';' ',' or '}', it is an array initializer.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4130 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4131 brackets = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4132 for (t = peek(&token); 1; t = peek(t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4133 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4134 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4135 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4136 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4137 brackets++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4138 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4139
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4140 case TOK.TOKrbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4141 if (--brackets == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4142 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4143 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4144 if (t.value != TOK.TOKsemicolon &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4145 t.value != TOK.TOKcomma &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4146 t.value != TOK.TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4147 goto Lexpression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4148 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4149 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4150 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4151
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4152 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4153 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4154
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4155 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4156 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4157 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4158 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4160
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4161 ia = new ArrayInitializer(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4162 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4163 comma = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4164 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4165 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4166 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4167 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4168 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4169 if (comma == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4170 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4171 error("comma expected separating array initializers, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4172 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4173 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4175 e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4176 if (!e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4177 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4178 if (token.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4179 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4180 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4181 value = parseInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4182 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4183 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4184 { value = new ExpInitializer(e.loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4185 e = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4186 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4187 ia.addInit(e, value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4188 comma = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4189 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4190
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4191 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4192 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4193 if (comma == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4194 error("comma expected separating array initializers, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4195 value = parseInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4196 ia.addInit(null, value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4197 comma = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4198 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4199
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4200 case TOK.TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4201 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4202 comma = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4203 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4204
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4205 case TOK.TOKrbracket: // allow trailing comma's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4206 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4207 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4208
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4209 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4210 error("found '%s' instead of array initializer", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4211 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4212 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4213 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4215 return ia;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4216
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4217 case TOK.TOKvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4218 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4219 if (t.value == TOK.TOKsemicolon || t.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4220 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4221 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4222 return new VoidInitializer(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4223 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4224 goto Lexpression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4225
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4226 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4227 Lexpression:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4228 e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4229 ie = new ExpInitializer(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4230 return ie;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4231 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4232 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4233
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4234 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4235 * Parses default argument initializer expression that is an assign expression,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4236 * with special handling for __FILE__ and __LINE__.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4237 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4238 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4239 Expression parseDefaultInitExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4240 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4241 if (token.value == TOK.TOKfile ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4242 token.value == TOK.TOKline)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4243 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4244 Token* t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4245 if (t.value == TOK.TOKcomma || t.value == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4246 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4247 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4248
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4249 if (token.value == TOK.TOKfile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4250 e = new FileInitExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4251 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4252 e = new LineInitExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4253 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4254 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4255 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4256 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4257
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4258 Expression e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4259 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4260 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4262 void check(Loc loc, TOK value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4263 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4264 if (token.value != value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4265 error(loc, "found '%s' when expecting '%s'", token.toChars(), Token.toChars(value));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4266 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4267 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4268
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4269 void check(TOK value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4270 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4271 check(loc, value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4272 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4273
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4274 void check(TOK value, string string_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4275 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4276 if (token.value != value) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4277 error("found '%s' when expecting '%s' following '%s'", token.toChars(), Token.toChars(value), string_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4278 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4279 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4281
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4282 /************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4283 * Determine if the scanner is sitting on the start of a declaration.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4284 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4285 * needId 0 no identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4286 * 1 identifier optional
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4287 * 2 must have identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4288 * Output:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4289 * if *pt is not null, it is set to the ending token, which would be endtok
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4290 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4291
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4292 bool isDeclaration(Token* t, int needId, TOK endtok, Token** pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4293 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4294 //printf("isDeclaration(needId = %d)\n", needId);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4295 int haveId = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4296
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4297 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4298 if ((t.value == TOK.TOKconst ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4299 t.value == TOK.TOKinvariant ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4300 t.value == TOK.TOKimmutable ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4301 t.value == TOK.TOKshared) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4302 peek(t).value != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4303 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4304 /* const type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4305 * immutable type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4306 * shared type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4307 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4308 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4310 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4311
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4312 if (!isBasicType(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4313 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4314 goto Lisnot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4315 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4316 if (!isDeclarator(&t, &haveId, endtok))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4317 goto Lisnot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4318 if ( needId == 1 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4319 (needId == 0 && !haveId) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4320 (needId == 2 && haveId))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4321 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4322 if (pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4323 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4324 goto Lis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4325 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4326 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4327 goto Lisnot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4328
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4329 Lis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4330 //printf("\tis declaration, t = %s\n", t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4331 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4332
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4333 Lisnot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4334 //printf("\tis not declaration\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4335 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4336 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4337
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4338 bool isBasicType(Token** pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4339 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4340 // This code parallels parseBasicType()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4341 Token* t = *pt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4342 Token* t2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4343 int parens;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4344 int haveId = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4345
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4346 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4347 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4348 case TOKwchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4349 case TOKdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4350 case TOKbit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4351 case TOKbool:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4352 case TOKchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4353 case TOKint8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4354 case TOKuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4355 case TOKint16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4356 case TOKuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4357 case TOKint32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4358 case TOKuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4359 case TOKint64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4360 case TOKuns64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4361 case TOKfloat32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4362 case TOKfloat64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4363 case TOKfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4364 case TOKimaginary32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4365 case TOKimaginary64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4366 case TOKimaginary80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4367 case TOKcomplex32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4368 case TOKcomplex64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4369 case TOKcomplex80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4370 case TOKvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4371 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4372 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4373
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4374 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4375 L5:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4376 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4377 if (t.value == TOK.TOKnot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4378 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4379 goto L4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4380 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4381 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4382 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4383 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4384 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4385 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4386 L3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4387 if (t.value == TOK.TOKdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4388 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4389 Ldot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4390 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4391 if (t.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4392 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4393 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4394 if (t.value != TOK.TOKnot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4395 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4396 L4:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4397 /* Seen a !
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4398 * Look for:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4399 * !( args ), !identifier, etc.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4400 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4401 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4402 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4403 { case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4404 goto L5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4405 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4406 if (!skipParens(t, &t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4407 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4408 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4409 case TOK.TOKwchar: case TOK.TOKdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4410 case TOK.TOKbit: case TOK.TOKbool: case TOK.TOKchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4411 case TOK.TOKint8: case TOK.TOKuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4412 case TOK.TOKint16: case TOK.TOKuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4413 case TOK.TOKint32: case TOK.TOKuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4414 case TOK.TOKint64: case TOK.TOKuns64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4415 case TOK.TOKfloat32: case TOK.TOKfloat64: case TOK.TOKfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4416 case TOK.TOKimaginary32: case TOK.TOKimaginary64: case TOK.TOKimaginary80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4417 case TOK.TOKcomplex32: case TOK.TOKcomplex64: case TOK.TOKcomplex80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4418 case TOK.TOKvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4419 case TOK.TOKint32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4420 case TOK.TOKuns32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4421 case TOK.TOKint64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4422 case TOK.TOKuns64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4423 case TOK.TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4424 case TOK.TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4425 case TOK.TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4426 case TOK.TOKimaginary32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4427 case TOK.TOKimaginary64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4428 case TOK.TOKimaginary80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4429 case TOK.TOKnull:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4430 case TOK.TOKtrue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4431 case TOK.TOKfalse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4432 case TOK.TOKcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4433 case TOK.TOKwcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4434 case TOK.TOKdcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4435 case TOK.TOKstring:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4436 case TOK.TOKfile:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4437 case TOK.TOKline:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4438 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4439 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4440 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4441 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4442 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4443 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4444 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4445 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4446 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4447
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4448 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4449 goto Ldot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4450
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4451 case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4452 /* typeof(exp).identifier...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4453 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4454 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4455 if (t.value != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4456 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4457 if (!skipParens(t, &t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4458 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4459 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4460
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4461 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4462 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4463 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4464 case TOK.TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4465 // const(type) or immutable(type) or shared(type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4466 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4467 if (t.value != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4468 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4469 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4470 if (!isDeclaration(t, 0, TOK.TOKrparen, &t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4471 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4472 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4473 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4474 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4475 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4476
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4477 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4478 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4479 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4480 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4481 //printf("is\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4482 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4483
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4484 Lfalse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4485 //printf("is not\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4486 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4487 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4488
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4489 bool isDeclarator(Token** pt, int* haveId, TOK endtok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4490 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4491 // This code parallels parseDeclarator()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4492 Token* t = *pt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4493 bool parens;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4494
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4495 //printf("Parser.isDeclarator()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4496 //t.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4497 if (t.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4498 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4499
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4500 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4501 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4502 parens = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4503 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4504 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4505 case TOK.TOKmul:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4506 //case TOKand:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4507 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4508 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4509
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4510 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4511 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4512 if (t.value == TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4513 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4514 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4515 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
4516 else if (t.value == TOKnew && peek(t).value == TOKrbracket)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
4517 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
4518 t = peek(t);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
4519 t = peek(t);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
4520 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4521 else if (isDeclaration(t, 0, TOK.TOKrbracket, &t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4522 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4523 // It's an associative array declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4524 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4525 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4526 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4527 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4528 // [ expression ]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4529 // [ expression .. expression ]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4530 if (!isExpression(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4531 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4532 if (t.value == TOK.TOKslice)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4533 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4534 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4535 if (!isExpression(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4536 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4537 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4538 if (t.value != TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4539 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4540 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4541 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4542 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4543
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4544 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4545 if (*haveId)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4546 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4547 *haveId = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4548 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4549 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4550
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4551 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4552 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4553
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4554 if (t.value == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4555 return false; // () is not a declarator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4556
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4557 /* Regard ( identifier ) as not a declarator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4558 * BUG: what about ( *identifier ) in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4559 * f(*p)(x);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4560 * where f is a class instance with overloaded () ?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4561 * Should we just disallow C-style function pointer declarations?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4562 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4563 if (t.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4564 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4565 Token *t2 = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4566 if (t2.value == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4567 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4568 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4569
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4570 if (!isDeclarator(&t, haveId, TOK.TOKrparen))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4571 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4572 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4573 parens = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4574 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4575
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4576 case TOK.TOKdelegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4577 case TOK.TOKfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4578 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4579 if (!isParameters(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4580 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4581 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4582 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4583 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4584 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4585 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4586 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4587
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4588 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4589 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4590 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4591 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4592 version (CARRAYDECL) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4593 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4594 parens = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4595 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4596 if (t.value == TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4597 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4598 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4599 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4600 else if (isDeclaration(t, 0, TOKrbracket, &t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4601 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4602 // It's an associative array declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4603 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4604 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4605 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4606 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4607 // [ expression ]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4608 if (!isExpression(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4609 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4610 if (t.value != TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4611 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4612 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4613 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4614 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4615 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4616
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4617 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4618 parens = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4619 if (!isParameters(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4620 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4621 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4622 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4623 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4624 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4625 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4626 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4627 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4628 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4629 case TOK.TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4630 case TOK.TOKpure:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4631 case TOK.TOKnothrow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4632 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4633 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4634 case TOK.TOKat:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4635 t = peek(t); // skip '@'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4636 t = peek(t); // skip identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4637 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4638 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4639 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4640 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4641 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4642 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4643 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4644 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4645
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4646 // Valid tokens that follow a declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4647 case TOK.TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4648 case TOK.TOKrbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4649 case TOK.TOKassign:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4650 case TOK.TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4651 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4652 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4653 case TOK.TOKin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4654 // The !parens is to disallow unnecessary parentheses
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4655 if (!parens && (endtok == TOK.TOKreserved || endtok == t.value))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4656 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4657 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4658 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4659 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4660 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4661
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4662 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4663 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4664 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4665 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4666 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4667
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4668 bool isParameters(Token** pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4669 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4670 // This code parallels parseParameters()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4671 Token* t = *pt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4672
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4673 //printf("isParameters()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4674 if (t.value != TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4675 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4676
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4677 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4678 for (;1; t = peek(t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4679 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4680 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4681 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4682 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4683 case TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4684 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4685
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4686 case TOKdotdotdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4687 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4688 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4689
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4690 case TOKin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4691 case TOKout:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4692 case TOKinout:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4693 case TOKref:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4694 case TOKlazy:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4695 case TOKfinal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4696 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4697
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4698 case TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4699 case TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4700 case TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4701 case TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4702 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4703 if (t.value == TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4704 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4705 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4706 if (!isDeclaration(t, 0, TOKrparen, &t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4707 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4708 t = peek(t); // skip past closing ')'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4709 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4710 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4711 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4712
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4713 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4714 case TOKstatic:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4715 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4716 case TOKauto:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4717 case TOKalias:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4718 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4719 if (t.value == TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4720 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4721 if (t.value == TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4722 { t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4723 if (!isExpression(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4724 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4725 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4726 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4727 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4728
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4729 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4730 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4731 if (!isBasicType(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4732 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4733 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4734 int tmp = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4735 if (t.value != TOKdotdotdot &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4736 !isDeclarator(&t, &tmp, TOKreserved))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4737 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4738 if (t.value == TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4739 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4740 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4741 if (!isExpression(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4742 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4743 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4744 if (t.value == TOKdotdotdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4745 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4746 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4747 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4748 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4749 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4750 L3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4751 if (t.value == TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4752 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4753 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4754 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4755 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4756 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4757 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4758 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4759
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4760 if (t.value != TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4761 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4762
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4763 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4764 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4765 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4766 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4767
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4768 bool isExpression(Token** pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4769 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4770 // This is supposed to determine if something is an expression.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4771 // What it actually does is scan until a closing right bracket
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4772 // is found.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4773
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4774 Token* t = *pt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4775 int brnest = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4776 int panest = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4777 int curlynest = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4778
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4779 for (;; t = peek(t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4780 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4781 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4782 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4783 case TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4784 brnest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4785 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4786
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4787 case TOKrbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4788 if (--brnest >= 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4789 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4790 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4791
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4792 case TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4793 panest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4794 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4795
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4796 case TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4797 if (brnest || panest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4798 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4799 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4800
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4801 case TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4802 if (--panest >= 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4803 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4804 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4805
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4806 case TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4807 curlynest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4808 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4809
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4810 case TOKrcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4811 if (--curlynest >= 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4812 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4813 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4814
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4815 case TOKslice:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4816 if (brnest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4817 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4818 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4819
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4820 case TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4821 if (curlynest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4822 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4823 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4824
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4825 case TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4826 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4827
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4828 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4829 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4830 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4831 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4832 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4833
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4834 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4835 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4836 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4837
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4838 int isTemplateInstance(Token t, Token* pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4839 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4840 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4841 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4842
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4843 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4844 * Skip parens, brackets.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4845 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4846 * t is on opening (
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4847 * Output:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4848 * *pt is set to closing token, which is ')' on success
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4849 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4850 * !=0 successful
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4851 * 0 some parsing error
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4852 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4853 bool skipParens(Token* t, Token** pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4854 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4855 int parens = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4856
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4857 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4858 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4859 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4860 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4861 case TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4862 parens++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4863 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4864
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4865 case TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4866 parens--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4867 if (parens < 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4868 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4869 if (parens == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4870 goto Ldone;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4871 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4872
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4873 case TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4874 case TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4875 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4876
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4877 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4878 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4879 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4880 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4881 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4882
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4883 Ldone:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4884 if (*pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4885 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4886 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4887
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4888 Lfalse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4889 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4890 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4891
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4892 Expression parseExpression()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4893 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4894 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4895 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4896 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4897
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4898 //printf("Parser.parseExpression() loc = %d\n", loc.linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4899 e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4900 while (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4901 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4902 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4903 e2 = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4904 e = new CommaExp(loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4905 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4906 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4907 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4908 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4909
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4910 Expression parsePrimaryExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4911 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4912 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4913 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4914 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4915 TOK save;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4916 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4917
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4918 //printf("parsePrimaryExp(): loc = %d\n", loc.linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4919 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4920 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4921 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4922 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4923 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4924 if (token.value == TOK.TOKnot && peekNext() != TOK.TOKis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4925 { // identifier!(template-argument-list)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4926 TemplateInstance tempinst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4927
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4928 tempinst = new TemplateInstance(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4929 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4930 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4931 // ident!(template_arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4932 tempinst.tiargs = parseTemplateArgumentList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4933 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4934 // ident!template_argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4935 tempinst.tiargs = parseTemplateArgument();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4936 e = new ScopeExp(loc, tempinst);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4937 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4938 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4939 e = new IdentifierExp(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4940 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4941
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4942 case TOK.TOKdollar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4943 if (!inBrackets)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4944 error("'$' is valid only inside [] of index or slice");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4945 e = new DollarExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4946 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4947 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4948
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4949 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4950 // Signal global scope '.' operator with "" identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4951 e = new IdentifierExp(loc, Id.empty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4952 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4953
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4954 case TOK.TOKthis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4955 e = new ThisExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4956 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4957 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4958
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4959 case TOK.TOKsuper:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4960 e = new SuperExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4961 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4962 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4963
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4964 case TOK.TOKint32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4965 e = new IntegerExp(loc, token.int32value, Type.tint32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4966 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4967 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4968
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4969 case TOK.TOKuns32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4970 e = new IntegerExp(loc, token.uns32value, Type.tuns32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4971 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4972 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4973
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4974 case TOK.TOKint64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4975 e = new IntegerExp(loc, token.int64value, Type.tint64);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4976 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4977 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4978
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4979 case TOK.TOKuns64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4980 e = new IntegerExp(loc, token.uns64value, Type.tuns64);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4981 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4982 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4983
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4984 case TOK.TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4985 e = new RealExp(loc, token.float80value, Type.tfloat32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4986 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4987 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4988
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4989 case TOK.TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4990 e = new RealExp(loc, token.float80value, Type.tfloat64);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4991 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4992 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4993
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4994 case TOK.TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4995 e = new RealExp(loc, token.float80value, Type.tfloat80);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4996 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4997 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4998
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4999 case TOK.TOKimaginary32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5000 e = new RealExp(loc, token.float80value, Type.timaginary32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5001 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5002 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5003
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5004 case TOK.TOKimaginary64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5005 e = new RealExp(loc, token.float80value, Type.timaginary64);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5006 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5007 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5008
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5009 case TOK.TOKimaginary80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5010 e = new RealExp(loc, token.float80value, Type.timaginary80);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5011 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5012 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5013
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5014 case TOK.TOKnull:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5015 e = new NullExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5016 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5017 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5018
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5019 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5020 case TOK.TOKfile:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5021 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5022 string s = loc.filename ? loc.filename : mod.ident.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5023 e = new StringExp(loc, s, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5024 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5025 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5026 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5027
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5028 case TOK.TOKline:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5029 e = new IntegerExp(loc, loc.linnum, Type.tint32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5030 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5031 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5032 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5033
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5034 case TOK.TOKtrue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5035 e = new IntegerExp(loc, 1, Type.tbool);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5036 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5037 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5038
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5039 case TOK.TOKfalse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5040 e = new IntegerExp(loc, 0, Type.tbool);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5041 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5042 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5043
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5044 case TOK.TOKcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5045 e = new IntegerExp(loc, token.uns32value, Type.tchar);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5046 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5047 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5048
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5049 case TOK.TOKwcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5050 e = new IntegerExp(loc, token.uns32value, Type.twchar);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5051 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5052 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5053
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5054 case TOK.TOKdcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5055 e = new IntegerExp(loc, token.uns32value, Type.tdchar);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5056 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5057 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5058
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5059 case TOK.TOKstring:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5060 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5061 const(char)* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5062 uint len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5063 ubyte postfix;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5064
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5065 // cat adjacent strings
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5066 s = token.ustring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5067 len = token.len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5068 postfix = token.postfix;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5069 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5070 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5071 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5072 if (token.value == TOK.TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5073 { uint len1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5074 uint len2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5075 char* s2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5076
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5077 if (token.postfix)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5078 { if (token.postfix != postfix)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5079 error("mismatched string literal postfixes '%c' and '%c'", postfix, token.postfix);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5080 postfix = token.postfix;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5081 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5082
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5083 len1 = len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5084 len2 = token.len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5085 len = len1 + len2;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
5086 s2 = cast(char*)GC.malloc((len + 1) * ubyte.sizeof);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5087 memcpy(s2, s, len1 * ubyte.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5088 memcpy(s2 + len1, token.ustring, (len2 + 1) * ubyte.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5089 s = s2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5090 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5091 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5092 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5093 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5094 e = new StringExp(loc, assumeUnique(s[0..len]), postfix);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5095 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5096 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5097
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5098 case TOK.TOKvoid: t = Type.tvoid; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5099 case TOK.TOKint8: t = Type.tint8; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5100 case TOK.TOKuns8: t = Type.tuns8; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5101 case TOK.TOKint16: t = Type.tint16; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5102 case TOK.TOKuns16: t = Type.tuns16; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5103 case TOK.TOKint32: t = Type.tint32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5104 case TOK.TOKuns32: t = Type.tuns32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5105 case TOK.TOKint64: t = Type.tint64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5106 case TOK.TOKuns64: t = Type.tuns64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5107 case TOK.TOKfloat32: t = Type.tfloat32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5108 case TOK.TOKfloat64: t = Type.tfloat64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5109 case TOK.TOKfloat80: t = Type.tfloat80; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5110 case TOK.TOKimaginary32: t = Type.timaginary32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5111 case TOK.TOKimaginary64: t = Type.timaginary64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5112 case TOK.TOKimaginary80: t = Type.timaginary80; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5113 case TOK.TOKcomplex32: t = Type.tcomplex32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5114 case TOK.TOKcomplex64: t = Type.tcomplex64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5115 case TOK.TOKcomplex80: t = Type.tcomplex80; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5116 case TOK.TOKbit: t = Type.tbit; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5117 case TOK.TOKbool: t = Type.tbool; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5118 case TOK.TOKchar: t = Type.tchar; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5119 case TOK.TOKwchar: t = Type.twchar; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5120 case TOK.TOKdchar: t = Type.tdchar; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5121 LabelX:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5122 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5123 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5124 check(TOK.TOKdot, t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5125 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5126 { error("found '%s' when expecting identifier following '%s.'", token.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5127 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5129 e = typeDotIdExp(loc, t, token.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5130 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5131 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5133 case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5134 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5135 t = parseTypeof();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5136 e = new TypeExp(loc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5137 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5138 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5139
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5140 case TOK.TOKtypeid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5141 { Type tt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5142
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5143 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5144 check(TOK.TOKlparen, "typeid");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5145 tt = parseType(); // ( type )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5146 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5147 e = new TypeidExp(loc, tt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5148 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5149 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5150
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5151 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5152 case TOK.TOKtraits:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5153 { /* __traits(identifier, args...)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5154 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5155 Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5156 Objects args = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5157
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5158 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5159 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5160 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5161 { error("__traits(identifier, args...) expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5162 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5163 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5164 ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5165 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5166 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5167 args = parseTemplateArgumentList2(); // __traits(identifier, args...)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5168 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5169 check(TOK.TOKrparen); // __traits(identifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5170
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5171 e = new TraitsExp(loc, ident, args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5172 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5173 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5175
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5176 case TOK.TOKis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5177 { Type targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5178 Identifier ident = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5179 Type tspec = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5180 TOK tok = TOK.TOKreserved;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5181 TOK tok2 = TOK.TOKreserved;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5182 TemplateParameters tpl = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5183 Loc loc2 = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5184
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5185 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5186 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5187 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5188 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5189 targ = parseType(&ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5190 if (token.value == TOK.TOKcolon || token.value == TOK.TOKequal)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5191 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5192 tok = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5193 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5194 if (tok == TOK.TOKequal &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5195 (token.value == TOK.TOKtypedef ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5196 token.value == TOK.TOKstruct ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5197 token.value == TOK.TOKunion ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5198 token.value == TOK.TOKclass ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5199 token.value == TOK.TOKsuper ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5200 token.value == TOK.TOKenum ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5201 token.value == TOK.TOKinterface ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5202 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5203 token.value == TOK.TOKconst && peek(&token).value == TOK.TOKrparen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5204 token.value == TOK.TOKinvariant && peek(&token).value == TOK.TOKrparen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5205 token.value == TOK.TOKimmutable && peek(&token).value == TOK.TOKrparen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5206 token.value == TOK.TOKshared && peek(&token).value == TOK.TOKrparen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5207 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5208 token.value == TOK.TOKfunction ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5209 token.value == TOK.TOKdelegate ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5210 token.value == TOK.TOKreturn))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5211 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5212 tok2 = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5213 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5215 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5216 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5217 tspec = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5218 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5219 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5220 if (ident && tspec)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5221 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5222 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5223 tpl = parseTemplateParameterList(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5224 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5225 { tpl = new TemplateParameters();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5226 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5227 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5228 TemplateParameter tp = new TemplateTypeParameter(loc2, ident, null, null);
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
5229 tpl.insert(0, tp);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5230 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5231 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5232 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5233 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5234 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5235 { error("(type identifier : specialization) expected following is");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5236 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5237 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5238 e = new IsExp(loc2, targ, ident, tok, tspec, tok2, tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5239 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5240 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5241
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5242 case TOK.TOKassert:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5243 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5244 Expression msg = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5245
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5246 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5247 check(TOK.TOKlparen, "assert");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5248 e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5249 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5250 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5251 msg = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5252 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5253 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5254 e = new AssertExp(loc, e, msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5255 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5256 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5257
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5258 case TOK.TOKmixin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5259 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5260 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5261 check(TOK.TOKlparen, "mixin");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5262 e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5263 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5264 e = new CompileExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5265 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5266 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5267
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5268 case TOK.TOKimport:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5269 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5270 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5271 check(TOK.TOKlparen, "import");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5272 e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5273 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5274 e = new FileExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5275 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5277
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5278 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5279 if (peekPastParen(&token).value == TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5280 { // (arguments) { statements... }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5281 save = TOK.TOKdelegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5282 goto case_delegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5283 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5284 // ( expression )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5285 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5286 e = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5287 check(loc, TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5288 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5289
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5290 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5291 { /* Parse array literals and associative array literals:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5292 * [ value, value, value ... ]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5293 * [ key:value, key:value, key:value ... ]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5294 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5295 Expressions values = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5296 Expressions keys = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5297
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5298 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5299 if (token.value != TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5300 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5301 while (token.value != TOK.TOKeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5303 Expression e2 = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5304 if (token.value == TOK.TOKcolon && (keys || values.dim == 0))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5305 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5306 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5307 if (!keys)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5308 keys = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
5309 keys.push(e2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5310 e2 = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5311 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5312 else if (keys)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5313 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5314 error("'key:value' expected for associative array literal");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5315 delete keys;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5316 keys = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5317 }
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
5318 values.push(e2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5319 if (token.value == TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5320 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5321 check(TOK.TOKcomma);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5322 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5323 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5324 check(TOK.TOKrbracket);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5325
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5326 if (keys)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5327 e = new AssocArrayLiteralExp(loc, keys, values);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5328 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5329 e = new ArrayLiteralExp(loc, values);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5330 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5331 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5332
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5333 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5334 // { statements... }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5335 save = TOK.TOKdelegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5336 goto case_delegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5337
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5338 case TOK.TOKfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5339 case TOK.TOKdelegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5340 save = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5341 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5342 case_delegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5343 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5344 /* function type(parameters) { body } pure nothrow
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5345 * delegate type(parameters) { body } pure nothrow
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5346 * (parameters) { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5347 * { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5348 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5349 Arguments arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5350 int varargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5351 FuncLiteralDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5352 Type tt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5353 bool isnothrow = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5354 bool ispure = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5355
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5356 if (token.value == TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5357 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5358 tt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5359 varargs = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5360 arguments = new Arguments();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5361 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5362 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5363 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5364 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5365 tt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5366 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5367 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5368 tt = parseBasicType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5369 tt = parseBasicType2(tt); // function return type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5370 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5371 arguments = parseParameters(&varargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5372 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5373 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5374 if (token.value == TOK.TOKpure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5375 ispure = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5376 else if (token.value == TOK.TOKnothrow)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5377 isnothrow = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5378 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5379 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5380 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5381 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5382 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5383
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5384 TypeFunction tf = new TypeFunction(arguments, tt, varargs, linkage);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5385 tf.ispure = ispure;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5386 tf.isnothrow = isnothrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5387 fd = new FuncLiteralDeclaration(loc, Loc(0), tf, save, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5388 parseContracts(fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5389 e = new FuncExp(loc, fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5390 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5391 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5392
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5393 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5394 error("expression expected, not '%s'", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5395 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5396 // Anything for e, as long as it's not null
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5397 e = new IntegerExp(loc, 0, Type.tint32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5398 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5399 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5400 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5401 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5402 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5403
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5404 Expression parseUnaryExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5405 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5406 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5407 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5408
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5409 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5410 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5411 case TOK.TOKand:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5412 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5413 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5414 e = new AddrExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5415 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5416
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5417 case TOK.TOKplusplus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5418 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5419 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5420 e = new AddAssignExp(loc, e, new IntegerExp(loc, 1, Type.tint32));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5421 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5422
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5423 case TOK.TOKminusminus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5424 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5425 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5426 e = new MinAssignExp(loc, e, new IntegerExp(loc, 1, Type.tint32));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5427 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5428
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5429 case TOK.TOKmul:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5430 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5431 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5432 e = new PtrExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5433 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5434
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5435 case TOK.TOKmin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5436 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5437 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5438 e = new NegExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5439 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5440
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5441 case TOK.TOKadd:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5442 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5443 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5444 e = new UAddExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5445 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5446
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5447 case TOK.TOKnot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5448 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5449 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5450 e = new NotExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5451 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5452
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5453 case TOK.TOKtilde:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5454 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5455 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5456 e = new ComExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5457 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5458
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5459 case TOK.TOKdelete:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5460 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5461 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5462 e = new DeleteExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5463 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5464
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5465 case TOK.TOKnew:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5466 e = parseNewExp(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5467 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5468
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5469 case TOK.TOKcast: // cast(type) expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5470 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5471 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5472 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5473 /* Look for cast(), cast(const), cast(immutable),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5474 * cast(shared), cast(shared const)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5475 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5476 MOD m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5477 if (token.value == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5478 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5479 m = MOD.MODundefined;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5480 goto Lmod1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5481 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5482 else if (token.value == TOK.TOKconst && peekNext() == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5483 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5484 m = MOD.MODconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5485 goto Lmod2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5486 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5487 else if ((token.value == TOK.TOKimmutable || token.value == TOK.TOKinvariant) && peekNext() == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5488 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5489 m = MOD.MODinvariant;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5490 goto Lmod2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5491 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5492 else if (token.value == TOK.TOKshared && peekNext() == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5493 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5494 m = MOD.MODshared;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5495 goto Lmod2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5496 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5497 else if (token.value == TOK.TOKconst && peekNext() == TOK.TOKshared && peekNext2() == TOK.TOKrparen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5498 token.value == TOK.TOKshared && peekNext() == TOK.TOKconst && peekNext2() == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5499 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5500 m = MOD.MODshared | MOD.MODconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5501 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5502 Lmod2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5503 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5504 Lmod1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5505 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5506 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5507 e = new CastExp(loc, e, m);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5508 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5509 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5510 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5511 Type t = parseType(); // ( type )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5512 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5513 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5514 e = new CastExp(loc, e, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5515 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5516 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5517 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5518
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5519 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5520 { Token *tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5521
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5522 tk = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5523 version (CCASTSYNTAX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5524 // If cast
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5525 if (isDeclaration(tk, 0, TOK.TOKrparen, &tk))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5526 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5527 tk = peek(tk); // skip over right parenthesis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5528 switch (tk.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5529 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5530 case TOK.TOKnot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5531 tk = peek(tk);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5532 if (tk.value == TOK.TOKis) // !is
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5533 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5534 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5535 case TOK.TOKplusplus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5536 case TOK.TOKminusminus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5537 case TOK.TOKdelete:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5538 case TOK.TOKnew:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5539 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5540 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5541 case TOK.TOKthis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5542 case TOK.TOKsuper:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5543 case TOK.TOKint32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5544 case TOK.TOKuns32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5545 case TOK.TOKint64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5546 case TOK.TOKuns64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5547 case TOK.TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5548 case TOK.TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5549 case TOK.TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5550 case TOK.TOKimaginary32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5551 case TOK.TOKimaginary64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5552 case TOK.TOKimaginary80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5553 case TOK.TOKnull:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5554 case TOK.TOKtrue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5555 case TOK.TOKfalse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5556 case TOK.TOKcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5557 case TOK.TOKwcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5558 case TOK.TOKdcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5559 case TOK.TOKstring:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5560 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5561 case TOK.TOKtilde:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5562 case TOK.TOKand:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5563 case TOK.TOKmul:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5564 case TOK.TOKmin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5565 case TOK.TOKadd:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5566 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5567 case TOK.TOKfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5568 case TOK.TOKdelegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5569 case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5570 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5571 case TOK.TOKfile:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5572 case TOK.TOKline:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5573 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5574 case TOK.TOKwchar: case TOK.TOKdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5575 case TOK.TOKbit: case TOK.TOKbool: case TOK.TOKchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5576 case TOK.TOKint8: case TOK.TOKuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5577 case TOK.TOKint16: case TOK.TOKuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5578 case TOK.TOKint32: case TOK.TOKuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5579 case TOK.TOKint64: case TOK.TOKuns64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5580 case TOK.TOKfloat32: case TOK.TOKfloat64: case TOK.TOKfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5581 case TOK.TOKimaginary32: case TOK.TOKimaginary64: case TOK.TOKimaginary80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5582 case TOK.TOKcomplex32: case TOK.TOKcomplex64: case TOK.TOKcomplex80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5583 case TOK.TOKvoid: // (type)int.size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5584 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5585 // (type) una_exp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5586 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5587 Type t = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5588 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5589
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5590 // if .identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5591 if (token.value == TOK.TOKdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5592 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5593 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5594 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5595 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5596 error("Identifier expected following (type).");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5597 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5598 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5599 e = typeDotIdExp(loc, t, token.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5600 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5601 e = parsePostExp(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5602 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5603 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5604 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5605 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5606 e = new CastExp(loc, e, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5607 error("C style cast illegal, use %s", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5608 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5609 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5610 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5611
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5612 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5613 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5614 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5615 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5616 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5617 e = parsePrimaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5618 e = parsePostExp(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5619 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5620 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5621 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5622 e = parsePrimaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5623 e = parsePostExp(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5624 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5625 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5626 assert(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5627 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5628 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5629
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5630 Expression parsePostExp(Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5631 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5632 Loc loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5633
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5634 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5635 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5636 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5637 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5638 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5639 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5640 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5641 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5642 { Identifier id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5643
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5644 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5645 if (token.value == TOK.TOKnot && peekNext() != TOK.TOKis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5646 { // identifier!(template-argument-list)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5647 TemplateInstance tempinst = new TemplateInstance(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5648 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5649 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5650 // ident!(template_arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5651 tempinst.tiargs = parseTemplateArgumentList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5652 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5653 // ident!template_argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5654 tempinst.tiargs = parseTemplateArgument();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5655 e = new DotTemplateInstanceExp(loc, e, tempinst);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5656 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5657 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5658 e = new DotIdExp(loc, e, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5659 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5660 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5661 else if (token.value == TOK.TOKnew)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5662 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5663 e = parseNewExp(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5664 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5665 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5666 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5667 error("identifier expected following '.', not '%s'", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5668 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5669
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5670 case TOK.TOKplusplus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5671 e = new PostExp(TOK.TOKplusplus, loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5672 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5673
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5674 case TOK.TOKminusminus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5675 e = new PostExp(TOK.TOKminusminus, loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5676 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5677
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5678 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5679 e = new CallExp(loc, e, parseArguments());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5680 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5681
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5682 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5683 { // array dereferences:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5684 // array[index]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5685 // array[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5686 // array[lwr .. upr]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5687 Expression index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5688 Expression upr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5689
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5690 inBrackets++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5691 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5692 if (token.value == TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5693 { // array[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5694 e = new SliceExp(loc, e, null, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5695 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5696 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5697 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5698 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5699 index = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5700 if (token.value == TOK.TOKslice)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5701 { // array[lwr .. upr]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5702 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5703 upr = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5704 e = new SliceExp(loc, e, index, upr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5705 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5706 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5707 { // array[index, i2, i3, i4, ...]
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
5708 auto arguments = new Expressions();
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
5709 arguments.push(index);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5710 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5711 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5712 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5713 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5714 { Expression arg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5715
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5716 arg = parseAssignExp();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
5717 arguments.push(arg);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5718 if (token.value == TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5719 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5720 check(TOK.TOKcomma);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5721 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5722 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5723 e = new ArrayExp(loc, e, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5724 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5725 check(TOK.TOKrbracket);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5726 inBrackets--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5727 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5728 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5729 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5730
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5731 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5732 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5733 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5734 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5735 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5736
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5737 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5738 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5739
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5740 Expression parseMulExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5741 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5742 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5743 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5744 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5745
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5746 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5747 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5748 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5749 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5750 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5751 case TOK.TOKmul: nextToken(); e2 = parseUnaryExp(); e = new MulExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5752 case TOK.TOKdiv: nextToken(); e2 = parseUnaryExp(); e = new DivExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5753 case TOK.TOKmod: nextToken(); e2 = parseUnaryExp(); e = new ModExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5754
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5755 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5756 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5757 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5758 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5759 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5760 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5761 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5762
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5763 Expression parseShiftExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5764 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5765 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5766 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5767 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5768
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5769 e = parseAddExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5770 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5771 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5772 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5773 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5774 case TOK.TOKshl: nextToken(); e2 = parseAddExp(); e = new ShlExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5775 case TOK.TOKshr: nextToken(); e2 = parseAddExp(); e = new ShrExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5776 case TOK.TOKushr: nextToken(); e2 = parseAddExp(); e = new UshrExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5777
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5778 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5779 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5780 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5781 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5782 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5783 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5784 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5785
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5786 Expression parseAddExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5787 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5788 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5789 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5790 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5791
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5792 e = parseMulExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5793 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5794 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5795 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5796 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5797 case TOK.TOKadd: nextToken(); e2 = parseMulExp(); e = new AddExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5798 case TOK.TOKmin: nextToken(); e2 = parseMulExp(); e = new MinExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5799 case TOK.TOKtilde: nextToken(); e2 = parseMulExp(); e = new CatExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5800
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5801 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5802 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5803 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5804 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5805 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5806 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5807 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5808
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5809 Expression parseRelExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5810 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5811 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5812 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5813
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5814 Expression parseEqualExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5815 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5816 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5817 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5818
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5819 Expression parseCmpExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5820 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5821 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5822 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5823 Token* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5824 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5825
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5826 e = parseShiftExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5827 TOK op = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5828
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5829 switch (op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5830 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5831 case TOK.TOKequal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5832 case TOK.TOKnotequal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5833 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5834 e2 = parseShiftExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5835 e = new EqualExp(op, loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5836 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5837
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5838 case TOK.TOKis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5839 op = TOK.TOKidentity;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5840 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5841
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5842 case TOK.TOKnot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5843 // Attempt to identify '!is'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5844 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5845 if (t.value != TOK.TOKis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5846 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5847 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5848 op = TOK.TOKnotidentity;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5849 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5850
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5851 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5852 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5853 e2 = parseShiftExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5854 e = new IdentityExp(op, loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5855 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5856
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5857 case TOK.TOKlt:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5858 case TOK.TOKle:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5859 case TOK.TOKgt:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5860 case TOK.TOKge:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5861 case TOK.TOKunord:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5862 case TOK.TOKlg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5863 case TOK.TOKleg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5864 case TOK.TOKule:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5865 case TOK.TOKul:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5866 case TOK.TOKuge:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5867 case TOK.TOKug:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5868 case TOK.TOKue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5869 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5870 e2 = parseShiftExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5871 e = new CmpExp(op, loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5872 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5873
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5874 case TOK.TOKin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5875 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5876 e2 = parseShiftExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5877 e = new InExp(loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5878 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5879
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5880 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5881 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5882 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5883 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5884 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5885
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5886 Expression parseAndExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5887 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5888 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5889 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5890 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5891
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5892 if (global.params.Dversion == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5893 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5894 e = parseEqualExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5895 while (token.value == TOK.TOKand)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5896 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5897 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5898 e2 = parseEqualExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5899 e = new AndExp(loc,e,e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5900 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5901 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5902 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5903 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5904 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5905 e = parseCmpExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5906 while (token.value == TOK.TOKand)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5907 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5908 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5909 e2 = parseCmpExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5910 e = new AndExp(loc,e,e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5911 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5912 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5913 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5914 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5915 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5916
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5917 Expression parseXorExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5918 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5919 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5920 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5921 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5922
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5923 e = parseAndExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5924 while (token.value == TOK.TOKxor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5925 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5926 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5927 e2 = parseAndExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5928 e = new XorExp(loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5929 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5930
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5931 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5932 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5933
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5934 Expression parseOrExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5935 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5936 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5937 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5938 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5939
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5940 e = parseXorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5941 while (token.value == TOK.TOKor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5942 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5943 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5944 e2 = parseXorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5945 e = new OrExp(loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5946 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5947 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5948 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5949
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5950 Expression parseAndAndExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5951 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5952 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5953 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5954 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5955
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5956 e = parseOrExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5957 while (token.value == TOK.TOKandand)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5958 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5959 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5960 e2 = parseOrExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5961 e = new AndAndExp(loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5962 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5963 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5964 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5965
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5966 Expression parseOrOrExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5967 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5968 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5969 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5970 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5971
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5972 e = parseAndAndExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5973 while (token.value == TOK.TOKoror)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5974 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5975 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5976 e2 = parseAndAndExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5977 e = new OrOrExp(loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5978 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5979
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5980 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5981 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5982
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5983 Expression parseCondExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5984 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5985 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5986 Expression e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5987 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5988 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5989
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5990 e = parseOrOrExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5991 if (token.value == TOK.TOKquestion)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5992 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5993 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5994 e1 = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5995 check(TOK.TOKcolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5996 e2 = parseCondExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5997 e = new CondExp(loc, e, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5998 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5999 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6000 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6001
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6002 Expression parseAssignExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6003 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6004 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6005 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6006 Loc loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6007
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6008 e = parseCondExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6009 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6010 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6011 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6012 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6013 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6014 case TOK.TOKassign: nextToken(); e2 = parseAssignExp(); e = new AssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6015 case TOK.TOKaddass: nextToken(); e2 = parseAssignExp(); e = new AddAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6016 case TOK.TOKminass: nextToken(); e2 = parseAssignExp(); e = new MinAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6017 case TOK.TOKmulass: nextToken(); e2 = parseAssignExp(); e = new MulAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6018 case TOK.TOKdivass: nextToken(); e2 = parseAssignExp(); e = new DivAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6019 case TOK.TOKmodass: nextToken(); e2 = parseAssignExp(); e = new ModAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6020 case TOK.TOKandass: nextToken(); e2 = parseAssignExp(); e = new AndAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6021 case TOK.TOKorass: nextToken(); e2 = parseAssignExp(); e = new OrAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6022 case TOK.TOKxorass: nextToken(); e2 = parseAssignExp(); e = new XorAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6023 case TOK.TOKshlass: nextToken(); e2 = parseAssignExp(); e = new ShlAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6024 case TOK.TOKshrass: nextToken(); e2 = parseAssignExp(); e = new ShrAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6025 case TOK.TOKushrass: nextToken(); e2 = parseAssignExp(); e = new UshrAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6026 case TOK.TOKcatass: nextToken(); e2 = parseAssignExp(); e = new CatAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6027
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6028 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6029 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6030 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6031 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6032 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6033
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6034 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6035 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6036
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6037 /*************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6038 * Collect argument list.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6039 * Assume current token is ',', '(' or '['.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6040 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6041 Expressions parseArguments()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6042 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6043 // function call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6044 Expressions arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6045 Expression arg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6046 TOK endtok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6047
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6048 if (token.value == TOK.TOKlbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6049 endtok = TOK.TOKrbracket;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6050 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6051 endtok = TOK.TOKrparen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6052
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6053 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6054 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6055 if (token.value != endtok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6056 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6057 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6058 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6059 arg = parseAssignExp();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
6060 arguments.push(arg);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6061 if (token.value == endtok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6062 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6063 check(TOK.TOKcomma);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6064 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6065 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6066 check(endtok);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6067 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6068 return arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6069 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6070
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6071 Expression parseNewExp(Expression thisexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6072 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6073 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6074 Expressions newargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6075 Expressions arguments = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6076 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6077 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6078
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6079 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6080 newargs = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6081 if (token.value == TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6082 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6083 newargs = parseArguments();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6084 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6085
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6086 // An anonymous nested class starts with "class"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6087 if (token.value == TOKclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6088 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6089 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6090 if (token.value == TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6091 arguments = parseArguments();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6092
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6093 BaseClasses baseclasses = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6094 if (token.value != TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6095 baseclasses = parseBaseClasses();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6096
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6097 Identifier id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6098 ClassDeclaration cd = new ClassDeclaration(loc, id, baseclasses);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6099
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6100 if (token.value != TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6101 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6102 error("{ members } expected for anonymous class");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6103 cd.members = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6105 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6106 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6107 nextToken();
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
6108 auto decl = parseDeclDefs(0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6109 if (token.value != TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6110 error("class member expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6111 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6112 cd.members = decl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6114
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6115 e = new NewAnonClassExp(loc, thisexp, newargs, cd, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6116
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6117 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6119
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6120 t = parseBasicType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6121 t = parseBasicType2(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6122 if (t.ty == Taarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6123 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6124 TypeAArray taa = cast(TypeAArray)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6125 Type index = taa.index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6127 Expression e2 = index.toExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6128 if (e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6129 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6130 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
6131 arguments.push(e2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6132 t = new TypeDArray(taa.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6133 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6134 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6135 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6136 error("need size of rightmost array, not type %s", index.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6137 return new NullExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6138 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6139 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6140 else if (t.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6141 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6142 TypeSArray tsa = cast(TypeSArray)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6143 Expression ee = tsa.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6145 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
6146 arguments.push(ee);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6147 t = new TypeDArray(tsa.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6148 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6149 else if (token.value == TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6150 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6151 arguments = parseArguments();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6152 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6153
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6154 e = new NewExp(loc, thisexp, newargs, t, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6155 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6156 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6157
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
6158 void addComment(Dsymbol s, const(char)[] blockComment)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6159 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6160 s.addComment(combineComments(blockComment, token.lineComment));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6161 token.lineComment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6162 }
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
6163 }