diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2010-08-05 17:02:25 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-08-05 17:53:14 +0200 |
commit | 9aa991d6368f011e215a482c60add86f7f6277a2 (patch) | |
tree | 87242f692241f1d5bca27c60ee16fa8937f080c3 /src/shared/cplusplus | |
parent | 5f440364241f0d1caa00926097ea3a535526e8b0 (diff) | |
download | qt-creator-9aa991d6368f011e215a482c60add86f7f6277a2.tar.gz |
Refactored CPlusPlus::Function.
Diffstat (limited to 'src/shared/cplusplus')
-rw-r--r-- | src/shared/cplusplus/CheckDeclarator.cpp | 2 | ||||
-rw-r--r-- | src/shared/cplusplus/Scope.cpp | 12 | ||||
-rw-r--r-- | src/shared/cplusplus/Scope.h | 5 | ||||
-rw-r--r-- | src/shared/cplusplus/Semantic.cpp | 8 | ||||
-rw-r--r-- | src/shared/cplusplus/Symbols.cpp | 40 | ||||
-rw-r--r-- | src/shared/cplusplus/Symbols.h | 8 |
6 files changed, 38 insertions, 37 deletions
diff --git a/src/shared/cplusplus/CheckDeclarator.cpp b/src/shared/cplusplus/CheckDeclarator.cpp index 8fb80549e6..013f3a308c 100644 --- a/src/shared/cplusplus/CheckDeclarator.cpp +++ b/src/shared/cplusplus/CheckDeclarator.cpp @@ -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) diff --git a/src/shared/cplusplus/Scope.cpp b/src/shared/cplusplus/Scope.cpp index de0f147eb3..2b6b141856 100644 --- a/src/shared/cplusplus/Scope.cpp +++ b/src/shared/cplusplus/Scope.cpp @@ -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; } diff --git a/src/shared/cplusplus/Scope.h b/src/shared/cplusplus/Scope.h index 09eded9907..8c0bee69af 100644 --- a/src/shared/cplusplus/Scope.h +++ b/src/shared/cplusplus/Scope.h @@ -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; }; diff --git a/src/shared/cplusplus/Semantic.cpp b/src/shared/cplusplus/Semantic.cpp index 019852cc78..91cb68513f 100644 --- a/src/shared/cplusplus/Semantic.cpp +++ b/src/shared/cplusplus/Semantic.cpp @@ -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); diff --git a/src/shared/cplusplus/Symbols.cpp b/src/shared/cplusplus/Symbols.cpp index c1dcec44a4..2016d565ca 100644 --- a/src/shared/cplusplus/Symbols.cpp +++ b/src/shared/cplusplus/Symbols.cpp @@ -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); } diff --git a/src/shared/cplusplus/Symbols.h b/src/shared/cplusplus/Symbols.h index 0f5d8d8374..edf2d8e573 100644 --- a/src/shared/cplusplus/Symbols.h +++ b/src/shared/cplusplus/Symbols.h @@ -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 |