C++: fix constantValue for EnumeratorDeclaration

For the case:
const int x = 12;
enum E { e = x };

constantValue for EnumeratorDeclaration has value=' x'. It should have 'x'.

Change-Id: Iaca77cccd1e0dc5274696b0c96cec6ac2f904979
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Przemyslaw Gorszkowski
2013-07-10 22:21:44 +02:00
committed by Erik Verbruggen
parent 46461fc183
commit 37430df636
2 changed files with 6 additions and 4 deletions

View File

@@ -476,7 +476,7 @@ void Bind::enumerator(EnumeratorAST *ast, Enum *symbol)
e->setType(control()->integerType(IntegerType::Int)); // ### introduce IntegerType::Enumerator
if (ExpressionAST *expr = ast->expression)
e->setConstantValue(asStringLiteral(expr->firstToken(), expr->lastToken()));
e->setConstantValue(asStringLiteral(expr->firstToken(), expr->lastToken(), false));
symbol->addMember(e);
}
@@ -1137,12 +1137,13 @@ FullySpecifiedType Bind::trailingReturnType(TrailingReturnTypeAST *ast, const Fu
return type;
}
const StringLiteral *Bind::asStringLiteral(unsigned firstToken, unsigned lastToken)
const StringLiteral *Bind::asStringLiteral(unsigned firstToken, unsigned lastToken,
bool addWhitespace)
{
std::string buffer;
for (unsigned index = firstToken; index != lastToken; ++index) {
const Token &tk = tokenAt(index);
if (tk.whitespace() || tk.newline())
if (addWhitespace && (tk.whitespace() || tk.newline()))
buffer += ' ';
buffer += tk.spell();
}