ASTPrinter

Traverses a Node tree and constructs a string representation.

Constructors

this
this(bool buildTokens, CompilationContext cc)

Constructs an ASTPrinter.

Members

Aliases

v
alias v = visitN

Shortcuts.

w
alias w = write

Shortcuts.

Classes

IndentLevel
class IndentLevel

Increases/decreases indentation on construction/destruction.

SetIndentLevel
class SetIndentLevel

Sets/restores indentation on construction/destruction.

UnindentLevel
class UnindentLevel

Decreases/increases indentation on construction/destruction.

Functions

Newline
Token* Newline()

Increments the line number and returns the newline token.

fixTokens
void fixTokens()

When the emitted text is complete, the pointers in the tokens are updated to point to the correct text fragments. (Considering the text buffer might get relocated when appending to it.)

getTplDecl
TemplateDecl getTplDecl()

Returns the currentTplDecl member and nulls it.

id
Token* id(Identifier* id)

Returns a Token for an Identifier.

ind
Token* ind()

Returns the current indentation as a token.

print
char[] print(Node n)

Starts the printer.

protToTOK
TOK protToTOK(PROT p)

Returns the token kind for p.

pushToken
void pushToken(TOK k, size_t start, size_t end, void* value)

Constructs a new Token with the given parameters and pushes to an array.

tokens
Token[] tokens()

Returns the tokens as a list.

write
void write(Token*[] ts...)

Writes a list of tokens.

write
void write(Expression n, PREC prec)

Writes an expression, wrapped in parentheses if necessary.

write
void write(Expression[] es)

Writes a comma-separated list of Expressions.

write
void write(BinaryExpr n)

Writes a binary expression.

write
void write(UnaryExpr n)

Writes a unary expression.

writeS
void writeS(cstring str)

Writes str to the text buffer.

writeSpan
void writeSpan(Token* b, Token* e)

Writes the tokens between b and e (inclusive.)

writeSpecDef
void writeSpecDef(Node s, Node d)

Writes specification and/or default values.

writeTParams
void writeTParams(TemplateDecl n)

Writes the template parameters and if-constraint of a TemplateDecl.

writeToken
void writeToken(Token* t)

Writes the contents of a token to the text.

ws
Token* ws(uint n)

Returns a new token containing 'n' number of whitespace characters.

ws
Token* ws()

Returns a new token containing a single whitespace character.

Variables

buildTokens
bool buildTokens;

True if the tokens should be built.

currentTplDecl
TemplateDecl currentTplDecl;

Set by a wrapping TemplateDecl.

indent
cstring indent;

The current indendation string.

indentStep
cstring indentStep;

The string used to increase the indentation level.

lineNum
uint_t lineNum;

Current line number.

nlToken
Token nlToken;

Provides a newline token (depends on the platform).

prevEnd
cchar* prevEnd;

End pointer of the previous token (t.end).

spaces
cstring spaces;

The current whitespace string.

tarray
TokenArray tarray;

The pre-built tokens of the text (Lexer not required.)

text
char[] text;

The printed text.

Inherited Members

From Visitor2

dispatch
void dispatch(Node n)

Calls the appropriate visit() method for a node.

dispatch
void dispatch(Node n, NodeKind k)

Allows calling the visit() method with a null node.

unhandled
void unhandled(Node n)

Called by visit() methods that were not overridden.

Meta