Some changes necessary for DCD

This commit is contained in:
Hackerpilot 2013-08-12 18:32:09 +00:00
parent 3e3052bd81
commit 0c8d894196
2 changed files with 69 additions and 15 deletions

View File

@ -18,6 +18,9 @@ module stdx.d.ast;
import stdx.d.lexer; import stdx.d.lexer;
import std.traits; import std.traits;
import std.algorithm;
import std.array;
import std.string;
// TODO: Many of these classes can be simplified by using std.variant.Algebraic // TODO: Many of these classes can be simplified by using std.variant.Algebraic
@ -886,6 +889,7 @@ public:
/** */ Constraint constraint; /** */ Constraint constraint;
/** */ MemberFunctionAttribute[] memberFunctionAttributes; /** */ MemberFunctionAttribute[] memberFunctionAttributes;
/** */ TemplateParameters templateParameters; /** */ TemplateParameters templateParameters;
/** */ size_t location;
} }
/// ///
@ -1083,6 +1087,16 @@ public:
mixin (visitIfNotNull!(enumMembers)); mixin (visitIfNotNull!(enumMembers));
} }
/** */ EnumMember[] enumMembers; /** */ EnumMember[] enumMembers;
/**
* Byte position of the opening brace
*/
size_t startLocation;
/**
* Byte position of the closing brace
*/
size_t endLocation;
} }
/// ///
@ -1878,6 +1892,20 @@ public:
{ {
mixin (visitIfNotNull!(type, name, default_)); mixin (visitIfNotNull!(type, name, default_));
} }
override string toString()
{
if (vararg)
return "...";
string rVal;
if (type !is null)
rVal = type.toString() ~ " ";
if (name.type != TokenType.invalid)
rVal ~= name.value;
rVal ~= parameterAttributes.map!(x => " " ~ getTokenValue(x)).join();
return rVal;
}
/** */ TokenType[] parameterAttributes; /** */ TokenType[] parameterAttributes;
/** */ Type type; /** */ Type type;
/** */ Token name; /** */ Token name;
@ -1893,6 +1921,13 @@ public:
{ {
mixin (visitIfNotNull!(parameters)); mixin (visitIfNotNull!(parameters));
} }
override string toString()
{
if (hasVarargs)
return "(...)";
return format("(%s)", parameters.map!"a.toString"().join(", ").array().idup);
}
/** */ Parameter[] parameters; /** */ Parameter[] parameters;
/** */ bool hasVarargs; /** */ bool hasVarargs;
} }

View File

@ -1434,8 +1434,10 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
Constructor parseConstructor() Constructor parseConstructor()
{ {
mixin(traceEnterAndExit!(__FUNCTION__)); mixin(traceEnterAndExit!(__FUNCTION__));
auto node = new Constructor; Constructor node = new Constructor;
if (expect(TokenType.this_) is null) return null; auto t = expect(TokenType.this_);
if (t is null) return null;
node.location = t.startIndex;
auto p = peekPastParens(); auto p = peekPastParens();
bool isTemplate = false; bool isTemplate = false;
if (p !is null && p.type == TokenType.lParen) if (p !is null && p.type == TokenType.lParen)
@ -1953,10 +1955,12 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
EnumBody parseEnumBody() EnumBody parseEnumBody()
{ {
mixin(traceEnterAndExit!(__FUNCTION__)); mixin(traceEnterAndExit!(__FUNCTION__));
auto node = new EnumBody; EnumBody node = new EnumBody;
if (!currentIs(TokenType.semicolon)) if (!currentIs(TokenType.semicolon))
{ {
expect (TokenType.lBrace); auto open = expect (TokenType.lBrace);
if (open is null) goto ret;
node.startLocation = open.startIndex;
while (moreTokens()) while (moreTokens())
{ {
if (!currentIsOneOf(TokenType.comma, TokenType.rBrace)) if (!currentIsOneOf(TokenType.comma, TokenType.rBrace))
@ -1974,7 +1978,9 @@ class ClassFour(A, B) if (someTest()) : Super {}}c;
goto ret; goto ret;
} }
} }
expect (TokenType.rBrace); auto close = expect (TokenType.rBrace);
if (close !is null)
node.endLocation = close.startIndex;
} }
ret: ret:
return node; return node;
@ -4532,10 +4538,16 @@ q{(int a, ...)
{ {
mixin(traceEnterAndExit!(__FUNCTION__)); mixin(traceEnterAndExit!(__FUNCTION__));
auto node = new StructBody; auto node = new StructBody;
node.startLocation = expect(TokenType.lBrace).startIndex; auto start = expect(TokenType.lBrace);
if (start !is null) node.startLocation = start.startIndex;
while (!currentIs(TokenType.rBrace) && moreTokens()) while (!currentIs(TokenType.rBrace) && moreTokens())
node.declarations ~= parseDeclaration(); {
node.endLocation = expect(TokenType.rBrace).startIndex; auto dec = parseDeclaration();
if (dec !is null)
node.declarations ~= dec;
}
auto end = expect(TokenType.rBrace);
if (end !is null) node.endLocation = end.startIndex;
return node; return node;
} }
@ -5902,6 +5914,19 @@ q{doStuff(5)}c;
*/ */
void function(string, int, int, string) messageFunction; void function(string, int, int, string) messageFunction;
bool isSliceExpression()
{
mixin(traceEnterAndExit!(__FUNCTION__));
if (startsWith(TokenType.lBracket, TokenType.rBracket))
return true;
return hasMagicDelimiter!(TokenType.slice)();
}
void setTokens(const(Token)[] tokens)
{
this.tokens = tokens;
}
private: private:
bool isCastQualifier() const bool isCastQualifier() const
@ -5926,13 +5951,7 @@ private:
return hasMagicDelimiter!(TokenType.colon)(); return hasMagicDelimiter!(TokenType.colon)();
} }
bool isSliceExpression()
{
mixin(traceEnterAndExit!(__FUNCTION__));
if (startsWith(TokenType.lBracket, TokenType.rBracket))
return true;
return hasMagicDelimiter!(TokenType.slice)();
}
bool hasMagicDelimiter(alias T)() bool hasMagicDelimiter(alias T)()
{ {