Changeset 176 for trunk/blade/SyntaxTree.d
- Timestamp:
- 01/16/08 05:01:53 (8 months ago)
- Files:
-
- trunk/blade/SyntaxTree.d (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/blade/SyntaxTree.d
r173 r176 62 62 { 63 63 char [][] symbols = replaceSymbolsWithPlaceholders(expression); 64 char [] result = `AbstractSyntaxTree(` ~ mixin_getPrecedence(expression) ~ `,[`;64 char [] result = `AbstractSyntaxTree(` ~ mixin_getPrecedence(expression) ~ `,[`; 65 65 66 66 for(int i=0; i<symbols.length; ++i) { 67 if (i>0) result ~= ",";67 if (i>0) result ~= ","; 68 68 result ~= `Symbol(` ~ mixin_typeOf(symbols[i]) 69 69 ~ `,` ~ mixin_valueOf(symbols[i]) … … 74 74 result ~="])"; 75 75 return `mixin("` ~ enquote(result) ~ `")`; 76 } 77 78 /** 79 * As for syntaxtreeof(), except that it creates a tuple as well as the abstract syntax tree 80 */ 81 char [] mixin_tupleAndSyntaxtreeof(char [] funcname, char [] expression) 82 { 83 char [][] symbols = replaceSymbolsWithPlaceholders(expression); 84 char [] result = `AbstractSyntaxTree(` ~ mixin_getPrecedence(expression) ~ `,[`; 85 char [] tuple; 86 87 for(int i=0; i<symbols.length; ++i) { 88 if (i>0) { 89 result ~= ","; 90 tuple ~= ","; 91 } 92 result ~= `Symbol(` ~ mixin_typeOf(symbols[i]) 93 ~ `,` ~ mixin_valueOf(symbols[i]) 94 ~ `,` ~ mixin_rankOf(symbols[i]) 95 ~ `,` ~ mixin_elementOf(symbols[i]) ~ `)`; 96 tuple ~= mixin_typeOfOrVoid(symbols[i]); 97 } 98 99 result ~="])"; 100 return funcname ~ `!(mixin("` ~ enquote(tuple) ~ `"))(mixin("` ~ enquote(result) ~ `"))`; 76 101 } 77 102 … … 314 339 } 315 340 341 char [] mixin_typeOfOrVoid(char [] sym) 342 { 343 // If sym is a function, we take its address, since 344 // typeof(x).stringof doesn't compile if x is a function. 345 // If sym doesn't compile at all, return "void". 346 return `mixin(!is(typeof(` ~ sym ~ `))?"\"void\"" : is(typeof(` ~ sym ~ `)==function)?"` ~ enquote("typeof(&" ~ sym ~ ").stringof")~`":"` ~ enquote("typeof(" ~ sym ~ ").stringof") ~ `")`; 347 } 348 316 349 // Returns sym.stringof, with workarounds for compiler bugs 317 350 char [] mixin_valueOf(char [] sym) … … 347 380 ~ s ~ `[0][0][0]":"` ~ s ~ `[0][0]":"` ~ s ~ `[0]":"` ~ s ~ `")`); 348 381 } 349 350 382 351 383 // ==== TESTS ==== … … 366 398 assert(mixin(mixin_getPrecedence("(A+B) in(C^D)"))=="(A+B)in(C^D)"); 367 399 assert(mixin(mixin_getPrecedence("A"))=="A"); 400 assert(mixin(mixin_getPrecedence("--A"))=="--A"); 401 // assert(mixin(mixin_getPrecedence("A--"))=="A--"); // BUG: fails 368 402 369 403 assert(mixin(mixin_getPrecedence("A[B,[C,D]]"))=="A[B,([C,D])]");
