| 
									
										
										
										
											2009-10-26 18:00:49 +01:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-03-05 11:25:49 +01:00
										 |  |  | ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2009-10-26 18:00:49 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ** 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.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | **************************************************************************/ | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-20 13:44:38 +02:00
										 |  |  | #include "DeprecatedGenTemplateInstance.h"
 | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | #include "Overview.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | #include <Control.h>
 | 
					
						
							|  |  |  | #include <Scope.h>
 | 
					
						
							|  |  |  | #include <Names.h>
 | 
					
						
							|  |  |  | #include <Symbols.h>
 | 
					
						
							|  |  |  | #include <CoreTypes.h>
 | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | #include <Literals.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | #include <QtCore/QVarLengthArray>
 | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | #include <QtCore/QDebug>
 | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace CPlusPlus; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | namespace { | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | class ApplySubstitution | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2010-05-20 13:44:38 +02:00
										 |  |  |     ApplySubstitution(Control *control, Symbol *symbol, const DeprecatedGenTemplateInstance::Substitution &substitution); | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |     ~ApplySubstitution(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-05 12:06:38 +02:00
										 |  |  |     inline Control *control() const { return _control; } | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 12:46:15 +01:00
										 |  |  |     FullySpecifiedType apply(const Name *name); | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  |     FullySpecifiedType apply(const FullySpecifiedType &type); | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 11:33:13 +01:00
										 |  |  |     int findSubstitution(const Identifier *id) const; | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |     FullySpecifiedType applySubstitution(int index) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     class ApplyToType: protected TypeVisitor | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         ApplyToType(ApplySubstitution *q) | 
					
						
							|  |  |  |             : q(q) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         FullySpecifiedType operator()(const FullySpecifiedType &ty) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             FullySpecifiedType previousType = switchType(ty); | 
					
						
							|  |  |  |             accept(ty.type()); | 
					
						
							|  |  |  |             return switchType(previousType); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected: | 
					
						
							|  |  |  |         using TypeVisitor::visit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Control *control() const | 
					
						
							|  |  |  |         { return q->control(); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         FullySpecifiedType switchType(const FullySpecifiedType &type) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             FullySpecifiedType previousType = _type; | 
					
						
							|  |  |  |             _type = type; | 
					
						
							|  |  |  |             return previousType; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(VoidType *) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // nothing to do
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(IntegerType *) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // nothing to do
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(FloatType *) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             // nothing to do
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(PointerToMemberType *) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qDebug() << Q_FUNC_INFO; // ### TODO
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(PointerType *ptrTy) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  |             _type.setType(control()->pointerType(q->apply(ptrTy->elementType()))); | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(ReferenceType *refTy) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  |             _type.setType(control()->referenceType(q->apply(refTy->elementType()))); | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(ArrayType *arrayTy) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  |             _type.setType(control()->arrayType(q->apply(arrayTy->elementType()), arrayTy->size())); | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(NamedType *ty) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  |             FullySpecifiedType n = q->apply(ty->name()); | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |             _type.setType(n.type()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(Function *funTy) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             Function *fun = control()->newFunction(/*sourceLocation=*/ 0, funTy->name()); | 
					
						
							|  |  |  |             fun->setScope(funTy->scope()); | 
					
						
							|  |  |  |             fun->setConst(funTy->isConst()); | 
					
						
							|  |  |  |             fun->setVolatile(funTy->isVolatile()); | 
					
						
							|  |  |  |             fun->setVirtual(funTy->isVirtual()); | 
					
						
							|  |  |  |             fun->setAmbiguous(funTy->isAmbiguous()); | 
					
						
							|  |  |  |             fun->setVariadic(funTy->isVariadic()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  |             fun->setReturnType(q->apply(funTy->returnType())); | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             for (unsigned i = 0; i < funTy->argumentCount(); ++i) { | 
					
						
							|  |  |  |                 Argument *originalArgument = funTy->argumentAt(i)->asArgument(); | 
					
						
							|  |  |  |                 Argument *arg = control()->newArgument(/*sourceLocation*/ 0, | 
					
						
							|  |  |  |                                                        originalArgument->name()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  |                 arg->setType(q->apply(originalArgument->type())); | 
					
						
							| 
									
										
										
										
											2009-12-08 11:34:22 +01:00
										 |  |  |                 arg->setInitializer(originalArgument->initializer()); | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |                 fun->arguments()->enterSymbol(arg); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             _type.setType(fun); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(Namespace *) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qDebug() << Q_FUNC_INFO; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(Class *) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qDebug() << Q_FUNC_INFO; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(Enum *) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qDebug() << Q_FUNC_INFO; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(ForwardClassDeclaration *) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qDebug() << Q_FUNC_INFO; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(ObjCClass *) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qDebug() << Q_FUNC_INFO; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(ObjCProtocol *) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qDebug() << Q_FUNC_INFO; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(ObjCMethod *) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qDebug() << Q_FUNC_INFO; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(ObjCForwardClassDeclaration *) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qDebug() << Q_FUNC_INFO; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(ObjCForwardProtocolDeclaration *) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qDebug() << Q_FUNC_INFO; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         ApplySubstitution *q; | 
					
						
							|  |  |  |         FullySpecifiedType _type; | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  |         QHash<Symbol *, FullySpecifiedType> _processed; | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class ApplyToName: protected NameVisitor | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         ApplyToName(ApplySubstitution *q): q(q) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 12:46:15 +01:00
										 |  |  |         FullySpecifiedType operator()(const Name *name) | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             FullySpecifiedType previousType = switchType(FullySpecifiedType()); | 
					
						
							|  |  |  |             accept(name); | 
					
						
							|  |  |  |             return switchType(previousType); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected: | 
					
						
							|  |  |  |         Control *control() const | 
					
						
							|  |  |  |         { return q->control(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 11:33:13 +01:00
										 |  |  |         int findSubstitution(const Identifier *id) const | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         { return q->findSubstitution(id); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         FullySpecifiedType applySubstitution(int index) const | 
					
						
							|  |  |  |         { return q->applySubstitution(index); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         FullySpecifiedType switchType(const FullySpecifiedType &type) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             FullySpecifiedType previousType = _type; | 
					
						
							|  |  |  |             _type = type; | 
					
						
							|  |  |  |             return previousType; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 12:46:15 +01:00
										 |  |  |         virtual void visit(const NameId *name) | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             int index = findSubstitution(name->identifier()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (index != -1) | 
					
						
							|  |  |  |                 _type = applySubstitution(index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 _type = control()->namedType(name); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 12:46:15 +01:00
										 |  |  |         virtual void visit(const TemplateNameId *name) | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             QVarLengthArray<FullySpecifiedType, 8> arguments(name->templateArgumentCount()); | 
					
						
							|  |  |  |             for (unsigned i = 0; i < name->templateArgumentCount(); ++i) { | 
					
						
							|  |  |  |                 FullySpecifiedType argTy = name->templateArgumentAt(i); | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  |                 arguments[i] = q->apply(argTy); | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 12:46:15 +01:00
										 |  |  |             const TemplateNameId *templId = control()->templateNameId(name->identifier(), | 
					
						
							|  |  |  |                                                                       arguments.data(), | 
					
						
							|  |  |  |                                                                       arguments.size()); | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |             _type = control()->namedType(templId); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-12 13:41:54 +02:00
										 |  |  |         const Name *instantiate(const Name *name) | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2010-07-12 13:41:54 +02:00
										 |  |  |             if (! name) | 
					
						
							|  |  |  |                 return name; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             else if (const Name *nameId = name->asNameId()) { | 
					
						
							|  |  |  |                 const Identifier *id = control()->findOrInsertIdentifier(nameId->identifier()->chars(), | 
					
						
							|  |  |  |                                                                          nameId->identifier()->size()); | 
					
						
							|  |  |  |                 return control()->nameId(id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             } else if (const TemplateNameId *templId = name->asTemplateNameId()) { | 
					
						
							|  |  |  |                 QVarLengthArray<FullySpecifiedType, 8> arguments(templId->templateArgumentCount()); | 
					
						
							|  |  |  |                 for (unsigned templateArgIndex = 0; templateArgIndex < templId->templateArgumentCount(); ++templateArgIndex) { | 
					
						
							|  |  |  |                     FullySpecifiedType argTy = templId->templateArgumentAt(templateArgIndex); | 
					
						
							|  |  |  |                     arguments[templateArgIndex] = q->apply(argTy); | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2010-07-12 13:41:54 +02:00
										 |  |  |                 const Identifier *id = control()->findOrInsertIdentifier(templId->identifier()->chars(), | 
					
						
							|  |  |  |                                                                          templId->identifier()->size()); | 
					
						
							|  |  |  |                 return control()->templateNameId(id, arguments.data(), arguments.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             } else if (const QualifiedNameId *qq = name->asQualifiedNameId()) { | 
					
						
							|  |  |  |                 const Name *base = instantiate(qq->base()); | 
					
						
							|  |  |  |                 const Name *name = instantiate(qq->name()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return control()->qualifiedNameId(base, name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             } else if (const OperatorNameId *op = name->asOperatorNameId()) { | 
					
						
							|  |  |  |                 return control()->operatorNameId(op->kind()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             } else if (const ConversionNameId *c = name->asConversionNameId()) { | 
					
						
							|  |  |  |                 FullySpecifiedType ty = q->apply(c->type()); | 
					
						
							|  |  |  |                 return control()->conversionNameId(ty); | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-12 13:41:54 +02:00
										 |  |  |             return 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         virtual void visit(const QualifiedNameId *name) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (const Name *n = instantiate(name)) | 
					
						
							|  |  |  |                 _type = control()->namedType(n); | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 12:46:15 +01:00
										 |  |  |         virtual void visit(const DestructorNameId *name) | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             Overview oo; | 
					
						
							|  |  |  |             qWarning() << "ignored name:" << oo(name); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 12:46:15 +01:00
										 |  |  |         virtual void visit(const OperatorNameId *name) | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             Overview oo; | 
					
						
							|  |  |  |             qWarning() << "ignored name:" << oo(name); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 12:46:15 +01:00
										 |  |  |         virtual void visit(const ConversionNameId *name) | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             Overview oo; | 
					
						
							|  |  |  |             qWarning() << "ignored name:" << oo(name); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 12:46:15 +01:00
										 |  |  |         virtual void visit(const SelectorNameId *name) | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             Overview oo; | 
					
						
							|  |  |  |             qWarning() << "ignored name:" << oo(name); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         ApplySubstitution *q; | 
					
						
							|  |  |  |         FullySpecifiedType _type; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: // attributes
 | 
					
						
							| 
									
										
										
										
											2010-05-05 12:06:38 +02:00
										 |  |  |     Control *_control; | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  |     Symbol *symbol; | 
					
						
							| 
									
										
										
										
											2010-05-20 13:44:38 +02:00
										 |  |  |     DeprecatedGenTemplateInstance::Substitution substitution; | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |     ApplyToType applyToType; | 
					
						
							|  |  |  |     ApplyToName applyToName; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-05 12:06:38 +02:00
										 |  |  | ApplySubstitution::ApplySubstitution(Control *control, Symbol *symbol, | 
					
						
							| 
									
										
										
										
											2010-05-20 13:44:38 +02:00
										 |  |  |                                      const DeprecatedGenTemplateInstance::Substitution &substitution) | 
					
						
							| 
									
										
										
										
											2010-05-05 12:06:38 +02:00
										 |  |  |     : _control(control), symbol(symbol), | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  |       substitution(substitution), | 
					
						
							|  |  |  |       applyToType(this), applyToName(this) | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | { } | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | ApplySubstitution::~ApplySubstitution() | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 12:46:15 +01:00
										 |  |  | FullySpecifiedType ApplySubstitution::apply(const Name *name) | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     FullySpecifiedType ty = applyToName(name); | 
					
						
							|  |  |  |     return ty; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  | FullySpecifiedType ApplySubstitution::apply(const FullySpecifiedType &type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     FullySpecifiedType ty = applyToType(type); | 
					
						
							|  |  |  |     return ty; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 11:33:13 +01:00
										 |  |  | int ApplySubstitution::findSubstitution(const Identifier *id) const | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     Q_ASSERT(id != 0); | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |     for (int index = 0; index < substitution.size(); ++index) { | 
					
						
							| 
									
										
										
										
											2009-12-01 11:33:13 +01:00
										 |  |  |         QPair<const Identifier *, FullySpecifiedType> s = substitution.at(index); | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |         if (id->isEqualTo(s.first)) | 
					
						
							|  |  |  |             return index; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | FullySpecifiedType ApplySubstitution::applySubstitution(int index) const | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |     Q_ASSERT(index != -1); | 
					
						
							|  |  |  |     Q_ASSERT(index < substitution.size()); | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |     return substitution.at(index).second; | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  | } // end of anonymous namespace
 | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-04 17:58:29 +02:00
										 |  |  | DeprecatedGenTemplateInstance::DeprecatedGenTemplateInstance(QSharedPointer<Control> control, const Substitution &substitution) | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |     : _symbol(0), | 
					
						
							| 
									
										
										
										
											2010-05-05 12:06:38 +02:00
										 |  |  |       _control(control), | 
					
						
							| 
									
										
										
										
											2009-10-26 17:54:32 +01:00
										 |  |  |       _substitution(substitution) | 
					
						
							|  |  |  | { } | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-20 13:44:38 +02:00
										 |  |  | FullySpecifiedType DeprecatedGenTemplateInstance::gen(Symbol *symbol) | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-04 17:58:29 +02:00
										 |  |  |     ApplySubstitution o(_control.data(), symbol, _substitution); | 
					
						
							| 
									
										
										
										
											2009-10-27 16:12:39 +01:00
										 |  |  |     return o.apply(symbol->type()); | 
					
						
							| 
									
										
										
										
											2009-10-26 12:41:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-04 17:58:29 +02:00
										 |  |  | FullySpecifiedType DeprecatedGenTemplateInstance::instantiate(const Name *className, Symbol *candidate, | 
					
						
							|  |  |  |                                                               QSharedPointer<Control> control) | 
					
						
							| 
									
										
										
										
											2010-05-06 14:01:38 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (className) { | 
					
						
							|  |  |  |         if (const TemplateNameId *templId = className->asTemplateNameId()) { | 
					
						
							|  |  |  |             if (Class *klass = candidate->enclosingSymbol()->asClass()) { | 
					
						
							| 
									
										
										
										
											2010-05-20 13:44:38 +02:00
										 |  |  |                 DeprecatedGenTemplateInstance::Substitution subst; | 
					
						
							| 
									
										
										
										
											2010-05-06 14:01:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 for (unsigned i = 0; i < templId->templateArgumentCount(); ++i) { | 
					
						
							|  |  |  |                     FullySpecifiedType templArgTy = templId->templateArgumentAt(i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if (i < klass->templateParameterCount()) { | 
					
						
							|  |  |  |                         const Name *templArgName = klass->templateParameterAt(i)->name(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         if (templArgName && templArgName->identifier()) { | 
					
						
							|  |  |  |                             const Identifier *templArgId = templArgName->identifier(); | 
					
						
							|  |  |  |                             subst.append(qMakePair(templArgId, templArgTy)); | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-20 13:44:38 +02:00
										 |  |  |                 DeprecatedGenTemplateInstance inst(control, subst); | 
					
						
							| 
									
										
										
										
											2010-05-06 14:01:38 +02:00
										 |  |  |                 return inst.gen(candidate); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return candidate->type(); | 
					
						
							|  |  |  | } |