esakella created this revision.
esakella added reviewers: klimek, bkramer, rsmith, spyffe.
esakella added subscribers: karies, cfe-commits.
Herald added subscribers: rengolin, aemerson.

Implemented the 

VisitSubstTemplateTypeParmType
VisitDependentNameType
VisitDependentSizedArrayType 

functions in the ASTImporter class and also added the necessary tests. 

Also made a necessary change in the VisitFunctionDecl function to support the 
dependent name type parameters. 

http://reviews.llvm.org/D17075

Files:
  lib/AST/ASTImporter.cpp
  test/ASTMerge/Inputs/class-template1.cpp
  test/ASTMerge/Inputs/class-template2.cpp

Index: test/ASTMerge/Inputs/class-template2.cpp
===================================================================
--- test/ASTMerge/Inputs/class-template2.cpp
+++ test/ASTMerge/Inputs/class-template2.cpp
@@ -33,3 +33,30 @@
 struct X0<wchar_t> {
   float member;
 };
+
+//Substituted template type parameter import test
+template<typename T>
+struct X7 {
+  T t;
+};
+
+X7<int> x;
+
+//Dependent name type import test
+struct X9 {
+ struct X10 { };
+};
+
+template<class T>
+struct X8 {
+  struct T::X10* t;
+  void f(struct T::X10* v){ }
+};
+
+X8<X9> x8;
+
+//Dependent sized array import test
+template<typename T, int S>
+struct X11 {
+  T data[S];
+};
Index: test/ASTMerge/Inputs/class-template1.cpp
===================================================================
--- test/ASTMerge/Inputs/class-template1.cpp
+++ test/ASTMerge/Inputs/class-template1.cpp
@@ -32,3 +32,30 @@
 struct X0<wchar_t> {
   int member;
 };
+
+//Substituted template type parameter import test
+template<typename T>
+struct X7 {
+  T t;
+};
+
+extern X7<int> x;
+
+//Dependent name type import test
+struct X9 {
+ struct X10 { };
+};
+
+template<class T>
+struct X8 {
+  struct T::X10* t;
+  void f(struct T::X10* v){ }
+};
+
+extern X8<X9> x8;
+
+//Dependent sized array import test
+template<typename T, int S>
+struct X11 {
+  T data[S];
+};
Index: lib/AST/ASTImporter.cpp
===================================================================
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -49,7 +49,7 @@
     QualType VisitConstantArrayType(const ConstantArrayType *T);
     QualType VisitIncompleteArrayType(const IncompleteArrayType *T);
     QualType VisitVariableArrayType(const VariableArrayType *T);
-    // FIXME: DependentSizedArrayType
+    QualType VisitDependentSizedArrayType(const DependentSizedArrayType *T);
     // FIXME: DependentSizedExtVectorType
     QualType VisitVectorType(const VectorType *T);
     QualType VisitExtVectorType(const ExtVectorType *T);
@@ -69,10 +69,10 @@
     QualType VisitEnumType(const EnumType *T);
     QualType VisitAttributedType(const AttributedType *T);
     // FIXME: TemplateTypeParmType
-    // FIXME: SubstTemplateTypeParmType
+    QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T);
     QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T);
     QualType VisitElaboratedType(const ElaboratedType *T);
-    // FIXME: DependentNameType
+    QualType VisitDependentNameType(const DependentNameType *T);
     // FIXME: DependentTemplateSpecializationType
     QualType VisitObjCInterfaceType(const ObjCInterfaceType *T);
     QualType VisitObjCObjectType(const ObjCObjectType *T);
@@ -1613,6 +1613,19 @@
                                                       Brackets);
 }
 
+QualType ASTNodeImporter::VisitDependentSizedArrayType(
+                                           const DependentSizedArrayType *T) {
+  QualType ToType = Importer.Import(T->getElementType());
+  if (ToType.isNull())
+    return QualType();
+
+  return
+    Importer.getToContext().getDependentSizedArrayType(ToType, T->getSizeExpr(),
+                                                       T->getSizeModifier(),
+                                                T->getIndexTypeCVRQualifiers(),
+                                                       T->getBracketsRange());
+}
+
 QualType ASTNodeImporter::VisitVectorType(const VectorType *T) {
   QualType ToElementType = Importer.Import(T->getElementType());
   if (ToElementType.isNull())
@@ -1776,6 +1789,18 @@
   return Importer.getToContext().getTagDeclType(ToDecl);
 }
 
+QualType ASTNodeImporter::VisitSubstTemplateTypeParmType(
+                                          const SubstTemplateTypeParmType *T) {
+
+  QualType ToType =  Importer.Import(T->getReplacementType());
+  if (ToType.isNull())
+    return QualType();
+
+  return Importer.getToContext().getSubstTemplateTypeParmType(
+                                                     T->getReplacedParameter(),
+                                                     T->getReplacementType());
+}
+
 QualType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
   QualType FromModifiedType = T->getModifiedType();
   QualType FromEquivalentType = T->getEquivalentType();
@@ -1838,6 +1863,21 @@
                                                    ToQualifier, ToNamedType);
 }
 
+QualType ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
+  NestedNameSpecifier *ToName
+    = dyn_cast_or_null<NestedNameSpecifier>(Importer.Import(T->getQualifier()));
+  if (!ToName)
+    return QualType();
+
+  IdentifierInfo *identifierInfo = Importer.Import(T->getIdentifier());
+  if (!identifierInfo)
+    return QualType();
+
+  return Importer.getToContext().getDependentNameType(T->getKeyword(), ToName,
+                                                      identifierInfo,
+                                                      T->getPointeeType());
+}
+
 QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
   ObjCInterfaceDecl *Class
     = dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl()));
@@ -2840,6 +2880,16 @@
   
   // Create the imported function.
   TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
+  // If it is a function with Dependent Type parameters
+  if (TInfo) {
+    for (unsigned I = 0; I < Parameters.size(); I++) {
+      if (FunctionProtoTypeLoc ToProtoLoc
+        = TInfo->getTypeLoc().getAs<FunctionProtoTypeLoc>()) {
+        ToProtoLoc.setParam(I, Parameters[I]);
+      }
+    }
+  }
+
   FunctionDecl *ToFunction = nullptr;
   SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart());
   if (CXXConstructorDecl *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to