Mercurial > projects > dil
comparison trunk/src/dil/ast/DefaultVisitor.d @ 769:5e3ef1b2011c
Added and improved documentation.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sun, 17 Feb 2008 02:21:55 +0100 |
parents | 0af3b145a405 |
children | 3b34f6a95a27 |
comparison
equal
deleted
inserted
replaced
768:d84349a60f5c | 769:5e3ef1b2011c |
---|---|
12 dil.ast.Statements, | 12 dil.ast.Statements, |
13 dil.ast.Types, | 13 dil.ast.Types, |
14 dil.ast.Parameters; | 14 dil.ast.Parameters; |
15 import common; | 15 import common; |
16 | 16 |
17 /++ | 17 /// This huge template function, when instantiated for a certain node class, |
18 This huge template function, when instantiated for a certain node class, | 18 /// generates a body of calls to visit() on the subnodes. |
19 generates a body of visit method calls on the subnodes. | |
20 +/ | |
21 returnType!(T.stringof) visitDefault(T)(T t) | 19 returnType!(T.stringof) visitDefault(T)(T t) |
22 { | 20 { |
23 assert(t !is null, "node passed to visitDefault() is null"); | 21 assert(t !is null, "node passed to visitDefault() is null"); |
24 //Stdout(t).newline; | 22 //Stdout(t).newline; |
25 | 23 |
346 else | 344 else |
347 assert(0, "Missing default visit method for: "~t.classinfo.name); | 345 assert(0, "Missing default visit method for: "~t.classinfo.name); |
348 return t; | 346 return t; |
349 } | 347 } |
350 | 348 |
351 /++ | 349 /// Generates the default visit methods. |
352 Generate default visit methods. | 350 /// |
353 E.g: | 351 /// E.g: |
354 private mixin .visitDefault!(ClassDeclaration) _ClassDeclaration; | 352 /// --- |
355 override returnType!("ClassDeclaration") visit(ClassDeclaration node) | 353 /// private mixin .visitDefault!(ClassDeclaration) _ClassDeclaration; |
356 { return _ClassDeclaration.visitDefault(node); } | 354 /// override returnType!("ClassDeclaration") visit(ClassDeclaration node) |
357 +/ | 355 /// { return _ClassDeclaration.visitDefault(node); } |
356 /// --- | |
358 char[] generateDefaultVisitMethods() | 357 char[] generateDefaultVisitMethods() |
359 { | 358 { |
360 char[] text; | 359 char[] text; |
361 foreach (className; classNames) | 360 foreach (className; classNames) |
362 text ~= "private mixin .visitDefault!("~className~") _"~className~";\n" | 361 text ~= "private mixin .visitDefault!("~className~") _"~className~";\n" |
363 "override returnType!(\""~className~"\") visit("~className~" node){return _"~className~".visitDefault(node);}\n"; | 362 "override returnType!(\""~className~"\") visit("~className~" node){return _"~className~".visitDefault(node);}\n"; |
364 return text; | 363 return text; |
365 } | 364 } |
366 // pragma(msg, generateDefaultVisitMethods()); | 365 // pragma(msg, generateDefaultVisitMethods()); |
367 | 366 |
368 /++ | 367 /// This class provides default methods for traversing nodes in a syntax tree. |
369 This class provides default methods for traversing nodes in a syntax tree. | |
370 +/ | |
371 class DefaultVisitor : Visitor | 368 class DefaultVisitor : Visitor |
372 { | 369 { |
373 // Comment out if too many errors are shown. | 370 // Comment out if too many errors are shown. |
374 mixin(generateDefaultVisitMethods()); | 371 mixin(generateDefaultVisitMethods()); |
375 } | 372 } |