Added location information to block statement and struct body

This commit is contained in:
Hackerpilot 2013-07-18 23:56:43 -07:00
parent 6e5742167a
commit 2ed0186eaa
2 changed files with 28 additions and 4 deletions

View File

@ -567,6 +567,17 @@ class BlockStatement : ASTNode
{
public:
mixin(DEFAULT_ACCEPT);
/**
* Byte position of the opening brace
*/
size_t startLocation;
/**
* Byte position of the closing brace
*/
size_t endLocation;
/** */ DeclarationsAndStatements declarationsAndStatements;
}
@ -1740,6 +1751,15 @@ class StructBody : ASTNode
{
public:
mixin(DEFAULT_ACCEPT);
/**
* Byte position of the opening brace
*/
size_t startLocation;
/**
* Byte position of the closing brace
*/
size_t endLocation;
/** */ Declaration[] declarations;
}

View File

@ -848,10 +848,14 @@ alias core.sys.posix.stdio.fileno fileno;
{
mixin(traceEnterAndExit!(__FUNCTION__));
auto node = new BlockStatement();
if (expect(TokenType.lBrace) is null) return null;
auto openBrace = expect(TokenType.lBrace);
if (openBrace is null) return null;
node.startLocation = openBrace.startIndex;
if (!currentIs(TokenType.rBrace))
node.declarationsAndStatements = parseDeclarationsAndStatements();
if (expect(TokenType.rBrace) is null) return null;
auto closeBrace = expect(TokenType.rBrace);
if (closeBrace is null) return null;
node.endLocation = closeBrace.startIndex;
return node;
}
@ -4539,10 +4543,10 @@ q{(int a, ...)
{
mixin(traceEnterAndExit!(__FUNCTION__));
auto node = new StructBody;
expect(TokenType.lBrace);
node.startLocation = expect(TokenType.lBrace).startIndex;
while (!currentIs(TokenType.rBrace) && moreTokens())
node.declarations ~= parseDeclaration();
expect(TokenType.rBrace);
node.endLocation = expect(TokenType.rBrace).startIndex;
return node;
}