Mercurial > projects > dil
comparison trunk/src/dil/ast/Visitor.d @ 797:cf2ad5df025c
Added documentation comments.
Removed Lexer.loadKeywords() and revised Lexer.isReservedIdentifier().
Also removed Lexer.getTokens().
Renamed keywords to g_reservedIds.
Renamed classNames to g_classNames.
Added PRE and DMDBUG macros.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Fri, 29 Feb 2008 22:51:24 +0100 |
parents | 5e3ef1b2011c |
children |
comparison
equal
deleted
inserted
replaced
796:f7688996bf08 | 797:cf2ad5df025c |
---|---|
19 /// Expression visit(CommaExpression){return null;}; | 19 /// Expression visit(CommaExpression){return null;}; |
20 /// --- | 20 /// --- |
21 char[] generateVisitMethods() | 21 char[] generateVisitMethods() |
22 { | 22 { |
23 char[] text; | 23 char[] text; |
24 foreach (className; classNames) | 24 foreach (className; g_classNames) |
25 text ~= "returnType!(\""~className~"\") visit("~className~" node){return node;}\n"; | 25 text ~= "returnType!(\""~className~"\") visit("~className~" node){return node;}\n"; |
26 return text; | 26 return text; |
27 } | 27 } |
28 // pragma(msg, generateAbstractVisitMethods()); | 28 // pragma(msg, generateAbstractVisitMethods()); |
29 | 29 |
61 /// } | 61 /// } |
62 /// --- | 62 /// --- |
63 char[] generateDispatchFunctions() | 63 char[] generateDispatchFunctions() |
64 { | 64 { |
65 char[] text; | 65 char[] text; |
66 foreach (className; classNames) | 66 foreach (className; g_classNames) |
67 text ~= "returnType!(\""~className~"\") visit"~className~"(Visitor visitor, "~className~" c)\n" | 67 text ~= "returnType!(\""~className~"\") visit"~className~"(Visitor visitor, "~className~" c)\n" |
68 "{ return visitor.visit(c); }\n"; | 68 "{ return visitor.visit(c); }\n"; |
69 return text; | 69 return text; |
70 } | 70 } |
71 // pragma(msg, generateDispatchFunctions()); | 71 // pragma(msg, generateDispatchFunctions()); |
81 --- | 81 --- |
82 +/ | 82 +/ |
83 char[] generateVTable() | 83 char[] generateVTable() |
84 { | 84 { |
85 char[] text = "["; | 85 char[] text = "["; |
86 foreach (className; classNames) | 86 foreach (className; g_classNames) |
87 text ~= "cast(void*)&visit"~className~",\n"; | 87 text ~= "cast(void*)&visit"~className~",\n"; |
88 return text[0..$-2]~"]"; // slice away last ",\n" | 88 return text[0..$-2]~"]"; // slice away last ",\n" |
89 } | 89 } |
90 // pragma(msg, generateVTable()); | 90 // pragma(msg, generateVTable()); |
91 | 91 |
100 static | 100 static |
101 mixin(generateDispatchFunctions()); | 101 mixin(generateDispatchFunctions()); |
102 | 102 |
103 /// The table holding function pointers to the second dispatch functions. | 103 /// The table holding function pointers to the second dispatch functions. |
104 static const void*[] dispatch_vtable = mixin(generateVTable()); | 104 static const void*[] dispatch_vtable = mixin(generateVTable()); |
105 static assert(dispatch_vtable.length == classNames.length, "vtable length doesn't match number of classes"); | 105 static assert(dispatch_vtable.length == g_classNames.length, "vtable length doesn't match number of classes"); |
106 | 106 |
107 /// Looks up the second dispatch function for n and returns that. | 107 /// Looks up the second dispatch function for n and returns that. |
108 Node function(Visitor, Node) getDispatchFunction()(Node n) | 108 Node function(Visitor, Node) getDispatchFunction()(Node n) |
109 { | 109 { |
110 return cast(Node function(Visitor, Node))dispatch_vtable[n.kind]; | 110 return cast(Node function(Visitor, Node))dispatch_vtable[n.kind]; |