Commit 37430df6 authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski Committed by Erik Verbruggen

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: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 46461fc1
......@@ -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();
}
......
......@@ -105,7 +105,8 @@ protected:
void capture(CaptureAST *ast);
void lambdaDeclarator(LambdaDeclaratorAST *ast);
FullySpecifiedType trailingReturnType(TrailingReturnTypeAST *ast, const FullySpecifiedType &init);
const StringLiteral *asStringLiteral(unsigned firstToken, unsigned lastToken);
const StringLiteral *asStringLiteral(unsigned firstToken, unsigned lastToken,
bool addWhitespace = true);
virtual bool preVisit(AST *);
virtual void postVisit(AST *);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment