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

Added initializers to the formal arguments.

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