Skip to content
Snippets Groups Projects
Commit 960716df authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Cleanup

parent 213316f2
No related branches found
No related tags found
No related merge requests found
...@@ -47,13 +47,13 @@ namespace { ...@@ -47,13 +47,13 @@ namespace {
class ApplySubstitution class ApplySubstitution
{ {
public: public:
ApplySubstitution(const LookupContext &context, const GenTemplateInstance::Substitution &substitution); ApplySubstitution(const LookupContext &context, Symbol *symbol, const GenTemplateInstance::Substitution &substitution);
~ApplySubstitution(); ~ApplySubstitution();
Control *control() const { return context.control(); } Control *control() const { return context.control(); }
FullySpecifiedType operator()(Name *name); FullySpecifiedType apply(Name *name);
FullySpecifiedType operator()(const FullySpecifiedType &type); FullySpecifiedType apply(const FullySpecifiedType &type);
int findSubstitution(Identifier *id) const; int findSubstitution(Identifier *id) const;
FullySpecifiedType applySubstitution(int index) const; FullySpecifiedType applySubstitution(int index) const;
...@@ -107,22 +107,22 @@ private: ...@@ -107,22 +107,22 @@ private:
virtual void visit(PointerType *ptrTy) virtual void visit(PointerType *ptrTy)
{ {
_type.setType(control()->pointerType(operator()(ptrTy->elementType()))); _type.setType(control()->pointerType(q->apply(ptrTy->elementType())));
} }
virtual void visit(ReferenceType *refTy) virtual void visit(ReferenceType *refTy)
{ {
_type.setType(control()->referenceType(operator()(refTy->elementType()))); _type.setType(control()->referenceType(q->apply(refTy->elementType())));
} }
virtual void visit(ArrayType *arrayTy) virtual void visit(ArrayType *arrayTy)
{ {
_type.setType(control()->arrayType(operator()(arrayTy->elementType()), arrayTy->size())); _type.setType(control()->arrayType(q->apply(arrayTy->elementType()), arrayTy->size()));
} }
virtual void visit(NamedType *ty) virtual void visit(NamedType *ty)
{ {
FullySpecifiedType n = q->operator ()(ty->name()); FullySpecifiedType n = q->apply(ty->name());
_type.setType(n.type()); _type.setType(n.type());
} }
...@@ -136,14 +136,14 @@ private: ...@@ -136,14 +136,14 @@ private:
fun->setAmbiguous(funTy->isAmbiguous()); fun->setAmbiguous(funTy->isAmbiguous());
fun->setVariadic(funTy->isVariadic()); fun->setVariadic(funTy->isVariadic());
fun->setReturnType(q->operator ()(funTy->returnType())); fun->setReturnType(q->apply(funTy->returnType()));
for (unsigned i = 0; i < funTy->argumentCount(); ++i) { for (unsigned i = 0; i < funTy->argumentCount(); ++i) {
Argument *originalArgument = funTy->argumentAt(i)->asArgument(); Argument *originalArgument = funTy->argumentAt(i)->asArgument();
Argument *arg = control()->newArgument(/*sourceLocation*/ 0, Argument *arg = control()->newArgument(/*sourceLocation*/ 0,
originalArgument->name()); originalArgument->name());
arg->setType(q->operator ()(originalArgument->type())); arg->setType(q->apply(originalArgument->type()));
arg->setInitializer(originalArgument->hasInitializer()); arg->setInitializer(originalArgument->hasInitializer());
fun->arguments()->enterSymbol(arg); fun->arguments()->enterSymbol(arg);
} }
...@@ -199,6 +199,7 @@ private: ...@@ -199,6 +199,7 @@ private:
private: private:
ApplySubstitution *q; ApplySubstitution *q;
FullySpecifiedType _type; FullySpecifiedType _type;
QHash<Symbol *, FullySpecifiedType> _processed;
}; };
class ApplyToName: protected NameVisitor class ApplyToName: protected NameVisitor
...@@ -246,7 +247,7 @@ private: ...@@ -246,7 +247,7 @@ private:
QVarLengthArray<FullySpecifiedType, 8> arguments(name->templateArgumentCount()); QVarLengthArray<FullySpecifiedType, 8> arguments(name->templateArgumentCount());
for (unsigned i = 0; i < name->templateArgumentCount(); ++i) { for (unsigned i = 0; i < name->templateArgumentCount(); ++i) {
FullySpecifiedType argTy = name->templateArgumentAt(i); FullySpecifiedType argTy = name->templateArgumentAt(i);
arguments[i] = q->operator ()(argTy); arguments[i] = q->apply(argTy);
} }
TemplateNameId *templId = control()->templateNameId(name->identifier(), arguments.data(), arguments.size()); TemplateNameId *templId = control()->templateNameId(name->identifier(), arguments.data(), arguments.size());
...@@ -263,7 +264,7 @@ private: ...@@ -263,7 +264,7 @@ private:
QVarLengthArray<FullySpecifiedType, 8> arguments(templId->templateArgumentCount()); QVarLengthArray<FullySpecifiedType, 8> arguments(templId->templateArgumentCount());
for (unsigned templateArgIndex = 0; templateArgIndex < templId->templateArgumentCount(); ++templateArgIndex) { for (unsigned templateArgIndex = 0; templateArgIndex < templId->templateArgumentCount(); ++templateArgIndex) {
FullySpecifiedType argTy = templId->templateArgumentAt(templateArgIndex); FullySpecifiedType argTy = templId->templateArgumentAt(templateArgIndex);
arguments[templateArgIndex] = q->operator ()(argTy); arguments[templateArgIndex] = q->apply(argTy);
} }
n = control()->templateNameId(templId->identifier(), arguments.data(), arguments.size()); n = control()->templateNameId(templId->identifier(), arguments.data(), arguments.size());
...@@ -307,26 +308,34 @@ private: ...@@ -307,26 +308,34 @@ private:
public: // attributes public: // attributes
LookupContext context; LookupContext context;
Symbol *symbol;
GenTemplateInstance::Substitution substitution; GenTemplateInstance::Substitution substitution;
private:
ApplyToType applyToType; ApplyToType applyToType;
ApplyToName applyToName; ApplyToName applyToName;
}; };
ApplySubstitution::ApplySubstitution(const LookupContext &context, const GenTemplateInstance::Substitution &substitution) ApplySubstitution::ApplySubstitution(const LookupContext &context, Symbol *symbol,
: context(context), substitution(substitution), applyToType(this), applyToName(this) const GenTemplateInstance::Substitution &substitution)
: context(context), symbol(symbol),
substitution(substitution),
applyToType(this), applyToName(this)
{ } { }
ApplySubstitution::~ApplySubstitution() ApplySubstitution::~ApplySubstitution()
{ {
} }
FullySpecifiedType ApplySubstitution::operator()(Name *name) FullySpecifiedType ApplySubstitution::apply(Name *name)
{ return applyToName(name); } {
FullySpecifiedType ty = applyToName(name);
return ty;
}
FullySpecifiedType ApplySubstitution::operator()(const FullySpecifiedType &type) FullySpecifiedType ApplySubstitution::apply(const FullySpecifiedType &type)
{ return applyToType(type); } {
FullySpecifiedType ty = applyToType(type);
return ty;
}
int ApplySubstitution::findSubstitution(Identifier *id) const int ApplySubstitution::findSubstitution(Identifier *id) const
{ {
...@@ -360,8 +369,8 @@ GenTemplateInstance::GenTemplateInstance(const LookupContext &context, const Sub ...@@ -360,8 +369,8 @@ GenTemplateInstance::GenTemplateInstance(const LookupContext &context, const Sub
FullySpecifiedType GenTemplateInstance::operator()(Symbol *symbol) FullySpecifiedType GenTemplateInstance::operator()(Symbol *symbol)
{ {
ApplySubstitution o(_context, _substitution); ApplySubstitution o(_context, symbol, _substitution);
return o(symbol->type()); return o.apply(symbol->type());
} }
Control *GenTemplateInstance::control() const Control *GenTemplateInstance::control() const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment