Commit af28f72e authored by Roberto Raggi's avatar Roberto Raggi

Store the default value of the formal argument in a string literal.

parent 89dba0e5
......@@ -56,6 +56,7 @@
#include "Literals.h"
#include "Scope.h"
#include <vector>
#include <string>
#include <memory>
#include <cassert>
......@@ -1696,6 +1697,20 @@ bool Bind::visit(ParameterDeclarationAST *ast)
Argument *arg = control()->newArgument(sourceLocation, argName);
arg->setType(type);
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()->stringLiteral(buffer.c_str(), buffer.size());
arg->setInitializer(initializer);
}
_scope->addMember(arg);
ast->symbol = arg;
......
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