mirror of
https://github.com/dlang-community/D-Scanner.git
synced 2025-04-27 22:00:17 +03:00
More AST classes can be printed as XML
This commit is contained in:
parent
4a9c8699a5
commit
c7424faf56
1 changed files with 777 additions and 414 deletions
407
astprinter.d
407
astprinter.d
|
@ -458,28 +458,105 @@ class XMLPrinter : ASTVisitor
|
|||
override void visit(ForStatement forStatement)
|
||||
{
|
||||
output.writeln("<forStatement>");
|
||||
// TODO
|
||||
forStatement.accept(this);
|
||||
output.writeln("<initialize>");
|
||||
visit(forStatement.declarationOrStatement);
|
||||
output.writeln("</initialize>");
|
||||
if (forStatement.test !is null)
|
||||
{
|
||||
output.writeln("<test>");
|
||||
visit(forStatement.test);
|
||||
output.writeln("</test>");
|
||||
}
|
||||
if (forStatement.increment !is null)
|
||||
{
|
||||
output.writeln("<increment>");
|
||||
visit(forStatement.increment);
|
||||
output.writeln("</increment>");
|
||||
}
|
||||
visit(forStatement.statementNoCaseNoDefault);
|
||||
output.writeln("</forStatement>");
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* BOOKMARK
|
||||
**************************************************************************/
|
||||
|
||||
override void visit(Module mod)
|
||||
override void visit(ForeachStatement foreachStatement)
|
||||
{
|
||||
output.writeln("<module>");
|
||||
mod.accept(this);
|
||||
output.writeln("</module>");
|
||||
output.writeln("<foreachStatement type=\"", getTokenValue(
|
||||
foreachStatement.foreachType), "\">");
|
||||
output.writeln("</foreachStatement>");
|
||||
}
|
||||
|
||||
override void visit(ModuleDeclaration modDec)
|
||||
override void visit(ForeachType foreachType)
|
||||
{
|
||||
output.writeln("<moduleDeclaration>");
|
||||
modDec.accept(this);
|
||||
output.writeln("</moduleDeclaration>");
|
||||
output.writeln("<foreachType>");
|
||||
foreach (constructor; foreachType.typeConstructors)
|
||||
{
|
||||
output.writeln("<typeConstructor>", getTokenValue(constructor), "</typeConstructor>");
|
||||
}
|
||||
if (foreachType.type !is null)
|
||||
visit(foreachType.type);
|
||||
visit(foreachType.identifier);
|
||||
output.writeln("</foreachType>");
|
||||
|
||||
}
|
||||
|
||||
override void visit(ForeachTypeList foreachTypeList)
|
||||
{
|
||||
mixin (tagAndAccept!"foreachTypeList");
|
||||
}
|
||||
|
||||
override void visit(FunctionAttribute functionAttribute)
|
||||
{
|
||||
mixin (tagAndAccept!"functionAttribute");
|
||||
}
|
||||
|
||||
override void visit(FunctionBody functionBody)
|
||||
{
|
||||
mixin (tagAndAccept!"functionBody");
|
||||
}
|
||||
|
||||
override void visit(FunctionCallExpression functionCallExpression)
|
||||
{
|
||||
mixin (tagAndAccept!"functionCallExpression");
|
||||
}
|
||||
|
||||
override void visit(FunctionCallStatement functionCallStatement)
|
||||
{
|
||||
mixin (tagAndAccept!"functionCallStatement");
|
||||
}
|
||||
|
||||
override void visit(FunctionDeclaration functionDec)
|
||||
{
|
||||
output.writeln("<functionDeclaration line=\"", functionDec.name.line, "\">");
|
||||
output.writeln("<name>", functionDec.name.value, "</name>");
|
||||
if (functionDec.hasAuto)
|
||||
output.writeln("<auto/>");
|
||||
if (functionDec.hasRef)
|
||||
output.writeln("<ref/>");
|
||||
functionDec.accept(this);
|
||||
output.writeln("</functionDeclaration>");
|
||||
}
|
||||
|
||||
override void visit(FunctionLiteralExpression functionLiteralExpression)
|
||||
{
|
||||
output.writeln("<functionLiteralExpression type=\"",
|
||||
getTokenValue(functionLiteralExpression.functionOrDelegate), "\">");
|
||||
functionLiteralExpression.accept(this);
|
||||
output.writeln("</functionLiteralExpression>");
|
||||
}
|
||||
|
||||
override void visit(GotoStatement gotoStatement)
|
||||
{
|
||||
if (gotoStatement.token.type == TokenType.default_)
|
||||
output.writeln("<gotoStatement default=\"true\"/>");
|
||||
else if (gotoStatement.token.type == TokenType.identifier)
|
||||
output.writeln("<gotoStatement label=\"", gotoStatement.token.value, "\">");
|
||||
else
|
||||
{
|
||||
output.writeln("<gotoStatement>");
|
||||
output.writeln("<case>");
|
||||
visit(gotoStatement.expression);
|
||||
output.writeln("</case>");
|
||||
output.writeln("</gotoStatement>");
|
||||
}
|
||||
}
|
||||
|
||||
override void visit(IdentifierChain chain)
|
||||
|
@ -496,17 +573,72 @@ class XMLPrinter : ASTVisitor
|
|||
output.writeln("</identifierList>");
|
||||
}
|
||||
|
||||
override void visit(FunctionBody functionBody)
|
||||
override void visit(IdentifierOrTemplateChain identifierOrTemplateChain)
|
||||
{
|
||||
mixin (tagAndAccept!"functionBody");
|
||||
mixin (tagAndAccept!"identifierOrTemplateChain");
|
||||
}
|
||||
|
||||
override void visit(FunctionDeclaration functionDec)
|
||||
override void visit(IdentifierOrTemplateInstance identifierOrTemplateInstance)
|
||||
{
|
||||
output.writeln("<functionDeclaration line=\"", functionDec.name.line, "\">");
|
||||
output.writeln("<name>", functionDec.name.value, "</name>");
|
||||
functionDec.accept(this);
|
||||
output.writeln("</functionDeclaration>");
|
||||
mixin (tagAndAccept!"identifierOrTemplateInstance");
|
||||
}
|
||||
|
||||
override void visit(IdentityExpression identityExpression)
|
||||
{
|
||||
if (identityExpression.negated)
|
||||
output.writeln("<identityExpression operator=\"!is\">");
|
||||
else
|
||||
output.writeln("<identityExpression operator=\"is\">");
|
||||
output.writeln("<left>");
|
||||
visit(identityExpression.left);
|
||||
output.writeln("</left>");
|
||||
output.writeln("<right>");
|
||||
visit(identityExpression.right);
|
||||
output.writeln("</right>");
|
||||
output.writeln("</identityExpression>");
|
||||
}
|
||||
|
||||
override void visit(IfStatement ifStatement)
|
||||
{
|
||||
output.writeln("<ifStatement>");
|
||||
|
||||
output.writeln("<condition>");
|
||||
if (ifStatement.identifier.type != TokenType.invalid)
|
||||
{
|
||||
if (ifStatement.type is null)
|
||||
output.writeln("<auto/>");
|
||||
else
|
||||
visit(ifStatement.type);
|
||||
visit(ifStatement.identifier);
|
||||
}
|
||||
visit(ifStatement.expression);
|
||||
output.writeln("</condition>");
|
||||
|
||||
output.writeln("<then>");
|
||||
visit(ifStatement.thenStatement);
|
||||
output.writeln("</then>");
|
||||
|
||||
if (ifStatement.elseStatement !is null)
|
||||
{
|
||||
output.writeln("<else>");
|
||||
visit(ifStatement.elseStatement);
|
||||
output.writeln("</else>");
|
||||
}
|
||||
output.writeln("</ifStatement>");
|
||||
}
|
||||
|
||||
override void visit(ImportBind importBind)
|
||||
{
|
||||
if (importBind.right.type == TokenType.invalid)
|
||||
output.writeln("<importBind symbol=\"", importBind.left, "\">");
|
||||
else
|
||||
output.writeln("<importBind symbol=\"", importBind.right,
|
||||
"\" rename=\"", importBind.left, "\">");
|
||||
}
|
||||
|
||||
override void visit(ImportBindings importBindings)
|
||||
{
|
||||
mixin (tagAndAccept!"importBindings");
|
||||
}
|
||||
|
||||
override void visit(ImportDeclaration importDeclaration)
|
||||
|
@ -514,6 +646,60 @@ class XMLPrinter : ASTVisitor
|
|||
mixin (tagAndAccept!"importDeclaration");
|
||||
}
|
||||
|
||||
override void visit(ImportExpression importExpression)
|
||||
{
|
||||
mixin (tagAndAccept!"importExpression");
|
||||
}
|
||||
|
||||
override void visit(IndexExpression indexExpression)
|
||||
{
|
||||
mixin (tagAndAccept!"indexExpression");
|
||||
}
|
||||
|
||||
override void visit(InExpression inExpression)
|
||||
{
|
||||
if (inExpression.negated)
|
||||
output.writeln("<inExpression operator=\"!in\">");
|
||||
else
|
||||
output.writeln("<inExpression operator=\"in\">");
|
||||
output.writeln("<left>");
|
||||
visit(inExpression.left);
|
||||
output.writeln("</left>");
|
||||
output.writeln("<right>");
|
||||
visit(inExpression.right);
|
||||
output.writeln("</right>");
|
||||
output.writeln("</inExpression>");
|
||||
}
|
||||
|
||||
override void visit(InStatement inStatement)
|
||||
{
|
||||
mixin (tagAndAccept!"inStatement");
|
||||
}
|
||||
|
||||
override void visit(Initialize initialize)
|
||||
{
|
||||
if (initialize.statementNoCaseNoDefault is null)
|
||||
output.writeln("<initialize/>");
|
||||
else
|
||||
{
|
||||
output.writeln("<initialize>");
|
||||
visit(initialize.statementNoCaseNoDefault);
|
||||
output.writeln("</initialize>");
|
||||
}
|
||||
}
|
||||
|
||||
override void visit(Initializer initializer)
|
||||
{
|
||||
if (initializer.nonVoidInitializer is null)
|
||||
output.writeln("<initializer void=\"true\"/>");
|
||||
else
|
||||
{
|
||||
output.writeln("<initializer>");
|
||||
visit(initializer.nonVoidInitializer);
|
||||
output.writeln("</initializer>");
|
||||
}
|
||||
}
|
||||
|
||||
override void visit(InterfaceDeclaration interfaceDec)
|
||||
{
|
||||
output.writeln("<interfaceDeclaration line=\"", interfaceDec.name.line, "\">");
|
||||
|
@ -522,6 +708,173 @@ class XMLPrinter : ASTVisitor
|
|||
output.writeln("</interfaceDeclaration>");
|
||||
}
|
||||
|
||||
override void visit(Invariant invariant_)
|
||||
{
|
||||
output.writeln("<invariant>");
|
||||
invariant_.accept(this);
|
||||
output.writeln("</invariant>");
|
||||
}
|
||||
|
||||
override void visit(IsExpression isExpression)
|
||||
{
|
||||
output.writeln("<isExpression>");
|
||||
visit(isExpression.type);
|
||||
if (isExpression.identifier.type != TokenType.invalid)
|
||||
visit(isExpression.identifier);
|
||||
if (isExpression.typeSpecialization !is null)
|
||||
{
|
||||
if (isExpression.equalsOrColon == TokenType.colon)
|
||||
output.writeln("<colon/>");
|
||||
else
|
||||
output.writeln("<equals/>");
|
||||
visit(isExpression.typeSpecialization);
|
||||
if (isExpression.templateParameterList !is null)
|
||||
visit(isExpression.templateParameterList);
|
||||
}
|
||||
output.writeln("</isExpression>");
|
||||
}
|
||||
|
||||
override void visit(KeyValuePair keyValuePair)
|
||||
{
|
||||
output.writeln("<keyValuePair>");
|
||||
output.writeln("<key>");
|
||||
visit(keyValuePair.key);
|
||||
output.writeln("</key>");
|
||||
output.writeln("<value>");
|
||||
visit(keyValuePair.value);
|
||||
output.writeln("<value>");
|
||||
output.writeln("</keyValuePair>");
|
||||
}
|
||||
|
||||
override void visit(KeyValuePairs keyValuePairs)
|
||||
{
|
||||
mixin (tagAndAccept!"keyValuePairs");
|
||||
}
|
||||
|
||||
override void visit (LabeledStatement labeledStatement)
|
||||
{
|
||||
output.writeln("<labeledStatement label=\"",
|
||||
labeledStatement.identifier.value ,"\">");
|
||||
visit(labeledStatement.declarationOrStatement);
|
||||
output.writeln("</labeledStatement>");
|
||||
}
|
||||
|
||||
override void visit(LambdaExpression lambdaExpression)
|
||||
{
|
||||
output.writeln("<lambdaExpression>");
|
||||
if (lambdaExpression.functionType == TokenType.function_)
|
||||
output.writeln("<function/>");
|
||||
if (lambdaExpression.functionType == TokenType.delegate_)
|
||||
output.writeln("<delegate/>");
|
||||
lambdaExpression.accept(this);
|
||||
output.writeln("</lambdaExpression>");
|
||||
}
|
||||
|
||||
override void visit(LastCatch lastCatch)
|
||||
{
|
||||
mixin (tagAndAccept!"lastCatch");
|
||||
}
|
||||
|
||||
override void visit(LinkageAttribute linkageAttribute)
|
||||
{
|
||||
if (linkageAttribute.hasPlusPlus)
|
||||
output.writeln("<linkageAttribute linkage=\"c++\"/>");
|
||||
else
|
||||
output.writeln("<linkageAttribute linkage=\"",
|
||||
linkageAttribute.identifier.value, "\"/>");
|
||||
}
|
||||
|
||||
override void visit(MemberFunctionAttribute memberFunctionAttribute)
|
||||
{
|
||||
output.writeln("<memberFunctionAttribute>");
|
||||
if (memberFunctionAttribute.atAttribute is null)
|
||||
output.writeln(getTokenValue(memberFunctionAttribute.tokenType));
|
||||
else
|
||||
memberFunctionAttribute.accept(this);
|
||||
output.writeln("</memberFunctionAttribute>");
|
||||
}
|
||||
|
||||
override void visit(MixinDeclaration mixinDeclaration)
|
||||
{
|
||||
mixin (tagAndAccept!"mixinDeclaration");
|
||||
}
|
||||
|
||||
override void visit(MixinExpression mixinExpression)
|
||||
{
|
||||
mixin (tagAndAccept!"mixinExpression");
|
||||
}
|
||||
|
||||
override void visit(MixinTemplateDeclaration mixinTemplateDeclaration)
|
||||
{
|
||||
mixin (tagAndAccept!"mixinTemplateDeclaration");
|
||||
}
|
||||
|
||||
override void visit(MixinTemplateName mixinTemplateName)
|
||||
{
|
||||
mixin (tagAndAccept!"mixinTemplateName");
|
||||
}
|
||||
|
||||
override void visit(Module module_)
|
||||
{
|
||||
output.writeln("<module>");
|
||||
module_.accept(this);
|
||||
output.writeln("</module>");
|
||||
}
|
||||
|
||||
override void visit(ModuleDeclaration moduleDeclaration)
|
||||
{
|
||||
mixin (tagAndAccept!"moduleDeclaration");
|
||||
}
|
||||
|
||||
override void visit(MulExpression mulExpression)
|
||||
{
|
||||
output.writeln("<mulExpression operator=\"", getTokenValue(mulExpression.operator) ,"\">");
|
||||
output.writeln("<left>");
|
||||
mulExpression.left.accept(this);
|
||||
output.writeln("</left>");
|
||||
if (mulExpression.right !is null)
|
||||
{
|
||||
output.writeln("<right>");
|
||||
mulExpression.right.accept(this);
|
||||
output.writeln("</right>");
|
||||
}
|
||||
output.writeln("</mulExpression>");
|
||||
}
|
||||
|
||||
override void visit(NewAnonClassExpression newAnonClassExpression)
|
||||
{
|
||||
mixin (tagAndAccept!"newAnonClassExpression");
|
||||
}
|
||||
|
||||
override void visit(NewExpression newExpression)
|
||||
{
|
||||
mixin (tagAndAccept!"newExpression");
|
||||
}
|
||||
|
||||
override void visit(StatementNoCaseNoDefault statementNoCaseNoDefault)
|
||||
{
|
||||
mixin (tagAndAccept!"statementNoCaseNoDefault");
|
||||
}
|
||||
|
||||
override void visit(NonVoidInitializer nonVoidInitializer)
|
||||
{
|
||||
mixin (tagAndAccept!"nonVoidInitializer");
|
||||
}
|
||||
|
||||
override void visit(OrExpression orExpression)
|
||||
{
|
||||
mixin(tagAndAccept!"orExpression");
|
||||
}
|
||||
|
||||
override void visit(OrExpression orOrExpression)
|
||||
{
|
||||
mixin(tagAndAccept!"orOrExpression");
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* BOOKMARK
|
||||
**************************************************************************/
|
||||
|
||||
override void visit(Parameters parameters)
|
||||
{
|
||||
mixin (tagAndAccept!"parameters");
|
||||
|
@ -542,6 +895,16 @@ class XMLPrinter : ASTVisitor
|
|||
output.writeln("</parameter>");
|
||||
}
|
||||
|
||||
override void visit(SingleImport singleImport)
|
||||
{
|
||||
if (singleImport.rename.type == TokenType.invalid)
|
||||
output.writeln("<singleImport>");
|
||||
else
|
||||
output.writeln("<singleImport rename=\"", singleImport.rename.value, "\">");
|
||||
visit(singleImport.identifierChain);
|
||||
output.writeln("</singleImport>");
|
||||
}
|
||||
|
||||
override void visit(StructDeclaration structDec)
|
||||
{
|
||||
output.writeln("<structDeclaration line=\"", structDec.name.line, "\">");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue