forked from qt-creator/qt-creator
Introduced type matchers.
This commit is contained in:
@@ -51,13 +51,11 @@
|
||||
|
||||
#include "CPlusPlusForwardDeclarations.h"
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
template <typename _Tp, int SEGMENT_SHIFT = 4>
|
||||
class Array
|
||||
class CPLUSPLUS_EXPORT Array
|
||||
{
|
||||
Array(const Array &other);
|
||||
void operator =(const Array &other);
|
||||
|
||||
@@ -49,6 +49,8 @@
|
||||
#ifndef CPLUSPLUS_CPLUSPLUSFORWARDDECLARATIONS_H
|
||||
#define CPLUSPLUS_CPLUSPLUSFORWARDDECLARATIONS_H
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#ifndef CPLUSPLUS_WITHOUT_QT
|
||||
# include <QtCore/qglobal.h>
|
||||
|
||||
@@ -91,6 +93,7 @@ class QualifiedNameId;
|
||||
class SelectorNameId;
|
||||
|
||||
// types
|
||||
class TypeMatcher;
|
||||
class FullySpecifiedType;
|
||||
class TypeVisitor;
|
||||
class Type;
|
||||
|
||||
@@ -55,11 +55,9 @@
|
||||
#include "Names.h"
|
||||
#include "Array.h"
|
||||
#include <map> // ### replace me with LiteralTable
|
||||
#include <string>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
|
||||
template <typename _Iterator>
|
||||
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<char>::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<char>::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<char>::length(chars);
|
||||
unsigned length = std::strlen(chars);
|
||||
return findOrInsertNumericLiteral(chars, length);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,11 +48,30 @@
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "TypeVisitor.h"
|
||||
#include "TypeMatcher.h"
|
||||
#include "Names.h"
|
||||
#include <algorithm>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@
|
||||
#include "FullySpecifiedType.h"
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -53,8 +53,6 @@
|
||||
#include <cctype>
|
||||
#include <cassert>
|
||||
|
||||
using namespace std;
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
Lexer::Lexer(TranslationUnit *unit)
|
||||
|
||||
@@ -51,8 +51,6 @@
|
||||
|
||||
#include "CPlusPlusForwardDeclarations.h"
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
|
||||
@@ -51,8 +51,6 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
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
|
||||
|
||||
@@ -47,14 +47,11 @@
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include "MemoryPool.h"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@
|
||||
#include <cstddef>
|
||||
#include <new>
|
||||
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
class CPLUSPLUS_EXPORT MemoryPool
|
||||
|
||||
@@ -53,7 +53,6 @@
|
||||
#include "Name.h"
|
||||
#include "FullySpecifiedType.h"
|
||||
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
class CPLUSPLUS_EXPORT QualifiedNameId: public Name
|
||||
|
||||
@@ -53,11 +53,7 @@
|
||||
#include "AST.h"
|
||||
#include "Literals.h"
|
||||
#include "ObjectiveCTypeQualifiers.h"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <cstdio> // 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; }
|
||||
|
||||
@@ -50,12 +50,8 @@
|
||||
#include "Symbols.h"
|
||||
#include "Names.h"
|
||||
#include "Literals.h"
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
@@ -278,7 +274,7 @@ void Scope::rehash()
|
||||
_hashSize = DefaultInitialSize;
|
||||
|
||||
_hash = reinterpret_cast<Symbol **>(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];
|
||||
|
||||
@@ -50,8 +50,8 @@
|
||||
#include "Names.h"
|
||||
#include "TypeVisitor.h"
|
||||
#include "SymbolVisitor.h"
|
||||
#include "TypeMatcher.h"
|
||||
#include "Scope.h"
|
||||
#include <cstdlib>
|
||||
|
||||
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<Function *>(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<ObjCMethod *>(this)); }
|
||||
|
||||
|
||||
@@ -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<ObjCBaseProtocol *> _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;
|
||||
|
||||
@@ -55,12 +55,9 @@
|
||||
#include "Literals.h"
|
||||
#include "DiagnosticClient.h"
|
||||
#include <stack>
|
||||
#include <cstdlib>
|
||||
#include <cstdarg>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
TranslationUnit::TranslationUnit(Control *control, StringLiteral *fileId)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
225
src/shared/cplusplus/TypeMatcher.cpp
Normal file
225
src/shared/cplusplus/TypeMatcher.cpp
Normal file
@@ -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;
|
||||
}
|
||||
73
src/shared/cplusplus/TypeMatcher.h
Normal file
73
src/shared/cplusplus/TypeMatcher.h
Normal file
@@ -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
|
||||
@@ -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 *) {}
|
||||
|
||||
@@ -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 \
|
||||
|
||||
Reference in New Issue
Block a user