From 5a0b7f8ec8376882bf2c1dc5a701fd813d8d827d Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 8 Dec 2009 11:34:22 +0100 Subject: Added initializers to the formal arguments. --- src/shared/cplusplus/CheckDeclaration.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/shared/cplusplus/CheckDeclaration.cpp') diff --git a/src/shared/cplusplus/CheckDeclaration.cpp b/src/shared/cplusplus/CheckDeclaration.cpp index 426a7d9de2..3349263e1e 100644 --- a/src/shared/cplusplus/CheckDeclaration.cpp +++ b/src/shared/cplusplus/CheckDeclaration.cpp @@ -56,6 +56,7 @@ #include "Symbols.h" #include "Control.h" #include "Literals.h" +#include #include using namespace CPlusPlus; @@ -419,8 +420,19 @@ bool CheckDeclaration::visit(ParameterDeclarationAST *ast) FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope); Argument *arg = control()->newArgument(sourceLocation, argName); ast->symbol = arg; - if (ast->expression) - arg->setInitializer(true); + if (ast->expression) { + unsigned startOfExpression = ast->expression->firstToken(); + unsigned endOfExpression = ast->expression->lastToken(); + std::string buffer; + for (unsigned index = startOfExpression; index != endOfExpression; ++index) { + const Token &tk = tokenAt(index); + if (tk.whitespace() || tk.newline()) + buffer += ' '; + buffer += tk.spell(); + } + const StringLiteral *initializer = control()->findOrInsertStringLiteral(buffer.c_str(), buffer.size()); + arg->setInitializer(initializer); + } arg->setType(argTy); _scope->enterSymbol(arg); return false; -- cgit v1.2.1