diff --git a/src/shared/cplusplus/Array.h b/src/shared/cplusplus/Array.h index d749cbec81d..d8da74a0713 100644 --- a/src/shared/cplusplus/Array.h +++ b/src/shared/cplusplus/Array.h @@ -51,13 +51,11 @@ #include "CPlusPlusForwardDeclarations.h" #include -#include - namespace CPlusPlus { template -class Array +class CPLUSPLUS_EXPORT Array { Array(const Array &other); void operator =(const Array &other); diff --git a/src/shared/cplusplus/CPlusPlusForwardDeclarations.h b/src/shared/cplusplus/CPlusPlusForwardDeclarations.h index c21d0bbd0e3..9909493fd1a 100644 --- a/src/shared/cplusplus/CPlusPlusForwardDeclarations.h +++ b/src/shared/cplusplus/CPlusPlusForwardDeclarations.h @@ -49,6 +49,8 @@ #ifndef CPLUSPLUS_CPLUSPLUSFORWARDDECLARATIONS_H #define CPLUSPLUS_CPLUSPLUSFORWARDDECLARATIONS_H +#include + #ifndef CPLUSPLUS_WITHOUT_QT # include @@ -91,6 +93,7 @@ class QualifiedNameId; class SelectorNameId; // types +class TypeMatcher; class FullySpecifiedType; class TypeVisitor; class Type; diff --git a/src/shared/cplusplus/Control.cpp b/src/shared/cplusplus/Control.cpp index 4d36658e5ca..28365a62599 100644 --- a/src/shared/cplusplus/Control.cpp +++ b/src/shared/cplusplus/Control.cpp @@ -55,11 +55,9 @@ #include "Names.h" #include "Array.h" #include // ### replace me with LiteralTable -#include using namespace CPlusPlus; - template static void delete_map_entries(_Iterator first, _Iterator last) { @@ -639,7 +637,7 @@ Identifier *Control::findOrInsertIdentifier(const char *chars, unsigned size) Identifier *Control::findOrInsertIdentifier(const char *chars) { - unsigned length = std::char_traits::length(chars); + unsigned length = std::strlen(chars); return findOrInsertIdentifier(chars, length); } @@ -666,7 +664,7 @@ StringLiteral *Control::findOrInsertStringLiteral(const char *chars, unsigned si StringLiteral *Control::findOrInsertStringLiteral(const char *chars) { - unsigned length = std::char_traits::length(chars); + unsigned length = std::strlen(chars); return findOrInsertStringLiteral(chars, length); } @@ -675,7 +673,7 @@ NumericLiteral *Control::findOrInsertNumericLiteral(const char *chars, unsigned NumericLiteral *Control::findOrInsertNumericLiteral(const char *chars) { - unsigned length = std::char_traits::length(chars); + unsigned length = std::strlen(chars); return findOrInsertNumericLiteral(chars, length); } diff --git a/src/shared/cplusplus/CoreTypes.cpp b/src/shared/cplusplus/CoreTypes.cpp index 87f41bfcdde..ed9a9c00611 100644 --- a/src/shared/cplusplus/CoreTypes.cpp +++ b/src/shared/cplusplus/CoreTypes.cpp @@ -48,11 +48,30 @@ #include "CoreTypes.h" #include "TypeVisitor.h" +#include "TypeMatcher.h" #include "Names.h" #include using namespace CPlusPlus; +bool UndefinedType::isEqualTo(const Type *other) const +{ + if (other->isUndefinedType()) + return true; + + return false; +} + +void UndefinedType::accept0(TypeVisitor *visitor) +{ visitor->visit(this); } + +bool UndefinedType::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const UndefinedType *otherUndefinedTy = otherType->asUndefinedType()) + return matcher->match(this, otherUndefinedTy); + + return false; +} bool VoidType::isEqualTo(const Type *other) const { @@ -63,6 +82,14 @@ bool VoidType::isEqualTo(const Type *other) const void VoidType::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool VoidType::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const VoidType *otherVoidTy = otherType->asVoidType()) + return matcher->match(this, otherVoidTy); + + return false; +} + PointerToMemberType::PointerToMemberType(Name *memberName, FullySpecifiedType elementType) : _memberName(memberName), _elementType(elementType) @@ -90,6 +117,14 @@ bool PointerToMemberType::isEqualTo(const Type *other) const void PointerToMemberType::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool PointerToMemberType::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const PointerToMemberType *otherTy = otherType->asPointerToMemberType()) + return matcher->match(this, otherTy); + + return false; +} + PointerType::PointerType(const FullySpecifiedType &elementType) : _elementType(elementType) { } @@ -108,6 +143,14 @@ bool PointerType::isEqualTo(const Type *other) const void PointerType::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool PointerType::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const PointerType *otherTy = otherType->asPointerType()) + return matcher->match(this, otherTy); + + return false; +} + FullySpecifiedType PointerType::elementType() const { return _elementType; } @@ -129,6 +172,14 @@ bool ReferenceType::isEqualTo(const Type *other) const void ReferenceType::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool ReferenceType::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const ReferenceType *otherTy = otherType->asReferenceType()) + return matcher->match(this, otherTy); + + return false; +} + FullySpecifiedType ReferenceType::elementType() const { return _elementType; } @@ -150,6 +201,14 @@ bool IntegerType::isEqualTo(const Type *other) const void IntegerType::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool IntegerType::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const IntegerType *otherTy = otherType->asIntegerType()) + return matcher->match(this, otherTy); + + return false; +} + int IntegerType::kind() const { return _kind; } @@ -163,6 +222,14 @@ FloatType::~FloatType() void FloatType::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool FloatType::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const FloatType *otherTy = otherType->asFloatType()) + return matcher->match(this, otherTy); + + return false; +} + int FloatType::kind() const { return _kind; } @@ -194,6 +261,14 @@ bool ArrayType::isEqualTo(const Type *other) const void ArrayType::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool ArrayType::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const ArrayType *otherTy = otherType->asArrayType()) + return matcher->match(this, otherTy); + + return false; +} + FullySpecifiedType ArrayType::elementType() const { return _elementType; } @@ -230,4 +305,10 @@ bool NamedType::isEqualTo(const Type *other) const void NamedType::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool NamedType::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const NamedType *otherTy = otherType->asNamedType()) + return matcher->match(this, otherTy); + return false; +} diff --git a/src/shared/cplusplus/CoreTypes.h b/src/shared/cplusplus/CoreTypes.h index 2d03d878962..3e2470857a2 100644 --- a/src/shared/cplusplus/CoreTypes.h +++ b/src/shared/cplusplus/CoreTypes.h @@ -54,7 +54,6 @@ #include "FullySpecifiedType.h" #include - namespace CPlusPlus { class CPLUSPLUS_EXPORT UndefinedType : public Type @@ -66,12 +65,17 @@ public: return &t; } - virtual bool isEqualTo(const Type *other) const - { return this == other; } + virtual const UndefinedType *asUndefinedType() const + { return this; } + + virtual UndefinedType *asUndefinedType() + { return this; } + + virtual bool isEqualTo(const Type *other) const; protected: - virtual void accept0(TypeVisitor *) - { } + virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; }; class CPLUSPLUS_EXPORT VoidType: public Type @@ -87,6 +91,7 @@ public: protected: virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; }; class CPLUSPLUS_EXPORT IntegerType: public Type @@ -118,6 +123,7 @@ public: protected: virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: int _kind; @@ -148,6 +154,7 @@ public: protected: virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: int _kind; @@ -171,6 +178,7 @@ public: protected: virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: FullySpecifiedType _elementType; @@ -195,6 +203,7 @@ public: protected: virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: Name *_memberName; @@ -219,6 +228,7 @@ public: protected: virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: FullySpecifiedType _elementType; @@ -243,6 +253,7 @@ public: protected: virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: FullySpecifiedType _elementType; @@ -267,6 +278,7 @@ public: protected: virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: Name *_name; @@ -274,5 +286,4 @@ private: } // end of namespace CPlusPlus - #endif // CPLUSPLUS_CORETYPES_H diff --git a/src/shared/cplusplus/FullySpecifiedType.cpp b/src/shared/cplusplus/FullySpecifiedType.cpp index a9063fda67f..a1485db9fca 100644 --- a/src/shared/cplusplus/FullySpecifiedType.cpp +++ b/src/shared/cplusplus/FullySpecifiedType.cpp @@ -229,3 +229,10 @@ void FullySpecifiedType::copySpecifiers(const FullySpecifiedType &type) f._isExplicit = type.f._isExplicit; } +bool FullySpecifiedType::match(const FullySpecifiedType &otherTy, TypeMatcher *matcher) const +{ + if (_flags != otherTy._flags) + return false; + + return type()->matchType(otherTy.type(), matcher); +} diff --git a/src/shared/cplusplus/FullySpecifiedType.h b/src/shared/cplusplus/FullySpecifiedType.h index 5aea04dca18..a557f4e8398 100644 --- a/src/shared/cplusplus/FullySpecifiedType.h +++ b/src/shared/cplusplus/FullySpecifiedType.h @@ -119,6 +119,8 @@ public: bool operator != (const FullySpecifiedType &other) const; bool operator < (const FullySpecifiedType &other) const; + bool match(const FullySpecifiedType &otherTy, TypeMatcher *matcher) const; + FullySpecifiedType simplified() const; void copySpecifiers(const FullySpecifiedType &type); diff --git a/src/shared/cplusplus/Lexer.cpp b/src/shared/cplusplus/Lexer.cpp index f8f1b6f1339..8d806471f26 100644 --- a/src/shared/cplusplus/Lexer.cpp +++ b/src/shared/cplusplus/Lexer.cpp @@ -53,8 +53,6 @@ #include #include -using namespace std; - using namespace CPlusPlus; Lexer::Lexer(TranslationUnit *unit) diff --git a/src/shared/cplusplus/LiteralTable.h b/src/shared/cplusplus/LiteralTable.h index 52816a5682e..ff4246748f9 100644 --- a/src/shared/cplusplus/LiteralTable.h +++ b/src/shared/cplusplus/LiteralTable.h @@ -51,8 +51,6 @@ #include "CPlusPlusForwardDeclarations.h" #include -#include - namespace CPlusPlus { diff --git a/src/shared/cplusplus/Literals.cpp b/src/shared/cplusplus/Literals.cpp index 078c0702705..dd5acd25e0b 100644 --- a/src/shared/cplusplus/Literals.cpp +++ b/src/shared/cplusplus/Literals.cpp @@ -51,8 +51,6 @@ #include #include -using namespace std; - using namespace CPlusPlus; //////////////////////////////////////////////////////////////////////////////// @@ -61,9 +59,8 @@ Literal::Literal(const char *chars, unsigned size) { _chars = new char[size + 1]; - strncpy(_chars, chars, size); + std::strncpy(_chars, chars, size); _chars[size] = '\0'; - _size = size; _hashCode = hashCode(_chars, _size); @@ -82,7 +79,7 @@ bool Literal::isEqualTo(const Literal *other) const return false; else if (size() != other->size()) return false; - return ! strcmp(chars(), other->chars()); + return ! std::strcmp(chars(), other->chars()); } Literal::iterator Literal::begin() const diff --git a/src/shared/cplusplus/MemoryPool.cpp b/src/shared/cplusplus/MemoryPool.cpp index 1453c62cd69..4e0004f0a10 100644 --- a/src/shared/cplusplus/MemoryPool.cpp +++ b/src/shared/cplusplus/MemoryPool.cpp @@ -47,14 +47,11 @@ // THE SOFTWARE. #include "MemoryPool.h" -#include #include #include using namespace CPlusPlus; -using namespace std; - MemoryPool::MemoryPool() : _initializeAllocatedMemory(true), _blocks(0), @@ -68,12 +65,12 @@ MemoryPool::~MemoryPool() { if (_blockCount != -1) { for (int i = 0; i < _blockCount + 1; ++i) { - free(_blocks[i]); + std::free(_blocks[i]); } } if (_blocks) - free(_blocks); + std::free(_blocks); } bool MemoryPool::initializeAllocatedMemory() const @@ -98,9 +95,9 @@ void *MemoryPool::allocate_helper(size_t size) char *&block = _blocks[_blockCount]; if (_initializeAllocatedMemory) - block = (char *) calloc(1, BLOCK_SIZE); + block = (char *) std::calloc(1, BLOCK_SIZE); else - block = (char *) malloc(BLOCK_SIZE); + block = (char *) std::malloc(BLOCK_SIZE); ptr = block; end = ptr + BLOCK_SIZE; @@ -117,7 +114,7 @@ void MemoryPool::rewind(const State &state) { if (_blockCount == state.blockCount && state.ptr < ptr) { if (_initializeAllocatedMemory) - memset(state.ptr, '\0', ptr - state.ptr); + std::memset(state.ptr, '\0', ptr - state.ptr); ptr = state.ptr; } diff --git a/src/shared/cplusplus/MemoryPool.h b/src/shared/cplusplus/MemoryPool.h index 5b6fae925ff..2f7cb920af3 100644 --- a/src/shared/cplusplus/MemoryPool.h +++ b/src/shared/cplusplus/MemoryPool.h @@ -53,7 +53,6 @@ #include #include - namespace CPlusPlus { class CPLUSPLUS_EXPORT MemoryPool diff --git a/src/shared/cplusplus/Names.h b/src/shared/cplusplus/Names.h index 1dd475774ff..a30bffb0135 100644 --- a/src/shared/cplusplus/Names.h +++ b/src/shared/cplusplus/Names.h @@ -53,7 +53,6 @@ #include "Name.h" #include "FullySpecifiedType.h" - namespace CPlusPlus { class CPLUSPLUS_EXPORT QualifiedNameId: public Name diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp index 7bcbfdc34d2..7e464b7d8ba 100644 --- a/src/shared/cplusplus/Parser.cpp +++ b/src/shared/cplusplus/Parser.cpp @@ -53,11 +53,7 @@ #include "AST.h" #include "Literals.h" #include "ObjectiveCTypeQualifiers.h" -#include -#include -#include -#include -#include +#include // for putchar #define CPLUSPLUS_NO_DEBUG_RULE @@ -72,7 +68,13 @@ class DebugRule { public: DebugRule(const char *name) : name(name) - { std::cout << std::string(depth++, ' ') << name << std::endl; } + { + for (int i = 0; i < depth; ++i) + putchar(' '); + + ++depth; + printf("%s\n", name); + } ~DebugRule() { --depth; } diff --git a/src/shared/cplusplus/Scope.cpp b/src/shared/cplusplus/Scope.cpp index 2c4eea10f71..0a7dd294d49 100644 --- a/src/shared/cplusplus/Scope.cpp +++ b/src/shared/cplusplus/Scope.cpp @@ -50,12 +50,8 @@ #include "Symbols.h" #include "Names.h" #include "Literals.h" -#include #include #include -#include - -using namespace std; using namespace CPlusPlus; @@ -278,7 +274,7 @@ void Scope::rehash() _hashSize = DefaultInitialSize; _hash = reinterpret_cast(realloc(_hash, sizeof(Symbol *) * _hashSize)); - memset(_hash, 0, sizeof(Symbol *) * _hashSize); + std::memset(_hash, 0, sizeof(Symbol *) * _hashSize); for (int index = 0; index < _symbolCount + 1; ++index) { Symbol *symbol = _symbols[index]; diff --git a/src/shared/cplusplus/Symbols.cpp b/src/shared/cplusplus/Symbols.cpp index 8ee8572d9b8..8c044ef03ca 100644 --- a/src/shared/cplusplus/Symbols.cpp +++ b/src/shared/cplusplus/Symbols.cpp @@ -50,8 +50,8 @@ #include "Names.h" #include "TypeVisitor.h" #include "SymbolVisitor.h" +#include "TypeMatcher.h" #include "Scope.h" -#include using namespace CPlusPlus; @@ -224,6 +224,14 @@ bool Function::isEqualTo(const Type *other) const void Function::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool Function::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const Function *otherTy = otherType->asFunctionType()) + return matcher->match(this, otherTy); + + return false; +} + FullySpecifiedType Function::type() const { return FullySpecifiedType(const_cast(this)); } @@ -380,6 +388,14 @@ bool Enum::isEqualTo(const Type *other) const void Enum::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool Enum::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const Enum *otherTy = otherType->asEnumType()) + return matcher->match(this, otherTy); + + return false; +} + void Enum::visitSymbol0(SymbolVisitor *visitor) { if (visitor->visit(this)) { @@ -411,6 +427,14 @@ bool Namespace::isEqualTo(const Type *other) const void Namespace::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool Namespace::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const Namespace *otherTy = otherType->asNamespaceType()) + return matcher->match(this, otherTy); + + return false; +} + void Namespace::visitSymbol0(SymbolVisitor *visitor) { if (visitor->visit(this)) { @@ -480,6 +504,14 @@ void ForwardClassDeclaration::visitSymbol0(SymbolVisitor *visitor) void ForwardClassDeclaration::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool ForwardClassDeclaration::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const ForwardClassDeclaration *otherTy = otherType->asForwardClassDeclarationType()) + return matcher->match(this, otherTy); + + return false; +} + Class::Class(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name) : ScopedSymbol(translationUnit, sourceLocation, name), _key(ClassKey), @@ -524,6 +556,14 @@ void Class::setTemplateParameters(TemplateParameters *templateParameters) void Class::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool Class::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const Class *otherTy = otherType->asClassType()) + return matcher->match(this, otherTy); + + return false; +} + unsigned Class::baseClassCount() const { return _baseClasses.count(); } @@ -632,6 +672,14 @@ void ObjCClass::visitSymbol0(SymbolVisitor *visitor) void ObjCClass::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool ObjCClass::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const ObjCClass *otherTy = otherType->asObjCClassType()) + return matcher->match(this, otherTy); + + return false; +} + ObjCProtocol::ObjCProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name): ScopedSymbol(translationUnit, sourceLocation, name) { @@ -668,6 +716,14 @@ void ObjCProtocol::visitSymbol0(SymbolVisitor *visitor) void ObjCProtocol::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool ObjCProtocol::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const ObjCProtocol *otherTy = otherType->asObjCProtocolType()) + return matcher->match(this, otherTy); + + return false; +} + ObjCForwardClassDeclaration::ObjCForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name): Symbol(translationUnit, sourceLocation, name) { @@ -699,6 +755,14 @@ void ObjCForwardClassDeclaration::visitSymbol0(SymbolVisitor *visitor) void ObjCForwardClassDeclaration::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool ObjCForwardClassDeclaration::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const ObjCForwardClassDeclaration *otherTy = otherType->asObjCForwardClassDeclarationType()) + return matcher->match(this, otherTy); + + return false; +} + ObjCForwardProtocolDeclaration::ObjCForwardProtocolDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name): Symbol(translationUnit, sourceLocation, name) { @@ -730,6 +794,14 @@ void ObjCForwardProtocolDeclaration::visitSymbol0(SymbolVisitor *visitor) void ObjCForwardProtocolDeclaration::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool ObjCForwardProtocolDeclaration::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const ObjCForwardProtocolDeclaration *otherTy = otherType->asObjCForwardProtocolDeclarationType()) + return matcher->match(this, otherTy); + + return false; +} + ObjCMethod::ObjCMethod(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name) : ScopedSymbol(translationUnit, sourceLocation, name), _flags(0) @@ -767,6 +839,14 @@ bool ObjCMethod::isEqualTo(const Type *other) const void ObjCMethod::accept0(TypeVisitor *visitor) { visitor->visit(this); } +bool ObjCMethod::matchType0(const Type *otherType, TypeMatcher *matcher) const +{ + if (const ObjCMethod *otherTy = otherType->asObjCMethodType()) + return matcher->match(this, otherTy); + + return false; +} + FullySpecifiedType ObjCMethod::type() const { return FullySpecifiedType(const_cast(this)); } diff --git a/src/shared/cplusplus/Symbols.h b/src/shared/cplusplus/Symbols.h index 85d720dfc61..022846d3c02 100644 --- a/src/shared/cplusplus/Symbols.h +++ b/src/shared/cplusplus/Symbols.h @@ -235,6 +235,7 @@ public: protected: virtual void visitSymbol0(SymbolVisitor *visitor); virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: TemplateParameters *_templateParameters; @@ -267,6 +268,7 @@ public: protected: virtual void visitSymbol0(SymbolVisitor *visitor); virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; }; class CPLUSPLUS_EXPORT Function: public ScopedSymbol, public Type @@ -346,6 +348,7 @@ public: protected: virtual void visitSymbol0(SymbolVisitor *visitor); virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: TemplateParameters *_templateParameters; @@ -393,6 +396,7 @@ public: protected: virtual void visitSymbol0(SymbolVisitor *visitor); virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; }; class CPLUSPLUS_EXPORT BaseClass: public Symbol @@ -469,6 +473,7 @@ public: protected: virtual void visitSymbol0(SymbolVisitor *visitor); virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: Key _key; @@ -543,6 +548,7 @@ public: protected: virtual void visitSymbol0(SymbolVisitor *visitor); virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: }; @@ -583,6 +589,7 @@ public: protected: virtual void visitSymbol0(SymbolVisitor *visitor); virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: Array _protocols; @@ -613,6 +620,7 @@ public: protected: virtual void visitSymbol0(SymbolVisitor *visitor); virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: }; @@ -665,6 +673,7 @@ public: protected: virtual void visitSymbol0(SymbolVisitor *visitor); virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: bool _isInterface; @@ -716,6 +725,7 @@ public: protected: virtual void visitSymbol0(SymbolVisitor *visitor); virtual void accept0(TypeVisitor *visitor); + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; private: FullySpecifiedType _returnType; diff --git a/src/shared/cplusplus/TranslationUnit.cpp b/src/shared/cplusplus/TranslationUnit.cpp index 0cecccf3199..92f2bfb5ce5 100644 --- a/src/shared/cplusplus/TranslationUnit.cpp +++ b/src/shared/cplusplus/TranslationUnit.cpp @@ -55,12 +55,9 @@ #include "Literals.h" #include "DiagnosticClient.h" #include -#include #include #include -using namespace std; - using namespace CPlusPlus; TranslationUnit::TranslationUnit(Control *control, StringLiteral *fileId) diff --git a/src/shared/cplusplus/Type.cpp b/src/shared/cplusplus/Type.cpp index 56a521cd85a..9d5d5f6ed3c 100644 --- a/src/shared/cplusplus/Type.cpp +++ b/src/shared/cplusplus/Type.cpp @@ -131,4 +131,8 @@ void Type::accept(Type *type, TypeVisitor *visitor) type->accept(visitor); } +bool Type::matchType(const Type *otherType, TypeMatcher *matcher) const +{ + return matchType0(otherType, matcher); +} diff --git a/src/shared/cplusplus/Type.h b/src/shared/cplusplus/Type.h index 82dfa1f63a2..a2e29bf56c0 100644 --- a/src/shared/cplusplus/Type.h +++ b/src/shared/cplusplus/Type.h @@ -51,7 +51,6 @@ #include "CPlusPlusForwardDeclarations.h" - namespace CPlusPlus { class CPLUSPLUS_EXPORT Type @@ -83,6 +82,7 @@ public: bool isObjCForwardClassDeclarationType() const; bool isObjCForwardProtocolDeclarationType() const; + virtual const UndefinedType *asUndefinedType() const { return 0; } virtual const VoidType *asVoidType() const { return 0; } virtual const IntegerType *asIntegerType() const { return 0; } virtual const FloatType *asFloatType() const { return 0; } @@ -102,6 +102,7 @@ public: virtual const ObjCForwardClassDeclaration *asObjCForwardClassDeclarationType() const { return 0; } virtual const ObjCForwardProtocolDeclaration *asObjCForwardProtocolDeclarationType() const { return 0; } + virtual UndefinedType *asUndefinedType() { return 0; } virtual VoidType *asVoidType() { return 0; } virtual IntegerType *asIntegerType() { return 0; } virtual FloatType *asFloatType() { return 0; } @@ -124,10 +125,21 @@ public: void accept(TypeVisitor *visitor); static void accept(Type *type, TypeVisitor *visitor); - virtual bool isEqualTo(const Type *other) const = 0; + static bool matchType(const Type *type, const Type *otherType, TypeMatcher *matcher) + { + if (! type) + return type == otherType; + + return type->matchType(otherType, matcher); + } + + bool matchType(const Type *otherType, TypeMatcher *matcher) const; + + virtual bool isEqualTo(const Type *other) const = 0; // ### remove protected: virtual void accept0(TypeVisitor *visitor) = 0; + virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const = 0; }; } // end of namespace CPlusPlus diff --git a/src/shared/cplusplus/TypeMatcher.cpp b/src/shared/cplusplus/TypeMatcher.cpp new file mode 100644 index 00000000000..a03ac98afeb --- /dev/null +++ b/src/shared/cplusplus/TypeMatcher.cpp @@ -0,0 +1,225 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "TypeMatcher.h" +#include "CoreTypes.h" +#include "Symbols.h" +#include "Names.h" +#include "Literals.h" + +using namespace CPlusPlus; + +TypeMatcher::TypeMatcher() +{ +} + +TypeMatcher::~TypeMatcher() +{ +} + +bool TypeMatcher::isEqualTo(const Name *name, const Name *otherName) const +{ + if (! name || ! otherName) + return name == otherName; + + return name->isEqualTo(otherName); +} + +bool TypeMatcher::match(const UndefinedType *, const UndefinedType *) +{ + return true; +} + +bool TypeMatcher::match(const VoidType *, const VoidType *) +{ + return true; +} + +bool TypeMatcher::match(const IntegerType *type, const IntegerType *otherType) +{ + if (type == otherType) + return true; + + else if (type->kind() != otherType->kind()) + return false; + + return true; +} + +bool TypeMatcher::match(const FloatType *type, const FloatType *otherType) +{ + if (type == otherType) + return true; + + else if (type->kind() != otherType->kind()) + return false; + + return true; +} + +bool TypeMatcher::match(const PointerToMemberType *type, const PointerToMemberType *otherType) +{ + if (type == otherType) + return true; + + else if (! isEqualTo(type->memberName(), otherType->memberName())) + return false; + + else if (! type->elementType().match(otherType->elementType(), this)) + return false; + + return true; +} + +bool TypeMatcher::match(const PointerType *type, const PointerType *otherType) +{ + if (type == otherType) + return true; + + else if (! type->elementType().match(otherType->elementType(), this)) + return false; + + return true; +} + +bool TypeMatcher::match(const ReferenceType *type, const ReferenceType *otherType) +{ + if (type == otherType) + return true; + + else if (! type->elementType().match(otherType->elementType(), this)) + return false; + + return true; +} + +bool TypeMatcher::match(const ArrayType *type, const ArrayType *otherType) +{ + if (type == otherType) + return true; + + else if (type->size() != otherType->size()) + return false; + + else if (! type->elementType().match(otherType->elementType(), this)) + return false; + + return true; +} + +bool TypeMatcher::match(const NamedType *type, const NamedType *otherType) +{ + if (type == otherType) + return true; + + else if (! isEqualTo(type->name(), otherType->name())) + return false; + + return true; +} + +bool TypeMatcher::match(const Function *type, const Function *otherType) +{ + if (type != otherType) + return false; + + return true; +} + +bool TypeMatcher::match(const Enum *type, const Enum *otherType) +{ + if (type != otherType) + return false; + + return true; +} + +bool TypeMatcher::match(const Namespace *type, const Namespace *otherType) +{ + if (type != otherType) + return false; + + return true; +} + +bool TypeMatcher::match(const ForwardClassDeclaration *type, const ForwardClassDeclaration *otherType) +{ + if (type != otherType) + return false; + + return true; +} + +bool TypeMatcher::match(const Class *type, const Class *otherType) +{ + if (type != otherType) + return false; + + return true; +} + +bool TypeMatcher::match(const ObjCClass *type, const ObjCClass *otherType) +{ + if (type != otherType) + return false; + + return true; +} + +bool TypeMatcher::match(const ObjCProtocol *type, const ObjCProtocol *otherType) +{ + if (type != otherType) + return false; + + return true; +} + +bool TypeMatcher::match(const ObjCForwardClassDeclaration *type, const ObjCForwardClassDeclaration *otherType) +{ + if (type != otherType) + return false; + + return true; +} + +bool TypeMatcher::match(const ObjCForwardProtocolDeclaration *type, const ObjCForwardProtocolDeclaration *otherType) +{ + if (type != otherType) + return false; + + return true; +} + +bool TypeMatcher::match(const ObjCMethod *type, const ObjCMethod *otherType) +{ + if (type != otherType) + return false; + + return true; +} diff --git a/src/shared/cplusplus/TypeMatcher.h b/src/shared/cplusplus/TypeMatcher.h new file mode 100644 index 00000000000..bad91af5d2e --- /dev/null +++ b/src/shared/cplusplus/TypeMatcher.h @@ -0,0 +1,73 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef TYPEMATCHER_H +#define TYPEMATCHER_H + +#include "CPlusPlusForwardDeclarations.h" + +namespace CPlusPlus { + +class CPLUSPLUS_EXPORT TypeMatcher +{ + TypeMatcher(const TypeMatcher &other); + void operator = (const TypeMatcher &other); + +public: + TypeMatcher(); + virtual ~TypeMatcher(); + + virtual bool match(const UndefinedType *type, const UndefinedType *otherType); + virtual bool match(const VoidType *type, const VoidType *otherType); + virtual bool match(const IntegerType *type, const IntegerType *otherType); + virtual bool match(const FloatType *type, const FloatType *otherType); + virtual bool match(const PointerToMemberType *type, const PointerToMemberType *otherType); + virtual bool match(const PointerType *type, const PointerType *otherType); + virtual bool match(const ReferenceType *type, const ReferenceType *otherType); + virtual bool match(const ArrayType *type, const ArrayType *otherType); + virtual bool match(const NamedType *type, const NamedType *otherType); + + virtual bool match(const Function *type, const Function *otherType); + virtual bool match(const Enum *type, const Enum *otherType); + virtual bool match(const Namespace *type, const Namespace *otherType); + virtual bool match(const ForwardClassDeclaration *type, const ForwardClassDeclaration *otherType); + virtual bool match(const Class *type, const Class *otherType); + virtual bool match(const ObjCClass *type, const ObjCClass *otherType); + virtual bool match(const ObjCProtocol *type, const ObjCProtocol *otherType); + virtual bool match(const ObjCForwardClassDeclaration *type, const ObjCForwardClassDeclaration *otherType); + virtual bool match(const ObjCForwardProtocolDeclaration *type, const ObjCForwardProtocolDeclaration *otherType); + virtual bool match(const ObjCMethod *type, const ObjCMethod *otherType); + +protected: + bool isEqualTo(const Name *name, const Name *otherName) const; +}; + +} // end of namespace CPlusPlus + +#endif // TYPEMATCHER_H diff --git a/src/shared/cplusplus/TypeVisitor.h b/src/shared/cplusplus/TypeVisitor.h index 5d0ef4cd542..99b1df06e1f 100644 --- a/src/shared/cplusplus/TypeVisitor.h +++ b/src/shared/cplusplus/TypeVisitor.h @@ -51,7 +51,6 @@ #include "CPlusPlusForwardDeclarations.h" - namespace CPlusPlus { class CPLUSPLUS_EXPORT TypeVisitor @@ -68,6 +67,7 @@ public: virtual bool preVisit(Type *) { return true; } virtual void postVisit(Type *) {} + virtual void visit(UndefinedType *) {} virtual void visit(VoidType *) {} virtual void visit(IntegerType *) {} virtual void visit(FloatType *) {} diff --git a/src/shared/cplusplus/cplusplus.pri b/src/shared/cplusplus/cplusplus.pri index 41c7ba0b274..4f1f30e7d52 100644 --- a/src/shared/cplusplus/cplusplus.pri +++ b/src/shared/cplusplus/cplusplus.pri @@ -9,6 +9,7 @@ HEADERS += \ $$PWD/ASTPatternBuilder.h \ $$PWD/ASTfwd.h \ $$PWD/Array.h \ + $$PWD/TypeMatcher.h \ $$PWD/CPlusPlusForwardDeclarations.h \ $$PWD/CheckDeclaration.h \ $$PWD/CheckDeclarator.h \ @@ -47,6 +48,7 @@ SOURCES += \ $$PWD/ASTVisitor.cpp \ $$PWD/ASTPatternBuilder.cpp \ $$PWD/ASTMatcher.cpp \ + $$PWD/TypeMatcher.cpp \ $$PWD/Array.cpp \ $$PWD/CheckDeclaration.cpp \ $$PWD/CheckDeclarator.cpp \