martong updated this revision to Diff 250568.
martong added a comment.

- Remove redundant VisitQualifiedTypeLoc and VisitAttributedTypeLoc


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71018/new/

https://reviews.llvm.org/D71018

Files:
  clang/lib/AST/ASTImporter.cpp

Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -8106,7 +8106,7 @@
 
 namespace clang {
 
-#define IMPORT_TYPE_LOC(NAME)                                                  \
+#define IMPORT_TYPE_LOC_OR_RETURN_ERROR(NAME)                                  \
   if (auto ImpOrErr = Importer.Import(From.get##NAME()))                       \
     To.set##NAME(*ImpOrErr);                                                   \
   else                                                                         \
@@ -8123,126 +8123,80 @@
   TypeLocImporter(ASTImporter &Importer, TypeLoc ToL)
       : Importer(Importer), ToL(ToL) {}
 
-  Error VisitTypeSpecTypeLoc(TypeSpecTypeLoc From) {
-    auto To = ToL.castAs<TypeSpecTypeLoc>();
-    IMPORT_TYPE_LOC(NameLoc);
+  Error VisitTypeLoc(TypeLoc From) {
+    // The visitor does not call directly VisitTypeSpecTypeLoc, because that is
+    // not a leaf node in the hierarchy (i.e. there is no such enum value in
+    // TypeNodes.inc).
+    if (auto FTS = From.getAs<TypeSpecTypeLoc>())
+      return VisitTypeSpecTypeLoc(FTS);
     return Error::success();
   }
 
-  Error VisitTypedefTypeLoc(TypedefTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error VisitRecordTypeLoc(RecordTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error VisitEnumTypeLoc(EnumTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error VisitSubstTemplateTypeParmTypeLoc(SubstTemplateTypeParmTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error
-  VisitSubstTemplateTypeParmPackTypeLoc(SubstTemplateTypeParmPackTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error VisitVectorTypeLoc(VectorTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error VisitDependentVectorTypeLoc(DependentVectorTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error VisitExtVectorTypeLoc(ExtVectorTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error
-  VisitDependentSizedExtVectorTypeLoc(DependentSizedExtVectorTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error VisitComplexTypeLoc(ComplexTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error VisitDecltypeTypeLoc(DecltypeTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error VisitDeducedTypeLoc(DeducedTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
-  }
-
-  Error VisitAutoTypeLoc(AutoTypeLoc From) {
-    return VisitTypeSpecTypeLoc(From);
+  Error VisitTypeSpecTypeLoc(TypeSpecTypeLoc From) {
+    auto To = ToL.castAs<TypeSpecTypeLoc>();
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(NameLoc);
+    return Error::success();
   }
 
   Error VisitBuiltinTypeLoc(BuiltinTypeLoc From) {
     auto To = ToL.castAs<BuiltinTypeLoc>();
-    IMPORT_TYPE_LOC(BuiltinLoc);
-    // FIXME: Import other attributes?
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(BuiltinLoc);
     return Error::success();
   }
 
   Error VisitParenTypeLoc(ParenTypeLoc From) {
     auto To = ToL.castAs<ParenTypeLoc>();
 
-    IMPORT_TYPE_LOC(LParenLoc);
-    IMPORT_TYPE_LOC(RParenLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(LParenLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(RParenLoc);
+
+    return Error::success();
+  }
 
+  Error VisitPointerTypeLoc(PointerTypeLoc From) {
+    auto To = ToL.castAs<PointerTypeLoc>();
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(StarLoc);
     return Error::success();
   }
 
   Error VisitBlockPointerTypeLoc(BlockPointerTypeLoc From) {
     auto To = ToL.castAs<BlockPointerTypeLoc>();
-    IMPORT_TYPE_LOC(CaretLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(CaretLoc);
     return Error::success();
   }
 
   Error VisitMemberPointerTypeLoc(MemberPointerTypeLoc From) {
     auto To = ToL.castAs<MemberPointerTypeLoc>();
-    IMPORT_TYPE_LOC(StarLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(StarLoc);
+    return Error::success();
+  }
+
+  Error VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc From) {
+    auto To = ToL.castAs<ObjCObjectPointerTypeLoc>();
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(StarLoc);
     return Error::success();
   }
 
   Error VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc From) {
     auto To = ToL.castAs<LValueReferenceTypeLoc>();
-    IMPORT_TYPE_LOC(AmpLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(AmpLoc);
     return Error::success();
   }
 
   Error VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc From) {
     auto To = ToL.castAs<RValueReferenceTypeLoc>();
-    IMPORT_TYPE_LOC(AmpAmpLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(AmpAmpLoc);
     return Error::success();
   }
 
   Error VisitFunctionTypeLoc(FunctionTypeLoc From) {
     auto To = ToL.castAs<FunctionTypeLoc>();
 
-    IMPORT_TYPE_LOC(LocalRangeBegin);
-    IMPORT_TYPE_LOC(LocalRangeEnd);
-    IMPORT_TYPE_LOC(LParenLoc);
-    IMPORT_TYPE_LOC(RParenLoc);
-    IMPORT_TYPE_LOC(ExceptionSpecRange);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(LocalRangeBegin);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(LocalRangeEnd);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(LParenLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(RParenLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(ExceptionSpecRange);
 
     for (unsigned I = 0; I < From.getNumParams(); ++I)
       To.setParam(
@@ -8257,19 +8211,19 @@
 
   Error VisitArrayTypeLoc(ArrayTypeLoc From) {
     auto To = ToL.castAs<ArrayTypeLoc>();
-    IMPORT_TYPE_LOC(LBracketLoc);
-    IMPORT_TYPE_LOC(RBracketLoc);
-    IMPORT_TYPE_LOC(SizeExpr);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(LBracketLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(RBracketLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(SizeExpr);
     return Error::success();
   }
 
   Error VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc From) {
     auto To = ToL.castAs<TemplateSpecializationTypeLoc>();
 
-    IMPORT_TYPE_LOC(TemplateKeywordLoc);
-    IMPORT_TYPE_LOC(LAngleLoc);
-    IMPORT_TYPE_LOC(RAngleLoc);
-    IMPORT_TYPE_LOC(TemplateNameLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(TemplateKeywordLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(LAngleLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(RAngleLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(TemplateNameLoc);
 
     ASTNodeImporter NodeImporter(Importer);
     for (unsigned I = 0; I < From.getNumArgs(); ++I) {
@@ -8285,46 +8239,46 @@
 
   Error VisitDependentAddressSpaceTypeLoc(DependentAddressSpaceTypeLoc From) {
     auto To = ToL.castAs<DependentAddressSpaceTypeLoc>();
-    IMPORT_TYPE_LOC(AttrNameLoc);
-    IMPORT_TYPE_LOC(AttrOperandParensRange);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(AttrNameLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(AttrOperandParensRange);
     // FIXME: Import other things?
     return Error::success();
   }
 
   Error VisitTypeOfTypeLoc(TypeOfTypeLoc From) {
     auto To = ToL.castAs<TypeOfTypeLoc>();
-    IMPORT_TYPE_LOC(UnderlyingTInfo);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(UnderlyingTInfo);
     return Error::success();
   }
 
   Error VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc From) {
     auto To = ToL.castAs<UnaryTransformTypeLoc>();
-    IMPORT_TYPE_LOC(KWLoc);
-    IMPORT_TYPE_LOC(LParenLoc);
-    IMPORT_TYPE_LOC(RParenLoc);
-    IMPORT_TYPE_LOC(UnderlyingTInfo);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(KWLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(LParenLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(RParenLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(UnderlyingTInfo);
     return Error::success();
   }
 
   Error VisitDeducedTemplateSpecializationTypeLoc(
       DeducedTemplateSpecializationTypeLoc From) {
     auto To = ToL.castAs<DeducedTemplateSpecializationTypeLoc>();
-    IMPORT_TYPE_LOC(TemplateNameLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(TemplateNameLoc);
     return Error::success();
   }
 
   Error VisitElaboratedTypeLoc(ElaboratedTypeLoc From) {
     auto To = ToL.castAs<ElaboratedTypeLoc>();
-    IMPORT_TYPE_LOC(ElaboratedKeywordLoc);
-    IMPORT_TYPE_LOC(QualifierLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(ElaboratedKeywordLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(QualifierLoc);
     return Error::success();
   }
 
   Error VisitDependentNameTypeLoc(DependentNameTypeLoc From) {
     auto To = ToL.castAs<DependentNameTypeLoc>();
-    IMPORT_TYPE_LOC(ElaboratedKeywordLoc);
-    IMPORT_TYPE_LOC(QualifierLoc);
-    IMPORT_TYPE_LOC(NameLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(ElaboratedKeywordLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(QualifierLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(NameLoc);
     return Error::success();
   }
 
@@ -8332,12 +8286,12 @@
       DependentTemplateSpecializationTypeLoc From) {
     auto To = ToL.castAs<DependentTemplateSpecializationTypeLoc>();
 
-    IMPORT_TYPE_LOC(ElaboratedKeywordLoc);
-    IMPORT_TYPE_LOC(QualifierLoc);
-    IMPORT_TYPE_LOC(TemplateKeywordLoc);
-    IMPORT_TYPE_LOC(TemplateNameLoc);
-    IMPORT_TYPE_LOC(LAngleLoc);
-    IMPORT_TYPE_LOC(RAngleLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(ElaboratedKeywordLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(QualifierLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(TemplateKeywordLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(TemplateNameLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(LAngleLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(RAngleLoc);
 
     ASTNodeImporter NodeImporter(Importer);
     for (unsigned I = 0; I < From.getNumArgs(); ++I) {
@@ -8353,29 +8307,29 @@
 
   Error VisitPackExpansionTypeLoc(PackExpansionTypeLoc From) {
     auto To = ToL.castAs<PackExpansionTypeLoc>();
-    IMPORT_TYPE_LOC(EllipsisLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(EllipsisLoc);
     return Error::success();
   }
 
   Error VisitAtomicTypeLoc(AtomicTypeLoc From) {
     auto To = ToL.castAs<AtomicTypeLoc>();
-    IMPORT_TYPE_LOC(KWLoc);
-    IMPORT_TYPE_LOC(LParenLoc);
-    IMPORT_TYPE_LOC(RParenLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(KWLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(LParenLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(RParenLoc);
     return Error::success();
   }
 
   Error VisitPipeTypeLoc(PipeTypeLoc From) {
     auto To = ToL.castAs<PipeTypeLoc>();
-    IMPORT_TYPE_LOC(KWLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(KWLoc);
     return Error::success();
   }
 
   Error VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc From) {
     auto To = ToL.castAs<ObjCTypeParamTypeLoc>();
     if (From.getNumProtocols()) {
-      IMPORT_TYPE_LOC(ProtocolLAngleLoc);
-      IMPORT_TYPE_LOC(ProtocolRAngleLoc);
+      IMPORT_TYPE_LOC_OR_RETURN_ERROR(ProtocolLAngleLoc);
+      IMPORT_TYPE_LOC_OR_RETURN_ERROR(ProtocolRAngleLoc);
       for (unsigned I = 0; I < From.getNumProtocols(); ++I) {
         if (ExpectedSLoc L = Importer.Import(From.getProtocolLoc(I)))
           To.setProtocolLoc(I, *L);
@@ -8389,8 +8343,8 @@
   Error VisitObjCObjectTypeLoc(ObjCObjectTypeLoc From) {
     auto To = ToL.castAs<ObjCObjectTypeLoc>();
 
-    IMPORT_TYPE_LOC(TypeArgsLAngleLoc);
-    IMPORT_TYPE_LOC(TypeArgsRAngleLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(TypeArgsLAngleLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(TypeArgsRAngleLoc);
 
     for (unsigned I = 0; I < From.getNumTypeArgs(); ++I) {
       if (Expected<TypeSourceInfo *> TSI =
@@ -8400,8 +8354,8 @@
         return TSI.takeError();
     }
 
-    IMPORT_TYPE_LOC(ProtocolLAngleLoc);
-    IMPORT_TYPE_LOC(ProtocolRAngleLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(ProtocolLAngleLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(ProtocolRAngleLoc);
 
     for (unsigned I = 0; I < From.getNumProtocols(); ++I) {
       if (ExpectedSLoc L = Importer.Import(From.getProtocolLoc(I)))
@@ -8417,20 +8371,13 @@
 
   Error VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc From) {
     auto To = ToL.castAs<ObjCInterfaceTypeLoc>();
-    IMPORT_TYPE_LOC(NameLoc);
-    return Error::success();
-  }
-
-  Error VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc From) {
-    auto To = ToL.castAs<ObjCObjectPointerTypeLoc>();
-    IMPORT_TYPE_LOC(StarLoc);
+    IMPORT_TYPE_LOC_OR_RETURN_ERROR(NameLoc);
     return Error::success();
   }
 
-  Error VisitTypeLoc(TypeLoc TyLoc) { return Error::success(); }
 };
 
-#undef IMPORT_TYPE_LOC
+#undef IMPORT_TYPE_LOC_OR_RETURN_ERROR
 
 } // namespace clang
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to