Moved string formatting out of the AST classes
This commit is contained in:
parent
31548a6e6d
commit
2088089e36
|
@ -7,6 +7,8 @@ import stdx.d.lexer;
|
|||
import stdx.d.ast;
|
||||
import std.stdio;
|
||||
import std.string;
|
||||
import std.array;
|
||||
import formatter;
|
||||
|
||||
template tagAndAccept(string tagName)
|
||||
{
|
||||
|
@ -1285,7 +1287,10 @@ class XMLPrinter : ASTVisitor
|
|||
|
||||
override void visit(Type type)
|
||||
{
|
||||
output.writeln("<type pretty=\"", type.toString(), "\">");
|
||||
auto app = appender!string();
|
||||
auto formatter = new Formatter!(typeof(app))(app);
|
||||
formatter.format(type);
|
||||
output.writeln("<type pretty=\"", app.data, "\">");
|
||||
type.accept(this);
|
||||
output.writeln("</type>");
|
||||
}
|
||||
|
|
2
build.sh
2
build.sh
|
@ -1,5 +1,5 @@
|
|||
#dmd *.d stdx/d/*.d -release -inline -noboundscheck -O -w -wi -m64 -property -ofdscanner-dmd
|
||||
dmd main.d stats.d imports.d highlighter.d ctags.d astprinter.d stdx/d/*.d -g -m64 -wi -ofdscanner
|
||||
dmd main.d stats.d imports.d highlighter.d ctags.d astprinter.d formatter.d stdx/d/*.d -g -m64 -wi -ofdscanner
|
||||
#ldc2 -O3 *.d stdx/d/*.d -of=dscanner-ldc -release -m64
|
||||
#ldc2 *.d stdx/d/*.d -of=dscanner -unittest -m64 -g
|
||||
#/opt/gdc/bin/gdc -O3 -odscanner-gdc -fno-bounds-check -frelease -m64 *.d stdx/d/*.d
|
||||
|
|
112
stdx/d/ast.d
112
stdx/d/ast.d
|
@ -1370,19 +1370,6 @@ public:
|
|||
mixin (visitIfNotNull!(identifiersOrTemplateInstances));
|
||||
}
|
||||
|
||||
override string toString()
|
||||
{
|
||||
string rVal;
|
||||
bool first = true;
|
||||
foreach (iot; identifiersOrTemplateInstances)
|
||||
{
|
||||
if (!first)
|
||||
rVal ~= ".";
|
||||
first = true;
|
||||
rVal ~= iot.toString();
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
/** */ IdentifierOrTemplateInstance[] identifiersOrTemplateInstances;
|
||||
}
|
||||
|
||||
|
@ -1395,13 +1382,6 @@ public:
|
|||
mixin (visitIfNotNull!(identifier, templateInstance));
|
||||
}
|
||||
|
||||
override string toString()
|
||||
{
|
||||
if (identifier.type == TokenType.identifier)
|
||||
return identifier.value;
|
||||
else
|
||||
return templateInstance.toString();
|
||||
}
|
||||
/** */ Token identifier;
|
||||
/** */ TemplateInstance templateInstance;
|
||||
}
|
||||
|
@ -1897,19 +1877,6 @@ public:
|
|||
mixin (visitIfNotNull!(type, name, default_));
|
||||
}
|
||||
|
||||
override string toString()
|
||||
{
|
||||
string rVal;
|
||||
rVal ~= parameterAttributes.map!(x => " " ~ getTokenValue(x)).join();
|
||||
if (type !is null)
|
||||
rVal = type.toString();
|
||||
if (vararg)
|
||||
rVal ~= "...";
|
||||
if (name.type != TokenType.invalid)
|
||||
rVal ~= " " ~ name.value;
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/** */ TokenType[] parameterAttributes;
|
||||
/** */ Type type;
|
||||
/** */ Token name;
|
||||
|
@ -1926,12 +1893,6 @@ public:
|
|||
mixin (visitIfNotNull!(parameters));
|
||||
}
|
||||
|
||||
override string toString()
|
||||
{
|
||||
if (hasVarargs)
|
||||
return "(...)";
|
||||
return format("(%s)", parameters.map!"a.toString"().join(", ").array().idup);
|
||||
}
|
||||
/** */ Parameter[] parameters;
|
||||
/** */ bool hasVarargs;
|
||||
}
|
||||
|
@ -2313,13 +2274,6 @@ public:
|
|||
mixin (visitIfNotNull!(dot, identifierOrTemplateChain));
|
||||
}
|
||||
|
||||
override string toString()
|
||||
{
|
||||
if (dot != TokenType.invalid)
|
||||
return "." ~ identifierOrTemplateChain.toString();
|
||||
else
|
||||
return identifierOrTemplateChain.toString();
|
||||
}
|
||||
/** */ IdentifierOrTemplateChain identifierOrTemplateChain;
|
||||
/** */ Token dot;
|
||||
}
|
||||
|
@ -2598,27 +2552,6 @@ public:
|
|||
mixin (visitIfNotNull!(type2, typeSuffixes));
|
||||
}
|
||||
|
||||
override string toString()
|
||||
{
|
||||
string result;
|
||||
bool first = true;
|
||||
foreach (constructor; typeConstructors)
|
||||
{
|
||||
if (!first)
|
||||
result ~= " ";
|
||||
first = false;
|
||||
result ~= getTokenValue(constructor);
|
||||
}
|
||||
if (typeConstructors.length > 0)
|
||||
result ~= " ";
|
||||
result ~= type2.toString();
|
||||
foreach (suffix; typeSuffixes)
|
||||
{
|
||||
result ~= suffix.toString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** */ TokenType[] typeConstructors;
|
||||
/** */ TypeSuffix[] typeSuffixes;
|
||||
/** */ Type2 type2;
|
||||
|
@ -2634,23 +2567,6 @@ public:
|
|||
identifierOrTemplateChain, type));
|
||||
}
|
||||
|
||||
override string toString()
|
||||
{
|
||||
if (symbol !is null)
|
||||
{
|
||||
return symbol.toString();
|
||||
}
|
||||
else if (typeofExpression !is null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else if (typeConstructor != TokenType.invalid)
|
||||
{
|
||||
return getTokenValue(typeConstructor) ~ "(" ~ type.toString() ~ ")";
|
||||
}
|
||||
else
|
||||
return getTokenValue(builtinType);
|
||||
}
|
||||
/** */ TokenType builtinType;
|
||||
/** */ Symbol symbol;
|
||||
/** */ TypeofExpression typeofExpression;
|
||||
|
@ -2681,34 +2597,6 @@ public:
|
|||
memberFunctionAttributes));
|
||||
}
|
||||
|
||||
override string toString()
|
||||
{
|
||||
if (star)
|
||||
return "*";
|
||||
else if (array)
|
||||
{
|
||||
if (type is null)
|
||||
{
|
||||
if (low is null)
|
||||
return "[]";
|
||||
else
|
||||
{
|
||||
if (high is null)
|
||||
return "[" ~ low.toString() ~ "]";
|
||||
else
|
||||
return "[" ~ low.toString() ~ ".." ~ high.toString() ~ "]";
|
||||
}
|
||||
}
|
||||
else
|
||||
return "[" ~ type.toString() ~ "]";
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO
|
||||
return " " ~ delegateOrFunction.value ~ "()";
|
||||
}
|
||||
}
|
||||
|
||||
/** */ Token delegateOrFunction;
|
||||
/** */ bool star;
|
||||
/** */ bool array;
|
||||
|
|
Loading…
Reference in New Issue