Skip to content

Commit

Permalink
add printAST()
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Oct 1, 2015
1 parent ae47818 commit e7a6820
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/expression.d
Expand Up @@ -2360,6 +2360,18 @@ public:
return buf.extractString();
}

/********************
* Print AST data structure in a nice format.
* Params:
* indent = indentation level
*/
void printAST(int indent = 0)
{
foreach (i; 0 .. indent)
printf(" ");
printf("%s %s\n", Token.toChars(op), type ? type.toChars() : "");
}

final void error(const(char)* format, ...)
{
if (type != Type.terror)
Expand Down Expand Up @@ -7092,6 +7104,12 @@ public:
{
v.visit(this);
}

override void printAST(int indent)
{
Expression.printAST(indent);
e1.printAST(indent + 2);
}
}

extern (C++) alias fp_t = UnionExp function(Loc loc, Type, Expression, Expression);
Expand Down Expand Up @@ -7393,6 +7411,13 @@ public:
{
v.visit(this);
}

override void printAST(int indent)
{
Expression.printAST(indent);
e1.printAST(indent + 2);
e2.printAST(indent + 2);
}
}

/***********************************************************
Expand Down
3 changes: 3 additions & 0 deletions src/expression.h
Expand Up @@ -143,6 +143,7 @@ class Expression : public RootObject

void print();
char *toChars();
virtual void printAST(int ident = 0);
void error(const char *format, ...);
void warning(const char *format, ...);
void deprecation(const char *format, ...);
Expand Down Expand Up @@ -741,6 +742,7 @@ class UnaExp : public Expression
Expression *resolveLoc(Loc loc, Scope *sc);

void accept(Visitor *v) { v->visit(this); }
void printAST(int ident);
};

typedef UnionExp (*fp_t)(Type *, Expression *, Expression *);
Expand Down Expand Up @@ -768,6 +770,7 @@ class BinExp : public Expression
Expression *reorderSettingAAElem(Scope *sc);

void accept(Visitor *v) { v->visit(this); }
void printAST(int ident);
};

class BinAssignExp : public BinExp
Expand Down

0 comments on commit e7a6820

Please sign in to comment.