Commit 9aa991d6 authored by Roberto Raggi's avatar Roberto Raggi Committed by Oswald Buddenhagen

Refactored CPlusPlus::Function.

parent 5f440364
......@@ -145,7 +145,7 @@ public:
newArg->setName(rewrite->rewriteName(arg->name()));
newArg->setType(rewrite->rewriteType(arg->type()));
funTy->arguments()->enterSymbol(newArg);
funTy->addMember(newArg);
}
temps.append(funTy);
......
......@@ -145,7 +145,7 @@ private:
arg->setType(q->apply(originalArgument->type()));
arg->setInitializer(originalArgument->initializer());
fun->arguments()->enterSymbol(arg);
fun->addMember(arg);
}
_type.setType(fun);
......
......@@ -282,7 +282,7 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const
} else if (scope->isFunctionScope()) {
Function *fun = scope->owner()->asFunction();
bindings()->lookupInScope(name, fun->arguments(), &candidates, /*templateId = */ 0, /*binding=*/ 0);
bindings()->lookupInScope(name, fun->members(), &candidates, /*templateId = */ 0, /*binding=*/ 0);
for (TemplateParameters *it = fun->templateParameters(); it && candidates.isEmpty(); it = it->previous())
bindings()->lookupInScope(name, it->scope(), &candidates, /* templateId = */ 0, /*binding=*/ 0);
......
......@@ -134,7 +134,7 @@ protected:
Function *fun = scope->owner()->asFunction();
if (findMember(fun->members(), ast, line, column))
return false;
else if (findMember(fun->arguments(), ast, line, column))
else if (findMember(fun->members(), ast, line, column))
return false;
} else if (scope->isObjCMethodScope()) {
ObjCMethod *method = scope->owner()->asObjCMethod();
......@@ -180,7 +180,7 @@ protected:
Function *fun = scope->owner()->asFunction();
if (findMember(fun->members(), ast, line, column))
return false;
else if (findMember(fun->arguments(), ast, line, column))
else if (fun->block() && findMember(fun->block()->members(), ast, line, column))
return false;
} else if (scope->isBlockScope()) {
if (findMember(scope, ast, line, column))
......
......@@ -1080,9 +1080,9 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope)
addCompletionItem(scope->symbolAt(i));
}
} else if (scope->isFunctionScope()) {
Scope *arguments = scope->owner()->asFunction()->arguments();
for (unsigned i = 0; i < arguments->symbolCount(); ++i) {
addCompletionItem(arguments->symbolAt(i));
Function *fun = scope->owner()->asFunction();
for (unsigned i = 0; i < fun->argumentCount(); ++i) {
addCompletionItem(fun->argumentAt(i));
}
break;
} else {
......
......@@ -175,7 +175,7 @@ bool CheckDeclarator::visit(FunctionDeclaratorAST *ast)
if (ast->parameters) {
DeclarationListAST *parameter_declarations = ast->parameters->parameter_declaration_list;
for (DeclarationListAST *decl = parameter_declarations; decl; decl = decl->next) {
semantic()->check(decl->value, fun->arguments());
semantic()->check(decl->value, fun->members());
}
if (ast->parameters->dot_dot_dot_token)
......
......@@ -58,9 +58,9 @@ using namespace CPlusPlus;
Scope::Scope(ScopedSymbol *owner)
: _owner(owner),
_symbols(0),
_hash(0),
_allocatedSymbols(0),
_symbolCount(-1),
_hash(0),
_hashSize(0),
_startOffset(0),
_endOffset(0)
......@@ -168,10 +168,7 @@ bool Scope::isBlockScope() const
bool Scope::isPrototypeScope() const
{
Function *f = 0;
if (_owner && 0 != (f = _owner->asFunction()))
return f->arguments() == this;
return false;
return isFunctionScope();
}
bool Scope::isObjCClassScope() const
......@@ -190,9 +187,8 @@ bool Scope::isObjCProtocolScope() const
bool Scope::isFunctionScope() const
{
Function *f = 0;
if (_owner && 0 != (f = _owner->asFunction()))
return f->arguments() != this;
if (_owner)
return _owner->isFunction();
return false;
}
......
......@@ -161,14 +161,11 @@ private:
enum { DefaultInitialSize = 11 };
ScopedSymbol *_owner;
Symbol **_symbols;
Symbol **_hash;
int _allocatedSymbols;
int _symbolCount;
Symbol **_hash;
int _hashSize;
unsigned _startOffset;
unsigned _endOffset;
};
......
......@@ -199,7 +199,13 @@ void Semantic::finishFunctionDefinition(FunctionDefinitionAST *ast)
Function *fun = ast->symbol;
d->checkDeclaration->check(ast->ctor_initializer, fun->scope());
check(ast->function_body, fun->members());
if (ast->function_body) {
check(ast->function_body, fun->members());
if (CompoundStatementAST *c = ast->function_body->asCompoundStatement())
fun->setBlock(c->symbol);
}
switchMethodKey(previousMethodKey);
switchVisibility(previousVisibility);
......
......@@ -191,14 +191,14 @@ void TypenameArgument::visitSymbol0(SymbolVisitor *visitor)
Function::Function(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
: ScopedSymbol(translationUnit, sourceLocation, name),
_templateParameters(0),
_flags(0)
{ _arguments = new Scope(this); }
_templateParameters(0),
_block(0),
_flags(0)
{ }
Function::~Function()
{
delete _templateParameters;
delete _arguments;
}
bool Function::isNormal() const
......@@ -219,6 +219,12 @@ int Function::methodKey() const
void Function::setMethodKey(int key)
{ f._methodKey = key; }
Block *Function::block() const
{ return _block; }
void Function::setBlock(Block *block)
{ _block = block; }
unsigned Function::templateParameterCount() const
{
if (! _templateParameters)
......@@ -255,13 +261,13 @@ bool Function::isEqualTo(const Type *other) const
const Name *l = identity();
const Name *r = o->identity();
if (l == r || (l && l->isEqualTo(r))) {
if (_arguments->symbolCount() != o->_arguments->symbolCount())
if (argumentCount() != o->argumentCount())
return false;
else if (! _returnType.isEqualTo(o->_returnType))
return false;
for (unsigned i = 0; i < _arguments->symbolCount(); ++i) {
Symbol *l = _arguments->symbolAt(i);
Symbol *r = o->_arguments->symbolAt(i);
for (unsigned i = 0; i < argumentCount(); ++i) {
Symbol *l = argumentAt(i);
Symbol *r = o->argumentAt(i);
if (! l->type().isEqualTo(r->type()))
return false;
}
......@@ -334,17 +340,14 @@ bool Function::hasReturnType() const
unsigned Function::argumentCount() const
{
if (! _arguments)
return 0;
if (_block)
return memberCount() - 1;
return _arguments->symbolCount();
return memberCount();
}
Symbol *Function::argumentAt(unsigned index) const
{ return _arguments->symbolAt(index); }
Scope *Function::arguments() const
{ return _arguments; }
{ return memberAt(index); }
bool Function::hasArguments() const
{
......@@ -356,8 +359,8 @@ unsigned Function::minimumArgumentCount() const
{
unsigned index = 0;
for (; index < _arguments->symbolCount(); ++index) {
if (Argument *arg = _arguments->symbolAt(index)->asArgument()) {
for (; index < argumentCount(); ++index) {
if (Argument *arg = argumentAt(index)->asArgument()) {
if (arg->hasInitializer())
break;
}
......@@ -405,9 +408,6 @@ void Function::setAmbiguous(bool isAmbiguous)
void Function::visitSymbol0(SymbolVisitor *visitor)
{
if (visitor->visit(this)) {
for (unsigned i = 0; i < _arguments->symbolCount(); ++i) {
visitSymbol(_arguments->symbolAt(i), visitor);
}
for (unsigned i = 0; i < memberCount(); ++i) {
visitSymbol(memberAt(i), visitor);
}
......
......@@ -342,6 +342,9 @@ public:
int methodKey() const;
void setMethodKey(int key);
Block *block() const;
void setBlock(Block *block);
unsigned templateParameterCount() const; // ### remove me
Symbol *templateParameterAt(unsigned index) const; // ### remove me
......@@ -356,7 +359,6 @@ public:
unsigned argumentCount() const;
Symbol *argumentAt(unsigned index) const;
Scope *arguments() const;
/** Convenience function that returns whether the function receives any arguments. */
bool hasArguments() const;
......@@ -408,8 +410,9 @@ protected:
virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const;
private:
TemplateParameters *_templateParameters;
FullySpecifiedType _returnType;
TemplateParameters *_templateParameters;
Block *_block;
struct Flags {
unsigned _isVirtual: 1;
unsigned _isVariadic: 1;
......@@ -423,7 +426,6 @@ private:
unsigned _flags;
Flags f;
};
Scope *_arguments;
};
class CPLUSPLUS_EXPORT Namespace: public ScopedSymbol, public Type
......
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