comparison trunk/src/dil/Declarations.d @ 494:9a7ca8c56e59

Refactored a few things in the Parser. Removed unnecessary 'bool hasBody' parameter from some declarations. Added shebang to list of tokens in Lexer unittest. Added some semantic methods.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 07 Dec 2007 18:22:35 +0100
parents 9c208925a3d4
children b60450804b6e
comparison
equal deleted inserted replaced
493:d13502b6fa5f 494:9a7ca8c56e59
56 56
57 void opCatAssign(Declarations ds) 57 void opCatAssign(Declarations ds)
58 { 58 {
59 addChildren(ds.children); 59 addChildren(ds.children);
60 } 60 }
61
62 void semantic(Scope scop)
63 {
64 foreach (node; this.children)
65 {
66 assert(node.category == NodeCategory.Declaration);
67 (cast(Declaration)cast(void*)node).semantic(scop);
68 }
69 }
61 } 70 }
62 71
63 class EmptyDeclaration : Declaration 72 class EmptyDeclaration : Declaration
64 { 73 {
65 this() 74 this()
66 { 75 {
67 mixin(set_kind); 76 mixin(set_kind);
68 } 77 }
78
79 void semantic(Scope)
80 {}
69 } 81 }
70 82
71 class IllegalDeclaration : Declaration 83 class IllegalDeclaration : Declaration
72 { 84 {
73 Token* token; 85 Token* token;
74 this(Token* token) 86 this(Token* token)
75 { 87 {
76 mixin(set_kind); 88 mixin(set_kind);
77 this.token = token; 89 this.token = token;
78 } 90 }
91
92 void semantic(Scope)
93 {}
79 } 94 }
80 95
81 /// FQN = fully qualified name 96 /// FQN = fully qualified name
82 alias Token*[] ModuleFQN; // Identifier(.Identifier)* 97 alias Token*[] ModuleFQN; // Identifier(.Identifier)*
83 98
213 { 228 {
214 Token* name; 229 Token* name;
215 TemplateParameters tparams; 230 TemplateParameters tparams;
216 BaseClass[] bases; 231 BaseClass[] bases;
217 Declarations decls; 232 Declarations decls;
218 this(Token* name, TemplateParameters tparams, BaseClass[] bases, Declarations decls, bool hasBody) 233 this(Token* name, TemplateParameters tparams, BaseClass[] bases, Declarations decls)
219 { 234 {
220 super.hasBody = hasBody; 235 super.hasBody = decls !is null;
221 mixin(set_kind); 236 mixin(set_kind);
222 addOptChild(tparams); 237 addOptChild(tparams);
223 addOptChildren(bases); 238 addOptChildren(bases);
224 addOptChild(decls); 239 addOptChild(decls);
225 240
234 { 249 {
235 Token* name; 250 Token* name;
236 TemplateParameters tparams; 251 TemplateParameters tparams;
237 BaseClass[] bases; 252 BaseClass[] bases;
238 Declarations decls; 253 Declarations decls;
239 this(Token* name, TemplateParameters tparams, BaseClass[] bases, Declarations decls, bool hasBody) 254 this(Token* name, TemplateParameters tparams, BaseClass[] bases, Declarations decls)
240 { 255 {
241 super.hasBody = hasBody; 256 super.hasBody = decls !is null;
242 mixin(set_kind); 257 mixin(set_kind);
243 addOptChild(tparams); 258 addOptChild(tparams);
244 addOptChildren(bases); 259 addOptChildren(bases);
245 addOptChild(decls); 260 addOptChild(decls);
246 261
254 class StructDeclaration : Declaration 269 class StructDeclaration : Declaration
255 { 270 {
256 Token* name; 271 Token* name;
257 TemplateParameters tparams; 272 TemplateParameters tparams;
258 Declarations decls; 273 Declarations decls;
259 this(Token* name, TemplateParameters tparams, Declarations decls, bool hasBody) 274 this(Token* name, TemplateParameters tparams, Declarations decls)
260 { 275 {
261 super.hasBody = hasBody; 276 super.hasBody = decls !is null;
262 mixin(set_kind); 277 mixin(set_kind);
263 addOptChild(tparams); 278 addOptChild(tparams);
264 addOptChild(decls); 279 addOptChild(decls);
265 280
266 this.name = name; 281 this.name = name;
272 class UnionDeclaration : Declaration 287 class UnionDeclaration : Declaration
273 { 288 {
274 Token* name; 289 Token* name;
275 TemplateParameters tparams; 290 TemplateParameters tparams;
276 Declarations decls; 291 Declarations decls;
277 this(Token* name, TemplateParameters tparams, Declarations decls, bool hasBody) 292 this(Token* name, TemplateParameters tparams, Declarations decls)
278 { 293 {
279 super.hasBody = hasBody; 294 super.hasBody = decls !is null;
280 mixin(set_kind); 295 mixin(set_kind);
281 addOptChild(tparams); 296 addOptChild(tparams);
282 addOptChild(decls); 297 addOptChild(decls);
283 298
284 this.name = name; 299 this.name = name;
559 super.prot = prot; 574 super.prot = prot;
560 } 575 }
561 576
562 void semantic(Scope scop) 577 void semantic(Scope scop)
563 { 578 {
564 /+ 579 // auto saved_prot = scop.protection;
565 void traverse(Node[] nodes) 580 // scop.protection = this.prot;
566 { 581 // decls.semantic(scop);
567 foreach (node; nodes) 582 // scop.protection = saved_prot;
568 {
569 if (node.kind == NodeKind.ProtectionDeclaration)
570 break;
571 if (node.category == NodeCategory.Declaration)
572 {
573 auto decl = cast(Declaration)cast(void*)node;
574 decl.prot = this.prot;
575 if (node.children)
576 traverse(node.children);
577 }
578 }
579 }
580 traverse([this.decls]);
581 +/
582 } 583 }
583 } 584 }
584 585
585 class ExternDeclaration : AttributeDeclaration 586 class ExternDeclaration : AttributeDeclaration
586 { 587 {