forked from qt-creator/qt-creator
Introduced CPlusPlus::TemplateArguments and fixed a possible mem-leak when using template members.
This commit is contained in:
@@ -90,6 +90,7 @@ class StringLiteral;
|
|||||||
class NumericLiteral;
|
class NumericLiteral;
|
||||||
|
|
||||||
class Scope;
|
class Scope;
|
||||||
|
class TemplateParameters;
|
||||||
|
|
||||||
// names
|
// names
|
||||||
class NameVisitor;
|
class NameVisitor;
|
||||||
|
@@ -72,10 +72,10 @@ CheckDeclaration::~CheckDeclaration()
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
void CheckDeclaration::check(DeclarationAST *declaration,
|
void CheckDeclaration::check(DeclarationAST *declaration,
|
||||||
Scope *scope, Scope *templateParameters)
|
Scope *scope, TemplateParameters *templateParameters)
|
||||||
{
|
{
|
||||||
Scope *previousScope = switchScope(scope);
|
Scope *previousScope = switchScope(scope);
|
||||||
Scope *previousTemplateParameters = switchTemplateParameters(templateParameters);
|
TemplateParameters *previousTemplateParameters = switchTemplateParameters(templateParameters);
|
||||||
DeclarationAST *previousDeclaration = switchDeclaration(declaration);
|
DeclarationAST *previousDeclaration = switchDeclaration(declaration);
|
||||||
accept(declaration);
|
accept(declaration);
|
||||||
(void) switchDeclaration(previousDeclaration);
|
(void) switchDeclaration(previousDeclaration);
|
||||||
@@ -97,9 +97,9 @@ Scope *CheckDeclaration::switchScope(Scope *scope)
|
|||||||
return previousScope;
|
return previousScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
Scope *CheckDeclaration::switchTemplateParameters(Scope *templateParameters)
|
TemplateParameters *CheckDeclaration::switchTemplateParameters(TemplateParameters *templateParameters)
|
||||||
{
|
{
|
||||||
Scope *previousTemplateParameters = _templateParameters;
|
TemplateParameters *previousTemplateParameters = _templateParameters;
|
||||||
_templateParameters = templateParameters;
|
_templateParameters = templateParameters;
|
||||||
return previousTemplateParameters;
|
return previousTemplateParameters;
|
||||||
}
|
}
|
||||||
@@ -395,13 +395,15 @@ bool CheckDeclaration::visit(ParameterDeclarationAST *ast)
|
|||||||
|
|
||||||
bool CheckDeclaration::visit(TemplateDeclarationAST *ast)
|
bool CheckDeclaration::visit(TemplateDeclarationAST *ast)
|
||||||
{
|
{
|
||||||
Scope *previousScope = switchScope(new Scope(_scope->owner()));
|
Scope *scope = new Scope(_scope->owner());
|
||||||
|
|
||||||
for (DeclarationListAST *param = ast->template_parameters; param; param = param->next) {
|
for (DeclarationListAST *param = ast->template_parameters; param; param = param->next) {
|
||||||
semantic()->check(param->declaration, _scope);
|
semantic()->check(param->declaration, scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
Scope *templateParameters = switchScope(previousScope);
|
semantic()->check(ast->declaration, _scope,
|
||||||
semantic()->check(ast->declaration, _scope, templateParameters);
|
new TemplateParameters(_templateParameters, scope));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,12 +61,12 @@ public:
|
|||||||
CheckDeclaration(Semantic *semantic);
|
CheckDeclaration(Semantic *semantic);
|
||||||
virtual ~CheckDeclaration();
|
virtual ~CheckDeclaration();
|
||||||
|
|
||||||
void check(DeclarationAST *declaration, Scope *scope, Scope *templateParameters);
|
void check(DeclarationAST *declaration, Scope *scope, TemplateParameters *templateParameters);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DeclarationAST *switchDeclaration(DeclarationAST *declaration);
|
DeclarationAST *switchDeclaration(DeclarationAST *declaration);
|
||||||
Scope *switchScope(Scope *scope);
|
Scope *switchScope(Scope *scope);
|
||||||
Scope *switchTemplateParameters(Scope *templateParameters);
|
TemplateParameters *switchTemplateParameters(TemplateParameters *templateParameters);
|
||||||
|
|
||||||
void checkFunctionArguments(Function *fun);
|
void checkFunctionArguments(Function *fun);
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
DeclarationAST *_declaration;
|
DeclarationAST *_declaration;
|
||||||
Scope *_scope;
|
Scope *_scope;
|
||||||
Scope *_templateParameters;
|
TemplateParameters *_templateParameters;
|
||||||
bool _checkAnonymousArguments: 1;
|
bool _checkAnonymousArguments: 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -123,7 +123,7 @@ Control *Semantic::control() const
|
|||||||
FullySpecifiedType Semantic::check(SpecifierAST *specifier, Scope *scope)
|
FullySpecifiedType Semantic::check(SpecifierAST *specifier, Scope *scope)
|
||||||
{ return d->checkSpecifier->check(specifier, scope); }
|
{ return d->checkSpecifier->check(specifier, scope); }
|
||||||
|
|
||||||
void Semantic::check(DeclarationAST *declaration, Scope *scope, Scope *templateParameters)
|
void Semantic::check(DeclarationAST *declaration, Scope *scope, TemplateParameters *templateParameters)
|
||||||
{ d->checkDeclaration->check(declaration, scope, templateParameters); }
|
{ d->checkDeclaration->check(declaration, scope, templateParameters); }
|
||||||
|
|
||||||
FullySpecifiedType Semantic::check(DeclaratorAST *declarator, FullySpecifiedType type,
|
FullySpecifiedType Semantic::check(DeclaratorAST *declarator, FullySpecifiedType type,
|
||||||
|
@@ -78,7 +78,7 @@ public:
|
|||||||
|
|
||||||
FullySpecifiedType check(ExpressionAST *expression, Scope *scope);
|
FullySpecifiedType check(ExpressionAST *expression, Scope *scope);
|
||||||
|
|
||||||
void check(DeclarationAST *declaration, Scope *scope, Scope *templateParameters = 0);
|
void check(DeclarationAST *declaration, Scope *scope, TemplateParameters *templateParameters = 0);
|
||||||
|
|
||||||
void check(StatementAST *statement, Scope *scope);
|
void check(StatementAST *statement, Scope *scope);
|
||||||
|
|
||||||
|
@@ -55,6 +55,26 @@
|
|||||||
|
|
||||||
CPLUSPLUS_BEGIN_NAMESPACE
|
CPLUSPLUS_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
TemplateParameters::TemplateParameters(Scope *scope)
|
||||||
|
: _previous(0), _scope(scope)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
TemplateParameters::TemplateParameters(TemplateParameters *previous, Scope *scope)
|
||||||
|
: _previous(previous), _scope(scope)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
TemplateParameters::~TemplateParameters()
|
||||||
|
{
|
||||||
|
delete _previous;
|
||||||
|
delete _scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateParameters *TemplateParameters::previous() const
|
||||||
|
{ return _previous; }
|
||||||
|
|
||||||
|
Scope *TemplateParameters::scope() const
|
||||||
|
{ return _scope; }
|
||||||
|
|
||||||
UsingNamespaceDirective::UsingNamespaceDirective(TranslationUnit *translationUnit,
|
UsingNamespaceDirective::UsingNamespaceDirective(TranslationUnit *translationUnit,
|
||||||
unsigned sourceLocation, Name *name)
|
unsigned sourceLocation, Name *name)
|
||||||
: Symbol(translationUnit, sourceLocation, name)
|
: Symbol(translationUnit, sourceLocation, name)
|
||||||
@@ -91,20 +111,10 @@ Declaration::Declaration(TranslationUnit *translationUnit, unsigned sourceLocati
|
|||||||
Declaration::~Declaration()
|
Declaration::~Declaration()
|
||||||
{ delete _templateParameters; }
|
{ delete _templateParameters; }
|
||||||
|
|
||||||
unsigned Declaration::templateParameterCount() const
|
TemplateParameters *Declaration::templateParameters() const
|
||||||
{
|
|
||||||
if (! _templateParameters)
|
|
||||||
return 0;
|
|
||||||
return _templateParameters->symbolCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
Symbol *Declaration::templateParameterAt(unsigned index) const
|
|
||||||
{ return _templateParameters->symbolAt(index); }
|
|
||||||
|
|
||||||
Scope *Declaration::templateParameters() const
|
|
||||||
{ return _templateParameters; }
|
{ return _templateParameters; }
|
||||||
|
|
||||||
void Declaration::setTemplateParameters(Scope *templateParameters)
|
void Declaration::setTemplateParameters(TemplateParameters *templateParameters)
|
||||||
{ _templateParameters = templateParameters; }
|
{ _templateParameters = templateParameters; }
|
||||||
|
|
||||||
void Declaration::setType(FullySpecifiedType type)
|
void Declaration::setType(FullySpecifiedType type)
|
||||||
@@ -170,16 +180,17 @@ unsigned Function::templateParameterCount() const
|
|||||||
{
|
{
|
||||||
if (! _templateParameters)
|
if (! _templateParameters)
|
||||||
return 0;
|
return 0;
|
||||||
return _templateParameters->symbolCount();
|
|
||||||
|
return _templateParameters->scope()->symbolCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
Symbol *Function::templateParameterAt(unsigned index) const
|
Symbol *Function::templateParameterAt(unsigned index) const
|
||||||
{ return _templateParameters->symbolAt(index); }
|
{ return _templateParameters->scope()->symbolAt(index); }
|
||||||
|
|
||||||
Scope *Function::templateParameters() const
|
TemplateParameters *Function::templateParameters() const
|
||||||
{ return _templateParameters; }
|
{ return _templateParameters; }
|
||||||
|
|
||||||
void Function::setTemplateParameters(Scope *templateParameters)
|
void Function::setTemplateParameters(TemplateParameters *templateParameters)
|
||||||
{ _templateParameters = templateParameters; }
|
{ _templateParameters = templateParameters; }
|
||||||
|
|
||||||
bool Function::isEqualTo(const Type *other) const
|
bool Function::isEqualTo(const Type *other) const
|
||||||
@@ -435,20 +446,10 @@ ForwardClassDeclaration::ForwardClassDeclaration(TranslationUnit *translationUni
|
|||||||
ForwardClassDeclaration::~ForwardClassDeclaration()
|
ForwardClassDeclaration::~ForwardClassDeclaration()
|
||||||
{ delete _templateParameters; }
|
{ delete _templateParameters; }
|
||||||
|
|
||||||
unsigned ForwardClassDeclaration::templateParameterCount() const
|
TemplateParameters *ForwardClassDeclaration::templateParameters() const
|
||||||
{
|
|
||||||
if (! _templateParameters)
|
|
||||||
return 0;
|
|
||||||
return _templateParameters->symbolCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
Symbol *ForwardClassDeclaration::templateParameterAt(unsigned index) const
|
|
||||||
{ return _templateParameters->symbolAt(index); }
|
|
||||||
|
|
||||||
Scope *ForwardClassDeclaration::templateParameters() const
|
|
||||||
{ return _templateParameters; }
|
{ return _templateParameters; }
|
||||||
|
|
||||||
void ForwardClassDeclaration::setTemplateParameters(Scope *templateParameters)
|
void ForwardClassDeclaration::setTemplateParameters(TemplateParameters *templateParameters)
|
||||||
{ _templateParameters = templateParameters; }
|
{ _templateParameters = templateParameters; }
|
||||||
|
|
||||||
FullySpecifiedType ForwardClassDeclaration::type() const
|
FullySpecifiedType ForwardClassDeclaration::type() const
|
||||||
@@ -501,16 +502,17 @@ unsigned Class::templateParameterCount() const
|
|||||||
{
|
{
|
||||||
if (! _templateParameters)
|
if (! _templateParameters)
|
||||||
return 0;
|
return 0;
|
||||||
return _templateParameters->symbolCount();
|
|
||||||
|
return _templateParameters->scope()->symbolCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
Symbol *Class::templateParameterAt(unsigned index) const
|
Symbol *Class::templateParameterAt(unsigned index) const
|
||||||
{ return _templateParameters->symbolAt(index); }
|
{ return _templateParameters->scope()->symbolAt(index); }
|
||||||
|
|
||||||
Scope *Class::templateParameters() const
|
TemplateParameters *Class::templateParameters() const
|
||||||
{ return _templateParameters; }
|
{ return _templateParameters; }
|
||||||
|
|
||||||
void Class::setTemplateParameters(Scope *templateParameters)
|
void Class::setTemplateParameters(TemplateParameters *templateParameters)
|
||||||
{ _templateParameters = templateParameters; }
|
{ _templateParameters = templateParameters; }
|
||||||
|
|
||||||
void Class::accept0(TypeVisitor *visitor)
|
void Class::accept0(TypeVisitor *visitor)
|
||||||
|
@@ -58,6 +58,21 @@
|
|||||||
CPLUSPLUS_BEGIN_HEADER
|
CPLUSPLUS_BEGIN_HEADER
|
||||||
CPLUSPLUS_BEGIN_NAMESPACE
|
CPLUSPLUS_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class TemplateParameters
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TemplateParameters(Scope *scope);
|
||||||
|
TemplateParameters(TemplateParameters *previous, Scope *scope);
|
||||||
|
~TemplateParameters();
|
||||||
|
|
||||||
|
TemplateParameters *previous() const;
|
||||||
|
Scope *scope() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
TemplateParameters *_previous;
|
||||||
|
Scope *_scope;
|
||||||
|
};
|
||||||
|
|
||||||
class CPLUSPLUS_EXPORT UsingNamespaceDirective: public Symbol
|
class CPLUSPLUS_EXPORT UsingNamespaceDirective: public Symbol
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -102,11 +117,8 @@ public:
|
|||||||
Declaration(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
|
Declaration(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
|
||||||
virtual ~Declaration();
|
virtual ~Declaration();
|
||||||
|
|
||||||
unsigned templateParameterCount() const;
|
TemplateParameters *templateParameters() const;
|
||||||
Symbol *templateParameterAt(unsigned index) const;
|
void setTemplateParameters(TemplateParameters *templateParameters);
|
||||||
|
|
||||||
Scope *templateParameters() const;
|
|
||||||
void setTemplateParameters(Scope *templateParameters);
|
|
||||||
|
|
||||||
void setType(FullySpecifiedType type);
|
void setType(FullySpecifiedType type);
|
||||||
|
|
||||||
@@ -124,7 +136,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
FullySpecifiedType _type;
|
FullySpecifiedType _type;
|
||||||
Scope *_templateParameters;
|
TemplateParameters *_templateParameters;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CPLUSPLUS_EXPORT Argument: public Symbol
|
class CPLUSPLUS_EXPORT Argument: public Symbol
|
||||||
@@ -201,11 +213,8 @@ public:
|
|||||||
ForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
|
ForwardClassDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
|
||||||
virtual ~ForwardClassDeclaration();
|
virtual ~ForwardClassDeclaration();
|
||||||
|
|
||||||
unsigned templateParameterCount() const;
|
TemplateParameters *templateParameters() const;
|
||||||
Symbol *templateParameterAt(unsigned index) const;
|
void setTemplateParameters(TemplateParameters *templateParameters);
|
||||||
|
|
||||||
Scope *templateParameters() const;
|
|
||||||
void setTemplateParameters(Scope *templateParameters);
|
|
||||||
|
|
||||||
virtual FullySpecifiedType type() const;
|
virtual FullySpecifiedType type() const;
|
||||||
|
|
||||||
@@ -228,7 +237,7 @@ protected:
|
|||||||
virtual void accept0(TypeVisitor *visitor);
|
virtual void accept0(TypeVisitor *visitor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Scope *_templateParameters;
|
TemplateParameters *_templateParameters;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CPLUSPLUS_EXPORT Enum: public ScopedSymbol, public Type
|
class CPLUSPLUS_EXPORT Enum: public ScopedSymbol, public Type
|
||||||
@@ -279,11 +288,11 @@ public:
|
|||||||
int methodKey() const;
|
int methodKey() const;
|
||||||
void setMethodKey(int key);
|
void setMethodKey(int key);
|
||||||
|
|
||||||
unsigned templateParameterCount() const;
|
unsigned templateParameterCount() const; // ### remove me
|
||||||
Symbol *templateParameterAt(unsigned index) const;
|
Symbol *templateParameterAt(unsigned index) const; // ### remove me
|
||||||
|
|
||||||
Scope *templateParameters() const;
|
TemplateParameters *templateParameters() const;
|
||||||
void setTemplateParameters(Scope *templateParameters);
|
void setTemplateParameters(TemplateParameters *templateParameters);
|
||||||
|
|
||||||
FullySpecifiedType returnType() const;
|
FullySpecifiedType returnType() const;
|
||||||
void setReturnType(FullySpecifiedType returnType);
|
void setReturnType(FullySpecifiedType returnType);
|
||||||
@@ -336,7 +345,7 @@ protected:
|
|||||||
virtual void accept0(TypeVisitor *visitor);
|
virtual void accept0(TypeVisitor *visitor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Scope *_templateParameters;
|
TemplateParameters *_templateParameters;
|
||||||
FullySpecifiedType _returnType;
|
FullySpecifiedType _returnType;
|
||||||
struct Flags {
|
struct Flags {
|
||||||
unsigned _isVariadic: 1;
|
unsigned _isVariadic: 1;
|
||||||
@@ -425,11 +434,11 @@ public:
|
|||||||
Key classKey() const;
|
Key classKey() const;
|
||||||
void setClassKey(Key key);
|
void setClassKey(Key key);
|
||||||
|
|
||||||
unsigned templateParameterCount() const;
|
unsigned templateParameterCount() const; // ### remove me
|
||||||
Symbol *templateParameterAt(unsigned index) const;
|
Symbol *templateParameterAt(unsigned index) const; // ### remove me
|
||||||
|
|
||||||
Scope *templateParameters() const;
|
TemplateParameters *templateParameters() const;
|
||||||
void setTemplateParameters(Scope *templateParameters);
|
void setTemplateParameters(TemplateParameters *templateParameters);
|
||||||
|
|
||||||
unsigned baseClassCount() const;
|
unsigned baseClassCount() const;
|
||||||
BaseClass *baseClassAt(unsigned index) const;
|
BaseClass *baseClassAt(unsigned index) const;
|
||||||
@@ -459,7 +468,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Key _key;
|
Key _key;
|
||||||
Scope *_templateParameters;
|
TemplateParameters *_templateParameters;
|
||||||
Array<BaseClass *> _baseClasses;
|
Array<BaseClass *> _baseClasses;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -102,7 +102,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! _removed.contains(i))
|
if (! _removed.contains(i))
|
||||||
out->append(source + tk.begin(), tk.length);
|
out->append(source + tk.begin(), tk.f.length);
|
||||||
|
|
||||||
it = _insertAfter.constFind(i);
|
it = _insertAfter.constFind(i);
|
||||||
for (; it != _insertAfter.constEnd() && it.key() == i; ++it) {
|
for (; it != _insertAfter.constEnd() && it.key() == i; ++it) {
|
||||||
|
Reference in New Issue
Block a user