forked from qt-creator/qt-creator
Added support to C++ symbols rewriting.
This should simplify full C++ template instantiations. Reviewed-by: Christian Kamm
This commit is contained in:
1
src/libs/3rdparty/cplusplus/CPlusPlus.h
vendored
1
src/libs/3rdparty/cplusplus/CPlusPlus.h
vendored
@@ -51,5 +51,6 @@
|
||||
#include "Type.h"
|
||||
#include "TypeMatcher.h"
|
||||
#include "TypeVisitor.h"
|
||||
#include "Templates.h"
|
||||
|
||||
#endif // CPLUSPLUS_CPLUSPLUS_H
|
||||
|
||||
@@ -79,6 +79,9 @@ class ArrayType;
|
||||
class NamedType;
|
||||
|
||||
// symbols
|
||||
class Clone;
|
||||
class Subst;
|
||||
|
||||
class SymbolVisitor;
|
||||
class Symbol;
|
||||
class Scope;
|
||||
|
||||
5
src/libs/3rdparty/cplusplus/Control.cpp
vendored
5
src/libs/3rdparty/cplusplus/Control.cpp
vendored
@@ -799,3 +799,8 @@ void Control::setTopLevelDeclarationProcessor(CPlusPlus::TopLevelDeclarationProc
|
||||
{
|
||||
d->processor = processor;
|
||||
}
|
||||
|
||||
void Control::addSymbol(Symbol *symbol)
|
||||
{
|
||||
d->symbols.push_back(symbol);
|
||||
}
|
||||
|
||||
1
src/libs/3rdparty/cplusplus/Control.h
vendored
1
src/libs/3rdparty/cplusplus/Control.h
vendored
@@ -208,6 +208,7 @@ public:
|
||||
Symbol **lastSymbol() const;
|
||||
|
||||
bool hasSymbol(Symbol *symbol) const;
|
||||
void addSymbol(Symbol *symbol);
|
||||
|
||||
void squeeze();
|
||||
|
||||
|
||||
11
src/libs/3rdparty/cplusplus/Scope.cpp
vendored
11
src/libs/3rdparty/cplusplus/Scope.cpp
vendored
@@ -22,6 +22,7 @@
|
||||
#include "Symbols.h"
|
||||
#include "Names.h"
|
||||
#include "Literals.h"
|
||||
#include "Templates.h"
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
@@ -228,6 +229,16 @@ Scope::Scope(TranslationUnit *translationUnit, unsigned sourceLocation, const Na
|
||||
_endOffset(0)
|
||||
{ }
|
||||
|
||||
Scope::Scope(Clone *clone, Subst *subst, Scope *original)
|
||||
: Symbol(clone, subst, original)
|
||||
, _members(0)
|
||||
, _startOffset(original->_startOffset)
|
||||
, _endOffset(original->_endOffset)
|
||||
{
|
||||
for (iterator it = original->firstMember(), end = original->lastMember(); it != end; ++it)
|
||||
addMember(clone->symbol(*it, subst));
|
||||
}
|
||||
|
||||
Scope::~Scope()
|
||||
{ delete _members; }
|
||||
|
||||
|
||||
1
src/libs/3rdparty/cplusplus/Scope.h
vendored
1
src/libs/3rdparty/cplusplus/Scope.h
vendored
@@ -31,6 +31,7 @@ class CPLUSPLUS_EXPORT Scope: public Symbol
|
||||
{
|
||||
public:
|
||||
Scope(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
Scope(Clone *clone, Subst *subst, Scope *original);
|
||||
virtual ~Scope();
|
||||
|
||||
/// Adds a Symbol to this Scope.
|
||||
|
||||
19
src/libs/3rdparty/cplusplus/Symbol.cpp
vendored
19
src/libs/3rdparty/cplusplus/Symbol.cpp
vendored
@@ -28,6 +28,7 @@
|
||||
#include "SymbolVisitor.h"
|
||||
#include "NameVisitor.h"
|
||||
#include "Scope.h"
|
||||
#include "Templates.h"
|
||||
#include <cassert>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
@@ -102,6 +103,24 @@ Symbol::Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const
|
||||
setName(name);
|
||||
}
|
||||
|
||||
Symbol::Symbol(Clone *clone, Subst *subst, Symbol *original)
|
||||
: _name(clone->name(original->_name, subst)),
|
||||
_scope(0),
|
||||
_next(0),
|
||||
_fileId(clone->control()->stringLiteral(original->fileName(), original->fileNameLength())),
|
||||
_sourceLocation(original->_sourceLocation),
|
||||
_hashCode(original->_hashCode),
|
||||
_storage(original->_storage),
|
||||
_visibility(original->_visibility),
|
||||
_index(0),
|
||||
_line(original->_line),
|
||||
_column(original->_column),
|
||||
_isGenerated(original->_isGenerated),
|
||||
_isDeprecated(original->_isDeprecated),
|
||||
_isUnavailable(original->_isUnavailable)
|
||||
{
|
||||
}
|
||||
|
||||
Symbol::~Symbol()
|
||||
{ }
|
||||
|
||||
|
||||
1
src/libs/3rdparty/cplusplus/Symbol.h
vendored
1
src/libs/3rdparty/cplusplus/Symbol.h
vendored
@@ -55,6 +55,7 @@ public:
|
||||
public:
|
||||
/// Constructs a Symbol with the given source location, name and translation unit.
|
||||
Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
Symbol(Clone *clone, Subst *subst, Symbol *original);
|
||||
|
||||
/// Destroy this Symbol.
|
||||
virtual ~Symbol();
|
||||
|
||||
128
src/libs/3rdparty/cplusplus/Symbols.cpp
vendored
128
src/libs/3rdparty/cplusplus/Symbols.cpp
vendored
@@ -24,6 +24,7 @@
|
||||
#include "SymbolVisitor.h"
|
||||
#include "TypeMatcher.h"
|
||||
#include "Scope.h"
|
||||
#include "Templates.h"
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
@@ -32,6 +33,10 @@ UsingNamespaceDirective::UsingNamespaceDirective(TranslationUnit *translationUni
|
||||
: Symbol(translationUnit, sourceLocation, name)
|
||||
{ }
|
||||
|
||||
UsingNamespaceDirective::UsingNamespaceDirective(Clone *clone, Subst *subst, UsingNamespaceDirective *original)
|
||||
: Symbol(clone, subst, original)
|
||||
{ }
|
||||
|
||||
UsingNamespaceDirective::~UsingNamespaceDirective()
|
||||
{ }
|
||||
|
||||
@@ -46,6 +51,11 @@ NamespaceAlias::NamespaceAlias(TranslationUnit *translationUnit,
|
||||
: Symbol(translationUnit, sourceLocation, name), _namespaceName(0)
|
||||
{ }
|
||||
|
||||
NamespaceAlias::NamespaceAlias(Clone *clone, Subst *subst, NamespaceAlias *original)
|
||||
: Symbol(clone, subst, original)
|
||||
, _namespaceName(clone->name(original->_namespaceName, subst))
|
||||
{ }
|
||||
|
||||
NamespaceAlias::~NamespaceAlias()
|
||||
{ }
|
||||
|
||||
@@ -67,6 +77,10 @@ UsingDeclaration::UsingDeclaration(TranslationUnit *translationUnit,
|
||||
: Symbol(translationUnit, sourceLocation, name)
|
||||
{ }
|
||||
|
||||
UsingDeclaration::UsingDeclaration(Clone *clone, Subst *subst, UsingDeclaration *original)
|
||||
: Symbol(clone, subst, original)
|
||||
{ }
|
||||
|
||||
UsingDeclaration::~UsingDeclaration()
|
||||
{ }
|
||||
|
||||
@@ -80,6 +94,11 @@ Declaration::Declaration(TranslationUnit *translationUnit, unsigned sourceLocati
|
||||
: Symbol(translationUnit, sourceLocation, name)
|
||||
{ }
|
||||
|
||||
Declaration::Declaration(Clone *clone, Subst *subst, Declaration *original)
|
||||
: Symbol(clone, subst, original)
|
||||
, _type(clone->type(original->_type, subst))
|
||||
{ }
|
||||
|
||||
Declaration::~Declaration()
|
||||
{ }
|
||||
|
||||
@@ -111,6 +130,12 @@ Argument::Argument(TranslationUnit *translationUnit, unsigned sourceLocation, co
|
||||
_initializer(0)
|
||||
{ }
|
||||
|
||||
Argument::Argument(Clone *clone, Subst *subst, Argument *original)
|
||||
: Symbol(clone, subst, original)
|
||||
, _initializer(clone->stringLiteral(original->_initializer))
|
||||
, _type(clone->type(original->_type, subst))
|
||||
{ }
|
||||
|
||||
Argument::~Argument()
|
||||
{ }
|
||||
|
||||
@@ -136,6 +161,11 @@ TypenameArgument::TypenameArgument(TranslationUnit *translationUnit, unsigned so
|
||||
: Symbol(translationUnit, sourceLocation, name)
|
||||
{ }
|
||||
|
||||
TypenameArgument::TypenameArgument(Clone *clone, Subst *subst, TypenameArgument *original)
|
||||
: Symbol(clone, subst, original)
|
||||
, _type(clone->type(original->_type, subst))
|
||||
{ }
|
||||
|
||||
TypenameArgument::~TypenameArgument()
|
||||
{ }
|
||||
|
||||
@@ -153,6 +183,12 @@ Function::Function(TranslationUnit *translationUnit, unsigned sourceLocation, co
|
||||
_flags(0)
|
||||
{ }
|
||||
|
||||
Function::Function(Clone *clone, Subst *subst, Function *original)
|
||||
: Scope(clone, subst, original)
|
||||
, _returnType(clone->type(original->_returnType, subst))
|
||||
, _flags(original->_flags)
|
||||
{ }
|
||||
|
||||
Function::~Function()
|
||||
{ }
|
||||
|
||||
@@ -376,6 +412,10 @@ Block::Block(TranslationUnit *translationUnit, unsigned sourceLocation)
|
||||
: Scope(translationUnit, sourceLocation, /*name = */ 0)
|
||||
{ }
|
||||
|
||||
Block::Block(Clone *clone, Subst *subst, Block *original)
|
||||
: Scope(clone, subst, original)
|
||||
{ }
|
||||
|
||||
Block::~Block()
|
||||
{ }
|
||||
|
||||
@@ -395,6 +435,10 @@ Enum::Enum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name
|
||||
: Scope(translationUnit, sourceLocation, name)
|
||||
{ }
|
||||
|
||||
Enum::Enum(Clone *clone, Subst *subst, Enum *original)
|
||||
: Scope(clone, subst, original)
|
||||
{ }
|
||||
|
||||
Enum::~Enum()
|
||||
{ }
|
||||
|
||||
@@ -439,6 +483,10 @@ Template::Template(TranslationUnit *translationUnit, unsigned sourceLocation, co
|
||||
: Scope(translationUnit, sourceLocation, name)
|
||||
{ }
|
||||
|
||||
Template::Template(Clone *clone, Subst *subst, Template *original)
|
||||
: Scope(clone, subst, original)
|
||||
{ }
|
||||
|
||||
Template::~Template()
|
||||
{ }
|
||||
|
||||
@@ -496,6 +544,10 @@ Namespace::Namespace(TranslationUnit *translationUnit, unsigned sourceLocation,
|
||||
: Scope(translationUnit, sourceLocation, name)
|
||||
{ }
|
||||
|
||||
Namespace::Namespace(Clone *clone, Subst *subst, Namespace *original)
|
||||
: Scope(clone, subst, original)
|
||||
{ }
|
||||
|
||||
Namespace::~Namespace()
|
||||
{ }
|
||||
|
||||
@@ -539,6 +591,12 @@ BaseClass::BaseClass(TranslationUnit *translationUnit, unsigned sourceLocation,
|
||||
_isVirtual(false)
|
||||
{ }
|
||||
|
||||
BaseClass::BaseClass(Clone *clone, Subst *subst, BaseClass *original)
|
||||
: Symbol(clone, subst, original)
|
||||
, _isVirtual(original->_isVirtual)
|
||||
, _type(clone->type(original->_type, subst))
|
||||
{ }
|
||||
|
||||
BaseClass::~BaseClass()
|
||||
{ }
|
||||
|
||||
@@ -562,6 +620,10 @@ ForwardClassDeclaration::ForwardClassDeclaration(TranslationUnit *translationUni
|
||||
: Symbol(translationUnit, sourceLocation, name)
|
||||
{ }
|
||||
|
||||
ForwardClassDeclaration::ForwardClassDeclaration(Clone *clone, Subst *subst, ForwardClassDeclaration *original)
|
||||
: Symbol(clone, subst, original)
|
||||
{ }
|
||||
|
||||
ForwardClassDeclaration::~ForwardClassDeclaration()
|
||||
{ }
|
||||
|
||||
@@ -600,6 +662,14 @@ Class::Class(TranslationUnit *translationUnit, unsigned sourceLocation, const Na
|
||||
_key(ClassKey)
|
||||
{ }
|
||||
|
||||
Class::Class(Clone *clone, Subst *subst, Class *original)
|
||||
: Scope(clone, subst, original)
|
||||
, _key(original->_key)
|
||||
{
|
||||
for (size_t i = 0; i < original->_baseClasses.size(); ++i)
|
||||
addBaseClass(clone->symbol(original->_baseClasses.at(i), subst)->asBaseClass());
|
||||
}
|
||||
|
||||
Class::~Class()
|
||||
{ }
|
||||
|
||||
@@ -672,6 +742,12 @@ QtPropertyDeclaration::QtPropertyDeclaration(TranslationUnit *translationUnit, u
|
||||
, _flags(NoFlags)
|
||||
{ }
|
||||
|
||||
QtPropertyDeclaration::QtPropertyDeclaration(Clone *clone, Subst *subst, QtPropertyDeclaration *original)
|
||||
: Symbol(clone, subst, original)
|
||||
, _type(clone->type(original->_type, subst))
|
||||
, _flags(original->_flags)
|
||||
{ }
|
||||
|
||||
QtPropertyDeclaration::~QtPropertyDeclaration()
|
||||
{ }
|
||||
|
||||
@@ -695,6 +771,10 @@ QtEnum::QtEnum(TranslationUnit *translationUnit, unsigned sourceLocation, const
|
||||
: Symbol(translationUnit, sourceLocation, name)
|
||||
{ }
|
||||
|
||||
QtEnum::QtEnum(Clone *clone, Subst *subst, QtEnum *original)
|
||||
: Symbol(clone, subst, original)
|
||||
{ }
|
||||
|
||||
QtEnum::~QtEnum()
|
||||
{ }
|
||||
|
||||
@@ -709,6 +789,10 @@ ObjCBaseClass::ObjCBaseClass(TranslationUnit *translationUnit, unsigned sourceLo
|
||||
: Symbol(translationUnit, sourceLocation, name)
|
||||
{ }
|
||||
|
||||
ObjCBaseClass::ObjCBaseClass(Clone *clone, Subst *subst, ObjCBaseClass *original)
|
||||
: Symbol(clone, subst, original)
|
||||
{ }
|
||||
|
||||
ObjCBaseClass::~ObjCBaseClass()
|
||||
{ }
|
||||
|
||||
@@ -722,6 +806,10 @@ ObjCBaseProtocol::ObjCBaseProtocol(TranslationUnit *translationUnit, unsigned so
|
||||
: Symbol(translationUnit, sourceLocation, name)
|
||||
{ }
|
||||
|
||||
ObjCBaseProtocol::ObjCBaseProtocol(Clone *clone, Subst *subst, ObjCBaseProtocol *original)
|
||||
: Symbol(clone, subst, original)
|
||||
{ }
|
||||
|
||||
ObjCBaseProtocol::~ObjCBaseProtocol()
|
||||
{ }
|
||||
|
||||
@@ -736,7 +824,18 @@ ObjCClass::ObjCClass(TranslationUnit *translationUnit, unsigned sourceLocation,
|
||||
_categoryName(0),
|
||||
_baseClass(0),
|
||||
_isInterface(false)
|
||||
{ }
|
||||
|
||||
ObjCClass::ObjCClass(Clone *clone, Subst *subst, ObjCClass *original)
|
||||
: Scope(clone, subst, original)
|
||||
, _categoryName(clone->name(original->_categoryName, subst))
|
||||
, _baseClass(0)
|
||||
, _isInterface(original->_isInterface)
|
||||
{
|
||||
if (original->_baseClass)
|
||||
_baseClass = clone->symbol(original->_baseClass, subst)->asObjCBaseClass();
|
||||
for (size_t i = 0; i < original->_protocols.size(); ++i)
|
||||
addProtocol(clone->symbol(original->_protocols.at(i), subst)->asObjCBaseProtocol());
|
||||
}
|
||||
|
||||
ObjCClass::~ObjCClass()
|
||||
@@ -819,6 +918,13 @@ ObjCProtocol::ObjCProtocol(TranslationUnit *translationUnit, unsigned sourceLoca
|
||||
{
|
||||
}
|
||||
|
||||
ObjCProtocol::ObjCProtocol(Clone *clone, Subst *subst, ObjCProtocol *original)
|
||||
: Scope(clone, subst, original)
|
||||
{
|
||||
for (size_t i = 0; i < original->_protocols.size(); ++i)
|
||||
addProtocol(clone->symbol(original->_protocols.at(i), subst)->asObjCBaseProtocol());
|
||||
}
|
||||
|
||||
ObjCProtocol::~ObjCProtocol()
|
||||
{}
|
||||
|
||||
@@ -873,6 +979,10 @@ ObjCForwardClassDeclaration::ObjCForwardClassDeclaration(TranslationUnit *transl
|
||||
{
|
||||
}
|
||||
|
||||
ObjCForwardClassDeclaration::ObjCForwardClassDeclaration(Clone *clone, Subst *subst, ObjCForwardClassDeclaration *original)
|
||||
: Symbol(clone, subst, original)
|
||||
{ }
|
||||
|
||||
ObjCForwardClassDeclaration::~ObjCForwardClassDeclaration()
|
||||
{}
|
||||
|
||||
@@ -913,6 +1023,10 @@ ObjCForwardProtocolDeclaration::ObjCForwardProtocolDeclaration(TranslationUnit *
|
||||
{
|
||||
}
|
||||
|
||||
ObjCForwardProtocolDeclaration::ObjCForwardProtocolDeclaration(Clone *clone, Subst *subst, ObjCForwardProtocolDeclaration *original)
|
||||
: Symbol(clone, subst, original)
|
||||
{ }
|
||||
|
||||
ObjCForwardProtocolDeclaration::~ObjCForwardProtocolDeclaration()
|
||||
{}
|
||||
|
||||
@@ -952,6 +1066,12 @@ ObjCMethod::ObjCMethod(TranslationUnit *translationUnit, unsigned sourceLocation
|
||||
_flags(0)
|
||||
{ }
|
||||
|
||||
ObjCMethod::ObjCMethod(Clone *clone, Subst *subst, ObjCMethod *original)
|
||||
: Scope(clone, subst, original)
|
||||
, _returnType(clone->type(original->_returnType, subst))
|
||||
, _flags(original->_flags)
|
||||
{ }
|
||||
|
||||
ObjCMethod::~ObjCMethod()
|
||||
{ }
|
||||
|
||||
@@ -1048,6 +1168,14 @@ ObjCPropertyDeclaration::ObjCPropertyDeclaration(TranslationUnit *translationUni
|
||||
_propertyAttributes(None)
|
||||
{}
|
||||
|
||||
ObjCPropertyDeclaration::ObjCPropertyDeclaration(Clone *clone, Subst *subst, ObjCPropertyDeclaration *original)
|
||||
: Symbol(clone, subst, original)
|
||||
, _getterName(clone->name(original->_getterName, subst))
|
||||
, _setterName(clone->name(original->_setterName, subst))
|
||||
, _type(clone->type(original->_type, subst))
|
||||
, _propertyAttributes(original->_propertyAttributes)
|
||||
{ }
|
||||
|
||||
ObjCPropertyDeclaration::~ObjCPropertyDeclaration()
|
||||
{}
|
||||
|
||||
|
||||
26
src/libs/3rdparty/cplusplus/Symbols.h
vendored
26
src/libs/3rdparty/cplusplus/Symbols.h
vendored
@@ -34,6 +34,7 @@ class CPLUSPLUS_EXPORT UsingNamespaceDirective: public Symbol
|
||||
{
|
||||
public:
|
||||
UsingNamespaceDirective(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
UsingNamespaceDirective(Clone *clone, Subst *subst, UsingNamespaceDirective *original);
|
||||
virtual ~UsingNamespaceDirective();
|
||||
|
||||
// Symbol's interface
|
||||
@@ -53,6 +54,7 @@ class CPLUSPLUS_EXPORT UsingDeclaration: public Symbol
|
||||
{
|
||||
public:
|
||||
UsingDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
UsingDeclaration(Clone *clone, Subst *subst, UsingDeclaration *original);
|
||||
virtual ~UsingDeclaration();
|
||||
|
||||
// Symbol's interface
|
||||
@@ -72,6 +74,7 @@ class CPLUSPLUS_EXPORT NamespaceAlias: public Symbol
|
||||
{
|
||||
public:
|
||||
NamespaceAlias(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
NamespaceAlias(Clone *clone, Subst *subst, NamespaceAlias *original);
|
||||
virtual ~NamespaceAlias();
|
||||
|
||||
const Name *namespaceName() const;
|
||||
@@ -97,6 +100,7 @@ class CPLUSPLUS_EXPORT Declaration: public Symbol
|
||||
{
|
||||
public:
|
||||
Declaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
Declaration(Clone *clone, Subst *subst, Declaration *original);
|
||||
virtual ~Declaration();
|
||||
|
||||
void setType(const FullySpecifiedType &type);
|
||||
@@ -146,6 +150,7 @@ class CPLUSPLUS_EXPORT Argument: public Symbol
|
||||
{
|
||||
public:
|
||||
Argument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
Argument(Clone *clone, Subst *subst, Argument *original);
|
||||
virtual ~Argument();
|
||||
|
||||
void setType(const FullySpecifiedType &type);
|
||||
@@ -176,6 +181,7 @@ class CPLUSPLUS_EXPORT TypenameArgument: public Symbol
|
||||
{
|
||||
public:
|
||||
TypenameArgument(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
TypenameArgument(Clone *clone, Subst *subst, TypenameArgument *original);
|
||||
virtual ~TypenameArgument();
|
||||
|
||||
void setType(const FullySpecifiedType &type);
|
||||
@@ -200,6 +206,7 @@ class CPLUSPLUS_EXPORT Block: public Scope
|
||||
{
|
||||
public:
|
||||
Block(TranslationUnit *translationUnit, unsigned sourceLocation);
|
||||
Block(Clone *clone, Subst *subst, Block *original);
|
||||
virtual ~Block();
|
||||
|
||||
// Symbol's interface
|
||||
@@ -219,6 +226,7 @@ class CPLUSPLUS_EXPORT ForwardClassDeclaration: public Symbol, public Type
|
||||
{
|
||||
public:
|
||||
ForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
ForwardClassDeclaration(Clone *clone, Subst *subst, ForwardClassDeclaration *original);
|
||||
virtual ~ForwardClassDeclaration();
|
||||
|
||||
virtual FullySpecifiedType type() const;
|
||||
@@ -247,6 +255,7 @@ class CPLUSPLUS_EXPORT Enum: public Scope, public Type
|
||||
{
|
||||
public:
|
||||
Enum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
Enum(Clone *clone, Subst *subst, Enum *original);
|
||||
virtual ~Enum();
|
||||
|
||||
// Symbol's interface
|
||||
@@ -285,6 +294,7 @@ public:
|
||||
|
||||
public:
|
||||
Function(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
Function(Clone *clone, Subst *subst, Function *original);
|
||||
virtual ~Function();
|
||||
|
||||
bool isNormal() const;
|
||||
@@ -375,6 +385,7 @@ class CPLUSPLUS_EXPORT Template: public Scope, public Type
|
||||
{
|
||||
public:
|
||||
Template(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
Template(Clone *clone, Subst *subst, Template *original);
|
||||
virtual ~Template();
|
||||
|
||||
unsigned templateParameterCount() const;
|
||||
@@ -410,6 +421,7 @@ class CPLUSPLUS_EXPORT Namespace: public Scope, public Type
|
||||
{
|
||||
public:
|
||||
Namespace(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
Namespace(Clone *clone, Subst *subst, Namespace *original);
|
||||
virtual ~Namespace();
|
||||
|
||||
// Symbol's interface
|
||||
@@ -440,6 +452,7 @@ class CPLUSPLUS_EXPORT BaseClass: public Symbol
|
||||
{
|
||||
public:
|
||||
BaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
BaseClass(Clone *clone, Subst *subst, BaseClass *original);
|
||||
virtual ~BaseClass();
|
||||
|
||||
bool isVirtual() const;
|
||||
@@ -467,6 +480,7 @@ class CPLUSPLUS_EXPORT Class: public Scope, public Type
|
||||
{
|
||||
public:
|
||||
Class(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
Class(Clone *clone, Subst *subst, Class *original);
|
||||
virtual ~Class();
|
||||
|
||||
enum Key {
|
||||
@@ -531,11 +545,12 @@ public:
|
||||
UserFlag = 1 << 10,
|
||||
UserFunction = 1 << 11,
|
||||
ConstantFlag = 1 << 12,
|
||||
FinalFlag = 1 << 13,
|
||||
FinalFlag = 1 << 13
|
||||
};
|
||||
|
||||
public:
|
||||
QtPropertyDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
QtPropertyDeclaration(Clone *clone, Subst *subst, QtPropertyDeclaration *original);
|
||||
virtual ~QtPropertyDeclaration();
|
||||
|
||||
void setType(const FullySpecifiedType &type);
|
||||
@@ -564,6 +579,7 @@ class CPLUSPLUS_EXPORT QtEnum: public Symbol
|
||||
{
|
||||
public:
|
||||
QtEnum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
QtEnum(Clone *clone, Subst *subst, QtEnum *original);
|
||||
virtual ~QtEnum();
|
||||
|
||||
// Symbol's interface
|
||||
@@ -583,6 +599,7 @@ class CPLUSPLUS_EXPORT ObjCBaseClass: public Symbol
|
||||
{
|
||||
public:
|
||||
ObjCBaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
ObjCBaseClass(Clone *clone, Subst *subst, ObjCBaseClass *original);
|
||||
virtual ~ObjCBaseClass();
|
||||
|
||||
// Symbol's interface
|
||||
@@ -602,6 +619,7 @@ class CPLUSPLUS_EXPORT ObjCBaseProtocol: public Symbol
|
||||
{
|
||||
public:
|
||||
ObjCBaseProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
ObjCBaseProtocol(Clone *clone, Subst *subst, ObjCBaseProtocol *original);
|
||||
virtual ~ObjCBaseProtocol();
|
||||
|
||||
// Symbol's interface
|
||||
@@ -621,6 +639,7 @@ class CPLUSPLUS_EXPORT ObjCForwardProtocolDeclaration: public Symbol, public Typ
|
||||
{
|
||||
public:
|
||||
ObjCForwardProtocolDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
ObjCForwardProtocolDeclaration(Clone *clone, Subst *subst, ObjCForwardProtocolDeclaration *original);
|
||||
virtual ~ObjCForwardProtocolDeclaration();
|
||||
|
||||
virtual FullySpecifiedType type() const;
|
||||
@@ -649,6 +668,7 @@ class CPLUSPLUS_EXPORT ObjCProtocol: public Scope, public Type
|
||||
{
|
||||
public:
|
||||
ObjCProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
ObjCProtocol(Clone *clone, Subst *subst, ObjCProtocol *original);
|
||||
virtual ~ObjCProtocol();
|
||||
|
||||
unsigned protocolCount() const;
|
||||
@@ -686,6 +706,7 @@ class CPLUSPLUS_EXPORT ObjCForwardClassDeclaration: public Symbol, public Type
|
||||
{
|
||||
public:
|
||||
ObjCForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
ObjCForwardClassDeclaration(Clone *clone, Subst *subst, ObjCForwardClassDeclaration *original);
|
||||
virtual ~ObjCForwardClassDeclaration();
|
||||
|
||||
virtual FullySpecifiedType type() const;
|
||||
@@ -714,6 +735,7 @@ class CPLUSPLUS_EXPORT ObjCClass: public Scope, public Type
|
||||
{
|
||||
public:
|
||||
ObjCClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
ObjCClass(Clone *clone, Subst *subst, ObjCClass *original);
|
||||
virtual ~ObjCClass();
|
||||
|
||||
bool isInterface() const;
|
||||
@@ -764,6 +786,7 @@ class CPLUSPLUS_EXPORT ObjCMethod: public Scope, public Type
|
||||
{
|
||||
public:
|
||||
ObjCMethod(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
|
||||
ObjCMethod(Clone *clone, Subst *subst, ObjCMethod *original);
|
||||
virtual ~ObjCMethod();
|
||||
|
||||
FullySpecifiedType returnType() const;
|
||||
@@ -837,6 +860,7 @@ public:
|
||||
ObjCPropertyDeclaration(TranslationUnit *translationUnit,
|
||||
unsigned sourceLocation,
|
||||
const Name *name);
|
||||
ObjCPropertyDeclaration(Clone *clone, Subst *subst, ObjCPropertyDeclaration *original);
|
||||
virtual ~ObjCPropertyDeclaration();
|
||||
|
||||
bool hasAttribute(int attribute) const;
|
||||
|
||||
535
src/libs/3rdparty/cplusplus/Templates.cpp
vendored
Normal file
535
src/libs/3rdparty/cplusplus/Templates.cpp
vendored
Normal file
@@ -0,0 +1,535 @@
|
||||
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include "Templates.h"
|
||||
#include "CoreTypes.h"
|
||||
#include "Symbols.h"
|
||||
#include "Control.h"
|
||||
#include "Names.h"
|
||||
#include "Literals.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
CloneType::CloneType(Clone *clone)
|
||||
: _clone(clone)
|
||||
, _control(clone->control())
|
||||
, _subst(0)
|
||||
{
|
||||
}
|
||||
|
||||
FullySpecifiedType CloneType::cloneType(const FullySpecifiedType &type, Subst *subst)
|
||||
{
|
||||
std::swap(_subst, subst);
|
||||
FullySpecifiedType ty(type);
|
||||
std::swap(_type, ty);
|
||||
accept(_type.type());
|
||||
std::swap(_type, ty);
|
||||
std::swap(_subst, subst);
|
||||
return ty;
|
||||
}
|
||||
|
||||
void CloneType::visit(UndefinedType *type)
|
||||
{
|
||||
_type.setType(type);
|
||||
}
|
||||
|
||||
void CloneType::visit(VoidType *)
|
||||
{
|
||||
_type.setType(_control->voidType());
|
||||
}
|
||||
|
||||
void CloneType::visit(IntegerType *type)
|
||||
{
|
||||
_type.setType(_control->integerType(type->kind()));
|
||||
}
|
||||
|
||||
void CloneType::visit(FloatType *type)
|
||||
{
|
||||
_type.setType(_control->floatType(type->kind()));
|
||||
}
|
||||
|
||||
void CloneType::visit(PointerToMemberType *type)
|
||||
{
|
||||
_type.setType(_control->pointerToMemberType(_clone->name(type->memberName(), _subst),
|
||||
_clone->type(type->elementType(), _subst)));
|
||||
}
|
||||
|
||||
void CloneType::visit(PointerType *type)
|
||||
{
|
||||
_type.setType(_control->pointerType(_clone->type(type->elementType(), _subst)));
|
||||
}
|
||||
|
||||
void CloneType::visit(ReferenceType *type)
|
||||
{
|
||||
_type.setType(_control->referenceType(_clone->type(type->elementType(), _subst)));
|
||||
}
|
||||
|
||||
void CloneType::visit(ArrayType *type)
|
||||
{
|
||||
_type.setType(_control->arrayType(_clone->type(type->elementType(), _subst), type->size()));
|
||||
}
|
||||
|
||||
void CloneType::visit(NamedType *type)
|
||||
{
|
||||
const Name *name = _clone->name(type->name(), _subst);
|
||||
FullySpecifiedType ty;
|
||||
if (_subst)
|
||||
ty = _subst->apply(name);
|
||||
if (! ty.isValid())
|
||||
ty = _control->namedType(name);
|
||||
_type.setType(ty.type());
|
||||
}
|
||||
|
||||
void CloneType::visit(Function *type)
|
||||
{
|
||||
Function *f = _clone->symbol(type, _subst)->asFunction();
|
||||
_type = f;
|
||||
}
|
||||
|
||||
void CloneType::visit(Namespace *type)
|
||||
{
|
||||
Namespace *ns = _clone->symbol(type, _subst)->asNamespace();
|
||||
_type = ns;
|
||||
}
|
||||
|
||||
void CloneType::visit(Template *type)
|
||||
{
|
||||
Template *templ = _clone->symbol(type, _subst)->asTemplate();
|
||||
_type = templ;
|
||||
}
|
||||
|
||||
void CloneType::visit(Class *type)
|
||||
{
|
||||
Class *klass = _clone->symbol(type, _subst)->asClass();
|
||||
_type = klass;
|
||||
}
|
||||
|
||||
void CloneType::visit(Enum *type)
|
||||
{
|
||||
Enum *e = _clone->symbol(type, _subst)->asEnum();
|
||||
_type = e;
|
||||
}
|
||||
|
||||
void CloneType::visit(ForwardClassDeclaration *type)
|
||||
{
|
||||
ForwardClassDeclaration *fwd = _clone->symbol(type, _subst)->asForwardClassDeclaration();
|
||||
_type = fwd;
|
||||
}
|
||||
|
||||
void CloneType::visit(ObjCClass *type)
|
||||
{
|
||||
ObjCClass *klass = _clone->symbol(type, _subst)->asObjCClass();
|
||||
_type = klass;
|
||||
}
|
||||
|
||||
void CloneType::visit(ObjCProtocol *type)
|
||||
{
|
||||
ObjCProtocol *proto = _clone->symbol(type, _subst)->asObjCProtocol();
|
||||
_type = proto;
|
||||
}
|
||||
|
||||
void CloneType::visit(ObjCMethod *type)
|
||||
{
|
||||
ObjCMethod *meth = _clone->symbol(type, _subst)->asObjCMethod();
|
||||
_type = meth;
|
||||
}
|
||||
|
||||
void CloneType::visit(ObjCForwardClassDeclaration *type)
|
||||
{
|
||||
ObjCForwardClassDeclaration *fwd = _clone->symbol(type, _subst)->asObjCForwardClassDeclaration();
|
||||
_type = fwd;
|
||||
}
|
||||
|
||||
void CloneType::visit(ObjCForwardProtocolDeclaration *type)
|
||||
{
|
||||
ObjCForwardProtocolDeclaration *fwd = _clone->symbol(type, _subst)->asObjCForwardProtocolDeclaration();
|
||||
_type = fwd;
|
||||
}
|
||||
|
||||
CloneSymbol::CloneSymbol(Clone *clone)
|
||||
: _clone(clone)
|
||||
, _control(clone->control())
|
||||
, _subst(0)
|
||||
, _symbol(0)
|
||||
{
|
||||
}
|
||||
|
||||
Symbol *CloneSymbol::cloneSymbol(Symbol *symbol, Subst *subst)
|
||||
{
|
||||
if (! symbol)
|
||||
return 0;
|
||||
|
||||
Symbol *r = 0;
|
||||
std::swap(_subst, subst);
|
||||
std::swap(_symbol, r);
|
||||
accept(symbol);
|
||||
std::swap(_symbol, r);
|
||||
std::swap(_subst, subst);
|
||||
assert(r != 0);
|
||||
return r;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(UsingNamespaceDirective *symbol)
|
||||
{
|
||||
UsingNamespaceDirective *u = new UsingNamespaceDirective(_clone, _subst, symbol);
|
||||
_symbol = u;
|
||||
_control->addSymbol(u);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(UsingDeclaration *symbol)
|
||||
{
|
||||
UsingDeclaration *u = new UsingDeclaration(_clone, _subst, symbol);
|
||||
_symbol = u;
|
||||
_control->addSymbol(u);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(NamespaceAlias *symbol)
|
||||
{
|
||||
NamespaceAlias *ns = new NamespaceAlias(_clone, _subst, symbol);
|
||||
_symbol = ns;
|
||||
_control->addSymbol(ns);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(Declaration *symbol)
|
||||
{
|
||||
Declaration *decl = new Declaration(_clone, _subst, symbol);
|
||||
_symbol = decl;
|
||||
_control->addSymbol(decl);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(Argument *symbol)
|
||||
{
|
||||
Argument *arg = new Argument(_clone, _subst, symbol);
|
||||
_symbol = arg;
|
||||
_control->addSymbol(arg);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(TypenameArgument *symbol)
|
||||
{
|
||||
TypenameArgument *arg = new TypenameArgument(_clone, _subst, symbol);
|
||||
_symbol = arg;
|
||||
_control->addSymbol(arg);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(BaseClass *symbol)
|
||||
{
|
||||
BaseClass *bc = new BaseClass(_clone, _subst, symbol);
|
||||
_symbol = bc;
|
||||
_control->addSymbol(bc);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(Enum *symbol)
|
||||
{
|
||||
Enum *e = new Enum(_clone, _subst, symbol);
|
||||
_symbol = e;
|
||||
_control->addSymbol(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(Function *symbol)
|
||||
{
|
||||
Function *fun = new Function(_clone, _subst, symbol);
|
||||
_symbol = fun;
|
||||
_control->addSymbol(fun);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(Namespace *symbol)
|
||||
{
|
||||
Namespace *ns = new Namespace(_clone, _subst, symbol);
|
||||
_symbol = ns;
|
||||
_control->addSymbol(ns);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(Template *symbol)
|
||||
{
|
||||
Template *templ = new Template(_clone, _subst, symbol);
|
||||
_symbol = templ;
|
||||
_control->addSymbol(templ);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(Class *symbol)
|
||||
{
|
||||
Class *klass = new Class(_clone, _subst, symbol);
|
||||
_symbol = klass;
|
||||
_control->addSymbol(klass);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(Block *symbol)
|
||||
{
|
||||
Block *block = new Block(_clone, _subst, symbol);
|
||||
_symbol = block;
|
||||
_control->addSymbol(block);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(ForwardClassDeclaration *symbol)
|
||||
{
|
||||
ForwardClassDeclaration *fwd = new ForwardClassDeclaration(_clone, _subst, symbol);
|
||||
_symbol = fwd;
|
||||
_control->addSymbol(fwd);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(QtPropertyDeclaration *symbol)
|
||||
{
|
||||
QtPropertyDeclaration *decl = new QtPropertyDeclaration(_clone, _subst, symbol);
|
||||
_symbol = decl;
|
||||
_control->addSymbol(decl);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(QtEnum *symbol)
|
||||
{
|
||||
QtEnum *e = new QtEnum(_clone, _subst, symbol);
|
||||
_symbol = e;
|
||||
_control->addSymbol(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(ObjCBaseClass *symbol)
|
||||
{
|
||||
ObjCBaseClass *bc = new ObjCBaseClass(_clone, _subst, symbol);
|
||||
_symbol = bc;
|
||||
_control->addSymbol(bc);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(ObjCBaseProtocol *symbol)
|
||||
{
|
||||
ObjCBaseProtocol *bc = new ObjCBaseProtocol(_clone, _subst, symbol);
|
||||
_symbol = bc;
|
||||
_control->addSymbol(bc);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(ObjCClass *symbol)
|
||||
{
|
||||
ObjCClass *klass = new ObjCClass(_clone, _subst, symbol);
|
||||
_symbol = klass;
|
||||
_control->addSymbol(klass);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(ObjCForwardClassDeclaration *symbol)
|
||||
{
|
||||
ObjCForwardClassDeclaration *fwd = new ObjCForwardClassDeclaration(_clone, _subst, symbol);
|
||||
_symbol = fwd;
|
||||
_control->addSymbol(fwd);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(ObjCProtocol *symbol)
|
||||
{
|
||||
ObjCProtocol *proto = new ObjCProtocol(_clone, _subst, symbol);
|
||||
_symbol = proto;
|
||||
_control->addSymbol(proto);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(ObjCForwardProtocolDeclaration *symbol)
|
||||
{
|
||||
ObjCForwardProtocolDeclaration *fwd = new ObjCForwardProtocolDeclaration(_clone, _subst, symbol);
|
||||
_symbol = fwd;
|
||||
_control->addSymbol(fwd);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(ObjCMethod *symbol)
|
||||
{
|
||||
ObjCMethod *meth = new ObjCMethod(_clone, _subst, symbol);
|
||||
_symbol = meth;
|
||||
_control->addSymbol(meth);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CloneSymbol::visit(ObjCPropertyDeclaration *symbol)
|
||||
{
|
||||
ObjCPropertyDeclaration *decl = new ObjCPropertyDeclaration(_clone, _subst, symbol);
|
||||
_symbol = decl;
|
||||
_control->addSymbol(decl);
|
||||
return false;
|
||||
}
|
||||
|
||||
CloneName::CloneName(Clone *clone)
|
||||
: _clone(clone)
|
||||
, _control(clone->control())
|
||||
, _subst(0)
|
||||
, _name(0)
|
||||
{
|
||||
}
|
||||
|
||||
const Name *CloneName::cloneName(const Name *name, Subst *subst)
|
||||
{
|
||||
if (! name)
|
||||
return 0;
|
||||
|
||||
const Name *r = 0;
|
||||
std::swap(_subst, subst);
|
||||
std::swap(_name, r);
|
||||
accept(name);
|
||||
std::swap(_name, r);
|
||||
std::swap(_subst, subst);
|
||||
assert(r != 0);
|
||||
return r;
|
||||
}
|
||||
|
||||
void CloneName::visit(const Identifier *name)
|
||||
{
|
||||
_name = _control->identifier(name->chars(), name->size());
|
||||
}
|
||||
|
||||
void CloneName::visit(const TemplateNameId *name)
|
||||
{
|
||||
std::vector<FullySpecifiedType> args(name->templateArgumentCount());
|
||||
for (unsigned i = 0; i < args.size(); ++i)
|
||||
args[i] = _clone->type(name->templateArgumentAt(i), _subst);
|
||||
if (args.empty())
|
||||
_name = _control->templateNameId(_clone->identifier(name->identifier()));
|
||||
else
|
||||
_name = _control->templateNameId(_clone->identifier(name->identifier()), &args[0], args.size());
|
||||
}
|
||||
|
||||
void CloneName::visit(const DestructorNameId *name)
|
||||
{
|
||||
_name = _control->destructorNameId(_clone->identifier(name->identifier()));
|
||||
}
|
||||
|
||||
void CloneName::visit(const OperatorNameId *name)
|
||||
{
|
||||
_name = _control->operatorNameId(name->kind());
|
||||
}
|
||||
|
||||
void CloneName::visit(const ConversionNameId *name)
|
||||
{
|
||||
_name = _control->conversionNameId(_clone->type(name->type(), _subst));
|
||||
}
|
||||
|
||||
void CloneName::visit(const QualifiedNameId *name)
|
||||
{
|
||||
_name = _control->qualifiedNameId(_clone->name(name->base(), _subst),
|
||||
_clone->name(name->name(), _subst));
|
||||
}
|
||||
|
||||
void CloneName::visit(const SelectorNameId *name)
|
||||
{
|
||||
assert(name->nameCount() > 0);
|
||||
std::vector<const Name *> names(name->nameCount());
|
||||
for (unsigned i = 0; i < names.size(); ++i)
|
||||
names[i] = _clone->name(name->nameAt(i), _subst);
|
||||
_name = _control->selectorNameId(&names[0], names.size(), name->hasArguments());
|
||||
}
|
||||
|
||||
|
||||
Clone::Clone(Control *control)
|
||||
: _control(control)
|
||||
, _type(this)
|
||||
, _name(this)
|
||||
, _symbol(this)
|
||||
{
|
||||
}
|
||||
|
||||
const StringLiteral *Clone::stringLiteral(const StringLiteral *literal)
|
||||
{
|
||||
return literal ? _control->stringLiteral(literal->chars(), literal->size()) : 0;
|
||||
}
|
||||
|
||||
const NumericLiteral *Clone::numericLiteral(const NumericLiteral *literal)
|
||||
{
|
||||
return literal ? _control->numericLiteral(literal->chars(), literal->size()) : 0;
|
||||
}
|
||||
|
||||
const Identifier *Clone::identifier(const Identifier *id)
|
||||
{
|
||||
return id ? _control->identifier(id->chars(), id->size()) : 0;
|
||||
}
|
||||
|
||||
FullySpecifiedType Clone::type(const FullySpecifiedType &type, Subst *subst)
|
||||
{
|
||||
return _type(type, subst);
|
||||
}
|
||||
|
||||
const Name *Clone::name(const Name *name, Subst *subst)
|
||||
{
|
||||
return _name(name, subst);
|
||||
}
|
||||
|
||||
Symbol *Clone::symbol(Symbol *symbol, Subst *subst)
|
||||
{
|
||||
return _symbol(symbol, subst);
|
||||
}
|
||||
|
||||
Symbol *Clone::instantiate(Template *templ, const FullySpecifiedType *const args, unsigned argc, Subst *s)
|
||||
{
|
||||
Subst subst(_control, s);
|
||||
for (unsigned i = 0, e = std::min(templ->templateParameterCount(), argc); i < e; ++i) {
|
||||
Symbol *formal = templ->templateParameterAt(i);
|
||||
FullySpecifiedType actual = args[i];
|
||||
subst.bind(name(formal->name(), 0), actual);
|
||||
}
|
||||
if (argc < templ->templateParameterCount()) {
|
||||
for (unsigned i = argc; i < templ->templateParameterCount(); ++i) {
|
||||
Symbol *formal = templ->templateParameterAt(i);
|
||||
if (TypenameArgument *tn = formal->asTypenameArgument()) {
|
||||
subst.bind(name(formal->name(), &subst), type(tn->type(), &subst));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Symbol *inst = symbol(templ->declaration(), &subst)) {
|
||||
inst->setScope(templ->enclosingScope());
|
||||
return inst;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// substitutions
|
||||
//
|
||||
FullySpecifiedType Subst::apply(const Name *name) const
|
||||
{
|
||||
if (name) {
|
||||
std::map<const Name *, FullySpecifiedType>::const_iterator it = _map.find(name);
|
||||
if (it != _map.end())
|
||||
return it->second;
|
||||
else if (_previous)
|
||||
return _previous->apply(name);
|
||||
|
||||
else if (const QualifiedNameId *q = name->asQualifiedNameId()) {
|
||||
const NamedType *name = apply(q->base())->asNamedType();
|
||||
const NamedType *unqualified = apply(q->name())->asNamedType();
|
||||
if (name && name->name()->identifier() != 0 && unqualified)
|
||||
return control()->namedType(control()->qualifiedNameId(name->name()->identifier(), unqualified->name()));
|
||||
}
|
||||
|
||||
}
|
||||
return FullySpecifiedType();
|
||||
}
|
||||
196
src/libs/3rdparty/cplusplus/Templates.h
vendored
Normal file
196
src/libs/3rdparty/cplusplus/Templates.h
vendored
Normal file
@@ -0,0 +1,196 @@
|
||||
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#ifndef CPLUSPLUS_TEMPLATES_H
|
||||
#define CPLUSPLUS_TEMPLATES_H
|
||||
|
||||
#include "CPlusPlusForwardDeclarations.h"
|
||||
#include "TypeVisitor.h"
|
||||
#include "FullySpecifiedType.h"
|
||||
#include "NameVisitor.h"
|
||||
#include "SymbolVisitor.h"
|
||||
#include <map>
|
||||
|
||||
namespace CPlusPlus {
|
||||
|
||||
class Clone;
|
||||
|
||||
class CPLUSPLUS_EXPORT Subst
|
||||
{
|
||||
Subst(const Subst &other);
|
||||
Subst &operator = (const Subst &other);
|
||||
|
||||
public:
|
||||
Subst(Control *control, Subst *previous = 0)
|
||||
: _control(control)
|
||||
, _previous(previous)
|
||||
{ }
|
||||
|
||||
Control *control() const { return _control; }
|
||||
Subst *previous() const { return _previous; }
|
||||
|
||||
FullySpecifiedType apply(const Name *name) const;
|
||||
|
||||
void bind(const Name *name, const FullySpecifiedType &ty)
|
||||
{ _map.insert(std::make_pair(name, ty)); }
|
||||
|
||||
FullySpecifiedType &operator[](const Name *name) { return _map[name]; }
|
||||
|
||||
private:
|
||||
Control *_control;
|
||||
Subst *_previous;
|
||||
std::map<const Name *, FullySpecifiedType> _map;
|
||||
};
|
||||
|
||||
class CPLUSPLUS_EXPORT CloneType: protected TypeVisitor
|
||||
{
|
||||
public:
|
||||
CloneType(Clone *clone);
|
||||
|
||||
FullySpecifiedType operator()(const FullySpecifiedType &type, Subst *subst) { return cloneType(type, subst); }
|
||||
FullySpecifiedType cloneType(const FullySpecifiedType &type, Subst *subst);
|
||||
|
||||
protected:
|
||||
virtual void visit(UndefinedType *type);
|
||||
virtual void visit(VoidType *type);
|
||||
virtual void visit(IntegerType *type);
|
||||
virtual void visit(FloatType *type);
|
||||
virtual void visit(PointerToMemberType *type);
|
||||
virtual void visit(PointerType *type);
|
||||
virtual void visit(ReferenceType *type);
|
||||
virtual void visit(ArrayType *type);
|
||||
virtual void visit(NamedType *type);
|
||||
virtual void visit(Function *type);
|
||||
virtual void visit(Namespace *type);
|
||||
virtual void visit(Template *type);
|
||||
virtual void visit(Class *type);
|
||||
virtual void visit(Enum *type);
|
||||
virtual void visit(ForwardClassDeclaration *type);
|
||||
virtual void visit(ObjCClass *type);
|
||||
virtual void visit(ObjCProtocol *type);
|
||||
virtual void visit(ObjCMethod *type);
|
||||
virtual void visit(ObjCForwardClassDeclaration *type);
|
||||
virtual void visit(ObjCForwardProtocolDeclaration *type);
|
||||
|
||||
protected:
|
||||
Clone *_clone;
|
||||
Control *_control;
|
||||
Subst *_subst;
|
||||
FullySpecifiedType _type;
|
||||
};
|
||||
|
||||
class CPLUSPLUS_EXPORT CloneName: protected NameVisitor
|
||||
{
|
||||
public:
|
||||
CloneName(Clone *clone);
|
||||
|
||||
const Name *operator()(const Name *name, Subst *subst) { return cloneName(name, subst); }
|
||||
const Name *cloneName(const Name *name, Subst *subst);
|
||||
|
||||
protected:
|
||||
virtual void visit(const Identifier *name);
|
||||
virtual void visit(const TemplateNameId *name);
|
||||
virtual void visit(const DestructorNameId *name);
|
||||
virtual void visit(const OperatorNameId *name);
|
||||
virtual void visit(const ConversionNameId *name);
|
||||
virtual void visit(const QualifiedNameId *name);
|
||||
virtual void visit(const SelectorNameId *name);
|
||||
|
||||
protected:
|
||||
Clone *_clone;
|
||||
Control *_control;
|
||||
Subst *_subst;
|
||||
const Name *_name;
|
||||
};
|
||||
|
||||
class CPLUSPLUS_EXPORT CloneSymbol: protected SymbolVisitor
|
||||
{
|
||||
public:
|
||||
CloneSymbol(Clone *clone);
|
||||
|
||||
Symbol *operator()(Symbol *symbol, Subst *subst) { return cloneSymbol(symbol, subst); }
|
||||
Symbol *cloneSymbol(Symbol *symbol, Subst *subst);
|
||||
|
||||
protected:
|
||||
virtual bool visit(UsingNamespaceDirective *symbol);
|
||||
virtual bool visit(UsingDeclaration *symbol);
|
||||
virtual bool visit(NamespaceAlias *symbol);
|
||||
virtual bool visit(Declaration *symbol);
|
||||
virtual bool visit(Argument *symbol);
|
||||
virtual bool visit(TypenameArgument *symbol);
|
||||
virtual bool visit(BaseClass *symbol);
|
||||
virtual bool visit(Enum *symbol);
|
||||
virtual bool visit(Function *symbol);
|
||||
virtual bool visit(Namespace *symbol);
|
||||
virtual bool visit(Template *symbol);
|
||||
virtual bool visit(Class *symbol);
|
||||
virtual bool visit(Block *symbol);
|
||||
virtual bool visit(ForwardClassDeclaration *symbol);
|
||||
|
||||
// Qt
|
||||
virtual bool visit(QtPropertyDeclaration *symbol);
|
||||
virtual bool visit(QtEnum *symbol);
|
||||
|
||||
// Objective-C
|
||||
virtual bool visit(ObjCBaseClass *symbol);
|
||||
virtual bool visit(ObjCBaseProtocol *symbol);
|
||||
virtual bool visit(ObjCClass *symbol);
|
||||
virtual bool visit(ObjCForwardClassDeclaration *symbol);
|
||||
virtual bool visit(ObjCProtocol *symbol);
|
||||
virtual bool visit(ObjCForwardProtocolDeclaration *symbol);
|
||||
virtual bool visit(ObjCMethod *symbol);
|
||||
virtual bool visit(ObjCPropertyDeclaration *symbol);
|
||||
|
||||
protected:
|
||||
Clone *_clone;
|
||||
Control *_control;
|
||||
Subst *_subst;
|
||||
Symbol *_symbol;
|
||||
};
|
||||
|
||||
class CPLUSPLUS_EXPORT Clone
|
||||
{
|
||||
Control *_control;
|
||||
|
||||
public:
|
||||
Clone(Control *control);
|
||||
|
||||
Control *control() const { return _control; }
|
||||
const StringLiteral *stringLiteral(const StringLiteral *literal);
|
||||
const NumericLiteral *numericLiteral(const NumericLiteral *literal);
|
||||
const Identifier *identifier(const Identifier *id);
|
||||
|
||||
FullySpecifiedType type(const FullySpecifiedType &type, Subst *subst);
|
||||
const Name *name(const Name *name, Subst *subst);
|
||||
Symbol *symbol(Symbol *symbol, Subst *subst);
|
||||
|
||||
Symbol *instantiate(Template *templ,
|
||||
const FullySpecifiedType *const args, unsigned argc,
|
||||
Subst *subst = 0);
|
||||
|
||||
private:
|
||||
CloneType _type;
|
||||
CloneName _name;
|
||||
CloneSymbol _symbol;
|
||||
};
|
||||
|
||||
} // end of namespace CPlusPlus
|
||||
|
||||
#endif // CPLUSPLUS_TEMPLATES_H
|
||||
6
src/libs/3rdparty/cplusplus/cplusplus.pri
vendored
6
src/libs/3rdparty/cplusplus/cplusplus.pri
vendored
@@ -33,7 +33,8 @@ HEADERS += \
|
||||
$$PWD/Type.h \
|
||||
$$PWD/TypeVisitor.h \
|
||||
$$PWD/ObjectiveCTypeQualifiers.h \
|
||||
$$PWD/QtContextKeywords.h
|
||||
$$PWD/QtContextKeywords.h \
|
||||
$$PWD/Templates.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/AST.cpp \
|
||||
@@ -68,4 +69,5 @@ SOURCES += \
|
||||
$$PWD/TranslationUnit.cpp \
|
||||
$$PWD/Type.cpp \
|
||||
$$PWD/TypeVisitor.cpp \
|
||||
$$PWD/QtContextKeywords.cpp
|
||||
$$PWD/QtContextKeywords.cpp \
|
||||
$$PWD/Templates.cpp
|
||||
|
||||
Reference in New Issue
Block a user