Commit 5a0b7f8e authored by Roberto Raggi's avatar Roberto Raggi

Added initializers to the formal arguments.

parent d20cdc64
......@@ -144,7 +144,7 @@ private:
originalArgument->name());
arg->setType(q->apply(originalArgument->type()));
arg->setInitializer(originalArgument->hasInitializer());
arg->setInitializer(originalArgument->initializer());
fun->arguments()->enterSymbol(arg);
}
......
......@@ -30,6 +30,7 @@
#include "Overview.h"
#include "TypePrettyPrinter.h"
#include <FullySpecifiedType.h>
#include <Literals.h>
#include <CoreTypes.h>
#include <Symbols.h>
#include <Scope.h>
......@@ -334,6 +335,11 @@ void TypePrettyPrinter::visit(Function *type)
_text += argumentText(arg->type(), name);
if (const StringLiteral *initializer = arg->initializer()) {
_text += QLatin1String(" =");
_text += QString::fromUtf8(initializer->chars(), initializer->size());
}
if (index + 1 == _overview->markedArgument())
const_cast<Overview*>(_overview)->setMarkedArgumentEnd(_text.length());
}
......
......@@ -56,6 +56,7 @@
#include "Symbols.h"
#include "Control.h"
#include "Literals.h"
#include <string>
#include <cassert>
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;
......
......@@ -426,7 +426,7 @@ bool CheckName::visit(ObjCMessageArgumentDeclarationAST *ast)
Argument *arg = control()->newArgument(ast->firstToken(), _name);
ast->argument = arg;
arg->setType(type);
arg->setInitializer(false);
arg->setInitializer(0);
_scope->enterSymbol(arg);
}
......
......@@ -128,17 +128,20 @@ void Declaration::visitSymbol0(SymbolVisitor *visitor)
Argument::Argument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
: Symbol(translationUnit, sourceLocation, name),
_initializer(false)
_initializer(0)
{ }
Argument::~Argument()
{ }
bool Argument::hasInitializer() const
{ return _initializer != 0; }
const StringLiteral *Argument::initializer() const
{ return _initializer; }
void Argument::setInitializer(bool hasInitializer)
{ _initializer = hasInitializer; }
void Argument::setInitializer(const StringLiteral *initializer)
{ _initializer = initializer; }
void Argument::setType(const FullySpecifiedType &type)
{ _type = type; }
......
......@@ -148,7 +148,9 @@ public:
void setType(const FullySpecifiedType &type);
bool hasInitializer() const;
void setInitializer(bool hasInitializer);
const StringLiteral *initializer() const;
void setInitializer(const StringLiteral *initializer);
// Symbol's interface
virtual FullySpecifiedType type() const;
......@@ -164,7 +166,7 @@ protected:
private:
FullySpecifiedType _type;
bool _initializer: 1;
const StringLiteral *_initializer;
};
class CPLUSPLUS_EXPORT ScopedSymbol: public Symbol
......
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