annotate dmd/Parser.d @ 191:52188e7e3fb5

Fixed deprecated features, now compiles with DMD2.058 Also changed Array allocation policy: Now doesn't reallocate but malloc's, followed by a memcpy (no free). (this fixes a crash while compiling druntime. Same bug in dmd)
author korDen@korDen-pc
date Sun, 25 Mar 2012 03:11:12 +0400
parents cd48cb899aee
children
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;
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
8 import dmd.SharedStaticCtorDeclaration;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
9 import dmd.SharedStaticDtorDeclaration;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.EnumMember;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.CtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.ShlAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.ShrAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.UshrAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.CatAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.StaticIfCondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.TraitsExp;
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
18 import dmd.TemplateMixin;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.BaseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.AssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.TemplateInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.NewExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.ArrayExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.DotTemplateInstanceExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.NewAnonClassExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.InterfaceDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.UnionDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.AnonDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.StructInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.ArrayInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.TemplateAliasParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.TemplateTupleParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.TemplateThisParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.TemplateValueParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.VoidInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.VersionCondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.DebugCondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.PostExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.SliceExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.FuncExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.AssocArrayLiteralExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.ArrayLiteralExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.IsExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.FuncLiteralDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.AssertExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.CompileExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.FileExp;
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
53 import dmd.TemplateMixin;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import dmd.TemplateParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.TemplateTypeParameter;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 import dmd.TypeidExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 import dmd.StringExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 import dmd.ScopeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 import dmd.IdentifierExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 import dmd.DollarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 import dmd.ThisExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 import dmd.SuperExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 import dmd.NullExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 import dmd.RealExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 import dmd.TypeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 import dmd.AddrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 import dmd.CastExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 import dmd.PtrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 import dmd.NegExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 import dmd.XorAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 import dmd.OrAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 import dmd.UAddExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 import dmd.NotExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 import dmd.ComExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 import dmd.DeleteExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 import dmd.MulAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 import dmd.ModAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 import dmd.MinAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 import dmd.DivAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 import dmd.AndAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 import dmd.AddAssignExp;
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
84 import dmd.PowAssignExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 import dmd.ModuleDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 import dmd.CaseRangeStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 import dmd.CommaExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 import dmd.XorExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 import dmd.CondExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 import dmd.CmpExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 import dmd.InExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 import dmd.OrOrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 import dmd.OrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 import dmd.AddExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 import dmd.MinExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 import dmd.CatExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 import dmd.AndAndExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 import dmd.EqualExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 import dmd.ShlExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 import dmd.ShrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 import dmd.DivExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 import dmd.MulExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 import dmd.ModExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 import dmd.UshrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 import dmd.IdentityExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 import dmd.AndExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 import dmd.LabelStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 import dmd.StaticAssertStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 import dmd.DeclarationStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 import dmd.ScopeStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 import dmd.PragmaStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 import dmd.WhileStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 import dmd.DoStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 import dmd.ForStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 import dmd.OnScopeStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 import dmd.IfStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 import dmd.SwitchStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 import dmd.CaseStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 import dmd.DefaultStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 import dmd.GotoDefaultStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 import dmd.GotoCaseStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 import dmd.GotoStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 import dmd.SynchronizedStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 import dmd.WithStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 import dmd.Catch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 import dmd.TryCatchStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 import dmd.TryFinallyStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 import dmd.ThrowStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 import dmd.VolatileStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 import dmd.ReturnStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 import dmd.BreakStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 import dmd.ContinueStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 import dmd.AsmStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 import dmd.TypeReturn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 import dmd.TypeTypeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 import dmd.ForeachRangeStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 import dmd.ForeachStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 import dmd.CompileStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 import dmd.CompoundStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 import dmd.ConditionalStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 import dmd.CompoundDeclarationStatement;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
144 import dmd.Parameter;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 import dmd.ParseStatementFlags;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
146 import dmd.TypeNewArray;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 import dmd.TypeNext;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 import dmd.TypeInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 import dmd.TypePointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 import dmd.TypeDArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 import dmd.TypeAArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 import dmd.TypeSlice;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 import dmd.TemplateInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 import dmd.TypeIdentifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 import dmd.TypeDelegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 import dmd.LinkDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 import dmd.TypedefDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 import dmd.AliasDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 import dmd.LINK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 import dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 import dmd.TemplateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 import dmd.StaticAssert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 import dmd.TypeQualified;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 import dmd.Condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 import dmd.PostBlitDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 import dmd.DtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 import dmd.ConditionalDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 import dmd.StaticCtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 import dmd.StaticDtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 import dmd.InvariantDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 import dmd.UnitTestDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 import dmd.NewDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 import dmd.DeleteDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 import dmd.EnumDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 import dmd.Import;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 import dmd.Initializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 import dmd.Token;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 import dmd.ParseStatementFlags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 import dmd.PROT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 import dmd.CompileDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 import dmd.StaticIfDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 import dmd.StorageClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 import dmd.LinkDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 import dmd.ProtDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 import dmd.AlignDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 import dmd.PragmaDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 import dmd.DebugSymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 import dmd.VersionSymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 import dmd.AliasThis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 import dmd.Global;
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
209 import dmd.TRUST;
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
210 import dmd.PowExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 import core.stdc.string : memcpy;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213
34
544b922227c7 update to work with dmd 2.048
korDen
parents: 24
diff changeset
214 import std.exception;
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
215 import core.memory;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 class Parser : Lexer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 ModuleDeclaration md;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 LINK linkage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 Loc endloc; // set to location of last right curly
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 int inBrackets; // inside [] of array index or slice
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 this(Module module_, ubyte* base, uint length, int doDocComment)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 135
diff changeset
226 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 super(module_, base, 0, length, doDocComment, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 //printf("Parser.Parser()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 linkage = LINK.LINKd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 //nextToken(); // start up the scanner
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
233 Dsymbols parseModule()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
235 typeof(return) decldefs;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 // ModuleDeclation leads off
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 if (token.value == TOK.TOKmodule)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
240 string comment = token.blockComment;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 bool safe = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 nextToken();
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
244 static if(false) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 error("module (system) identifier expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 Identifier id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 if (id is Id.system)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 safe = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 error("(safe) expected, not %s", id.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 }
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
264 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 error("Identifier expected following module");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 {
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
273 Identifiers a = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 Identifier id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 while (nextToken() == TOK.TOKdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 if (!a)
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
278 a = new Identifiers();
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
279 a.push(id);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 { error("Identifier expected following package");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 md = new ModuleDeclaration(a, id, safe);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 if (token.value != TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 error("';' expected following module declaration instead of %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 addComment(mod, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 decldefs = parseDeclDefs(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 if (token.value != TOK.TOKeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 error("unrecognized declaration");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 return decldefs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 while (token.value != TOK.TOKsemicolon && token.value != TOK.TOKeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 nextToken();
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
312 return new Dsymbols();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
315 Dsymbols parseDeclDefs(int once)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 Dsymbol s;
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
318 Dsymbols decldefs;
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
319 Dsymbols a;
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
320 Dsymbols aelse;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 PROT prot;
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
322 StorageClass stc;
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
323 StorageClass storageClass;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 Condition condition;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
325 string comment;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 //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
328 decldefs = new Dsymbols();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 comment = token.blockComment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 storageClass = STC.STCundefined;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 case TOK.TOKenum:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 { /* Determine if this is a manifest constant declaration,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 * or a conventional enum.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 Token *t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 if (t.value == TOK.TOKlcurly || t.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 s = parseEnum();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 else if (t.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 if (t.value == TOK.TOKlcurly || t.value == TOK.TOKcolon ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 t.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 s = parseEnum();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 }
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 case TOK.TOKstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 case TOK.TOKunion:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 case TOK.TOKclass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 case TOK.TOKinterface:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 s = parseAggregate();
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.TOKimport:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 s = parseImport(decldefs, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 case TOK.TOKtemplate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 s = cast(Dsymbol)parseTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 case TOK.TOKmixin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 { Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 { // mixin(string)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 check(TOK.TOKlparen, "mixin");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 Expression e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 check(TOK.TOKsemicolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 s = new CompileDeclaration(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 s = parseMixin();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 case TOK.TOKwchar: case TOK.TOKdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 case TOK.TOKbit: case TOK.TOKbool: case TOK.TOKchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 case TOK.TOKint8: case TOK.TOKuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 case TOK.TOKint16: case TOK.TOKuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 case TOK.TOKint32: case TOK.TOKuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 case TOK.TOKint64: case TOK.TOKuns64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 case TOK.TOKfloat32: case TOK.TOKfloat64: case TOK.TOKfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 case TOK.TOKimaginary32: case TOK.TOKimaginary64: case TOK.TOKimaginary80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 case TOK.TOKcomplex32: case TOK.TOKcomplex64: case TOK.TOKcomplex80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 case TOK.TOKvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 case TOK.TOKalias:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 case TOK.TOKtypedef:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 Ldeclaration:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 a = parseDeclarations(STC.STCundefined);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 decldefs.append(a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 case TOK.TOKthis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 s = parseCtor();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 static if (false) { // dead end, use this(this){} instead
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 case TOK.TOKassign:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 s = parsePostBlit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 case TOK.TOKtilde:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 s = parseDtor();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 { Token *t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 if (t.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 if (peek(t).value == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 // invariant() forms start of class invariant
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 s = parseInvariant();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 // invariant(type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 stc = STC.STCimmutable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 case TOK.TOKunittest:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 s = parseUnitTest();
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.TOKnew:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 s = parseNew();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 case TOK.TOKdelete:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 s = parseDelete();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 case TOK.TOKrcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 return decldefs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 case TOK.TOKstatic:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 if (token.value == TOK.TOKthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 s = parseStaticCtor();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 else if (token.value == TOK.TOKtilde)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 s = parseStaticDtor();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 else if (token.value == TOK.TOKassert)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 s = parseStaticAssert();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 else if (token.value == TOK.TOKif)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 { condition = parseStaticIfCondition();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 aelse = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 if (token.value == TOK.TOKelse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 aelse = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 s = new StaticIfDeclaration(condition, a, aelse);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 else if (token.value == TOK.TOKimport)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 s = parseImport(decldefs, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 { stc = STC.STCstatic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 goto Lstc2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 case TOK.TOKconst:
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
486 if (peekNext() == TOKlparen)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 stc = STC.STCconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 case TOK.TOKimmutable:
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
492 if (peekNext() == TOKlparen)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 stc = STC.STCimmutable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 case TOK.TOKshared:
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
498 {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
499 TOK next = peekNext();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
500 if (next == TOKlparen)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
501 goto Ldeclaration;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
502 if (next == TOKstatic)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
503 {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
504 TOK next2 = peekNext2();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
505 if (next2 == TOKthis)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
506 {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
507 s = parseSharedStaticCtor();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
508 break;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
509 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
510 if (next2 == TOKtilde)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
511 {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
512 s = parseSharedStaticDtor();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
513 break;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
514 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
515 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
516 stc = STCshared;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
517 goto Lstc;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
518 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
519
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
520 case TOKwild:
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
521 if (peekNext() == TOKlparen)
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
522 goto Ldeclaration;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
523 stc = STCwild;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
524 goto Lstc;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
525
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 case TOK.TOKfinal: stc = STC.STCfinal; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 case TOK.TOKauto: stc = STC.STCauto; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 case TOK.TOKscope: stc = STC.STCscope; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 case TOK.TOKoverride: stc = STC.STCoverride; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 case TOK.TOKabstract: stc = STC.STCabstract; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 case TOK.TOKsynchronized: stc = STC.STCsynchronized; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 case TOK.TOKdeprecated: stc = STC.STCdeprecated; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 case TOK.TOKnothrow: stc = STC.STCnothrow; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 case TOK.TOKpure: stc = STC.STCpure; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 case TOK.TOKref: stc = STC.STCref; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 case TOK.TOKtls: stc = STC.STCtls; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 case TOK.TOKgshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 stc = STC.STCgshared; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 //case TOK.TOKmanifest: stc = STC.STCmanifest; goto Lstc;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
541 case TOK.TOKat: stc = parseAttribute(); goto Lstc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 Lstc:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 if (storageClass & stc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 error("redundant storage class %s", Token.toChars(token.value));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 composeStorageClass(storageClass | stc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 Lstc2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 storageClass |= stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 case TOK.TOKshared:
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
557 case TOKwild:
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 // If followed by a (, it is not a storage class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 if (token.value == TOK.TOKconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 stc = STC.STCconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 else if (token.value == TOK.TOKshared)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 stc = STC.STCshared;
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
565 else if (token.value == TOKwild)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
566 stc = STC.STCwild;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 stc = STC.STCimmutable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 case TOK.TOKfinal: stc = STC.STCfinal; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 case TOK.TOKauto: stc = STC.STCauto; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 case TOK.TOKscope: stc = STC.STCscope; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 case TOK.TOKoverride: stc = STC.STCoverride; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 case TOK.TOKabstract: stc = STC.STCabstract; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 case TOK.TOKsynchronized: stc = STC.STCsynchronized; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 case TOK.TOKdeprecated: stc = STC.STCdeprecated; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 case TOK.TOKnothrow: stc = STC.STCnothrow; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 case TOK.TOKpure: stc = STC.STCpure; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 case TOK.TOKref: stc = STC.STCref; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 case TOK.TOKtls: stc = STC.STCtls; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 case TOK.TOKgshared: stc = STC.STCgshared; goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 //case TOK.TOKmanifest: stc = STC.STCmanifest; goto Lstc;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
583 case TOK.TOKat: stc = parseAttribute(); goto Lstc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 /* Look for auto initializers:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 * storage_class identifier = initializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 if (token.value == TOK.TOKidentifier &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 peek(&token).value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 a = parseAutoDeclarations(storageClass, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 decldefs.append(a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 /* Look for return type inference for template functions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 Token *tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 if (token.value == TOK.TOKidentifier &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 (tk = peek(&token)).value == TOK.TOKlparen &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 skipParens(tk, &tk) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 (peek(tk).value == TOK.TOKlparen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 peek(tk).value == TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 a = parseDeclarations(storageClass);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 decldefs.append(a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 s = new StorageClassDeclaration(storageClass, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 case TOK.TOKextern:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 if (peek(&token).value != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 stc = STC.STCextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 goto Lstc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 LINK linksave = linkage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 linkage = parseLinkage();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 s = new LinkDeclaration(linkage, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 linkage = linksave;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 case TOK.TOKprivate: prot = PROT.PROTprivate; goto Lprot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 case TOK.TOKpackage: prot = PROT.PROTpackage; goto Lprot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 case TOK.TOKprotected: prot = PROT.PROTprotected; goto Lprot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 case TOK.TOKpublic: prot = PROT.PROTpublic; goto Lprot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 case TOK.TOKexport: prot = PROT.PROTexport; goto Lprot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 Lprot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 case TOK.TOKprivate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 case TOK.TOKpackage:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 case TOK.TOKprotected:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 case TOK.TOKpublic:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 case TOK.TOKexport:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 error("redundant protection attribute");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 s = new ProtDeclaration(prot, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 case TOK.TOKalign:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 { uint n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 if (token.value == TOK.TOKint32v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 n = cast(uint)token.uns64value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 { error("integer expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 n = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 n = global.structalign; // default
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 s = new AlignDeclaration(n, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 case TOK.TOKpragma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 { Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 Expressions args = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 { error("pragma(identifier expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 if (token.value == TOK.TOKcomma && peekNext() != TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 args = parseArguments(); // pragma(identifier, args...)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 check(TOK.TOKrparen); // pragma(identifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 a = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 s = new PragmaDeclaration(loc, ident, args, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 case TOK.TOKdebug:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 if (token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 s = new DebugSymbol(loc, token.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 else if (token.value == TOK.TOKint32v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713 s = new DebugSymbol(loc, cast(uint)token.uns64value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 { error("identifier or integer expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 if (token.value != TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 error("semicolon expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 nextToken();
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 condition = parseDebugCondition();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 goto Lcondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 case TOK.TOKversion:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 if (token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 s = new VersionSymbol(loc, token.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735 else if (token.value == TOK.TOKint32v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 s = new VersionSymbol(loc, cast(uint)token.uns64value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 { error("identifier or integer expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 if (token.value != TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 error("semicolon expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 condition = parseVersionCondition();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 goto Lcondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 Lcondition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 a = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 aelse = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 if (token.value == TOK.TOKelse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 aelse = parseBlock();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 s = new ConditionalDeclaration(condition, a, aelse);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 case TOK.TOKsemicolon: // empty declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 error("Declaration expected, not '%s'",token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 Lerror:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 while (token.value != TOK.TOKsemicolon && token.value != TOK.TOKeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 if (s)
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
774 { decldefs.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 addComment(s, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 } while (!once);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 return decldefs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 * Parse auto declarations of the form:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 * storageClass ident = init, ident = init, ... ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 * and return the array of them.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785 * Starts with token on the first ident.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 * Ends with scanner past closing ';'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 */
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
788 version (DMDV2)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
789 {
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
790 Dsymbols parseAutoDeclarations(StorageClass storageClass, const(char)[] comment)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
792 auto a = new Dsymbols;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 Identifier ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 nextToken(); // skip over ident
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 assert(token.value == TOKassign);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 nextToken(); // skip over '='
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 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
801 auto v = new VarDeclaration(loc, null, ident, init);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 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
803 a.push(v);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 if (token.value == TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 addComment(v, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 else if (token.value == TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 if (token.value == TOKidentifier &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 peek(&token).value == TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 addComment(v, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 error("Identifier expected following comma");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 error("semicolon expected following auto declaration, not '%s'", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 /********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 * Parse declarations after an align, protection, or extern decl.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 */
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
831 Dsymbols parseBlock()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
833 Dsymbols a = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 Dsymbol ss;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 //printf("parseBlock()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 error("declaration expected following attribute, not ';'");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845 error("declaration expected following attribute, not EOF");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 a = parseDeclDefs(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 if (token.value != TOK.TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 { /* { */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 error("matching '}' expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 case TOK.TOKcolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 a = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 a = parseDeclDefs(0); // grab declarations up to closing curly bracket
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 a = parseDeclDefs(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 }
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
874 version(DMDV2) {
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
875 void composeStorageClass(StorageClass stc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876 {
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
877 StorageClass u = stc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 u &= STC.STCconst | STC.STCimmutable | STC.STCmanifest;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 if (u & (u - 1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 error("conflicting storage class %s", Token.toChars(token.value));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 u = stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883 u &= STC.STCgshared | STC.STCshared | STC.STCtls;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 if (u & (u - 1))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 error("conflicting storage class %s", Token.toChars(token.value));
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
886 u = stc;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
887 u &= STCsafe | STCsystem | STCtrusted;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
888 if (u & (u - 1))
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
889 error("conflicting attribute @%s", token.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 }
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
891 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
892
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
893 /***********************************************
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
894 * Parse storage class, lexer is on '@'
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
895 */
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
896
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
897 version(DMDV2) {
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
898 StorageClass parseAttribute()
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
899 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
900 nextToken();
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
901 StorageClass stc = STCundefined;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
902 if (token.value != TOKidentifier)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
903 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
904 error("identifier expected after @, not %s", token.toChars());
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
905 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
906 else if (token.ident == Id.property)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
907 stc = STCproperty;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
908 else if (token.ident == Id.safe)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
909 stc = STCsafe;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
910 else if (token.ident == Id.trusted)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
911 stc = STCtrusted;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
912 else if (token.ident == Id.system)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
913 stc = STCsystem;
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
914 else if (token.ident == Id.disable)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
915 stc = STCdisable;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
916 else
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
917 error("valid attribute identifiers are @property, @safe, @trusted, @system, @disable not @%s", token.toChars());
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
918
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
919 return stc;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
920 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
921 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 * Parse constraint.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 * Constraint is of the form:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 * if ( ConstraintExpression )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 Expression parseConstraint()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 Expression e = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 if (token.value == TOKif)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 nextToken(); // skip over 'if'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 check(TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 e = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 * Parse a TemplateDeclaration.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 TemplateDeclaration parseTemplateDeclaration()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 TemplateDeclaration tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 TemplateParameters tpl;
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
950 Dsymbols decldefs;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 Expression constraint = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955 if (token.value != TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 error("TemplateIdentifier expected following template");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 tpl = parseTemplateParameterList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963 if (!tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 constraint = parseConstraint();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 if (token.value != TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 error("members of template declaration expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 decldefs = parseDeclDefs(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 if (token.value != TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 error("template member expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 tempdecl = new TemplateDeclaration(loc, id, tpl, constraint, decldefs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 return tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 /******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 * Parse template parameter list.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 * flag 0: parsing "( list )"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 * 1: parsing non-empty "list )"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 TemplateParameters parseTemplateParameterList(int flag = 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 TemplateParameters tpl = new TemplateParameters();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 if (!flag && token.value != TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 error("parenthesized TemplateParameterList expected following TemplateIdentifier");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 // Get array of TemplateParameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 if (flag || token.value != TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 int isvariadic = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 TemplateParameter tp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 Identifier tp_ident = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018 Type tp_spectype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 Type tp_valtype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 Type tp_defaulttype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 Expression tp_specvalue = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 Expression tp_defaultvalue = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 Token* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 // Get TemplateParameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 // First, look ahead to see if it is a TypeParameter or a ValueParameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 if (token.value == TOKalias)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 // AliasParameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 Type spectype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 if (isDeclaration(&token, 2, TOKreserved, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 spectype = parseType(&tp_ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 if (token.value != TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 error("identifier expected for template alias parameter");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 tp_ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 Object spec = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 if (token.value == TOKcolon) // : Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052 if (isDeclaration(&token, 0, TOKreserved, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 spec = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 spec = parseCondExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 Object def = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 if (token.value == TOKassign) // = Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 if (isDeclaration(&token, 0, TOKreserved, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 def = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 def = parseCondExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 tp = new TemplateAliasParameter(loc, tp_ident, spectype, spec, def);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 else if (t.value == TOKcolon || t.value == TOKassign ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 t.value == TOKcomma || t.value == TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 { // TypeParameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071 if (token.value != TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072 { error("identifier expected for template type parameter");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075 tp_ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 if (token.value == TOKcolon) // : Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 tp_spectype = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 if (token.value == TOKassign) // = Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 tp_defaulttype = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 tp = new TemplateTypeParameter(loc, tp_ident, tp_spectype, tp_defaulttype);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089 else if (token.value == TOKidentifier && t.value == TOKdotdotdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 { // ident...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091 if (isvariadic)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092 error("variadic template parameter must be last");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 isvariadic = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 tp_ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 tp = new TemplateTupleParameter(loc, tp_ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 /// version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 else if (token.value == TOKthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 { // ThisParameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103 if (token.value != TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104 { error("identifier expected for template this parameter");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107 tp_ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109 if (token.value == TOKcolon) // : Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1112 tp_spectype = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1114 if (token.value == TOKassign) // = Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117 tp_defaulttype = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1119 tp = new TemplateThisParameter(loc, tp_ident, tp_spectype, tp_defaulttype);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1122 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123 { // ValueParameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124 tp_valtype = parseType(&tp_ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125 if (!tp_ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1127 error("identifier expected for template value parameter");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128 tp_ident = new Identifier("error", TOKidentifier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130 if (token.value == TOKcolon) // : CondExpression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1131 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1132 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1133 tp_specvalue = parseCondExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1134 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1135 if (token.value == TOKassign) // = CondExpression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1136 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1137 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1138 tp_defaultvalue = parseDefaultInitExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1139 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1140 tp = new TemplateValueParameter(loc, tp_ident, tp_valtype, tp_specvalue, tp_defaultvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1141 }
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1142 tpl.push(tp);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1143 if (token.value != TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1144 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1145 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1146 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1147 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1148 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1149
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1150 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1151 return tpl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1152 }
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1153
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1154 /******************************************
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1155 * Parse template mixin.
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1156 * mixin Foo;
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1157 * mixin Foo!(args);
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1158 * 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
1159 * mixin Foo!(args) identifier;
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1160 * mixin typeof(expr).identifier!(args);
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1161 */
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1162
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1163 Dsymbol parseMixin()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1164 {
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1165 TemplateMixin tm;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1166 Identifier id;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1167 Type tqual;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1168 Objects tiargs;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1169 Array idents;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1170
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1171 //printf("parseMixin()\n");
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1172 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1173 tqual = null;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1174 if (token.value == TOKdot)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1175 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1176 id = Id.empty;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1177 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1178 else
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1179 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1180 if (token.value == TOKtypeof)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1181 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1182 tqual = parseTypeof();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1183 check(TOKdot);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1184 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1185 if (token.value != TOKidentifier)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1186 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1187 error("identifier expected, not %s", token.toChars());
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1188 id = Id.empty;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1189 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1190 else
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1191 id = token.ident;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1192 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1193 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1194
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1195 idents = new Array();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1196 while (1)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1197 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1198 tiargs = null;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1199 if (token.value == TOKnot)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1200 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1201 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1202 if (token.value == TOKlparen)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1203 tiargs = parseTemplateArgumentList();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1204 else
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1205 tiargs = parseTemplateArgument();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1206 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1207 if (token.value != TOKdot)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1208 break;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1209 if (tiargs)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1210 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1211 TemplateInstance tempinst = new TemplateInstance(loc, id);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1212 tempinst.tiargs = tiargs;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1213 id = cast(Identifier)tempinst;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1214 tiargs = null;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1215 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1216 idents.push(cast(void*)id);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1217 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1218 if (token.value != TOKidentifier)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1219 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1220 error("identifier expected following '.' instead of '%s'", token.toChars());
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1221 break;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1222 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1223 id = token.ident;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1224 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1225 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1226 idents.push(cast(void*)id);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1227 if (token.value == TOKidentifier)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1228 {
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1229 id = token.ident;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1230 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1231 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1232 else
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1233 id = null;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1234
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1235 tm = new TemplateMixin(loc, id, tqual, idents, tiargs);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1236 if (token.value != TOKsemicolon)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1237 error("';' expected after mixin");
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1238 nextToken();
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 4
diff changeset
1239 return tm;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1241
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 /******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1243 * Parse template argument list.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1244 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1245 * current token is opening '('
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1246 * Output:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1247 * current token is one after closing ')'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1248 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1249 Objects parseTemplateArgumentList()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1250 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1251 //printf("Parser.parseTemplateArgumentList()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1252 if (token.value != TOKlparen && token.value != TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1253 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1254 error("!(TemplateArgumentList) expected following TemplateIdentifier");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1255 return new Objects();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1256 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1257 return parseTemplateArgumentList2();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1258 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1259
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1260 Objects parseTemplateArgumentList2()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1261 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1262 //printf("Parser.parseTemplateArgumentList2()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1263 Objects tiargs = new Objects();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1264 TOK endtok = TOKrparen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1265 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1266
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1267 // Get TemplateArgumentList
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1268 if (token.value != endtok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1269 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1270 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1271 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1272 // See if it is an Expression or a Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1273 if (isDeclaration(&token, 0, TOKreserved, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1274 { // Template argument is a type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1275 Type ta = parseType();
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
1276 tiargs.push(ta);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1277 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1278 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1279 { // Template argument is an expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1280 Expression ea = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1281
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1282 if (ea.op == TOKfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1283 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1284 FuncLiteralDeclaration fd = (cast(FuncExp)ea).fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1285 if (fd.type.ty == Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1286 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1287 TypeFunction tf = cast(TypeFunction)fd.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1288 /* If there are parameters that consist of only an identifier,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1289 * rather than assuming the identifier is a type, as we would
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1290 * for regular function declarations, assume the identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1291 * is the parameter name, and we're building a template with
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1292 * a deduced type.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1293 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1294 TemplateParameters tpl = null;
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 125
diff changeset
1295 foreach (param; tf.parameters)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1296 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1297 if (param.ident is null &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1298 param.type &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1299 param.type.ty == Tident &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1300 (cast(TypeIdentifier)param.type).idents.dim == 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1301 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1303 /* Switch parameter type to parameter identifier,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1304 * parameterize with template type parameter _T
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1305 */
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 125
diff changeset
1306 auto pt = cast(TypeIdentifier)param.type;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1307 param.ident = pt.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1308 Identifier id = Lexer.uniqueId("__T");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1309 param.type = new TypeIdentifier(pt.loc, id);
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1310 auto tp = new TemplateTypeParameter(fd.loc, id, null, null);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1311 if (!tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1312 tpl = new TemplateParameters();
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1313 tpl.push(tp);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1314 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1315 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1317 if (tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1318 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1319 // 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
1320 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
1321 decldefs.push(fd);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
1322 auto tempdecl = new TemplateDeclaration(fd.loc, fd.ident, tpl, null, decldefs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1323 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
1324 tiargs.push(tempdecl);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1325 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1326 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1327 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1328 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1329
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
1330 tiargs.push(ea);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1331 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1332 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1333 if (token.value != TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1334 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1335 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1336 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1337 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1338 check(endtok, "template argument list");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1339 return tiargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1340 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1341
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1342 /*****************************
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1343 * Parse single template argument, to support the syntax:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1344 * foo!arg
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1345 * Input:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1346 * current token is the arg
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1347 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1348 Objects parseTemplateArgument()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1349 {
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1350 //printf("parseTemplateArgument()\n");
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1351 Objects tiargs = new Objects();
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1352 Type ta;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1353 switch (token.value)
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1354 {
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1355 case TOKidentifier:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1356 ta = new TypeIdentifier(loc, token.ident);
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1357 goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1358
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1359 case TOKvoid: ta = Type.tvoid; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1360 case TOKint8: ta = Type.tint8; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1361 case TOKuns8: ta = Type.tuns8; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1362 case TOKint16: ta = Type.tint16; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1363 case TOKuns16: ta = Type.tuns16; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1364 case TOKint32: ta = Type.tint32; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1365 case TOKuns32: ta = Type.tuns32; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1366 case TOKint64: ta = Type.tint64; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1367 case TOKuns64: ta = Type.tuns64; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1368 case TOKfloat32: ta = Type.tfloat32; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1369 case TOKfloat64: ta = Type.tfloat64; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1370 case TOKfloat80: ta = Type.tfloat80; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1371 case TOKimaginary32: ta = Type.timaginary32; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1372 case TOKimaginary64: ta = Type.timaginary64; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1373 case TOKimaginary80: ta = Type.timaginary80; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1374 case TOKcomplex32: ta = Type.tcomplex32; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1375 case TOKcomplex64: ta = Type.tcomplex64; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1376 case TOKcomplex80: ta = Type.tcomplex80; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1377 case TOKbit: ta = Type.tbit; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1378 case TOKbool: ta = Type.tbool; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1379 case TOKchar: ta = Type.tchar; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1380 case TOKwchar: ta = Type.twchar; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1381 case TOKdchar: ta = Type.tdchar; goto LabelX;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1382 LabelX:
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
1383 tiargs.push(ta);
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1384 nextToken();
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1385 break;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1386
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1387 case TOKint32v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1388 case TOKuns32v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1389 case TOKint64v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1390 case TOKuns64v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1391 case TOKfloat32v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1392 case TOKfloat64v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1393 case TOKfloat80v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1394 case TOKimaginary32v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1395 case TOKimaginary64v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1396 case TOKimaginary80v:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1397 case TOKnull:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1398 case TOKtrue:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1399 case TOKfalse:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1400 case TOKcharv:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1401 case TOKwcharv:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1402 case TOKdcharv:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1403 case TOKstring:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1404 case TOKfile:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1405 case TOKline:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1406 {
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1407 // Template argument is an expression
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1408 Expression ea = parsePrimaryExp();
94
3a0b150c9841 Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 84
diff changeset
1409 tiargs.push(ea);
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1410 break;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1411 }
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1412
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1413 default:
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1414 error("template argument expected following !");
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1415 break;
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1416 }
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1417
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1418 if (token.value == TOKnot)
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1419 error("multiple ! arguments are not allowed");
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1420 return tiargs;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1421 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1422
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1423 /**********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1424 * Parse a static assertion.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1425 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1426 StaticAssert parseStaticAssert()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1427 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1428 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1429 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1430 Expression msg = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1431
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1432 //printf("parseStaticAssert()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1433 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1434 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1435 exp = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1436 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1437 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1438 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1439 msg = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1440 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1441
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1442 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1443 check(TOK.TOKsemicolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1444
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1445 return new StaticAssert(loc, exp, msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1446 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1447
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1448 TypeQualified parseTypeof()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1449 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1450 TypeQualified t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1451 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1452
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1453 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1454 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1455 if (token.value == TOK.TOKreturn) // typeof(return)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1456 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1457 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1458 t = new TypeReturn(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1459 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1460 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1461 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1462 Expression exp = parseExpression(); // typeof(expression)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1463 t = new TypeTypeof(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1464 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1465 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1466 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1467 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1468
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1469 /***********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1470 * Parse extern (linkage)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1471 * The parser is on the 'extern' token.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1472 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1473 LINK parseLinkage()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1474 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1475 LINK link = LINK.LINKdefault;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1476 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1477 assert(token.value == TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1478 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1479 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1480 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1481 Identifier id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1482
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1483 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1484 if (id == Id.Windows)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1485 link = LINK.LINKwindows;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1486 else if (id == Id.Pascal)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1487 link = LINK.LINKpascal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1488 else if (id == Id.D)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1489 link = LINK.LINKd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1490 else if (id == Id.C)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1491 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1492 link = LINK.LINKc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1493 if (token.value == TOK.TOKplusplus)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1494 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1495 link = LINK.LINKcpp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1496 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1497 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1498 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1499 else if (id == Id.System)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1500 {
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 110
diff changeset
1501 version (Windows)
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 110
diff changeset
1502 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1503 link = LINK.LINKwindows;
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 110
diff changeset
1504 }
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 110
diff changeset
1505 else
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 110
diff changeset
1506 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1507 link = LINK.LINKc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1508 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1509 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1510 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1511 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1512 error("valid linkage identifiers are D, C, C++, Pascal, Windows, System");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1513 link = LINK.LINKd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1514 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1515 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1516 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1517 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1518 link = LINK.LINKd; // default
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1519 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1520 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1521
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1522 return link;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1523 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1524
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1525
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1526 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1527 * Parse a debug conditional
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1528 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1529 Condition parseDebugCondition()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1530 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1531 Condition c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1532
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1533 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1534 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1535 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1536 uint level = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1537 Identifier id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1538
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1539 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1540 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1541 else if (token.value == TOK.TOKint32v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1542 level = cast(uint)token.uns64value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1543 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1544 error("identifier or integer expected, not %s", token.toChars());
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 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1548
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1549 c = new DebugCondition(mod, level, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1550 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1551 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1552 c = new DebugCondition(mod, 1, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1553
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1554 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1555 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1556
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1557 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1558 * Parse a version conditional
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1559 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1560 Condition parseVersionCondition()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1561 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1562 Condition c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1563 uint level = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1564 Identifier id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1565
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1566 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1567 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1568 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1569 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1570 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1571 else if (token.value == TOK.TOKint32v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1572 level = cast(uint)token.uns64value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1573 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1574 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1575 /* Allow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1576 * version (unittest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1577 * even though unittest is a keyword
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1578 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1579 if (token.value == TOK.TOKunittest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1580 id = Lexer.idPool(Token.toChars(TOK.TOKunittest));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1581 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1582 error("identifier or integer expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1583 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1584 error("identifier or integer expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1585 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1586 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1587 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1588 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1589 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1590 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1591 error("(condition) expected following version");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1592
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1593 c = new VersionCondition(mod, level, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1594
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1595 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1596 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1597
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1598 /***********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1599 * static if (expression)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1600 * body
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1601 * else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1602 * body
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1603 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1604 Condition parseStaticIfCondition()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1605 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1606 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1607 Condition condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1608 Array aif;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1609 Array aelse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1610 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1611
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1612 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1613 if (token.value == TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1614 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1615 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1616 exp = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1617 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1618 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1619 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1620 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1621 error("(expression) expected following static if");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1622 exp = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1623 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1624 condition = new StaticIfCondition(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1625 return condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1626 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1627
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1628 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1629 * Parse a constructor definition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1630 * this(parameters) { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1631 * or postblit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1632 * this(this) { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1633 * or constructor template:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1634 * this(templateparameters)(parameters) { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1635 * Current token is 'this'.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1636 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1637
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1638 Dsymbol parseCtor()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1639 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1640 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1641
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1642 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1643 if (token.value == TOK.TOKlparen && peek(&token).value == TOK.TOKthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1644 { // this(this) { ... }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1645 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1646 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1647 check(TOK.TOKrparen);
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
1648 auto f = new PostBlitDeclaration(loc, Loc(0));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1649 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1650 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1651 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1652
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1653 /* Look ahead to see if:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1654 * this(...)(...)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1655 * which is a constructor template
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1656 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1657 TemplateParameters tpl = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1658 if (token.value == TOK.TOKlparen && peekPastParen(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1659 { tpl = parseTemplateParameterList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1660
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1661 int varargs;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
1662 auto arguments = parseParameters(&varargs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1663
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1664 Expression constraint = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1665 if (tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1666 constraint = parseConstraint();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1667
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1668 CtorDeclaration f = new CtorDeclaration(loc, Loc(0), arguments, varargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1669 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1670
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1671 // 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
1672 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
1673 decldefs.push(f);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
1674 auto tempdecl = new TemplateDeclaration(loc, f.ident, tpl, constraint, decldefs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1675 return tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1676 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1677
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1678 /* Just a regular constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1679 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1680 int varargs;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
1681 auto arguments = parseParameters(&varargs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1682 CtorDeclaration f = new CtorDeclaration(loc, Loc(0), arguments, varargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1683 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1684 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1685 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1686
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1687 PostBlitDeclaration parsePostBlit()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1688 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1689 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1690 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1691
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1692 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1693 * Parse a destructor definition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1694 * ~this() { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1695 * Current token is '~'.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1696 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1697 DtorDeclaration parseDtor()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1698 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1699 DtorDeclaration f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1700 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1701
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1702 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1703 check(TOKthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1704 check(TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1705 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1706
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1707 f = new DtorDeclaration(loc, Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1708 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1709 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1710 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1711
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1712 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1713 * Parse a static constructor definition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1714 * static this() { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1715 * Current token is 'this'.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1716 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1717 StaticCtorDeclaration parseStaticCtor()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1718 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1719 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1720
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1721 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1722 check(TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1723 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1724
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1725 StaticCtorDeclaration f = new StaticCtorDeclaration(loc, Loc(0));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1726 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1727 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1728 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1729
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1730 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1731 * Parse a static destructor definition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1732 * static ~this() { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1733 * Current token is '~'.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1734 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1735 StaticDtorDeclaration parseStaticDtor()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1736 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1737 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1738
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1739 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1740 check(TOKthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1741 check(TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1742 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1743
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1744 StaticDtorDeclaration f = new StaticDtorDeclaration(loc, Loc(0));
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1745 parseContracts(f);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1746 return f;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1747
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1748 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1749
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1750 /*****************************************
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1751 * Parse a shared static constructor definition:
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1752 * shared static this() { body }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1753 * Current token is 'shared'.
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1754 */
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1755 SharedStaticCtorDeclaration parseSharedStaticCtor()
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1756 {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1757 Loc loc = this.loc;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1758
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1759 nextToken();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1760 nextToken();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1761 nextToken();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1762 check(TOKlparen);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1763 check(TOKrparen);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1764
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1765 SharedStaticCtorDeclaration f = new SharedStaticCtorDeclaration(loc, Loc(0));
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1766 parseContracts(f);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1767 return f;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1768 }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1769
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1770 /*****************************************
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1771 * Parse a shared static destructor definition:
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1772 * shared static ~this() { body }
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1773 * Current token is 'shared'.
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1774 */
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1775 SharedStaticDtorDeclaration parseSharedStaticDtor()
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1776 {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1777 Loc loc = this.loc;
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1778
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1779 nextToken();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1780 nextToken();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1781 nextToken();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1782 check(TOKthis);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1783 check(TOKlparen);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1784 check(TOKrparen);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1785
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
1786 SharedStaticDtorDeclaration f = new SharedStaticDtorDeclaration(loc, Loc(0));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1787 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1788 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1789 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1790
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1791 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1792 * Parse an invariant definition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1793 * invariant() { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1794 * Current token is 'invariant'.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1795 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1796 InvariantDeclaration parseInvariant()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1797 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1798 InvariantDeclaration f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1799 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1800
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1801 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1802 if (token.value == TOKlparen) // optional ()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1803 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1804 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1805 check(TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1806 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1807
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1808 f = new InvariantDeclaration(loc, Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1809 f.fbody = parseStatement(ParseStatementFlags.PScurly);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1810 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1811 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1812
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1813 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1814 * Parse a unittest definition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1815 * unittest { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1816 * Current token is 'unittest'.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1817 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1818 UnitTestDeclaration parseUnitTest()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1819 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1820 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1821
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1822 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1823
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1824 UnitTestDeclaration f = new UnitTestDeclaration(loc, this.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1825 f.fbody = parseStatement(ParseStatementFlags.PScurly);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1826
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1827 return f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1828 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1829
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1830 /*****************************************
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1831 * Parse a new definition:
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1832 * new(arguments) { body }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1833 * Current token is 'new'.
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1834 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1835 NewDeclaration parseNew()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1836 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1837 NewDeclaration f;
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 179
diff changeset
1838 auto arguments = new Parameters();
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1839 int varargs;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1840 Loc loc = this.loc;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1841
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1842 nextToken();
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1843 arguments = parseParameters(&varargs);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1844 f = new NewDeclaration(loc, Loc(0), arguments, varargs);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1845 parseContracts(f);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1846 return f;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1847 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1848
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1849 /*****************************************
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1850 * Parse a delete definition:
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1851 * delete(arguments) { body }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1852 * Current token is 'delete'.
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1853 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1854 DeleteDeclaration parseDelete()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1855 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1856 DeleteDeclaration f;
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 179
diff changeset
1857 Parameters arguments;
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1858 int varargs;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1859 Loc loc = this.loc;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1860
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1861 nextToken();
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1862 arguments = parseParameters(&varargs);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1863 if (varargs)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1864 error("... not allowed in delete function parameter list");
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1865 f = new DeleteDeclaration(loc, Loc(0), arguments);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1866 parseContracts(f);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
1867 return f;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1868 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1869
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
1870 Parameters parseParameters(int* pvarargs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1871 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
1872 auto arguments = new Parameters();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1873 int varargs = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1874 int hasdefault = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1875
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1876 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1877 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1878 { Type *tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1879 Identifier ai = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1880 Type at;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
1881 Parameter a;
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1882 StorageClass storageClass = STC.STCundefined;
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1883 StorageClass stc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1884 Expression ae;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1885
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1886 for ( ;1; nextToken())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1887 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1888 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1889 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1890 case TOK.TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1891 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1892
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1893 case TOK.TOKdotdotdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1894 varargs = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1895 nextToken();
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 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1899 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1900 goto Ldefault;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1901 stc = STC.STCconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1902 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1903
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1904 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1905 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1906 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1907 goto Ldefault;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1908 stc = STC.STCimmutable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1909 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1910
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1911 case TOK.TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1912 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1913 goto Ldefault;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1914 stc = STC.STCshared;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1915 goto L2;
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
1916
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
1917 case TOKwild:
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
1918 if (peek(&token).value == TOK.TOKlparen)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
1919 goto Ldefault;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
1920 stc = STCwild;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
1921 goto L2;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1922
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1923 case TOK.TOKin: stc = STC.STCin; goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1924 case TOK.TOKout: stc = STC.STCout; goto L2;
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
1925 version(D1INOUT) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1926 case TOK.TOKinout:
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
1927 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1928 case TOK.TOKref: stc = STC.STCref; goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1929 case TOK.TOKlazy: stc = STC.STClazy; goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1930 case TOK.TOKscope: stc = STC.STCscope; goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1931 case TOK.TOKfinal: stc = STC.STCfinal; goto L2;
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
1932 case TOK.TOKauto: stc = STCauto; goto L2;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1933 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1934 if (storageClass & stc ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1935 (storageClass & STC.STCin && stc & (STC.STCconst | STC.STCscope)) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1936 (stc & STC.STCin && storageClass & (STC.STCconst | STC.STCscope))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1937 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1938 error("redundant storage class %s", Token.toChars(token.value));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1939 storageClass |= stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1940 composeStorageClass(storageClass);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1941 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1942
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1943 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1944 case TOK.TOKstatic: stc = STC.STCstatic; goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1945 case TOK.TOKauto: storageClass = STC.STCauto; goto L4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1946 case TOK.TOKalias: storageClass = STC.STCalias; goto L4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1947 L4:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1948 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1949 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1950 { ai = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1951 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1952 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1953 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1954 ai = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1955 at = null; // no type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1956 ae = null; // no default argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1957 if (token.value == TOK.TOKassign) // = defaultArg
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1958 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1959 ae = parseDefaultInitExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1960 hasdefault = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1961 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1962 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1963 { if (hasdefault)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1964 error("default argument expected for alias %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1965 ai ? ai.toChars() : "");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1966 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1967 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1968 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1969
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1970 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1971 Ldefault:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1972 stc = (storageClass & (STC.STCin | STC.STCout | STC.STCref | STC.STClazy));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1973 if (stc & (stc - 1)) // if stc is not a power of 2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1974 error("incompatible parameter storage classes");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1975 if ((storageClass & (STC.STCconst | STC.STCout)) == (STC.STCconst | STC.STCout))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1976 error("out cannot be const");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1977 if ((storageClass & (STC.STCimmutable | STC.STCout)) == (STC.STCimmutable | STC.STCout))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1978 error("out cannot be immutable");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1979 if ((storageClass & STC.STCscope) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1980 (storageClass & (STC.STCref | STC.STCout)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1981 error("scope cannot be ref or out");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1982 at = parseType(&ai);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1983 ae = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1984 if (token.value == TOK.TOKassign) // = defaultArg
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1985 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1986 ae = parseDefaultInitExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1987 hasdefault = 1;
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 { if (hasdefault)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1991 error("default argument expected for %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1992 ai ? ai.toChars() : at.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1993 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1994 if (token.value == TOK.TOKdotdotdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1995 { /* This is:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1996 * at ai ...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1997 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1998
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1999 if (storageClass & (STC.STCout | STC.STCref))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2000 error("variadic argument cannot be out or ref");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2001 varargs = 2;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2002 a = new Parameter(storageClass, at, ai, ae);
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 125
diff changeset
2003 arguments.push(a);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2004 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2005 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2006 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2007 L3:
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2008 a = new Parameter(storageClass, at, ai, ae);
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 125
diff changeset
2009 arguments.push(a);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2010 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2011 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2012 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2013 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2014 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2015 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2016 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2017 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2018 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2019
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2020 L1: ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2021 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2022 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2023 *pvarargs = varargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2024 return arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2025 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2026
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2027 EnumDeclaration parseEnum()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2028 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2029 EnumDeclaration e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2030 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2031 Type memtype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2032 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2033
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2034 //printf("Parser.parseEnum()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2035 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2036 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2037 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2038 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2039 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2040 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2041 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2042 id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2043
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2044 if (token.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2045 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2046 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2047 memtype = parseBasicType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2048 memtype = parseDeclarator(memtype, null, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2049 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2050 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2051 memtype = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2052
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2053 e = new EnumDeclaration(loc, id, memtype);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2054 if (token.value == TOK.TOKsemicolon && id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2055 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2056 else if (token.value == TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2057 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2058 //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
2059 e.members = new Dsymbols();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2060 nextToken();
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2061 string comment = token.blockComment;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2062 while (token.value != TOK.TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2063 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2064 /* Can take the following forms:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2065 * 1. ident
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2066 * 2. ident = value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2067 * 3. type ident = value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2068 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2069
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2070 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2071
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2072 Type type = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2073 Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2074 Token* tp = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2075 if (token.value == TOK.TOKidentifier &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2076 (tp.value == TOK.TOKassign || tp.value == TOK.TOKcomma || tp.value == TOK.TOKrcurly))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2077 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2078 ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2079 type = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2080 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2081 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2082 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2083 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2084 type = parseType(&ident, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2085 if (id || memtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2086 error("type only allowed if anonymous enum and no enum type");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2087 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2088
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2089 Expression value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2090 if (token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2091 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2092 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2093 value = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2094 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2095 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2096 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2097 value = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2098 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2099 error("if type, there must be an initializer");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2101
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2102 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
2103 e.members.push(em);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2104
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2105 if (token.value == TOK.TOKrcurly) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2106 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2107 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2108 addComment(em, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2109 comment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2110 check(TOK.TOKcomma);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2112 addComment(em, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2113 comment = token.blockComment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2114 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2115 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2117 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2118 error("enum declaration is invalid");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2119
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2120 //printf("-parseEnum() %s\n", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2121 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2123
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2124 Dsymbol parseAggregate()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2125 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2126 AggregateDeclaration a = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2127 int anon = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2128 TOK tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2129 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2130 TemplateParameters tpl = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2131 Expression constraint = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2133 //printf("Parser.parseAggregate()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2134 tok = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2135 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2136 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2137 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2138 id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2139 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2140 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2141 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2142 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2143 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2145 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2146 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2147 // Class template declaration.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2149 // Gather template parameter list
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2150 tpl = parseTemplateParameterList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2151 constraint = parseConstraint();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2152 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2153 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2154
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2155 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2156 switch (tok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2157 { case TOK.TOKclass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2158 case TOK.TOKinterface:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2159 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2160 if (!id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2161 error("anonymous classes not allowed");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2162
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2163 // Collect base class(es)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2164 BaseClasses baseclasses = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2165 if (token.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2166 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2167 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2168 baseclasses = parseBaseClasses();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2169
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2170 if (token.value != TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2171 error("members expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2172 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2173
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2174 if (tok == TOK.TOKclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2175 a = new ClassDeclaration(loc, id, baseclasses);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2176 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2177 a = new InterfaceDeclaration(loc, id, baseclasses);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2178 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2180
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2181 case TOK.TOKstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2182 if (id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2183 a = new StructDeclaration(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2184 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2185 anon = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2186 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2187
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2188 case TOK.TOKunion:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2189 if (id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2190 a = new UnionDeclaration(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2191 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2192 anon = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2193 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2194
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2195 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2196 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2197 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2198 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2199 if (a && token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2200 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2201 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2202 else if (token.value == TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2203 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2204 //printf("aggregate definition\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2205 nextToken();
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2206 auto decl = parseDeclDefs(0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2207 if (token.value != TOK.TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2208 error("} expected following member declarations in aggregate");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2209 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2210 if (anon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2211 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2212 /* Anonymous structs/unions are more like attributes.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2213 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2214 return new AnonDeclaration(loc, anon - 1, decl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2216 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2217 a.members = decl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2218 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2219 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2220 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2221 error("{ } expected following aggregate declaration");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2222 a = new StructDeclaration(loc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2223 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2224
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2225 if (tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2226 { // Wrap a template around the aggregate declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2227
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2228 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
2229 decldefs.push(a);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2230 auto tempdecl = new TemplateDeclaration(loc, id, tpl, constraint, decldefs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2231 return tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2232 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2233
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2234 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2235 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2236
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2237 BaseClasses parseBaseClasses()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2238 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2239 BaseClasses baseclasses = new BaseClasses();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2240
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2241 for (; 1; nextToken())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2242 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2243 PROT protection = PROT.PROTpublic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2244 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2245 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2246 case TOK.TOKprivate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2247 protection = PROT.PROTprivate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2248 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2249 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2250 case TOK.TOKpackage:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2251 protection = PROT.PROTpackage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2252 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2253 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2254 case TOK.TOKprotected:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2255 protection = PROT.PROTprotected;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2256 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2257 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2258 case TOK.TOKpublic:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2259 protection = PROT.PROTpublic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2260 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2261 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2262 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2263 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2264 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2265 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2266 {
125
767a01c2a272 BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
2267 auto b = new BaseClass(parseBasicType(), protection);
767a01c2a272 BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 123
diff changeset
2268 baseclasses.push(b);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2269 if (token.value != TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2270 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2271 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2272 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2273 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2274 error("base classes expected instead of %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2275 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2277 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2278 return baseclasses;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2279 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2280
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2281 Import parseImport(Dsymbols decldefs, int isstatic)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2282 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2283 Import s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2284 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2285 Identifier aliasid = null;
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
2286 Identifiers a;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2287 Loc loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2288
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2289 //printf("Parser.parseImport()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2290 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2291 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2292 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2293 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2294 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2295 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2296 error("Identifier expected following import");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2297 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2298 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2299
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2300 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2301 a = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2302 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2303 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2304 if (!aliasid && token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2305 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2306 aliasid = id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2307 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2308 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2309 while (token.value == TOK.TOKdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2310 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2311 if (!a)
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
2312 a = new Identifiers();
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
2313 a.push(id);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2314 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2315 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2316 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2317 error("identifier expected following package");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2318 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2319 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2320 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2321 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2322 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2323
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2324 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
2325 decldefs.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2326
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2327 /* Look for
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2328 * : alias=name, alias=name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2329 * syntax.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2330 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2331 if (token.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2332 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2333 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2334 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2335 Identifier name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2336
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2337 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2338 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2339 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2340 error("Identifier expected following :");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2341 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2342 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2343 Identifier alias_ = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2344 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2345 if (token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2346 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2347 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2348 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2349 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2350 error("Identifier expected following %s=", alias_.toChars());
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 name = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2354 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2355 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2356 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2357 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2358 name = alias_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2359 alias_ = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2360 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2361 s.addAlias(name, alias_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2362 } while (token.value == TOK.TOKcomma);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2363
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2364 break; // no comma-separated imports of this form
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2365 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2366
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2367 aliasid = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2368
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2369 } while (token.value == TOK.TOKcomma);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2370
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2371 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2372 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2373 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2374 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2375 error("';' expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2376 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2377 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2378
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2379 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2380 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2381
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2382 Type parseType(Identifier* pident = null, TemplateParameters* tpl = null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2383 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2384 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2385
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2386 /* Take care of the storage class prefixes that
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2387 * serve as type attributes:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2388 * const shared, shared const, const, invariant, shared
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2389 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2390 if (token.value == TOK.TOKconst && peekNext() == TOK.TOKshared && peekNext2() != TOK.TOKlparen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2391 token.value == TOK.TOKshared && peekNext() == TOK.TOKconst && peekNext2() != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2392 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2393 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2394 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2395 /* shared const type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2396 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2397 t = parseType(pident, tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2398 t = t.makeSharedConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2399 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2400 }
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2401 else if (token.value == TOKwild && peekNext() == TOKshared && peekNext2() != TOKlparen ||
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2402 token.value == TOKshared && peekNext() == TOKwild && peekNext2() != TOKlparen)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2403 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2404 nextToken();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2405 nextToken();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2406 /* shared wild type
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2407 */
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2408 t = parseType(pident, tpl);
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2409 t = t.makeSharedWild();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2410 return t;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2411 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2412 else if (token.value == TOK.TOKconst && peekNext() != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2413 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2414 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2415 /* const type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2416 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2417 t = parseType(pident, tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2418 t = t.makeConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2419 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2420 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2421 else if ((token.value == TOK.TOKinvariant || token.value == TOK.TOKimmutable) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2422 peekNext() != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2423 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2424 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2425 /* invariant type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2426 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2427 t = parseType(pident, tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2428 t = t.makeInvariant();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2429 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2430 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2431 else if (token.value == TOK.TOKshared && peekNext() != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2432 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2433 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2434 /* shared type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2435 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2436 t = parseType(pident, tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2437 t = t.makeShared();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2438 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2439 }
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2440 else if (token.value == TOKwild && peekNext() != TOKlparen)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2441 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2442 nextToken();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2443 /* wild type
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2444 */
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2445 t = parseType(pident, tpl);
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2446 t = t.makeWild();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2447 return t;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2448 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2449 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2450 t = parseBasicType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2451 t = parseDeclarator(t, pident, tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2452 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2453 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2454
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2455 Type parseBasicType()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2456 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2457 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2458 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2459 TypeQualified tid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2460
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2461 //printf("parseBasicType()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2462 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2463 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2464 case TOK.TOKvoid: t = Type.tvoid; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2465 case TOK.TOKint8: t = Type.tint8; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2466 case TOK.TOKuns8: t = Type.tuns8; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2467 case TOK.TOKint16: t = Type.tint16; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2468 case TOK.TOKuns16: t = Type.tuns16; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2469 case TOK.TOKint32: t = Type.tint32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2470 case TOK.TOKuns32: t = Type.tuns32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2471 case TOK.TOKint64: t = Type.tint64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2472 case TOK.TOKuns64: t = Type.tuns64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2473 case TOK.TOKfloat32: t = Type.tfloat32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2474 case TOK.TOKfloat64: t = Type.tfloat64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2475 case TOK.TOKfloat80: t = Type.tfloat80; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2476 case TOK.TOKimaginary32: t = Type.timaginary32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2477 case TOK.TOKimaginary64: t = Type.timaginary64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2478 case TOK.TOKimaginary80: t = Type.timaginary80; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2479 case TOK.TOKcomplex32: t = Type.tcomplex32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2480 case TOK.TOKcomplex64: t = Type.tcomplex64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2481 case TOK.TOKcomplex80: t = Type.tcomplex80; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2482 case TOK.TOKbit: t = Type.tbit; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2483 case TOK.TOKbool: t = Type.tbool; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2484 case TOK.TOKchar: t = Type.tchar; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2485 case TOK.TOKwchar: t = Type.twchar; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2486 case TOK.TOKdchar: t = Type.tdchar; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2487 LabelX:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2488 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2489 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2490
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2491 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2492 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2493 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2494 if (token.value == TOK.TOKnot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2495 { // ident!(template_arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2496 TemplateInstance tempinst = new TemplateInstance(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2497 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2498 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2499 // ident!(template_arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2500 tempinst.tiargs = parseTemplateArgumentList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2501 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2502 // ident!template_argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2503 tempinst.tiargs = parseTemplateArgument();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2504 tid = new TypeInstance(loc, tempinst);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2505 goto Lident2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2506 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2507 Lident:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2508 tid = new TypeIdentifier(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2509 Lident2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2510 while (token.value == TOK.TOKdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2511 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2512 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2513 { error("identifier expected following '.' instead of '%s'", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2514 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2515 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2516 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2517 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2518 if (token.value == TOK.TOKnot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2519 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2520 TemplateInstance tempinst = new TemplateInstance(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2521 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2522 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2523 // ident!(template_arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2524 tempinst.tiargs = parseTemplateArgumentList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2525 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2526 // ident!template_argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2527 tempinst.tiargs = parseTemplateArgument();
56
51605de93870 TupleExp.optimize
korDen
parents: 34
diff changeset
2528 tid.addIdent(tempinst);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2529 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2530 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2531 tid.addIdent(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2532 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2533 t = tid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2534 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2535
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2536 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2537 // Leading . as in .foo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2538 id = Id.empty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2539 goto Lident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2540
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2541 case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2542 // typeof(expression)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2543 tid = parseTypeof();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2544 goto Lident2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2545
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2546 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2547 // const(type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2548 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2549 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2550 t = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2551 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2552 if (t.isShared())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2553 t = t.makeSharedConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2554 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2555 t = t.makeConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2556 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2557
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2558 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2559 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2560 // invariant(type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2561 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2562 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2563 t = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2564 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2565 t = t.makeInvariant();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2566 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2567
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2568 case TOK.TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2569 // shared(type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2570 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2571 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2572 t = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2573 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2574 if (t.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2575 t = t.makeSharedConst();
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2576 else if (t.isWild())
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2577 t = t.makeSharedWild();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2578 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2579 t = t.makeShared();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2580 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2581
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2582 case TOKwild:
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2583 // wild(type)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2584 nextToken();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2585 check(TOK.TOKlparen);
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2586 t = parseType();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2587 check(TOK.TOKrparen);
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2588 if (t.isShared())
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2589 t = t.makeSharedWild();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2590 else
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2591 t = t.makeWild();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2592 break;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2593
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2594 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2595 error("basic type expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2596 t = Type.tint32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2597 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2598 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2599 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2600 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2601
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2602 Type parseBasicType2(Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2603 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2604 //writef("parseBasicType2()\n");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2605 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2606 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2607 switch (token.value)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2608 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2609 case TOK.TOKmul:
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2610 t = new TypePointer(t);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2611 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2612 continue;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2613
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2614 case TOK.TOKlbracket:
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2615 // Handle []. Make sure things like
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2616 // int[3][1] a;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2617 // is (array[1] of array[3] of int)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2618 nextToken();
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2619 if (token.value == TOK.TOKrbracket)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2620 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2621 t = new TypeDArray(t); // []
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2622 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2623 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2624 else if (token.value == TOKnew && peekNext() == TOKrbracket)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2625 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2626 t = new TypeNewArray(t); // [new]
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2627 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2628 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2629 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2630 else if (isDeclaration(&token, 0, TOK.TOKrbracket, null))
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2631 { // It's an associative array declaration
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2632
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2633 //printf("it's an associative array\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2634 Type index = parseType(); // [ type ]
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2635 t = new TypeAArray(t, index);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2636 check(TOK.TOKrbracket);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2637 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2638 else
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2639 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2640 //printf("it's type[expression]\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2641 inBrackets++;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2642 Expression e = parseAssignExp(); // [ expression ]
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2643 if (token.value == TOK.TOKslice)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2644 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2645 nextToken();
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2646 Expression e2 = parseAssignExp(); // [ exp .. exp ]
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2647 t = new TypeSlice(t, e, e2);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2648 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2649 else
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2650 t = new TypeSArray(t,e);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2651 inBrackets--;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2652 check(TOK.TOKrbracket);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2653 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2654 continue;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2655
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2656 case TOK.TOKdelegate:
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2657 case TOK.TOKfunction:
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2658 { // Handle delegate declaration:
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2659 // t delegate(parameter list) nothrow pure
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2660 // t function(parameter list) nothrow pure
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2661 Parameters arguments;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2662 int varargs;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2663 bool ispure = false;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2664 bool isnothrow = false;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2665 bool isproperty = false;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2666 TOK save = token.value;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2667 TRUST trust = TRUSTdefault;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2668
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2669 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2670 arguments = parseParameters(&varargs);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2671 while (1)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2672 { // Postfixes
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2673 if (token.value == TOK.TOKpure)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2674 ispure = true;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2675 else if (token.value == TOK.TOKnothrow)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2676 isnothrow = true;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2677 else if (token.value == TOKat)
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
2678 { StorageClass stc = parseAttribute();
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2679 switch (cast(uint)(stc >> 32))
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2680 { case STCproperty >> 32:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2681 isproperty = true;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2682 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2683 case STCsafe >> 32:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2684 trust = TRUSTsafe;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2685 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2686 case STCsystem >> 32:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2687 trust = TRUSTsystem;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2688 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2689 case STCtrusted >> 32:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2690 trust = TRUSTtrusted;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2691 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2692 case 0:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2693 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2694 default:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2695 assert(0);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2696 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2697 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2698 else
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2699 break;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2700 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2701 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2702 TypeFunction tf = new TypeFunction(arguments, t, varargs, linkage);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2703 tf.ispure = ispure;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2704 tf.isnothrow = isnothrow;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2705 tf.isproperty = isproperty;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2706 tf.trust = trust;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2707 if (save == TOK.TOKdelegate)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2708 t = new TypeDelegate(tf);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2709 else
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2710 t = new TypePointer(tf); // pointer to function
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2711 continue;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2712 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2713
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2714 default:
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2715 return t;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2716 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2717 assert(0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2718 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2719 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2720 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2721 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2722
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2723 Type parseDeclarator(Type t, Identifier* pident, TemplateParameters* tpl = null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2724 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2725 Type ts;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2726
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2727 //printf("parseDeclarator(tpl = %p)\n", tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2728 t = parseBasicType2(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2729
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2730 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2731 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2732
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2733 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2734 if (pident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2735 *pident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2736 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2737 error("unexpected identifer '%s' in declarator", token.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2738 ts = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2739 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2740 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2741
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2742 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2743 /* Parse things with parentheses around the identifier, like:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2744 * int (*ident[3])[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2745 * although the D style would be:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2746 * int[]*[3] ident
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2747 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2748 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2749 ts = parseDeclarator(t, pident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2750 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2751 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2752
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2753 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2754 ts = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2755 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2756 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2757
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2758 // parse DeclaratorSuffixes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2759 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2760 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2761 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2762 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2763 version (CARRAYDECL) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2764 /* Support C style array syntax:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2765 * int ident[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2766 * as opposed to D-style:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2767 * int[] ident
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2768 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2769 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2770 { // This is the old C-style post [] syntax.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2771 TypeNext ta;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2772 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2773 if (token.value == TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2774 { // It's a dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2775 ta = new TypeDArray(t); // []
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2776 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2777 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2778 else if (token.value == TOKnew && peekNext() == TOKrbracket)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2779 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2780 t = new TypeNewArray(t); // [new]
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2781 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2782 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2783 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2784 else if (isDeclaration(&token, 0, TOK.TOKrbracket, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2785 { // It's an associative array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2786
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2787 //printf("it's an associative array\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2788 Type index = parseType(); // [ type ]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2789 check(TOK.TOKrbracket);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2790 ta = new TypeAArray(t, index);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2791 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2792 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2793 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2794 //printf("It's a static array\n");
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2795 Expression e = parseAssignExp(); // [ expression ]
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2796 ta = new TypeSArray(t, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2797 check(TOK.TOKrbracket);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2798 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2799
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2800 /* Insert ta into
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2801 * ts . ... . t
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2802 * so that
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2803 * ts . ... . ta . t
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2804 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2805 Type* pt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2806 for (pt = &ts; *pt !is t; pt = &(cast(TypeNext)*pt).next) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2807 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2808 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2809 *pt = ta;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2810 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2811 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2812 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2813 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2814 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2815 if (tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2816 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2817 /* Look ahead to see if this is (...)(...),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2818 * i.e. a function template declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2819 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2820 if (peekPastParen(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2821 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2822 //printf("function template declaration\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2823
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2824 // Gather template parameter list
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2825 *tpl = parseTemplateParameterList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2826 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2827 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2828
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2829 int varargs;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2830 auto arguments = parseParameters(&varargs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2831 Type tf = new TypeFunction(arguments, t, varargs, linkage);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2832
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2833 /* Parse const/invariant/nothrow/pure postfix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2834 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2835 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2836 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2837 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2838 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2839 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2840 if (tf.isShared())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2841 tf = tf.makeSharedConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2842 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2843 tf = tf.makeConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2844 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2845 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2846
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2847 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2848 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2849 tf = tf.makeInvariant();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2850 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2851 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2852
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2853 case TOK.TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2854 if (tf.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2855 tf = tf.makeSharedConst();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2856 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2857 tf = tf.makeShared();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2858 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2859 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2860
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2861 case TOKwild:
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2862 if (tf.isShared())
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2863 tf = tf.makeSharedWild();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2864 else
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2865 tf = tf.makeWild();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2866 nextToken();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2867 continue;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
2868
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2869 case TOK.TOKnothrow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2870 (cast(TypeFunction)tf).isnothrow = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2871 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2872 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2873
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2874 case TOK.TOKpure:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2875 (cast(TypeFunction)tf).ispure = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2876 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2877 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2878
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2879 case TOK.TOKat:
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2880 {
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
2881 StorageClass stc = parseAttribute();
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2882 auto tfunc = cast(TypeFunction)tf;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2883 switch (cast(uint)(stc >> 32))
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2884 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2885 case STCproperty >> 32:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2886 tfunc.isproperty = 1;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2887 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2888 case STCsafe >> 32:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2889 tfunc.trust = TRUSTsafe;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2890 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2891 case STCsystem >> 32:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2892 tfunc.trust = TRUSTsystem;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2893 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2894 case STCtrusted >> 32:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2895 tfunc.trust = TRUSTtrusted;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2896 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2897 case 0:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2898 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2899 default:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2900 assert(0);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2901 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2902 nextToken();
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2903 continue;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
2904 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2905 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2906 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2907 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2908 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2909 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2910
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2911 /* Insert tf into
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2912 * ts . ... . t
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2913 * so that
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2914 * ts . ... . tf . t
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2915 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2916 Type* pt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2917 for (pt = &ts; *pt !is t; pt = &(cast(TypeNext)*pt).next) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2918 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2919 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2920 *pt = tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2921 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2922 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2923
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2924 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2925 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2926 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2927 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2928 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2929
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2930 return ts;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2931 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2932
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
2933 Dsymbols parseDeclarations(StorageClass storage_class)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2934 {
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
2935 StorageClass stc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2936 Type ts;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2937 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2938 Type tfirst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2939 Identifier ident;
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2940 Dsymbols a;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2941 TOK tok = TOK.TOKreserved;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
2942 string comment = token.blockComment;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2943 LINK link = linkage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2944
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2945 //printf("parseDeclarations() %s\n", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2946 if (storage_class)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2947 { ts = null; // infer type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2948 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2949 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2950
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2951 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2952 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2953 case TOK.TOKalias:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2954 /* Look for:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2955 * alias identifier this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2956 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2957 tok = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2958 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2959 if (token.value == TOK.TOKidentifier && peek(&token).value == TOK.TOKthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2960 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2961 AliasThis s = new AliasThis(this.loc, token.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2962 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2963 check(TOK.TOKthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2964 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
2965 a = new Dsymbols();
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
2966 a.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2967 addComment(s, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2968 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2969 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2970 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2971 case TOK.TOKtypedef:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2972 tok = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2973 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2974 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2975 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2976 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2977 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2978
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2979 storage_class = STC.STCundefined;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2980 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2981 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2982 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2983 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2984 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2985 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2986 break; // const as type constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2987 stc = STC.STCconst; // const as storage class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2988 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2989
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2990 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2991 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2992 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2993 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2994 stc = STC.STCimmutable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2995 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2996
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2997 case TOK.TOKshared:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2998 if (peek(&token).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2999 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3000 stc = STC.STCshared;
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
3001 goto L1;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
3002
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
3003 case TOKwild:
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
3004 if (peek(&token).value == TOK.TOKlparen)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
3005 break;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
3006 stc = STC.STCwild;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3007 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3008
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3009 case TOK.TOKstatic: stc = STC.STCstatic; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3010 case TOK.TOKfinal: stc = STC.STCfinal; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3011 case TOK.TOKauto: stc = STC.STCauto; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3012 case TOK.TOKscope: stc = STC.STCscope; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3013 case TOK.TOKoverride: stc = STC.STCoverride; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3014 case TOK.TOKabstract: stc = STC.STCabstract; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3015 case TOK.TOKsynchronized: stc = STC.STCsynchronized; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3016 case TOK.TOKdeprecated: stc = STC.STCdeprecated; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3017 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3018 case TOK.TOKnothrow: stc = STC.STCnothrow; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3019 case TOK.TOKpure: stc = STC.STCpure; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3020 case TOK.TOKref: stc = STC.STCref; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3021 case TOK.TOKtls: stc = STC.STCtls; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3022 case TOK.TOKgshared: stc = STC.STCgshared; goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3023 case TOK.TOKenum: stc = STC.STCmanifest; goto L1;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3024 case TOK.TOKat: stc = parseAttribute(); goto L1;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3025 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3026 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3027 if (storage_class & stc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3028 error("redundant storage class '%s'", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3029 storage_class = (storage_class | stc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3030 composeStorageClass(storage_class);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3031 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3032 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3033
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3034 case TOK.TOKextern:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3035 if (peek(&token).value != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3036 { stc = STC.STCextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3037 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3038 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3039
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3040 link = parseLinkage();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3041 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3042
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3043 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3044 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3045 }
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3049 /* Look for auto initializers:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3050 * storage_class identifier = initializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3051 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3052 if (storage_class &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3053 token.value == TOK.TOKidentifier &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3054 peek(&token).value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3055 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3056 return parseAutoDeclarations(storage_class, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3057 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3058
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3059 if (token.value == TOK.TOKclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3060 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3061 AggregateDeclaration s = cast(AggregateDeclaration)parseAggregate();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3062 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
3063 a = new Dsymbols();
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3064 a.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3065 addComment(s, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3066 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3067 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3068
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3069 /* Look for return type inference for template functions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3070 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3071 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3072 Token *tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3073 if (storage_class &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3074 token.value == TOK.TOKidentifier &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3075 (tk = peek(&token)).value == TOK.TOKlparen &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3076 skipParens(tk, &tk) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3077 peek(tk).value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3078 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3079 ts = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3080 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3081 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3082 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3083 ts = parseBasicType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3084 ts = parseBasicType2(ts);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3085 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3086 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3087
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3088 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3089 tfirst = null;
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3090 a = new Dsymbols();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3091
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3092 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3093 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3094 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3095 TemplateParameters tpl = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3096
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3097 ident = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3098 t = parseDeclarator(ts, &ident, &tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3099 assert(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3100 if (!tfirst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3101 tfirst = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3102 else if (t != tfirst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3103 error("multiple declarations must have the same type, not %s and %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3104 tfirst.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3105 if (!ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3106 error("no identifier for declarator %s", t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3108 if (tok == TOK.TOKtypedef || tok == TOK.TOKalias)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3109 { Declaration v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3110 Initializer init = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3112 if (token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3114 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3115 init = parseInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3117 if (tok == TOK.TOKtypedef)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3118 v = new TypedefDeclaration(loc, ident, t, init);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3119 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3120 { if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3121 error("alias cannot have initializer");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3122 v = new AliasDeclaration(loc, ident, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3124 v.storage_class = storage_class;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3125 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
3126 a.push(v);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3127 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3128 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3129 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
3130 ax.push(v);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3131 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
3132 a.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3133 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3134 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3135 { case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3136 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3137 addComment(v, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3138 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3139
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3140 case TOK.TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3141 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3142 addComment(v, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3143 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3145 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3146 error("semicolon expected to close %s declaration", Token.toChars(tok));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3147 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3148 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3149 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3150 else if (t.ty == TY.Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3151 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3152 auto tf = cast(TypeFunction)t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3153 Expression constraint = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3154 static if (false) {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3155 if (Parameter.isTPL(tf.parameters))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3156 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3157 if (!tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3158 tpl = new TemplateParameters();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3160 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3161 FuncDeclaration f =
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3162 new FuncDeclaration(loc, Loc(0), ident, storage_class, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3163 addComment(f, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3164 if (tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3165 constraint = parseConstraint();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3166 parseContracts(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3167 addComment(f, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3168 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3169 if (link == linkage)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3170 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3171 s = f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3172 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3173 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3174 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3175 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
3176 ax.push(f);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3177 s = new LinkDeclaration(link, ax);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3178 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3179 /* A template parameter list means it's a function template
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3180 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3181 if (tpl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3182 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3183 // 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
3184 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
3185 decldefs.push(s);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3186 auto tempdecl =
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3187 new TemplateDeclaration(loc, s.ident, tpl, constraint, decldefs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3188 s = tempdecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3189 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3190 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
3191 a.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3192 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3193 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3194 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3195 Initializer init = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3196 if (token.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3197 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3198 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3199 init = parseInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3200 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3201
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3202 VarDeclaration v = new VarDeclaration(loc, t, ident, init);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3203 v.storage_class = storage_class;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3204 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
3205 a.push(v);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3206 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3207 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3208 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
3209 ax.push(v);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3210 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
3211 a.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3212 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3213 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3214 { case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3215 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3216 addComment(v, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3217 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3218
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3219 case TOK.TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3220 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3221 addComment(v, comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3222 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3223
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3224 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3225 error("semicolon expected, not '%s'", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3226 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3227 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3228 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3229 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3230 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3231 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3232 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3233
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3234 void parseContracts(FuncDeclaration f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3235 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3236 LINK linksave = linkage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3237
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3238 // The following is irrelevant, as it is overridden by sc.linkage in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3239 // TypeFunction.semantic
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3240 linkage = LINK.LINKd; // nested functions have D linkage
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3241 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3242 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3243 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3244 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3245 if (f.frequire || f.fensure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3246 error("missing body { ... } after in or out");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3247 f.fbody = parseStatement(ParseStatementFlags.PSsemi);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3248 f.endloc = endloc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3249 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3250
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3251 case TOK.TOKbody:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3252 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3253 f.fbody = parseStatement(ParseStatementFlags.PScurly);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3254 f.endloc = endloc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3255 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3256
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3257 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3258 if (f.frequire || f.fensure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3259 error("missing body { ... } after in or out");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3260 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3261 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3262
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3263 static if (false) { // Do we want this for function declarations, so we can do:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3264 // int x, y, foo(), z;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3265 case TOK.TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3266 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3267 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3269
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3270 static if (false) { // Dumped feature
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3271 case TOK.TOKthrow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3272 if (!f.fthrows)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3273 f.fthrows = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3274 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3275 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3276 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3277 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3278 Type tb = parseBasicType();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3279 f.fthrows.push(tb);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3280 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3281 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3282 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3283 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3284 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3285 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3286 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3287 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3288 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3289
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3290 case TOK.TOKin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3291 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3292 if (f.frequire)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3293 error("redundant 'in' statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3294 f.frequire = parseStatement(ParseStatementFlags.PScurly | ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3295 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3296
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3297 case TOK.TOKout:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3298 // parse: out (identifier) { statement }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3299 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3300 if (token.value != TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3301 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3302 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3303 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3304 error("(identifier) following 'out' expected, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3305 f.outId = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3306 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3307 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3308 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3309 if (f.fensure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3310 error("redundant 'out' statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3311 f.fensure = parseStatement(ParseStatementFlags.PScurly | ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3312 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3313
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3314 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3315 error("semicolon expected following function declaration");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3316 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3317 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3318 linkage = linksave;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3319 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3320
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3321 Statement parseStatement(ParseStatementFlags flags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3322 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3323 Statement s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3324 Token* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3325 Condition condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3326 Statement ifbody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3327 Statement elsebody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3328 bool isfinal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3329 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3330
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3331 //printf("parseStatement()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3332
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3333 if (flags & ParseStatementFlags.PScurly && token.value != TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3334 error("statement expected to be { }, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3335
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3336 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3337 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3338 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3339 /* A leading identifier can be a declaration, label, or expression.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3340 * The easiest case to check first is label:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3341 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3342 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3343 if (t.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3344 { // It's a label
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3345
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3346 Identifier ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3347 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3348 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3349 s = parseStatement(ParseStatementFlags.PSsemi);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3350 s = new LabelStatement(loc, ident, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3351 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3352 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3353 // fallthrough to TOK.TOKdot
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3354 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3355 case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3356 if (isDeclaration(&token, 2, TOK.TOKreserved, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3357 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3358 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3359 goto Lexp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3360 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3361
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3362 case TOK.TOKassert:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3363 case TOK.TOKthis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3364 case TOK.TOKsuper:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3365 case TOK.TOKint32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3366 case TOK.TOKuns32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3367 case TOK.TOKint64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3368 case TOK.TOKuns64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3369 case TOK.TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3370 case TOK.TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3371 case TOK.TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3372 case TOK.TOKimaginary32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3373 case TOK.TOKimaginary64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3374 case TOK.TOKimaginary80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3375 case TOK.TOKcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3376 case TOK.TOKwcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3377 case TOK.TOKdcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3378 case TOK.TOKnull:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3379 case TOK.TOKtrue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3380 case TOK.TOKfalse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3381 case TOK.TOKstring:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3382 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3383 case TOK.TOKcast:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3384 case TOK.TOKmul:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3385 case TOK.TOKmin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3386 case TOK.TOKadd:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3387 case TOK.TOKplusplus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3388 case TOK.TOKminusminus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3389 case TOK.TOKnew:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3390 case TOK.TOKdelete:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3391 case TOK.TOKdelegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3392 case TOK.TOKfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3393 case TOK.TOKtypeid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3394 case TOK.TOKis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3395 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3396 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3397 case TOK.TOKtraits:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3398 case TOK.TOKfile:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3399 case TOK.TOKline:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3400 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3401 Lexp:
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3402 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3403 auto exp = parseExpression();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3404 check(TOK.TOKsemicolon, "statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3405 s = new ExpStatement(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3406 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3407 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3408
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3409 case TOK.TOKstatic:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3410 { // Look ahead to see if it's static assert() or static if()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3411 Token *tt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3412
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3413 tt = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3414 if (tt.value == TOK.TOKassert)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3415 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3416 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3417 s = new StaticAssertStatement(parseStaticAssert());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3418 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3419 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3420 if (tt.value == TOK.TOKif)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3421 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3422 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3423 condition = parseStaticIfCondition();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3424 goto Lcondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3425 }
132
c494af1dba80 Fixes for dmd 2.037
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 131
diff changeset
3426 if (tt.value == TOK.TOKstruct || tt.value == TOK.TOKunion || tt.value == TOK.TOKclass)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3427 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3428 nextToken();
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3429 auto a = parseBlock();
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3430 Dsymbol d = new StorageClassDeclaration(STCstatic, a);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3431 s = new DeclarationStatement(loc, d);
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
3432 if (flags & ParseStatementFlags.PSscope)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3433 s = new ScopeStatement(loc, s);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3434 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3435 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3436 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3437 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3438
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3439 case TOK.TOKfinal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3440 if (peekNext() == TOK.TOKswitch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3441 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3442 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3443 isfinal = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3444 goto Lswitch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3445 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3446 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3447
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3448 case TOK.TOKwchar: case TOK.TOKdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3449 case TOK.TOKbit: case TOK.TOKbool: case TOK.TOKchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3450 case TOK.TOKint8: case TOK.TOKuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3451 case TOK.TOKint16: case TOK.TOKuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3452 case TOK.TOKint32: case TOK.TOKuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3453 case TOK.TOKint64: case TOK.TOKuns64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3454 case TOK.TOKfloat32: case TOK.TOKfloat64: case TOK.TOKfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3455 case TOK.TOKimaginary32: case TOK.TOKimaginary64: case TOK.TOKimaginary80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3456 case TOK.TOKcomplex32: case TOK.TOKcomplex64: case TOK.TOKcomplex80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3457 case TOK.TOKvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3458 case TOK.TOKtypedef:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3459 case TOK.TOKalias:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3460 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3461 case TOK.TOKauto:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3462 case TOK.TOKextern:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3463 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3464 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3465 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3466 case TOK.TOKshared:
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
3467 case TOKwild:
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3468 case TOK.TOKnothrow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3469 case TOK.TOKpure:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3470 case TOK.TOKtls:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3471 case TOK.TOKgshared:
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3472 case TOK.TOKat:
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3473 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3474 // case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3475 Ldeclaration:
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
3476 { Dsymbols a;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3477
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3478 a = parseDeclarations(STC.STCundefined);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3479 if (a.dim > 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3480 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3481 Statements as = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3482 as.reserve(a.dim);
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
3483 foreach(Dsymbol d; a)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3484 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3485 s = new DeclarationStatement(loc, d);
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
3486 as.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3487 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3488 s = new CompoundDeclarationStatement(loc, as);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3489 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3490 else if (a.dim == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3491 {
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
3492 auto d = a[0];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3493 s = new DeclarationStatement(loc, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3494 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3495 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3496 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3497 if (flags & ParseStatementFlags.PSscope)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3498 s = new ScopeStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3499 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3500 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3501
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3502 case TOK.TOKstruct:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3503 case TOK.TOKunion:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3504 case TOK.TOKclass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3505 case TOK.TOKinterface:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3506 { Dsymbol d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3507
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3508 d = parseAggregate();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3509 s = new DeclarationStatement(loc, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3510 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3511 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3512
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3513 case TOK.TOKenum:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3514 { /* Determine if this is a manifest constant declaration,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3515 * or a conventional enum.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3516 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3517 Dsymbol d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3518 Token* tt = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3519 if (tt.value == TOK.TOKlcurly || tt.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3520 d = parseEnum();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3521 else if (tt.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3522 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3523 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3524 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3525 tt = peek(tt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3526 if (tt.value == TOK.TOKlcurly || tt.value == TOK.TOKcolon ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3527 tt.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3528 d = parseEnum();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3529 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3530 goto Ldeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3531 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3532 s = new DeclarationStatement(loc, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3533 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3534 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3535
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3536 case TOK.TOKmixin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3537 { t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3538 if (t.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3539 { // mixin(string)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3540 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3541 check(TOK.TOKlparen, "mixin");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3542 Expression e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3543 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3544 check(TOK.TOKsemicolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3545 s = new CompileStatement(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3546 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3547 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3548 Dsymbol d = parseMixin();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3549 s = new DeclarationStatement(loc, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3550 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3551 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3552
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3553 case TOK.TOKlcurly:
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
3554 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
3555 nextToken();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
3556 Statements statements = new Statements();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
3557 while (token.value != TOK.TOKrcurly && token.value != TOKeof)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3558 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
3559 statements.push(parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3560 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3561 endloc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3562 s = new CompoundStatement(loc, statements);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3563 if (flags & (ParseStatementFlags.PSscope | ParseStatementFlags.PScurlyscope))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3564 s = new ScopeStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3565 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3566 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3567 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3568
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3569 case TOK.TOKwhile:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3570 { Expression condition2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3571 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3572
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 condition2 = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3576 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3577 body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3578 s = new WhileStatement(loc, condition2, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3579 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3580 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3581
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3582 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3583 if (!(flags & ParseStatementFlags.PSsemi))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3584 error("use '{ }' for an empty statement, not a ';'");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3585 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3586 s = new ExpStatement(loc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3587 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3588
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3589 case TOK.TOKdo:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3590 { Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3591 Expression condition2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3592
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3593 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3594 body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3595 check(TOK.TOKwhile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3596 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3597 condition2 = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3598 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3599 s = new DoStatement(loc, body_, condition2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3600 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3601 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3602
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3603 case TOK.TOKfor:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3604 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3605 Statement init;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3606 Expression condition2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3607 Expression increment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3608 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3609
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3610 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3611 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3612 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3613 { init = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3614 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3615 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3616 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3617 { init = parseStatement(cast(ParseStatementFlags)0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3618 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3619 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3620 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3621 condition2 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3622 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3623 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3624 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3625 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3626 condition2 = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3627 check(TOK.TOKsemicolon, "for condition");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3628 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3629 if (token.value == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3630 { increment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3631 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3632 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3633 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3634 { increment = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3635 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3636 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3637 body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3638 s = new ForStatement(loc, init, condition2, increment, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3639 if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3640 s = new ScopeStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3641 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3642 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3643
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3644 case TOK.TOKforeach:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3645 case TOK.TOKforeach_reverse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3646 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3647 TOK op = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3648
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3649 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3650 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3651
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3652 auto arguments = new Parameters();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3653
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3654 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3655 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3656 Identifier ai = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3657 Type at;
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
3658 StorageClass storageClass = STC.STCundefined;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3659
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
3660 if (token.value == TOKref
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
3661 //#if D1INOUT
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
3662 // || token.value == TOKinout
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
3663 //#endif
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
3664 )
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3665 { storageClass = STC.STCref;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3666 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3667 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3668 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3669 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3670 Token *tt = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3671 if (tt.value == TOK.TOKcomma || tt.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3672 { ai = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3673 at = null; // infer argument type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3674 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3675 goto Larg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3676 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3677 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3678 at = parseType(&ai);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3679 if (!ai)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3680 error("no identifier for declarator %s", at.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3681 Larg:
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3682 auto a = new Parameter(storageClass, at, ai, null);
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 125
diff changeset
3683 arguments.push(a);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3684 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3685 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3686 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3687 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3688 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3689 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3690 check(TOK.TOKsemicolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3691
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3692 Expression aggr = parseExpression();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3693 if (token.value == TOK.TOKslice && arguments.dim == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3694 {
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 125
diff changeset
3695 auto a = arguments[0];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3696 delete arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3697 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3698 Expression upr = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3699 check(TOK.TOKrparen);
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3700 auto body_ = parseStatement(cast(ParseStatementFlags)0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3701 s = new ForeachRangeStatement(loc, op, a, aggr, upr, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3702 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3703 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3704 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3705 check(TOK.TOKrparen);
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3706 auto body_ = parseStatement(cast(ParseStatementFlags)0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3707 s = new ForeachStatement(loc, op, arguments, aggr, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3708 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3709 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3710 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3711
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3712 case TOK.TOKif:
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3713 { Parameter arg = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3714 Expression condition2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3715 Statement ifbody2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3716 Statement elsebody2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3717
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3718 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3719 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3720
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3721 if (token.value == TOK.TOKauto)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3722 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3723 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3724 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3725 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3726 Token *tt = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3727 if (tt.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3728 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3729 arg = new Parameter(STC.STCundefined, null, token.ident, null);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3730 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3731 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3732 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3733 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3734 { error("= expected following auto identifier");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3735 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3736 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3737 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3738 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3739 { error("identifier expected following auto");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3740 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3741 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3742 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3743 else if (isDeclaration(&token, 2, TOK.TOKassign, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3744 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3745 Type at;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3746 Identifier ai;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3747
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3748 at = parseType(&ai);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3749 check(TOK.TOKassign);
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3750 arg = new Parameter(STC.STCundefined, at, ai, null);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3751 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3752
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3753 // Check for " ident;"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3754 else if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3755 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3756 Token *tt = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3757 if (tt.value == TOK.TOKcomma || tt.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3758 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
3759 arg = new Parameter(STC.STCundefined, null, token.ident, null);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3760 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3761 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3762 if (1 || !global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3763 error("if (v; e) is deprecated, use if (auto v = e)");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3764 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3765 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3766
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3767 condition2 = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3768 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3769 ifbody2 = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3770 if (token.value == TOK.TOKelse)
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 elsebody2 = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3774 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3775 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3776 elsebody2 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3777 s = new IfStatement(loc, arg, condition2, ifbody2, elsebody2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3778 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3779 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3780
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3781 case TOK.TOKscope:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3782 if (peek(&token).value != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3783 goto Ldeclaration; // scope used as storage class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3784 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3785 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3786 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3787 { error("scope identifier expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3788 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3789 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3790 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3791 { TOK tt = TOK.TOKon_scope_exit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3792 Identifier id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3793
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3794 if (id == Id.exit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3795 tt = TOK.TOKon_scope_exit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3796 else if (id == Id.failure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3797 tt = TOK.TOKon_scope_failure;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3798 else if (id == Id.success)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3799 tt = TOK.TOKon_scope_success;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3800 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3801 error("valid scope identifiers are exit, failure, or success, not %s", id.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3802 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3803 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3804 Statement st = parseStatement(ParseStatementFlags.PScurlyscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3805 s = new OnScopeStatement(loc, tt, st);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3806 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3807 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3808
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3809 case TOK.TOKdebug:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3810 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3811 condition = parseDebugCondition();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3812 goto Lcondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3813
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3814 case TOK.TOKversion:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3815 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3816 condition = parseVersionCondition();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3817 goto Lcondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3818
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3819 Lcondition:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3820 ifbody = parseStatement(cast(ParseStatementFlags)0 /*ParseStatementFlags.PSsemi*/);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3821 elsebody = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3822 if (token.value == TOK.TOKelse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3823 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3824 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3825 elsebody = parseStatement(cast(ParseStatementFlags)0 /*ParseStatementFlags.PSsemi*/);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3826 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3827 s = new ConditionalStatement(loc, condition, ifbody, elsebody);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3828 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3829
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3830 case TOK.TOKpragma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3831 { Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3832 Expressions args = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3833 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3834
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3835 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3836 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3837 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3838 { error("pragma(identifier expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3839 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3840 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3841 ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3842 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3843 if (token.value == TOK.TOKcomma && peekNext() != TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3844 args = parseArguments(); // pragma(identifier, args...);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3845 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3846 check(TOK.TOKrparen); // pragma(identifier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3847 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3848 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3849 body_ = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3850 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3851 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3852 body_ = parseStatement(ParseStatementFlags.PSsemi);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3853 s = new PragmaStatement(loc, ident, args, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3854 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3855 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3856
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3857 case TOK.TOKswitch:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3858 isfinal = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3859 goto Lswitch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3860
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3861 Lswitch:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3862 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3863 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3864 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3865 Expression condition2 = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3866 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3867 Statement body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3868 s = new SwitchStatement(loc, condition2, body_, isfinal);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3869 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3870 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3871
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3872 case TOK.TOKcase:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3873 { Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3874 Statements statements;
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
3875 scope cases = new Expressions(); // array of Expression's
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3876 Expression last = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3877
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3878 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3879 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3880 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3881 exp = parseAssignExp();
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
3882 cases.push(exp);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3883 if (token.value != TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3884 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3885 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3886 check(TOK.TOKcolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3887
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3888 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3889 /* case exp: .. case last:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3890 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3891 if (token.value == TOK.TOKslice)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3892 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3893 if (cases.dim > 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3894 error("only one case allowed for start of case range");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3895 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3896 check(TOK.TOKcase);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3897 last = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3898 check(TOK.TOKcolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3899 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3900 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3901
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3902 statements = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3903 while (token.value != TOK.TOKcase &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3904 token.value != TOK.TOKdefault &&
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
3905 token.value != TOKeof &&
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3906 token.value != TOK.TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3907 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
3908 statements.push(parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3909 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3910 s = new CompoundStatement(loc, statements);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3911 s = new ScopeStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3912
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3913 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3914 if (last)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3915 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3916 s = new CaseRangeStatement(loc, exp, last, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3917 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3918 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3919 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3920 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3921 // Keep cases in order by building the case statements backwards
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3922 for (int i = cases.dim; i; i--)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3923 {
128
e6e542f37b94 Some more Array -> Vector conversions
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
3924 exp = cases[i - 1];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3925 s = new CaseStatement(loc, exp, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3926 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3927 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3928 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3929 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3930
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3931 case TOK.TOKdefault:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3932 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3933 Statements statements;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3934
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3935 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3936 check(TOK.TOKcolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3937
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3938 statements = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3939 while (token.value != TOK.TOKcase &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3940 token.value != TOK.TOKdefault &&
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
3941 token.value != TOKeof &&
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3942 token.value != TOK.TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3943 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
3944 statements.push(parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3945 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3946 s = new CompoundStatement(loc, statements);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3947 s = new ScopeStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3948 s = new DefaultStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3949 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3950 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3951
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3952 case TOK.TOKreturn:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3953 { Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3954
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3955 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3956 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3957 exp = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3958 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3959 exp = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3960 check(TOK.TOKsemicolon, "return statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3961 s = new ReturnStatement(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3962 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3963 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3964
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3965 case TOK.TOKbreak:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3966 { Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3967
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3968 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3969 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3970 { ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3971 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3972 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3973 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3974 ident = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3975 check(TOK.TOKsemicolon, "break statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3976 s = new BreakStatement(loc, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3977 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3978 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3979
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3980 case TOK.TOKcontinue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3981 { Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3982
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3983 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3984 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3985 { ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3986 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3987 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3988 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3989 ident = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3990 check(TOK.TOKsemicolon, "continue statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3991 s = new ContinueStatement(loc, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3992 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3993 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3994
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3995 case TOK.TOKgoto:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3996 { Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3997
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3998 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3999 if (token.value == TOK.TOKdefault)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4000 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4001 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4002 s = new GotoDefaultStatement(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4003 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4004 else if (token.value == TOK.TOKcase)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4005 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4006 Expression exp = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4007
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4008 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4009 if (token.value != TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4010 exp = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4011 s = new GotoCaseStatement(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4012 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4013 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4014 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4015 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4016 { error("Identifier expected following goto");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4017 ident = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4018 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4019 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4020 { ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4021 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4022 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4023 s = new GotoStatement(loc, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4024 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4025 check(TOK.TOKsemicolon, "goto statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4026 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4027 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4028
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4029 case TOK.TOKsynchronized:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4030 { Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4031 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4032
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4033 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4034 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4035 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4036 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4037 exp = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4038 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4039 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4040 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4041 exp = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4042 body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4043 s = new SynchronizedStatement(loc, exp, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4044 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4045 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4046
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4047 case TOK.TOKwith:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4048 { Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4049 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4050
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4051 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4052 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4053 exp = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4054 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4055 body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4056 s = new WithStatement(loc, exp, body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4057 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4058 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4059
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4060 case TOK.TOKtry:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4061 { Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4062 Array catches = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4063 Statement finalbody = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4064
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4065 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4066 body_ = parseStatement(ParseStatementFlags.PSscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4067 while (token.value == TOK.TOKcatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4068 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4069 Statement handler;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4070 Catch c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4071 Type tt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4072 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4073 Loc loc2 = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4074
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4075 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4076 if (token.value == TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4077 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4078 tt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4079 id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4080 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4081 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4082 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4083 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4084 id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4085 tt = parseType(&id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4086 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4087 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4088 handler = parseStatement(cast(ParseStatementFlags)0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4089 c = new Catch(loc2, tt, id, handler);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4090 if (!catches)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4091 catches = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4092 catches.push(cast(void*)c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4093 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4094
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4095 if (token.value == TOK.TOKfinally)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4096 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4097 finalbody = parseStatement(cast(ParseStatementFlags)0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4098 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4099
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4100 s = body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4101 if (!catches && !finalbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4102 error("catch or finally expected following try");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4103 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4104 { if (catches)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4105 s = new TryCatchStatement(loc, body_, catches);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4106 if (finalbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4107 s = new TryFinallyStatement(loc, s, finalbody);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4109 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4110 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4112 case TOK.TOKthrow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4113 { Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4114
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4115 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4116 exp = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4117 check(TOK.TOKsemicolon, "throw statement");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4118 s = new ThrowStatement(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4119 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4121
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4122 case TOK.TOKvolatile:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4123 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4124 s = parseStatement(ParseStatementFlags.PSsemi | ParseStatementFlags.PScurlyscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4125 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4126 if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4127 error("volatile statements deprecated; used synchronized statements instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4129 s = new VolatileStatement(loc, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4130 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4131
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4132 case TOK.TOKasm:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4133 { Statements statements;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4134 Identifier label;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4135 Loc labelloc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4136 Token* toklist;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4137 Token** ptoklist;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4138
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4139 // Parse the asm block into a sequence of AsmStatements,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4140 // each AsmStatement is one instruction.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4141 // Separate out labels.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4142 // Defer parsing of AsmStatements until semantic processing.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4143
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4144 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4145 check(TOK.TOKlcurly);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4146 toklist = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4147 ptoklist = &toklist;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4148 label = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4149 statements = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4150 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4151 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4152 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4153 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4154 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4155 if (!toklist)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4156 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4157 // Look ahead to see if it is a label
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4158 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4159 if (t.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4160 { // It's a label
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4161 label = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4162 labelloc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4163 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4164 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4165 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4166 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4167 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4168 goto Ldefault;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4169
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4170 case TOK.TOKrcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4171 if (toklist || label)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4172 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4173 error("asm statements must end in ';'");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4175 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4176
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4177 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4178 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4179 if (toklist || label)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4180 { // Create AsmStatement from list of tokens we've saved
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4181 s = new AsmStatement(this.loc, toklist);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4182 toklist = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4183 ptoklist = &toklist;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4184 if (label)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4185 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4186 s = new LabelStatement(labelloc, label, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4187 label = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4188 }
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 121
diff changeset
4189 statements.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4190 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4191 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4192 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4193
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4194 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4195 /* { */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4196 error("matching '}' expected, not end of file");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4197 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4198
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4199 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4200 Ldefault:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4201 *ptoklist = new Token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4202 memcpy(*ptoklist, &token, Token.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4203 ptoklist = &(*ptoklist).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4204 *ptoklist = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4205
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4206 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4207 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4208 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4209 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4210 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4211 s = new CompoundStatement(loc, statements);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4212 nextToken();
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4216 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4217 error("found '%s' instead of statement", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4218 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4219
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4220 Lerror:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4221 while (token.value != TOK.TOKrcurly &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4222 token.value != TOK.TOKsemicolon &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4223 token.value != TOK.TOKeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4224 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4225 if (token.value == TOK.TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4226 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4227 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4228 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4229 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4230
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4231 return s;
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 * Parse initializer for variable declaration.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4236 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4237 Initializer parseInitializer()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4238 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4239 StructInitializer is_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4240 ArrayInitializer ia;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4241 ExpInitializer ie;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4242 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4243 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4244 Initializer value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4245 int comma;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4246 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4247 Token* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4248 int braces;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4249 int brackets;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4250
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4251 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4252 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4253 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4254 /* Scan ahead to see if it is a struct initializer or
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4255 * a function literal.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4256 * If it contains a ';', it is a function literal.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4257 * Treat { } as a struct initializer.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4258 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4259 braces = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4260 for (t = peek(&token); 1; t = peek(t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4261 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4262 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4263 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4264 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4265 case TOK.TOKreturn:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4266 goto Lexpression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4267
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4268 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4269 braces++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4270 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4271
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4272 case TOK.TOKrcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4273 if (--braces == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4274 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4275 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4276
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4277 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4278 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4279
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4280 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4281 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4282 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4283 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4284 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4285
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4286 is_ = new StructInitializer(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4287 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4288 comma = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4289 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4290 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4291 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4292 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4293 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4294 if (comma == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4295 error("comma expected separating field initializers");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4296 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4297 if (t.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4298 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4299 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4300 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4301 nextToken(); // skip over ':'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4302 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4303 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4304 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4305 id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4306 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4307 value = parseInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4308 is_.addInit(id, value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4309 comma = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4310 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4311
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4312 case TOK.TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4313 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4314 comma = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4315 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4317 case TOK.TOKrcurly: // allow trailing comma's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4318 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4319 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4320
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4321 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4322 error("found EOF instead of initializer");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4323 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4325 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4326 value = parseInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4327 is_.addInit(null, value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4328 comma = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4329 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4330 //error("found '%s' instead of field initializer", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4331 //break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4332 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4333 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4334 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4335 return is_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4336
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4337 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4338 /* Scan ahead to see if it is an array initializer or
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4339 * an expression.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4340 * If it ends with a ';' ',' or '}', it is an array initializer.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4341 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4342 brackets = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4343 for (t = peek(&token); 1; t = peek(t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4344 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4345 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4346 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4347 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4348 brackets++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4349 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4350
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4351 case TOK.TOKrbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4352 if (--brackets == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4353 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4354 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4355 if (t.value != TOK.TOKsemicolon &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4356 t.value != TOK.TOKcomma &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4357 t.value != TOK.TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4358 goto Lexpression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4359 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4360 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4361 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4362
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4363 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4364 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4365
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4366 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4367 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4368 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4369 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4370 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4371
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4372 ia = new ArrayInitializer(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4373 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4374 comma = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4375 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4376 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4377 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4378 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4379 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4380 if (comma == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4381 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4382 error("comma expected separating array initializers, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4383 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4384 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4385 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4386 e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4387 if (!e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4388 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4389 if (token.value == TOK.TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4390 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4391 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4392 value = parseInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4393 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4394 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4395 { value = new ExpInitializer(e.loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4396 e = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4397 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4398 ia.addInit(e, value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4399 comma = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4400 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4401
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4402 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4403 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4404 if (comma == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4405 error("comma expected separating array initializers, not %s", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4406 value = parseInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4407 ia.addInit(null, value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4408 comma = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4409 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4410
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4411 case TOK.TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4412 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4413 comma = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4414 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4415
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4416 case TOK.TOKrbracket: // allow trailing comma's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4417 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4418 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4419
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4420 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4421 error("found '%s' instead of array initializer", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4422 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4423 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4424 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4425 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4426 return ia;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4427
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4428 case TOK.TOKvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4429 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4430 if (t.value == TOK.TOKsemicolon || t.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4431 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4432 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4433 return new VoidInitializer(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4434 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4435 goto Lexpression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4436
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4437 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4438 Lexpression:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4439 e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4440 ie = new ExpInitializer(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4441 return ie;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4442 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4443 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4444
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4445 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4446 * Parses default argument initializer expression that is an assign expression,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4447 * with special handling for __FILE__ and __LINE__.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4448 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4449 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4450 Expression parseDefaultInitExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4451 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4452 if (token.value == TOK.TOKfile ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4453 token.value == TOK.TOKline)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4454 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4455 Token* t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4456 if (t.value == TOK.TOKcomma || t.value == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4457 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4458 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4459
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4460 if (token.value == TOK.TOKfile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4461 e = new FileInitExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4462 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4463 e = new LineInitExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4464 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4465 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4466 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4467 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4468
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4469 Expression e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4470 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4471 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4472 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4473 void check(Loc loc, TOK value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4474 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4475 if (token.value != value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4476 error(loc, "found '%s' when expecting '%s'", token.toChars(), Token.toChars(value));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4477 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4478 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4479
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4480 void check(TOK value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4481 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4482 check(loc, value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4483 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4484
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4485 void check(TOK value, string string_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4486 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4487 if (token.value != value) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4488 error("found '%s' when expecting '%s' following '%s'", token.toChars(), Token.toChars(value), string_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4489 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4490 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4491 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4492
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4493 /************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4494 * Determine if the scanner is sitting on the start of a declaration.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4495 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4496 * needId 0 no identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4497 * 1 identifier optional
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4498 * 2 must have identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4499 * Output:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4500 * if *pt is not null, it is set to the ending token, which would be endtok
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4501 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4502
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4503 bool isDeclaration(Token* t, int needId, TOK endtok, Token** pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4504 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4505 //printf("isDeclaration(needId = %d)\n", needId);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4506 int haveId = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4507
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4508 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4509 if ((t.value == TOK.TOKconst ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4510 t.value == TOK.TOKinvariant ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4511 t.value == TOK.TOKimmutable ||
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
4512 t.value == TOKwild ||
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4513 t.value == TOK.TOKshared) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4514 peek(t).value != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4515 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4516 /* const type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4517 * immutable type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4518 * shared type
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
4519 * wild type
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4520 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4521 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4522 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4523 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4524
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4525 if (!isBasicType(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4526 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4527 goto Lisnot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4528 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4529 if (!isDeclarator(&t, &haveId, endtok))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4530 goto Lisnot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4531 if ( needId == 1 ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4532 (needId == 0 && !haveId) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4533 (needId == 2 && haveId))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4534 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4535 if (pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4536 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4537 goto Lis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4538 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4539 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4540 goto Lisnot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4541
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4542 Lis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4543 //printf("\tis declaration, t = %s\n", t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4544 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4545
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4546 Lisnot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4547 //printf("\tis not declaration\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4548 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4549 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4550
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4551 bool isBasicType(Token** pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4552 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4553 // This code parallels parseBasicType()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4554 Token* t = *pt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4555 Token* t2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4556 int parens;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4557 int haveId = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4558
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4559 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4560 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4561 case TOKwchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4562 case TOKdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4563 case TOKbit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4564 case TOKbool:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4565 case TOKchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4566 case TOKint8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4567 case TOKuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4568 case TOKint16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4569 case TOKuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4570 case TOKint32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4571 case TOKuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4572 case TOKint64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4573 case TOKuns64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4574 case TOKfloat32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4575 case TOKfloat64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4576 case TOKfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4577 case TOKimaginary32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4578 case TOKimaginary64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4579 case TOKimaginary80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4580 case TOKcomplex32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4581 case TOKcomplex64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4582 case TOKcomplex80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4583 case TOKvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4584 t = peek(t);
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 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4588 L5:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4589 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4590 if (t.value == TOK.TOKnot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4591 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4592 goto L4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4593 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4594 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4595 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4596 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4597 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4598 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4599 L3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4600 if (t.value == TOK.TOKdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4601 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4602 Ldot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4603 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4604 if (t.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4605 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4606 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4607 if (t.value != TOK.TOKnot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4608 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4609 L4:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4610 /* Seen a !
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4611 * Look for:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4612 * !( args ), !identifier, etc.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4613 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4614 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4615 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4616 { case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4617 goto L5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4618 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4619 if (!skipParens(t, &t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4620 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4621 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4622 case TOK.TOKwchar: case TOK.TOKdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4623 case TOK.TOKbit: case TOK.TOKbool: case TOK.TOKchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4624 case TOK.TOKint8: case TOK.TOKuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4625 case TOK.TOKint16: case TOK.TOKuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4626 case TOK.TOKint32: case TOK.TOKuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4627 case TOK.TOKint64: case TOK.TOKuns64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4628 case TOK.TOKfloat32: case TOK.TOKfloat64: case TOK.TOKfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4629 case TOK.TOKimaginary32: case TOK.TOKimaginary64: case TOK.TOKimaginary80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4630 case TOK.TOKcomplex32: case TOK.TOKcomplex64: case TOK.TOKcomplex80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4631 case TOK.TOKvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4632 case TOK.TOKint32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4633 case TOK.TOKuns32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4634 case TOK.TOKint64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4635 case TOK.TOKuns64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4636 case TOK.TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4637 case TOK.TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4638 case TOK.TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4639 case TOK.TOKimaginary32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4640 case TOK.TOKimaginary64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4641 case TOK.TOKimaginary80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4642 case TOK.TOKnull:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4643 case TOK.TOKtrue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4644 case TOK.TOKfalse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4645 case TOK.TOKcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4646 case TOK.TOKwcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4647 case TOK.TOKdcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4648 case TOK.TOKstring:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4649 case TOK.TOKfile:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4650 case TOK.TOKline:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4651 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4652 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4653 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4654 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4655 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4656 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4657 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4658 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4659 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4660
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4661 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4662 goto Ldot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4663
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4664 case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4665 /* typeof(exp).identifier...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4666 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4667 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4668 if (t.value != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4669 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4670 if (!skipParens(t, &t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4671 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4672 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4673
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4674 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4675 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4676 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4677 case TOK.TOKshared:
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
4678 case TOKwild:
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
4679 // const(type) or immutable(type) or shared(type) or wild(type)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4680 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4681 if (t.value != TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4682 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4683 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4684 if (!isDeclaration(t, 0, TOK.TOKrparen, &t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4685 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4686 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4687 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4688 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4689 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4690
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4691 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4692 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4693 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4694 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4695 //printf("is\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4696 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4697
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4698 Lfalse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4699 //printf("is not\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4700 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4701 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4702
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4703 bool isDeclarator(Token** pt, int* haveId, TOK endtok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4704 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4705 // This code parallels parseDeclarator()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4706 Token* t = *pt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4707 bool parens;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4708
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4709 //printf("Parser.isDeclarator()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4710 //t.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4711 if (t.value == TOK.TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4712 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4713
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4714 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4715 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4716 parens = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4717 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4718 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4719 case TOK.TOKmul:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4720 //case TOKand:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4721 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4722 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4723
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4724 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4725 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4726 if (t.value == TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4727 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4728 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4729 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
4730 else if (t.value == TOKnew && peek(t).value == TOKrbracket)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
4731 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
4732 t = peek(t);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
4733 t = peek(t);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
4734 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4735 else if (isDeclaration(t, 0, TOK.TOKrbracket, &t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4736 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4737 // It's an associative array declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4738 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4739 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4740 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4741 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4742 // [ expression ]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4743 // [ expression .. expression ]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4744 if (!isExpression(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4745 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4746 if (t.value == TOK.TOKslice)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4747 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4748 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4749 if (!isExpression(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4750 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4751 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4752 if (t.value != TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4753 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4754 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4755 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4756 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4757
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4758 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4759 if (*haveId)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4760 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4761 *haveId = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4762 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4763 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4764
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4765 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4766 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4767
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4768 if (t.value == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4769 return false; // () is not a declarator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4770
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4771 /* Regard ( identifier ) as not a declarator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4772 * BUG: what about ( *identifier ) in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4773 * f(*p)(x);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4774 * where f is a class instance with overloaded () ?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4775 * Should we just disallow C-style function pointer declarations?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4776 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4777 if (t.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4778 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4779 Token *t2 = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4780 if (t2.value == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4781 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4782 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4783
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4784 if (!isDeclarator(&t, haveId, TOK.TOKrparen))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4785 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4786 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4787 parens = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4788 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4789
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4790 case TOK.TOKdelegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4791 case TOK.TOKfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4792 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4793 if (!isParameters(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4794 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4795 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4796 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4797 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4798 }
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4802 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4803 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4804 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4805 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4806 version (CARRAYDECL) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4807 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4808 parens = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4809 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4810 if (t.value == TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4811 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4812 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4813 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4814 else if (isDeclaration(t, 0, TOKrbracket, &t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4815 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4816 // It's an associative array declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4817 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4818 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4819 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4820 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4821 // [ expression ]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4822 if (!isExpression(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4823 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4824 if (t.value != TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4825 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4826 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4827 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4828 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4829 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4830
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4831 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4832 parens = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4833 if (!isParameters(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4834 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4835 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4836 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4837 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4838 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4839 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4840 case TOK.TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4841 case TOK.TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4842 case TOK.TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4843 case TOK.TOKshared:
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
4844 case TOKwild:
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4845 case TOK.TOKpure:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4846 case TOK.TOKnothrow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4847 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4848 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4849 case TOK.TOKat:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4850 t = peek(t); // skip '@'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4851 t = peek(t); // skip identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4852 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4853 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4854 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4855 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4856 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4857 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4858 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4859 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4860
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4861 // Valid tokens that follow a declaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4862 case TOK.TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4863 case TOK.TOKrbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4864 case TOK.TOKassign:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4865 case TOK.TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4866 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4867 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4868 case TOK.TOKin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4869 // The !parens is to disallow unnecessary parentheses
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4870 if (!parens && (endtok == TOK.TOKreserved || endtok == t.value))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4871 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4872 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4873 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4874 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4875 return false;
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 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4879 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4880 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4881 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4882
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4883 bool isParameters(Token** pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4884 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4885 // This code parallels parseParameters()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4886 Token* t = *pt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4887
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4888 //printf("isParameters()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4889 if (t.value != TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4890 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4891
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4892 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4893 for (;1; t = peek(t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4894 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4895 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4896 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4897 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4898 case TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4899 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4900
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4901 case TOKdotdotdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4902 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4903 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4904
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
4905 version(D1INOUT) {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
4906 case TOKinout:
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
4907 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4908 case TOKin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4909 case TOKout:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4910 case TOKref:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4911 case TOKlazy:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4912 case TOKfinal:
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
4913 case TOKauto:
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4914 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4915
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4916 case TOKconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4917 case TOKinvariant:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4918 case TOKimmutable:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4919 case TOKshared:
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
4920 case TOKwild:
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4921 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4922 if (t.value == TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4923 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4924 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4925 if (!isDeclaration(t, 0, TOKrparen, &t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4926 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4927 t = peek(t); // skip past closing ')'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4928 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4929 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4930 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4931
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4932 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4933 case TOKstatic:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4934 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4935 case TOKauto:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4936 case TOKalias:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4937 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4938 if (t.value == TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4939 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4940 if (t.value == TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4941 { t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4942 if (!isExpression(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4943 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4944 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4945 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4946 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4947
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4948 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4949 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4950 if (!isBasicType(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4951 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4952 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4953 int tmp = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4954 if (t.value != TOKdotdotdot &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4955 !isDeclarator(&t, &tmp, TOKreserved))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4956 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4957 if (t.value == TOKassign)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4958 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4959 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4960 if (!isExpression(&t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4961 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4962 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4963 if (t.value == TOKdotdotdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4964 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4965 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4966 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4967 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4968 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4969 L3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4970 if (t.value == TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4971 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4972 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4973 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4974 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4975 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4976 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4977 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4978
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4979 if (t.value != TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4980 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4981
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4982 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4983 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4984 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4985 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4986
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4987 bool isExpression(Token** pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4988 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4989 // This is supposed to determine if something is an expression.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4990 // What it actually does is scan until a closing right bracket
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4991 // is found.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4992
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4993 Token* t = *pt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4994 int brnest = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4995 int panest = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4996 int curlynest = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4997
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4998 for (;; t = peek(t))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4999 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5000 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5001 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5002 case TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5003 brnest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5004 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5005
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5006 case TOKrbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5007 if (--brnest >= 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5008 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5009 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5010
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5011 case TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5012 panest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5013 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5014
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5015 case TOKcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5016 if (brnest || panest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5017 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5018 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5019
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5020 case TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5021 if (--panest >= 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5022 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5023 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5024
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5025 case TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5026 curlynest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5027 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5028
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5029 case TOKrcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5030 if (--curlynest >= 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5031 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5032 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5033
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5034 case TOKslice:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5035 if (brnest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5036 continue;
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 TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5040 if (curlynest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5041 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5042 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5043
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5044 case TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5045 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5046
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5047 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5048 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5049 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5050 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5051 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5052
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5053 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5054 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5055 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5056
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5057 int isTemplateInstance(Token t, Token* pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5058 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5059 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5060 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5061
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5062 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5063 * Skip parens, brackets.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5064 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5065 * t is on opening (
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5066 * Output:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5067 * *pt is set to closing token, which is ')' on success
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5068 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5069 * !=0 successful
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5070 * 0 some parsing error
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5071 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5072 bool skipParens(Token* t, Token** pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5073 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5074 int parens = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5075
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5076 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5077 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5078 switch (t.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5079 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5080 case TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5081 parens++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5082 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5083
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5084 case TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5085 parens--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5086 if (parens < 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5087 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5088 if (parens == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5089 goto Ldone;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5090 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5091
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5092 case TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5093 case TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5094 goto Lfalse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5095
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5096 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5097 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5098 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5099 t = peek(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5102 Ldone:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5103 if (*pt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5104 *pt = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5105 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5106
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5107 Lfalse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5108 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5111 Expression parseExpression()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5113 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5114 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5115 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5116
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5117 //printf("Parser.parseExpression() loc = %d\n", loc.linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5118 e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5119 while (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5121 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5122 e2 = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5123 e = new CommaExp(loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5124 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5125 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5126 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5127 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5129 Expression parsePrimaryExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5130 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5131 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5132 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5133 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5134 TOK save;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5135 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5137 //printf("parsePrimaryExp(): loc = %d\n", loc.linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5138 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5139 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5140 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5141 id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5142 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5143 if (token.value == TOK.TOKnot && peekNext() != TOK.TOKis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5144 { // identifier!(template-argument-list)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5145 TemplateInstance tempinst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5146
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5147 tempinst = new TemplateInstance(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5148 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5149 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5150 // ident!(template_arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5151 tempinst.tiargs = parseTemplateArgumentList();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5152 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5153 // ident!template_argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5154 tempinst.tiargs = parseTemplateArgument();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5155 e = new ScopeExp(loc, tempinst);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5156 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5157 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5158 e = new IdentifierExp(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5159 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5160
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5161 case TOK.TOKdollar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5162 if (!inBrackets)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5163 error("'$' is valid only inside [] of index or slice");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5164 e = new DollarExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5165 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5166 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5167
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5168 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5169 // Signal global scope '.' operator with "" identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5170 e = new IdentifierExp(loc, Id.empty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5171 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5172
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5173 case TOK.TOKthis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5174 e = new ThisExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5175 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5176 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5177
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5178 case TOK.TOKsuper:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5179 e = new SuperExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5180 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5181 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5182
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5183 case TOK.TOKint32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5184 e = new IntegerExp(loc, token.int32value, Type.tint32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5185 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5186 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5187
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5188 case TOK.TOKuns32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5189 e = new IntegerExp(loc, token.uns32value, Type.tuns32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5190 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5191 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5192
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5193 case TOK.TOKint64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5194 e = new IntegerExp(loc, token.int64value, Type.tint64);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5195 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5196 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5197
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5198 case TOK.TOKuns64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5199 e = new IntegerExp(loc, token.uns64value, Type.tuns64);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5200 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5201 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5202
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5203 case TOK.TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5204 e = new RealExp(loc, token.float80value, Type.tfloat32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5205 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5206 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5207
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5208 case TOK.TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5209 e = new RealExp(loc, token.float80value, Type.tfloat64);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5210 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5211 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5212
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5213 case TOK.TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5214 e = new RealExp(loc, token.float80value, Type.tfloat80);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5215 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5216 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5217
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5218 case TOK.TOKimaginary32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5219 e = new RealExp(loc, token.float80value, Type.timaginary32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5220 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5221 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5222
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5223 case TOK.TOKimaginary64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5224 e = new RealExp(loc, token.float80value, Type.timaginary64);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5225 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5226 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5227
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5228 case TOK.TOKimaginary80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5229 e = new RealExp(loc, token.float80value, Type.timaginary80);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5230 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5231 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5232
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5233 case TOK.TOKnull:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5234 e = new NullExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5235 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5236 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5237
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5238 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5239 case TOK.TOKfile:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5240 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5241 string s = loc.filename ? loc.filename : mod.ident.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5242 e = new StringExp(loc, s, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5243 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5244 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5245 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5246
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5247 case TOK.TOKline:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5248 e = new IntegerExp(loc, loc.linnum, Type.tint32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5249 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5250 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5251 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5252
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5253 case TOK.TOKtrue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5254 e = new IntegerExp(loc, 1, Type.tbool);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5255 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5256 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5257
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5258 case TOK.TOKfalse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5259 e = new IntegerExp(loc, 0, Type.tbool);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5260 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5261 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5262
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5263 case TOK.TOKcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5264 e = new IntegerExp(loc, token.uns32value, Type.tchar);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5265 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5266 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5267
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5268 case TOK.TOKwcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5269 e = new IntegerExp(loc, token.uns32value, Type.twchar);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5270 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5271 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5272
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5273 case TOK.TOKdcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5274 e = new IntegerExp(loc, token.uns32value, Type.tdchar);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5275 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5276 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5277
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5278 case TOK.TOKstring:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5279 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5280 const(char)* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5281 uint len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5282 ubyte postfix;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5283
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5284 // cat adjacent strings
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5285 s = token.ustring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5286 len = token.len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5287 postfix = token.postfix;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5288 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5289 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5290 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5291 if (token.value == TOK.TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5292 { uint len1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5293 uint len2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5294 char* s2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5295
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5296 if (token.postfix)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5297 { if (token.postfix != postfix)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5298 error("mismatched string literal postfixes '%c' and '%c'", postfix, token.postfix);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5299 postfix = token.postfix;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5300 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5301
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5302 len1 = len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5303 len2 = token.len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5304 len = len1 + len2;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
5305 s2 = cast(char*)GC.malloc((len + 1) * ubyte.sizeof);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5306 memcpy(s2, s, len1 * ubyte.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5307 memcpy(s2 + len1, token.ustring, (len2 + 1) * ubyte.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5308 s = s2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5310 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5311 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5312 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5313 e = new StringExp(loc, assumeUnique(s[0..len]), postfix);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5314 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5315 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5317 case TOK.TOKvoid: t = Type.tvoid; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5318 case TOK.TOKint8: t = Type.tint8; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5319 case TOK.TOKuns8: t = Type.tuns8; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5320 case TOK.TOKint16: t = Type.tint16; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5321 case TOK.TOKuns16: t = Type.tuns16; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5322 case TOK.TOKint32: t = Type.tint32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5323 case TOK.TOKuns32: t = Type.tuns32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5324 case TOK.TOKint64: t = Type.tint64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5325 case TOK.TOKuns64: t = Type.tuns64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5326 case TOK.TOKfloat32: t = Type.tfloat32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5327 case TOK.TOKfloat64: t = Type.tfloat64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5328 case TOK.TOKfloat80: t = Type.tfloat80; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5329 case TOK.TOKimaginary32: t = Type.timaginary32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5330 case TOK.TOKimaginary64: t = Type.timaginary64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5331 case TOK.TOKimaginary80: t = Type.timaginary80; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5332 case TOK.TOKcomplex32: t = Type.tcomplex32; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5333 case TOK.TOKcomplex64: t = Type.tcomplex64; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5334 case TOK.TOKcomplex80: t = Type.tcomplex80; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5335 case TOK.TOKbit: t = Type.tbit; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5336 case TOK.TOKbool: t = Type.tbool; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5337 case TOK.TOKchar: t = Type.tchar; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5338 case TOK.TOKwchar: t = Type.twchar; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5339 case TOK.TOKdchar: t = Type.tdchar; goto LabelX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5340 LabelX:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5341 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5342 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5343 check(TOK.TOKdot, t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5344 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5345 { error("found '%s' when expecting identifier following '%s.'", token.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5346 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5347 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5348 e = typeDotIdExp(loc, t, token.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5349 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5350 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5351
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5352 case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5353 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5354 t = parseTypeof();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5355 e = new TypeExp(loc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5356 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5357 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5358
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5359 case TOK.TOKtypeid:
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5360 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5361 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5362 check(TOK.TOKlparen, "typeid");
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5363 Object o;
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
5364 if (isDeclaration(&token, 0, TOKreserved, null))
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5365 { // argument is a type
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5366 o = parseType();
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5367 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5368 else
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5369 { // argument is an expression
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5370 o = parseAssignExp();
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5371 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5372 check(TOK.TOKrparen);
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5373 e = new TypeidExp(loc, o);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5374 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5375 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5376
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5377 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5378 case TOK.TOKtraits:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5379 { /* __traits(identifier, args...)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5380 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5381 Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5382 Objects args = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5383
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5384 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5385 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5386 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5387 { error("__traits(identifier, args...) expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5388 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5389 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5390 ident = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5391 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5392 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5393 args = parseTemplateArgumentList2(); // __traits(identifier, args...)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5394 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5395 check(TOK.TOKrparen); // __traits(identifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5396
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5397 e = new TraitsExp(loc, ident, args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5398 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5399 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5400 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5401
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5402 case TOK.TOKis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5403 { Type targ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5404 Identifier ident = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5405 Type tspec = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5406 TOK tok = TOK.TOKreserved;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5407 TOK tok2 = TOK.TOKreserved;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5408 TemplateParameters tpl = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5409 Loc loc2 = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5410
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5411 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5412 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5413 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5414 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5415 targ = parseType(&ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5416 if (token.value == TOK.TOKcolon || token.value == TOK.TOKequal)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5417 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5418 tok = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5419 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5420 if (tok == TOK.TOKequal &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5421 (token.value == TOK.TOKtypedef ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5422 token.value == TOK.TOKstruct ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5423 token.value == TOK.TOKunion ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5424 token.value == TOK.TOKclass ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5425 token.value == TOK.TOKsuper ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5426 token.value == TOK.TOKenum ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5427 token.value == TOK.TOKinterface ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5428 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5429 token.value == TOK.TOKconst && peek(&token).value == TOK.TOKrparen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5430 token.value == TOK.TOKinvariant && peek(&token).value == TOK.TOKrparen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5431 token.value == TOK.TOKimmutable && peek(&token).value == TOK.TOKrparen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5432 token.value == TOK.TOKshared && peek(&token).value == TOK.TOKrparen ||
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5433 token.value == TOKwild && peek(&token).value == TOKrparen ||
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5434 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5435 token.value == TOK.TOKfunction ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5436 token.value == TOK.TOKdelegate ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5437 token.value == TOK.TOKreturn))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5438 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5439 tok2 = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5440 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5441 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5442 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5443 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5444 tspec = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5445 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5446 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5447 if (ident && tspec)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5448 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5449 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5450 tpl = parseTemplateParameterList(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5451 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5452 { tpl = new TemplateParameters();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5453 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5454 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5455 TemplateParameter tp = new TemplateTypeParameter(loc2, ident, null, null);
121
347de076ad34 TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
5456 tpl.insert(0, tp);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5457 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5458 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5459 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5460 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5461 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5462 { error("(type identifier : specialization) expected following is");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5463 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5464 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5465 e = new IsExp(loc2, targ, ident, tok, tspec, tok2, tpl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5466 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5467 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5468
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5469 case TOK.TOKassert:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5470 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5471 Expression msg = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5472
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5473 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5474 check(TOK.TOKlparen, "assert");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5475 e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5476 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5477 { nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5478 msg = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5479 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5480 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5481 e = new AssertExp(loc, e, msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5482 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5483 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5484
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5485 case TOK.TOKmixin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5486 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5487 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5488 check(TOK.TOKlparen, "mixin");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5489 e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5490 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5491 e = new CompileExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5492 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5493 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5494
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5495 case TOK.TOKimport:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5496 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5497 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5498 check(TOK.TOKlparen, "import");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5499 e = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5500 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5501 e = new FileExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5502 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5503 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5504
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5505 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5506 if (peekPastParen(&token).value == TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5507 { // (arguments) { statements... }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5508 save = TOK.TOKdelegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5509 goto case_delegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5510 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5511 // ( expression )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5512 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5513 e = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5514 check(loc, TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5515 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5516
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5517 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5518 { /* Parse array literals and associative array literals:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5519 * [ value, value, value ... ]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5520 * [ key:value, key:value, key:value ... ]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5521 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5522 Expressions values = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5523 Expressions keys = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5524
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5525 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5526 if (token.value != TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5527 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5528 while (token.value != TOK.TOKeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5529 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5530 Expression e2 = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5531 if (token.value == TOK.TOKcolon && (keys || values.dim == 0))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5532 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5533 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5534 if (!keys)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5535 keys = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
5536 keys.push(e2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5537 e2 = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5538 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5539 else if (keys)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5540 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5541 error("'key:value' expected for associative array literal");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5542 delete keys;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5543 keys = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5544 }
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
5545 values.push(e2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5546 if (token.value == TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5547 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5548 check(TOK.TOKcomma);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5549 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5550 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5551 check(TOK.TOKrbracket);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5552
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5553 if (keys)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5554 e = new AssocArrayLiteralExp(loc, keys, values);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5555 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5556 e = new ArrayLiteralExp(loc, values);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5557 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5558 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5559
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5560 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5561 // { statements... }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5562 save = TOK.TOKdelegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5563 goto case_delegate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5564
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5565 case TOK.TOKfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5566 case TOK.TOKdelegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5567 save = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5568 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5569 case_delegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5570 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5571 /* function type(parameters) { body } pure nothrow
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5572 * delegate type(parameters) { body } pure nothrow
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5573 * (parameters) { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5574 * { body }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5575 */
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5576 Parameters arguments;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5577 int varargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5578 FuncLiteralDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5579 Type tt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5580 bool isnothrow = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5581 bool ispure = false;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5582 bool isproperty = false;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5583 TRUST trust = TRUSTdefault;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5584
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5585 if (token.value == TOK.TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5586 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5587 tt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5588 varargs = 0;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5589 arguments = new Parameters();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5590 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5591 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5592 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5593 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5594 tt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5595 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5596 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5597 tt = parseBasicType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5598 tt = parseBasicType2(tt); // function return type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5599 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5600 arguments = parseParameters(&varargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5601 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5602 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5603 if (token.value == TOK.TOKpure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5604 ispure = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5605 else if (token.value == TOK.TOKnothrow)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5606 isnothrow = true;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5607 else if (token.value == TOKat)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5608 {
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
5609 StorageClass stc = parseAttribute();
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5610 switch (cast(uint)(stc >> 32))
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5611 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5612 case STCproperty >> 32:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5613 isproperty = true;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5614 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5615 case STCsafe >> 32:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5616 trust = TRUSTsafe;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5617 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5618 case STCsystem >> 32:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5619 trust = TRUSTsystem;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5620 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5621 case STCtrusted >> 32:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5622 trust = TRUSTtrusted;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5623 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5624 case 0:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5625 break;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5626 default:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5627 assert(0);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5628 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5629 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5630 else
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5631 break;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5632 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5633 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5634 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5635
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5636 TypeFunction tf = new TypeFunction(arguments, tt, varargs, linkage);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5637 tf.ispure = ispure;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5638 tf.isnothrow = isnothrow;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5639 tf.isproperty = isproperty;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5640 tf.trust = trust;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5641 fd = new FuncLiteralDeclaration(loc, Loc(0), tf, save, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5642 parseContracts(fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5643 e = new FuncExp(loc, fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5644 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5645 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5646
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5647 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5648 error("expression expected, not '%s'", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5649 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5650 // Anything for e, as long as it's not null
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5651 e = new IntegerExp(loc, 0, Type.tint32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5652 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5653 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5654 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5655 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5656 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5657
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5658 Expression parseUnaryExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5659 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5660 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5661 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5662
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5663 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5664 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5665 case TOK.TOKand:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5666 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5667 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5668 e = new AddrExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5669 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5670
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5671 case TOK.TOKplusplus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5672 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5673 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5674 e = new AddAssignExp(loc, e, new IntegerExp(loc, 1, Type.tint32));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5675 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5676
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5677 case TOK.TOKminusminus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5678 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5679 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5680 e = new MinAssignExp(loc, e, new IntegerExp(loc, 1, Type.tint32));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5681 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5682
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5683 case TOK.TOKmul:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5684 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5685 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5686 e = new PtrExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5687 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5688
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5689 case TOK.TOKmin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5690 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5691 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5692 e = new NegExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5693 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5694
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5695 case TOK.TOKadd:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5696 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5697 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5698 e = new UAddExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5699 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5700
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5701 case TOK.TOKnot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5702 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5703 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5704 e = new NotExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5705 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5706
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5707 case TOK.TOKtilde:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5708 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5709 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5710 e = new ComExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5711 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5712
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5713 case TOK.TOKdelete:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5714 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5715 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5716 e = new DeleteExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5717 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5718
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5719 case TOK.TOKnew:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5720 e = parseNewExp(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5721 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5722
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5723 case TOK.TOKcast: // cast(type) expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5724 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5725 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5726 check(TOK.TOKlparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5727 /* Look for cast(), cast(const), cast(immutable),
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5728 * cast(shared), cast(shared const), cast(wild), cast(shared wild)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5729 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5730 MOD m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5731 if (token.value == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5732 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5733 m = MOD.MODundefined;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5734 goto Lmod1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5735 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5736 else if (token.value == TOK.TOKconst && peekNext() == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5737 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5738 m = MOD.MODconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5739 goto Lmod2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5740 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5741 else if ((token.value == TOK.TOKimmutable || token.value == TOK.TOKinvariant) && peekNext() == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5742 {
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5743 m = MOD.MODimmutable;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5744 goto Lmod2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5745 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5746 else if (token.value == TOK.TOKshared && peekNext() == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5747 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5748 m = MOD.MODshared;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5749 goto Lmod2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5750 }
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5751 else if (token.value == TOKwild && peekNext() == TOK.TOKrparen)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5752 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5753 m = MODwild;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5754 goto Lmod2;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5755 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5756 else if (token.value == TOKwild && peekNext() == TOK.TOKshared && peekNext2() == TOK.TOKrparen ||
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5757 token.value == TOK.TOKshared && peekNext() == TOKwild && peekNext2() == TOK.TOKrparen)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5758 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5759 m = MOD.MODshared | MOD.MODwild;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5760 goto Lmod3;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5761 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5762 else if (token.value == TOK.TOKconst && peekNext() == TOK.TOKshared && peekNext2() == TOK.TOKrparen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5763 token.value == TOK.TOKshared && peekNext() == TOK.TOKconst && peekNext2() == TOK.TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5764 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5765 m = MOD.MODshared | MOD.MODconst;
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5766 Lmod3:
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5767 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5768 Lmod2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5769 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5770 Lmod1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5771 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5772 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5773 e = new CastExp(loc, e, m);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5774 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5775 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5776 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5777 Type t = parseType(); // ( type )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5778 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5779 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5780 e = new CastExp(loc, e, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5781 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5782 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5783 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5784
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5785 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5786 { Token *tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5787
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5788 tk = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5789 version (CCASTSYNTAX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5790 // If cast
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5791 if (isDeclaration(tk, 0, TOK.TOKrparen, &tk))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5792 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5793 tk = peek(tk); // skip over right parenthesis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5794 switch (tk.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5795 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5796 case TOK.TOKnot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5797 tk = peek(tk);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5798 if (tk.value == TOK.TOKis) // !is
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5799 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5800 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5801 case TOK.TOKplusplus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5802 case TOK.TOKminusminus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5803 case TOK.TOKdelete:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5804 case TOK.TOKnew:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5805 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5806 case TOK.TOKidentifier:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5807 case TOK.TOKthis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5808 case TOK.TOKsuper:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5809 case TOK.TOKint32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5810 case TOK.TOKuns32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5811 case TOK.TOKint64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5812 case TOK.TOKuns64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5813 case TOK.TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5814 case TOK.TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5815 case TOK.TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5816 case TOK.TOKimaginary32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5817 case TOK.TOKimaginary64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5818 case TOK.TOKimaginary80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5819 case TOK.TOKnull:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5820 case TOK.TOKtrue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5821 case TOK.TOKfalse:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5822 case TOK.TOKcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5823 case TOK.TOKwcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5824 case TOK.TOKdcharv:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5825 case TOK.TOKstring:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5826 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5827 case TOK.TOKtilde:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5828 case TOK.TOKand:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5829 case TOK.TOKmul:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5830 case TOK.TOKmin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5831 case TOK.TOKadd:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5832 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5833 case TOK.TOKfunction:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5834 case TOK.TOKdelegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5835 case TOK.TOKtypeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5836 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5837 case TOK.TOKfile:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5838 case TOK.TOKline:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5839 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5840 case TOK.TOKwchar: case TOK.TOKdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5841 case TOK.TOKbit: case TOK.TOKbool: case TOK.TOKchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5842 case TOK.TOKint8: case TOK.TOKuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5843 case TOK.TOKint16: case TOK.TOKuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5844 case TOK.TOKint32: case TOK.TOKuns32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5845 case TOK.TOKint64: case TOK.TOKuns64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5846 case TOK.TOKfloat32: case TOK.TOKfloat64: case TOK.TOKfloat80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5847 case TOK.TOKimaginary32: case TOK.TOKimaginary64: case TOK.TOKimaginary80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5848 case TOK.TOKcomplex32: case TOK.TOKcomplex64: case TOK.TOKcomplex80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5849 case TOK.TOKvoid: // (type)int.size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5850 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5851 // (type) una_exp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5852 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5853 Type t = parseType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5854 check(TOK.TOKrparen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5855
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5856 // if .identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5857 if (token.value == TOK.TOKdot)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5858 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5859 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5860 if (token.value != TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5861 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5862 error("Identifier expected following (type).");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5863 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5864 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5865 e = typeDotIdExp(loc, t, token.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5866 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5867 e = parsePostExp(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5868 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5869 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5870 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5871 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5872 e = new CastExp(loc, e, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5873 error("C style cast illegal, use %s", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5874 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5875 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5876 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5877
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5878 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5879 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5880 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5881 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5882 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5883 e = parsePrimaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5884 e = parsePostExp(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5885 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5886 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5887 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5888 e = parsePrimaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5889 e = parsePostExp(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5890 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5891 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5892 assert(e);
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5893
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5894 // ^^ is right associative and has higher precedence than the unary operators
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5895 while (token.value == TOK.TOKpow)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5896 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5897 nextToken();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5898 Expression e2 = parseUnaryExp();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5899 e = new PowExp(loc, e, e2);
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5900 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
5901
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5902 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5903 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5904
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5905 Expression parsePostExp(Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5906 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5907 Loc loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5908
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5909 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5910 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5911 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5912 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5913 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5914 case TOK.TOKdot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5915 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5916 if (token.value == TOK.TOKidentifier)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5917 { Identifier id = token.ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5918
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5919 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5920 if (token.value == TOK.TOKnot && peekNext() != TOK.TOKis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5921 { // identifier!(template-argument-list)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5922 TemplateInstance tempinst = new TemplateInstance(loc, id);
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5923 Objects tiargs;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5924 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5925 if (token.value == TOK.TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5926 // ident!(template_arguments)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5927 tiargs = parseTemplateArgumentList();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5928 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5929 // ident!template_argument
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
5930 tiargs = parseTemplateArgument();
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
5931 e = new DotTemplateInstanceExp(loc, e, id, tiargs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5932 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5933 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5934 e = new DotIdExp(loc, e, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5935 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5936 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5937 else if (token.value == TOK.TOKnew)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5938 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5939 e = parseNewExp(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5940 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5941 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5942 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5943 error("identifier expected following '.', not '%s'", token.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5944 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5945
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5946 case TOK.TOKplusplus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5947 e = new PostExp(TOK.TOKplusplus, loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5948 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5949
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5950 case TOK.TOKminusminus:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5951 e = new PostExp(TOK.TOKminusminus, loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5952 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5953
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5954 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5955 e = new CallExp(loc, e, parseArguments());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5956 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5957
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5958 case TOK.TOKlbracket:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5959 { // array dereferences:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5960 // array[index]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5961 // array[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5962 // array[lwr .. upr]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5963 Expression index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5964 Expression upr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5965
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5966 inBrackets++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5967 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5968 if (token.value == TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5969 { // array[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5970 e = new SliceExp(loc, e, null, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5971 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5972 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5973 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5974 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5975 index = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5976 if (token.value == TOK.TOKslice)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5977 { // array[lwr .. upr]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5978 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5979 upr = parseAssignExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5980 e = new SliceExp(loc, e, index, upr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5981 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5982 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5983 { // array[index, i2, i3, i4, ...]
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
5984 auto arguments = new Expressions();
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
5985 arguments.push(index);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5986 if (token.value == TOK.TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5987 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5988 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5989 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5990 { Expression arg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5991
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5992 arg = parseAssignExp();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
5993 arguments.push(arg);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5994 if (token.value == TOK.TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5995 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5996 check(TOK.TOKcomma);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5997 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5998 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5999 e = new ArrayExp(loc, e, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6000 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6001 check(TOK.TOKrbracket);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6002 inBrackets--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6003 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6004 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6005 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6006
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6007 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6008 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6009 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6010 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6011 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6012
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6013 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6014 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6015
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6016 Expression parseMulExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6017 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6018 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6019 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6020 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6021
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6022 e = parseUnaryExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6023 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6024 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6025 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6026 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6027 case TOK.TOKmul: nextToken(); e2 = parseUnaryExp(); e = new MulExp(loc,e,e2); continue;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
6028 case TOK.TOKdiv: nextToken(); e2 = parseUnaryExp(); e = new DivExp(loc,e,e2); continue;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 128
diff changeset
6029 case TOK.TOKmod: nextToken(); e2 = parseUnaryExp(); e = new ModExp(loc,e,e2); continue;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6030
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6031 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6032 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6033 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6034 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6035 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6036 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6037 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6038
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6039 Expression parseShiftExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6040 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6041 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6042 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6043 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6044
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6045 e = parseAddExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6046 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6047 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6048 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6049 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6050 case TOK.TOKshl: nextToken(); e2 = parseAddExp(); e = new ShlExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6051 case TOK.TOKshr: nextToken(); e2 = parseAddExp(); e = new ShrExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6052 case TOK.TOKushr: nextToken(); e2 = parseAddExp(); e = new UshrExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6053
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6054 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6055 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6056 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6057 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6058 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6059 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6060 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6061
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6062 Expression parseAddExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6063 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6064 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6065 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6066 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6067
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6068 e = parseMulExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6069 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6070 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6071 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6072 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6073 case TOK.TOKadd: nextToken(); e2 = parseMulExp(); e = new AddExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6074 case TOK.TOKmin: nextToken(); e2 = parseMulExp(); e = new MinExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6075 case TOK.TOKtilde: nextToken(); e2 = parseMulExp(); e = new CatExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6076
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6077 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6078 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6079 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6080 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6081 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6082 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6083 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6084
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6085 Expression parseRelExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6086 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6087 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6088 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6089
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6090 Expression parseEqualExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6091 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6092 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6093 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6094
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6095 Expression parseCmpExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6096 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6097 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6098 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6099 Token* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6100 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6102 e = parseShiftExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6103 TOK op = token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6104
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6105 switch (op)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6106 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6107 case TOK.TOKequal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6108 case TOK.TOKnotequal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6109 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6110 e2 = parseShiftExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6111 e = new EqualExp(op, loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6112 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6114 case TOK.TOKis:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6115 op = TOK.TOKidentity;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6116 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6118 case TOK.TOKnot:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6119 // Attempt to identify '!is'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6120 t = peek(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6121 if (t.value != TOK.TOKis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6122 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6123 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6124 op = TOK.TOKnotidentity;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6125 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6127 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6128 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6129 e2 = parseShiftExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6130 e = new IdentityExp(op, loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6131 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6133 case TOK.TOKlt:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6134 case TOK.TOKle:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6135 case TOK.TOKgt:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6136 case TOK.TOKge:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6137 case TOK.TOKunord:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6138 case TOK.TOKlg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6139 case TOK.TOKleg:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6140 case TOK.TOKule:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6141 case TOK.TOKul:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6142 case TOK.TOKuge:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6143 case TOK.TOKug:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6144 case TOK.TOKue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6145 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6146 e2 = parseShiftExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6147 e = new CmpExp(op, loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6148 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6149
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6150 case TOK.TOKin:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6151 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6152 e2 = parseShiftExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6153 e = new InExp(loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6154 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6155
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6156 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6157 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6158 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6159 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6160 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6161
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6162 Expression parseAndExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6163 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6164 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6165 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6166 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6167
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6168 if (global.params.Dversion == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6169 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6170 e = parseEqualExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6171 while (token.value == TOK.TOKand)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6172 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6173 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6174 e2 = parseEqualExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6175 e = new AndExp(loc,e,e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6176 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6177 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6178 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6179 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6180 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6181 e = parseCmpExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6182 while (token.value == TOK.TOKand)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6183 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6184 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6185 e2 = parseCmpExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6186 e = new AndExp(loc,e,e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6187 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6188 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6189 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6190 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6191 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6192
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6193 Expression parseXorExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6194 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6195 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6196 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6197 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6198
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6199 e = parseAndExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6200 while (token.value == TOK.TOKxor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6201 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6202 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6203 e2 = parseAndExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6204 e = new XorExp(loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6206
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6207 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6208 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6209
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6210 Expression parseOrExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6211 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6212 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6213 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6214 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6215
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6216 e = parseXorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6217 while (token.value == TOK.TOKor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6218 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6219 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6220 e2 = parseXorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6221 e = new OrExp(loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6222 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6223 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6224 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6225
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6226 Expression parseAndAndExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6227 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6228 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6229 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6230 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6231
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6232 e = parseOrExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6233 while (token.value == TOK.TOKandand)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6234 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6235 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6236 e2 = parseOrExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6237 e = new AndAndExp(loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6238 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6239 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6240 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6241
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6242 Expression parseOrOrExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6243 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6244 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6245 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6246 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6247
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6248 e = parseAndAndExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6249 while (token.value == TOK.TOKoror)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6250 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6251 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6252 e2 = parseAndAndExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6253 e = new OrOrExp(loc, e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6254 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6255
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6256 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6257 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6258
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6259 Expression parseCondExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6260 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6261 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6262 Expression e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6263 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6264 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6265
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6266 e = parseOrOrExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6267 if (token.value == TOK.TOKquestion)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6268 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6269 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6270 e1 = parseExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6271 check(TOK.TOKcolon);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6272 e2 = parseCondExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6273 e = new CondExp(loc, e, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6274 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6275 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6277
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6278 Expression parseAssignExp()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6279 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6280 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6281 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6282 Loc loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6283
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6284 e = parseCondExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6285 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6286 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6287 loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6288 switch (token.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6289 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6290 case TOK.TOKassign: nextToken(); e2 = parseAssignExp(); e = new AssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6291 case TOK.TOKaddass: nextToken(); e2 = parseAssignExp(); e = new AddAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6292 case TOK.TOKminass: nextToken(); e2 = parseAssignExp(); e = new MinAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6293 case TOK.TOKmulass: nextToken(); e2 = parseAssignExp(); e = new MulAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6294 case TOK.TOKdivass: nextToken(); e2 = parseAssignExp(); e = new DivAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6295 case TOK.TOKmodass: nextToken(); e2 = parseAssignExp(); e = new ModAssignExp(loc,e,e2); continue;
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 132
diff changeset
6296 case TOK.TOKpowass: nextToken(); e2 = parseAssignExp(); e = new PowAssignExp(loc,e,e2); continue;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6297 case TOK.TOKandass: nextToken(); e2 = parseAssignExp(); e = new AndAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6298 case TOK.TOKorass: nextToken(); e2 = parseAssignExp(); e = new OrAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6299 case TOK.TOKxorass: nextToken(); e2 = parseAssignExp(); e = new XorAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6300 case TOK.TOKshlass: nextToken(); e2 = parseAssignExp(); e = new ShlAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6301 case TOK.TOKshrass: nextToken(); e2 = parseAssignExp(); e = new ShrAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6302 case TOK.TOKushrass: nextToken(); e2 = parseAssignExp(); e = new UshrAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6303 case TOK.TOKcatass: nextToken(); e2 = parseAssignExp(); e = new CatAssignExp(loc,e,e2); continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6304
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6305 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6306 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6307 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6308 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6310
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6311 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6312 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6313
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6314 /*************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6315 * Collect argument list.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6316 * Assume current token is ',', '(' or '['.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6317 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6318 Expressions parseArguments()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6319 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6320 // function call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6321 Expressions arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6322 Expression arg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6323 TOK endtok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6325 if (token.value == TOK.TOKlbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6326 endtok = TOK.TOKrbracket;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6327 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6328 endtok = TOK.TOKrparen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6329
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6330 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6331 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6332 if (token.value != endtok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6333 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6334 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6335 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6336 arg = parseAssignExp();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
6337 arguments.push(arg);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6338 if (token.value == endtok)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6339 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6340 check(TOK.TOKcomma);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6341 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6342 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6343 check(endtok);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6344 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6345 return arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6346 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6347
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6348 Expression parseNewExp(Expression thisexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6349 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6350 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6351 Expressions newargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6352 Expressions arguments = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6353 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6354 Loc loc = this.loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6355
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6356 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6357 newargs = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6358 if (token.value == TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6359 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6360 newargs = parseArguments();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6361 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6362
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6363 // An anonymous nested class starts with "class"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6364 if (token.value == TOKclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6365 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6366 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6367 if (token.value == TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6368 arguments = parseArguments();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6369
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6370 BaseClasses baseclasses = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6371 if (token.value != TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6372 baseclasses = parseBaseClasses();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6373
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6374 Identifier id = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6375 ClassDeclaration cd = new ClassDeclaration(loc, id, baseclasses);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6376
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6377 if (token.value != TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6378 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6379 error("{ members } expected for anonymous class");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6380 cd.members = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6381 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6382 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6383 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6384 nextToken();
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 56
diff changeset
6385 auto decl = parseDeclDefs(0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6386 if (token.value != TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6387 error("class member expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6388 nextToken();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6389 cd.members = decl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6390 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6391
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6392 e = new NewAnonClassExp(loc, thisexp, newargs, cd, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6393
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6394 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6395 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6396
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6397 t = parseBasicType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6398 t = parseBasicType2(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6399 if (t.ty == Taarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6400 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6401 TypeAArray taa = cast(TypeAArray)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6402 Type index = taa.index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6403
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6404 Expression e2 = index.toExpression();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6405 if (e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6406 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6407 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
6408 arguments.push(e2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6409 t = new TypeDArray(taa.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6410 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6411 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6412 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6413 error("need size of rightmost array, not type %s", index.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6414 return new NullExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6415 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6416 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6417 else if (t.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6418 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6419 TypeSArray tsa = cast(TypeSArray)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6420 Expression ee = tsa.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6421
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6422 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
6423 arguments.push(ee);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6424 t = new TypeDArray(tsa.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6425 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6426 else if (token.value == TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6427 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6428 arguments = parseArguments();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6429 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6430
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6431 e = new NewExp(loc, thisexp, newargs, t, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6432 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6433 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6434
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
6435 void addComment(Dsymbol s, const(char)[] blockComment)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6436 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6437 s.addComment(combineComments(blockComment, token.lineComment));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6438 token.lineComment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6439 }
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
6440 }