Skip to content

Commit befc696

Browse files
committed
macro function
1 parent 8a16c50 commit befc696

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

compiler/src/dmd/cparse.d

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5702,6 +5702,35 @@ final class CParser(AST) : Parser!AST
57025702
}
57035703
break;
57045704

5705+
case TOK.identifier:
5706+
{
5707+
const idx = id.toString();
5708+
auto ident = token.ident;
5709+
nextToken();
5710+
5711+
if (idx.length > 2 && idx[0] == '_' && idx[1] == '_')
5712+
{
5713+
++p;
5714+
continue;
5715+
}
5716+
5717+
/*
5718+
* macros refering to functions
5719+
* #define test func(2,3)
5720+
* where func has its definition elsewhere
5721+
* create a variable with a call expression initializer
5722+
*/
5723+
if (token.value == TOK.leftParenthesis)
5724+
{
5725+
auto call = new AST.CallExp(loc, new AST.IdentifierExp(loc, ident), cparseArguments());
5726+
auto var = new AST.VarDeclaration(loc, null, id, new AST.ExpInitializer(loc, call), STC.static_);
5727+
addSym(var);
5728+
5729+
++p;
5730+
continue;
5731+
}
5732+
break;
5733+
}
57055734
case TOK.leftParenthesis:
57065735
{
57075736
/* Look for:

0 commit comments

Comments
 (0)