2010-02-06 01:54:41 +08:00
|
|
|
//===--- ASTImporter.cpp - Importing ASTs from other Contexts ---*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the ASTImporter class which imports AST nodes from one
|
|
|
|
// context into another context.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/AST/ASTImporter.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
2010-02-10 08:15:17 +08:00
|
|
|
#include "clang/AST/ASTDiagnostic.h"
|
2010-02-11 08:48:18 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2010-02-06 01:54:41 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2010-02-09 05:09:39 +08:00
|
|
|
#include "clang/AST/DeclVisitor.h"
|
2010-02-12 03:21:55 +08:00
|
|
|
#include "clang/AST/StmtVisitor.h"
|
2010-02-06 01:54:41 +08:00
|
|
|
#include "clang/AST/TypeVisitor.h"
|
2010-02-10 08:15:17 +08:00
|
|
|
#include "clang/Basic/FileManager.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2010-02-16 06:01:00 +08:00
|
|
|
#include <deque>
|
2010-02-06 01:54:41 +08:00
|
|
|
|
2011-11-04 02:07:07 +08:00
|
|
|
namespace clang {
|
2010-02-09 05:09:39 +08:00
|
|
|
class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, QualType>,
|
2010-02-12 03:21:55 +08:00
|
|
|
public DeclVisitor<ASTNodeImporter, Decl *>,
|
|
|
|
public StmtVisitor<ASTNodeImporter, Stmt *> {
|
2010-02-06 01:54:41 +08:00
|
|
|
ASTImporter &Importer;
|
2016-04-14 19:51:27 +08:00
|
|
|
|
2010-02-06 01:54:41 +08:00
|
|
|
public:
|
|
|
|
explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) { }
|
|
|
|
|
|
|
|
using TypeVisitor<ASTNodeImporter, QualType>::Visit;
|
2010-02-10 03:21:46 +08:00
|
|
|
using DeclVisitor<ASTNodeImporter, Decl *>::Visit;
|
2010-02-12 03:21:55 +08:00
|
|
|
using StmtVisitor<ASTNodeImporter, Stmt *>::Visit;
|
2010-02-06 01:54:41 +08:00
|
|
|
|
|
|
|
// Importing types
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType VisitType(const Type *T);
|
|
|
|
QualType VisitBuiltinType(const BuiltinType *T);
|
|
|
|
QualType VisitComplexType(const ComplexType *T);
|
|
|
|
QualType VisitPointerType(const PointerType *T);
|
|
|
|
QualType VisitBlockPointerType(const BlockPointerType *T);
|
|
|
|
QualType VisitLValueReferenceType(const LValueReferenceType *T);
|
|
|
|
QualType VisitRValueReferenceType(const RValueReferenceType *T);
|
|
|
|
QualType VisitMemberPointerType(const MemberPointerType *T);
|
|
|
|
QualType VisitConstantArrayType(const ConstantArrayType *T);
|
|
|
|
QualType VisitIncompleteArrayType(const IncompleteArrayType *T);
|
|
|
|
QualType VisitVariableArrayType(const VariableArrayType *T);
|
2010-02-06 01:54:41 +08:00
|
|
|
// FIXME: DependentSizedArrayType
|
|
|
|
// FIXME: DependentSizedExtVectorType
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType VisitVectorType(const VectorType *T);
|
|
|
|
QualType VisitExtVectorType(const ExtVectorType *T);
|
|
|
|
QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T);
|
|
|
|
QualType VisitFunctionProtoType(const FunctionProtoType *T);
|
2010-02-06 01:54:41 +08:00
|
|
|
// FIXME: UnresolvedUsingType
|
2011-08-12 00:56:07 +08:00
|
|
|
QualType VisitParenType(const ParenType *T);
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType VisitTypedefType(const TypedefType *T);
|
|
|
|
QualType VisitTypeOfExprType(const TypeOfExprType *T);
|
2010-02-06 01:54:41 +08:00
|
|
|
// FIXME: DependentTypeOfExprType
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType VisitTypeOfType(const TypeOfType *T);
|
|
|
|
QualType VisitDecltypeType(const DecltypeType *T);
|
2011-05-25 06:41:36 +08:00
|
|
|
QualType VisitUnaryTransformType(const UnaryTransformType *T);
|
2011-02-20 11:19:35 +08:00
|
|
|
QualType VisitAutoType(const AutoType *T);
|
2016-04-14 19:51:27 +08:00
|
|
|
QualType VisitInjectedClassNameType(const InjectedClassNameType *T);
|
2010-02-06 01:54:41 +08:00
|
|
|
// FIXME: DependentDecltypeType
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType VisitRecordType(const RecordType *T);
|
|
|
|
QualType VisitEnumType(const EnumType *T);
|
2015-04-03 07:50:08 +08:00
|
|
|
QualType VisitAttributedType(const AttributedType *T);
|
2016-04-14 19:51:27 +08:00
|
|
|
QualType VisitTemplateTypeParmType(const TemplateTypeParmType *T);
|
2010-02-06 01:54:41 +08:00
|
|
|
// FIXME: SubstTemplateTypeParmType
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T);
|
|
|
|
QualType VisitElaboratedType(const ElaboratedType *T);
|
2010-04-01 01:34:00 +08:00
|
|
|
// FIXME: DependentNameType
|
2010-06-11 08:33:02 +08:00
|
|
|
// FIXME: DependentTemplateSpecializationType
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType VisitObjCInterfaceType(const ObjCInterfaceType *T);
|
|
|
|
QualType VisitObjCObjectType(const ObjCObjectType *T);
|
|
|
|
QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T);
|
2010-02-09 05:09:39 +08:00
|
|
|
|
2012-01-25 02:36:04 +08:00
|
|
|
// Importing declarations
|
2010-02-11 03:54:31 +08:00
|
|
|
bool ImportDeclParts(NamedDecl *D, DeclContext *&DC,
|
|
|
|
DeclContext *&LexicalDC, DeclarationName &Name,
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *&ToD, SourceLocation &Loc);
|
2014-05-12 13:36:57 +08:00
|
|
|
void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
|
2010-08-12 06:01:17 +08:00
|
|
|
void ImportDeclarationNameLoc(const DeclarationNameInfo &From,
|
|
|
|
DeclarationNameInfo& To);
|
2011-01-18 11:11:38 +08:00
|
|
|
void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
|
2016-04-14 19:51:27 +08:00
|
|
|
|
|
|
|
typedef DesignatedInitExpr::Designator Designator;
|
|
|
|
Designator ImportDesignator(const Designator &D);
|
|
|
|
|
2012-02-02 05:00:38 +08:00
|
|
|
|
2012-01-25 02:36:04 +08:00
|
|
|
/// \brief What we should import from the definition.
|
|
|
|
enum ImportDefinitionKind {
|
|
|
|
/// \brief Import the default subset of the definition, which might be
|
|
|
|
/// nothing (if minimal import is set) or might be everything (if minimal
|
|
|
|
/// import is not set).
|
|
|
|
IDK_Default,
|
|
|
|
/// \brief Import everything.
|
|
|
|
IDK_Everything,
|
|
|
|
/// \brief Import only the bare bones needed to establish a valid
|
|
|
|
/// DeclContext.
|
|
|
|
IDK_Basic
|
|
|
|
};
|
|
|
|
|
2012-02-02 05:00:38 +08:00
|
|
|
bool shouldForceImportDeclContext(ImportDefinitionKind IDK) {
|
|
|
|
return IDK == IDK_Everything ||
|
|
|
|
(IDK == IDK_Default && !Importer.isMinimalImport());
|
|
|
|
}
|
|
|
|
|
2011-07-30 07:31:30 +08:00
|
|
|
bool ImportDefinition(RecordDecl *From, RecordDecl *To,
|
2012-01-25 02:36:04 +08:00
|
|
|
ImportDefinitionKind Kind = IDK_Default);
|
2013-08-06 09:03:05 +08:00
|
|
|
bool ImportDefinition(VarDecl *From, VarDecl *To,
|
|
|
|
ImportDefinitionKind Kind = IDK_Default);
|
2011-07-30 07:31:30 +08:00
|
|
|
bool ImportDefinition(EnumDecl *From, EnumDecl *To,
|
2012-02-02 05:00:38 +08:00
|
|
|
ImportDefinitionKind Kind = IDK_Default);
|
2012-01-25 01:42:07 +08:00
|
|
|
bool ImportDefinition(ObjCInterfaceDecl *From, ObjCInterfaceDecl *To,
|
2012-02-02 05:00:38 +08:00
|
|
|
ImportDefinitionKind Kind = IDK_Default);
|
2012-01-25 01:42:07 +08:00
|
|
|
bool ImportDefinition(ObjCProtocolDecl *From, ObjCProtocolDecl *To,
|
2012-02-02 05:00:38 +08:00
|
|
|
ImportDefinitionKind Kind = IDK_Default);
|
2010-12-01 03:14:50 +08:00
|
|
|
TemplateParameterList *ImportTemplateParameterList(
|
|
|
|
TemplateParameterList *Params);
|
2010-12-01 09:36:18 +08:00
|
|
|
TemplateArgument ImportTemplateArgument(const TemplateArgument &From);
|
|
|
|
bool ImportTemplateArguments(const TemplateArgument *FromArgs,
|
|
|
|
unsigned NumFromArgs,
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVectorImpl<TemplateArgument> &ToArgs);
|
2012-07-18 05:16:27 +08:00
|
|
|
bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord,
|
|
|
|
bool Complain = true);
|
2013-08-06 09:03:05 +08:00
|
|
|
bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar,
|
|
|
|
bool Complain = true);
|
2010-02-16 06:01:00 +08:00
|
|
|
bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord);
|
2012-11-15 06:29:20 +08:00
|
|
|
bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC);
|
2010-12-01 03:14:50 +08:00
|
|
|
bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To);
|
2013-08-06 09:03:05 +08:00
|
|
|
bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To);
|
2010-02-10 06:48:33 +08:00
|
|
|
Decl *VisitDecl(Decl *D);
|
2016-02-19 07:08:36 +08:00
|
|
|
Decl *VisitAccessSpecDecl(AccessSpecDecl *D);
|
2011-11-18 07:20:56 +08:00
|
|
|
Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D);
|
2010-02-22 02:26:36 +08:00
|
|
|
Decl *VisitNamespaceDecl(NamespaceDecl *D);
|
2011-04-15 22:24:37 +08:00
|
|
|
Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
|
2010-02-11 05:10:29 +08:00
|
|
|
Decl *VisitTypedefDecl(TypedefDecl *D);
|
2011-04-15 22:24:37 +08:00
|
|
|
Decl *VisitTypeAliasDecl(TypeAliasDecl *D);
|
2016-04-14 19:51:27 +08:00
|
|
|
Decl *VisitLabelDecl(LabelDecl *D);
|
2010-02-13 06:17:39 +08:00
|
|
|
Decl *VisitEnumDecl(EnumDecl *D);
|
2010-02-11 08:48:18 +08:00
|
|
|
Decl *VisitRecordDecl(RecordDecl *D);
|
2010-02-13 06:17:39 +08:00
|
|
|
Decl *VisitEnumConstantDecl(EnumConstantDecl *D);
|
2010-02-11 03:54:31 +08:00
|
|
|
Decl *VisitFunctionDecl(FunctionDecl *D);
|
2010-02-22 02:29:16 +08:00
|
|
|
Decl *VisitCXXMethodDecl(CXXMethodDecl *D);
|
|
|
|
Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D);
|
|
|
|
Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D);
|
|
|
|
Decl *VisitCXXConversionDecl(CXXConversionDecl *D);
|
2010-02-11 08:48:18 +08:00
|
|
|
Decl *VisitFieldDecl(FieldDecl *D);
|
2010-11-21 14:08:52 +08:00
|
|
|
Decl *VisitIndirectFieldDecl(IndirectFieldDecl *D);
|
2010-02-17 08:34:30 +08:00
|
|
|
Decl *VisitObjCIvarDecl(ObjCIvarDecl *D);
|
2010-02-09 05:09:39 +08:00
|
|
|
Decl *VisitVarDecl(VarDecl *D);
|
2010-02-18 05:22:52 +08:00
|
|
|
Decl *VisitImplicitParamDecl(ImplicitParamDecl *D);
|
2010-02-11 03:54:31 +08:00
|
|
|
Decl *VisitParmVarDecl(ParmVarDecl *D);
|
2010-02-17 10:12:47 +08:00
|
|
|
Decl *VisitObjCMethodDecl(ObjCMethodDecl *D);
|
Parsing, semantic analysis, and AST for Objective-C type parameters.
Produce type parameter declarations for Objective-C type parameters,
and attach lists of type parameters to Objective-C classes,
categories, forward declarations, and extensions as
appropriate. Perform semantic analysis of type bounds for type
parameters, both in isolation and across classes/categories/extensions
to ensure consistency.
Also handle (de-)serialization of Objective-C type parameter lists,
along with sundry other things one must do to add a new declaration to
Clang.
Note that Objective-C type parameters are typedef name declarations,
like typedefs and C++11 type aliases, in support of type erasure.
Part of rdar://problem/6294649.
llvm-svn: 241541
2015-07-07 11:57:15 +08:00
|
|
|
Decl *VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
|
2010-02-18 09:47:50 +08:00
|
|
|
Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D);
|
2010-02-18 00:12:00 +08:00
|
|
|
Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D);
|
2014-12-10 08:00:37 +08:00
|
|
|
Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D);
|
Parsing, semantic analysis, and AST for Objective-C type parameters.
Produce type parameter declarations for Objective-C type parameters,
and attach lists of type parameters to Objective-C classes,
categories, forward declarations, and extensions as
appropriate. Perform semantic analysis of type bounds for type
parameters, both in isolation and across classes/categories/extensions
to ensure consistency.
Also handle (de-)serialization of Objective-C type parameter lists,
along with sundry other things one must do to add a new declaration to
Clang.
Note that Objective-C type parameters are typedef name declarations,
like typedefs and C++11 type aliases, in support of type erasure.
Part of rdar://problem/6294649.
llvm-svn: 241541
2015-07-07 11:57:15 +08:00
|
|
|
|
|
|
|
ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list);
|
2010-02-16 09:20:57 +08:00
|
|
|
Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
|
2010-12-07 23:32:12 +08:00
|
|
|
Decl *VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
|
2010-12-07 09:26:03 +08:00
|
|
|
Decl *VisitObjCImplementationDecl(ObjCImplementationDecl *D);
|
2010-02-18 02:02:10 +08:00
|
|
|
Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D);
|
2010-12-08 02:32:03 +08:00
|
|
|
Decl *VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
|
2010-12-01 03:14:50 +08:00
|
|
|
Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
|
|
|
|
Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
|
|
|
|
Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
|
|
|
|
Decl *VisitClassTemplateDecl(ClassTemplateDecl *D);
|
2010-12-01 09:36:18 +08:00
|
|
|
Decl *VisitClassTemplateSpecializationDecl(
|
|
|
|
ClassTemplateSpecializationDecl *D);
|
2013-08-06 09:03:05 +08:00
|
|
|
Decl *VisitVarTemplateDecl(VarTemplateDecl *D);
|
|
|
|
Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
|
|
|
|
|
2010-02-12 03:21:55 +08:00
|
|
|
// Importing statements
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
DeclGroupRef ImportDeclGroup(DeclGroupRef DG);
|
|
|
|
|
2010-02-12 03:21:55 +08:00
|
|
|
Stmt *VisitStmt(Stmt *S);
|
2016-04-14 19:51:27 +08:00
|
|
|
Stmt *VisitGCCAsmStmt(GCCAsmStmt *S);
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
Stmt *VisitDeclStmt(DeclStmt *S);
|
|
|
|
Stmt *VisitNullStmt(NullStmt *S);
|
|
|
|
Stmt *VisitCompoundStmt(CompoundStmt *S);
|
|
|
|
Stmt *VisitCaseStmt(CaseStmt *S);
|
|
|
|
Stmt *VisitDefaultStmt(DefaultStmt *S);
|
|
|
|
Stmt *VisitLabelStmt(LabelStmt *S);
|
|
|
|
Stmt *VisitAttributedStmt(AttributedStmt *S);
|
|
|
|
Stmt *VisitIfStmt(IfStmt *S);
|
|
|
|
Stmt *VisitSwitchStmt(SwitchStmt *S);
|
|
|
|
Stmt *VisitWhileStmt(WhileStmt *S);
|
|
|
|
Stmt *VisitDoStmt(DoStmt *S);
|
|
|
|
Stmt *VisitForStmt(ForStmt *S);
|
|
|
|
Stmt *VisitGotoStmt(GotoStmt *S);
|
|
|
|
Stmt *VisitIndirectGotoStmt(IndirectGotoStmt *S);
|
|
|
|
Stmt *VisitContinueStmt(ContinueStmt *S);
|
|
|
|
Stmt *VisitBreakStmt(BreakStmt *S);
|
|
|
|
Stmt *VisitReturnStmt(ReturnStmt *S);
|
|
|
|
// FIXME: MSAsmStmt
|
|
|
|
// FIXME: SEHExceptStmt
|
|
|
|
// FIXME: SEHFinallyStmt
|
|
|
|
// FIXME: SEHTryStmt
|
|
|
|
// FIXME: SEHLeaveStmt
|
|
|
|
// FIXME: CapturedStmt
|
|
|
|
Stmt *VisitCXXCatchStmt(CXXCatchStmt *S);
|
|
|
|
Stmt *VisitCXXTryStmt(CXXTryStmt *S);
|
|
|
|
Stmt *VisitCXXForRangeStmt(CXXForRangeStmt *S);
|
|
|
|
// FIXME: MSDependentExistsStmt
|
|
|
|
Stmt *VisitObjCForCollectionStmt(ObjCForCollectionStmt *S);
|
|
|
|
Stmt *VisitObjCAtCatchStmt(ObjCAtCatchStmt *S);
|
|
|
|
Stmt *VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S);
|
|
|
|
Stmt *VisitObjCAtTryStmt(ObjCAtTryStmt *S);
|
|
|
|
Stmt *VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S);
|
|
|
|
Stmt *VisitObjCAtThrowStmt(ObjCAtThrowStmt *S);
|
|
|
|
Stmt *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S);
|
2010-02-12 03:21:55 +08:00
|
|
|
|
|
|
|
// Importing expressions
|
|
|
|
Expr *VisitExpr(Expr *E);
|
2016-04-14 19:51:27 +08:00
|
|
|
Expr *VisitVAArgExpr(VAArgExpr *E);
|
|
|
|
Expr *VisitGNUNullExpr(GNUNullExpr *E);
|
|
|
|
Expr *VisitPredefinedExpr(PredefinedExpr *E);
|
2010-02-19 09:17:02 +08:00
|
|
|
Expr *VisitDeclRefExpr(DeclRefExpr *E);
|
2016-04-14 19:51:27 +08:00
|
|
|
Expr *VisitImplicitValueInitExpr(ImplicitValueInitExpr *ILE);
|
|
|
|
Expr *VisitDesignatedInitExpr(DesignatedInitExpr *E);
|
|
|
|
Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
|
2010-02-12 03:21:55 +08:00
|
|
|
Expr *VisitIntegerLiteral(IntegerLiteral *E);
|
2016-04-14 19:51:27 +08:00
|
|
|
Expr *VisitFloatingLiteral(FloatingLiteral *E);
|
2010-02-18 10:21:22 +08:00
|
|
|
Expr *VisitCharacterLiteral(CharacterLiteral *E);
|
2016-04-14 19:51:27 +08:00
|
|
|
Expr *VisitStringLiteral(StringLiteral *E);
|
|
|
|
Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
|
|
|
|
Expr *VisitAtomicExpr(AtomicExpr *E);
|
|
|
|
Expr *VisitAddrLabelExpr(AddrLabelExpr *E);
|
2010-02-19 09:07:06 +08:00
|
|
|
Expr *VisitParenExpr(ParenExpr *E);
|
2016-04-14 19:51:27 +08:00
|
|
|
Expr *VisitParenListExpr(ParenListExpr *E);
|
|
|
|
Expr *VisitStmtExpr(StmtExpr *E);
|
2010-02-19 09:07:06 +08:00
|
|
|
Expr *VisitUnaryOperator(UnaryOperator *E);
|
2011-03-12 03:24:49 +08:00
|
|
|
Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E);
|
2010-02-19 09:07:06 +08:00
|
|
|
Expr *VisitBinaryOperator(BinaryOperator *E);
|
2016-04-14 19:51:27 +08:00
|
|
|
Expr *VisitConditionalOperator(ConditionalOperator *E);
|
|
|
|
Expr *VisitBinaryConditionalOperator(BinaryConditionalOperator *E);
|
|
|
|
Expr *VisitOpaqueValueExpr(OpaqueValueExpr *E);
|
2010-02-19 09:07:06 +08:00
|
|
|
Expr *VisitCompoundAssignOperator(CompoundAssignOperator *E);
|
2010-02-13 06:17:39 +08:00
|
|
|
Expr *VisitImplicitCastExpr(ImplicitCastExpr *E);
|
2010-02-19 09:32:14 +08:00
|
|
|
Expr *VisitCStyleCastExpr(CStyleCastExpr *E);
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
Expr *VisitCXXConstructExpr(CXXConstructExpr *E);
|
2016-03-29 05:43:01 +08:00
|
|
|
Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E);
|
|
|
|
Expr *VisitCXXThisExpr(CXXThisExpr *E);
|
|
|
|
Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
Expr *VisitMemberExpr(MemberExpr *E);
|
|
|
|
Expr *VisitCallExpr(CallExpr *E);
|
2016-03-29 05:43:01 +08:00
|
|
|
Expr *VisitInitListExpr(InitListExpr *E);
|
2016-05-17 04:48:03 +08:00
|
|
|
Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
|
|
|
|
Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
|
2016-04-14 19:51:27 +08:00
|
|
|
|
|
|
|
template<typename IIter, typename OIter>
|
|
|
|
void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) {
|
|
|
|
typedef typename std::remove_reference<decltype(*Obegin)>::type ItemT;
|
|
|
|
ASTImporter &ImporterRef = Importer;
|
|
|
|
std::transform(Ibegin, Iend, Obegin,
|
|
|
|
[&ImporterRef](ItemT From) -> ItemT {
|
|
|
|
return ImporterRef.Import(From);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename IIter, typename OIter>
|
|
|
|
bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
|
|
|
|
typedef typename std::remove_reference<decltype(**Obegin)>::type ItemT;
|
|
|
|
ASTImporter &ImporterRef = Importer;
|
2016-03-29 05:43:01 +08:00
|
|
|
bool Failed = false;
|
2016-04-14 19:51:27 +08:00
|
|
|
std::transform(Ibegin, Iend, Obegin,
|
|
|
|
[&ImporterRef, &Failed](ItemT *From) -> ItemT * {
|
|
|
|
ItemT *To = ImporterRef.Import(From);
|
|
|
|
if (!To && From)
|
2016-03-29 05:43:01 +08:00
|
|
|
Failed = true;
|
2016-04-14 19:51:27 +08:00
|
|
|
return To;
|
2016-03-29 05:43:01 +08:00
|
|
|
});
|
2016-04-14 19:51:27 +08:00
|
|
|
return Failed;
|
2016-03-29 05:43:01 +08:00
|
|
|
}
|
2010-02-06 01:54:41 +08:00
|
|
|
};
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2016-04-14 19:51:27 +08:00
|
|
|
|
2011-11-04 02:07:07 +08:00
|
|
|
using namespace clang;
|
2010-02-06 01:54:41 +08:00
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Structural Equivalence
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct StructuralEquivalenceContext {
|
|
|
|
/// \brief AST contexts for which we are checking structural equivalence.
|
|
|
|
ASTContext &C1, &C2;
|
|
|
|
|
|
|
|
/// \brief The set of "tentative" equivalences between two canonical
|
|
|
|
/// declarations, mapping from a declaration in the first context to the
|
|
|
|
/// declaration in the second context that we believe to be equivalent.
|
|
|
|
llvm::DenseMap<Decl *, Decl *> TentativeEquivalences;
|
|
|
|
|
|
|
|
/// \brief Queue of declarations in the first context whose equivalence
|
|
|
|
/// with a declaration in the second context still needs to be verified.
|
|
|
|
std::deque<Decl *> DeclsToCheck;
|
|
|
|
|
2010-02-16 07:54:17 +08:00
|
|
|
/// \brief Declaration (from, to) pairs that are known not to be equivalent
|
|
|
|
/// (which we have already complained about).
|
|
|
|
llvm::DenseSet<std::pair<Decl *, Decl *> > &NonEquivalentDecls;
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
/// \brief Whether we're being strict about the spelling of types when
|
|
|
|
/// unifying two types.
|
|
|
|
bool StrictTypeSpelling;
|
2012-07-18 05:16:27 +08:00
|
|
|
|
|
|
|
/// \brief Whether to complain about failures.
|
|
|
|
bool Complain;
|
|
|
|
|
2012-12-20 10:22:15 +08:00
|
|
|
/// \brief \c true if the last diagnostic came from C2.
|
|
|
|
bool LastDiagFromC2;
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
StructuralEquivalenceContext(ASTContext &C1, ASTContext &C2,
|
2010-02-16 07:54:17 +08:00
|
|
|
llvm::DenseSet<std::pair<Decl *, Decl *> > &NonEquivalentDecls,
|
2012-07-18 05:16:27 +08:00
|
|
|
bool StrictTypeSpelling = false,
|
|
|
|
bool Complain = true)
|
2010-11-19 04:06:41 +08:00
|
|
|
: C1(C1), C2(C2), NonEquivalentDecls(NonEquivalentDecls),
|
2012-12-20 10:22:15 +08:00
|
|
|
StrictTypeSpelling(StrictTypeSpelling), Complain(Complain),
|
|
|
|
LastDiagFromC2(false) {}
|
2010-02-16 06:01:00 +08:00
|
|
|
|
|
|
|
/// \brief Determine whether the two declarations are structurally
|
|
|
|
/// equivalent.
|
|
|
|
bool IsStructurallyEquivalent(Decl *D1, Decl *D2);
|
|
|
|
|
|
|
|
/// \brief Determine whether the two types are structurally equivalent.
|
|
|
|
bool IsStructurallyEquivalent(QualType T1, QualType T2);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// \brief Finish checking all of the structural equivalences.
|
|
|
|
///
|
|
|
|
/// \returns true if an error occurred, false otherwise.
|
|
|
|
bool Finish();
|
|
|
|
|
|
|
|
public:
|
|
|
|
DiagnosticBuilder Diag1(SourceLocation Loc, unsigned DiagID) {
|
2012-10-26 23:34:11 +08:00
|
|
|
assert(Complain && "Not allowed to complain");
|
2012-12-20 10:22:15 +08:00
|
|
|
if (LastDiagFromC2)
|
|
|
|
C1.getDiagnostics().notePriorDiagnosticFrom(C2.getDiagnostics());
|
|
|
|
LastDiagFromC2 = false;
|
2010-11-19 04:06:41 +08:00
|
|
|
return C1.getDiagnostics().Report(Loc, DiagID);
|
2010-02-16 06:01:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DiagnosticBuilder Diag2(SourceLocation Loc, unsigned DiagID) {
|
2012-10-26 23:34:11 +08:00
|
|
|
assert(Complain && "Not allowed to complain");
|
2012-12-20 10:22:15 +08:00
|
|
|
if (!LastDiagFromC2)
|
|
|
|
C2.getDiagnostics().notePriorDiagnosticFrom(C1.getDiagnostics());
|
|
|
|
LastDiagFromC2 = true;
|
2010-11-19 04:06:41 +08:00
|
|
|
return C2.getDiagnostics().Report(Loc, DiagID);
|
2010-02-16 06:01:00 +08:00
|
|
|
}
|
|
|
|
};
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2010-02-16 06:01:00 +08:00
|
|
|
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
QualType T1, QualType T2);
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
Decl *D1, Decl *D2);
|
|
|
|
|
|
|
|
/// \brief Determine structural equivalence of two expressions.
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
Expr *E1, Expr *E2) {
|
|
|
|
if (!E1 || !E2)
|
|
|
|
return E1 == E2;
|
|
|
|
|
|
|
|
// FIXME: Actually perform a structural comparison!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determine whether two identifiers are equivalent.
|
|
|
|
static bool IsStructurallyEquivalent(const IdentifierInfo *Name1,
|
|
|
|
const IdentifierInfo *Name2) {
|
|
|
|
if (!Name1 || !Name2)
|
|
|
|
return Name1 == Name2;
|
|
|
|
|
|
|
|
return Name1->getName() == Name2->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determine whether two nested-name-specifiers are equivalent.
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
NestedNameSpecifier *NNS1,
|
|
|
|
NestedNameSpecifier *NNS2) {
|
|
|
|
// FIXME: Implement!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determine whether two template arguments are equivalent.
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
const TemplateArgument &Arg1,
|
|
|
|
const TemplateArgument &Arg2) {
|
2010-12-01 09:36:18 +08:00
|
|
|
if (Arg1.getKind() != Arg2.getKind())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (Arg1.getKind()) {
|
|
|
|
case TemplateArgument::Null:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case TemplateArgument::Type:
|
|
|
|
return Context.IsStructurallyEquivalent(Arg1.getAsType(), Arg2.getAsType());
|
2012-09-26 10:36:12 +08:00
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
case TemplateArgument::Integral:
|
|
|
|
if (!Context.IsStructurallyEquivalent(Arg1.getIntegralType(),
|
|
|
|
Arg2.getIntegralType()))
|
|
|
|
return false;
|
|
|
|
|
2012-07-15 08:23:57 +08:00
|
|
|
return llvm::APSInt::isSameValue(Arg1.getAsIntegral(), Arg2.getAsIntegral());
|
2010-12-01 09:36:18 +08:00
|
|
|
|
|
|
|
case TemplateArgument::Declaration:
|
|
|
|
return Context.IsStructurallyEquivalent(Arg1.getAsDecl(), Arg2.getAsDecl());
|
2012-09-26 10:36:12 +08:00
|
|
|
|
|
|
|
case TemplateArgument::NullPtr:
|
|
|
|
return true; // FIXME: Is this correct?
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
case TemplateArgument::Template:
|
|
|
|
return IsStructurallyEquivalent(Context,
|
|
|
|
Arg1.getAsTemplate(),
|
|
|
|
Arg2.getAsTemplate());
|
2011-01-06 02:58:31 +08:00
|
|
|
|
|
|
|
case TemplateArgument::TemplateExpansion:
|
|
|
|
return IsStructurallyEquivalent(Context,
|
|
|
|
Arg1.getAsTemplateOrTemplatePattern(),
|
|
|
|
Arg2.getAsTemplateOrTemplatePattern());
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
case TemplateArgument::Expression:
|
|
|
|
return IsStructurallyEquivalent(Context,
|
|
|
|
Arg1.getAsExpr(), Arg2.getAsExpr());
|
|
|
|
|
|
|
|
case TemplateArgument::Pack:
|
|
|
|
if (Arg1.pack_size() != Arg2.pack_size())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (unsigned I = 0, N = Arg1.pack_size(); I != N; ++I)
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Arg1.pack_begin()[I],
|
|
|
|
Arg2.pack_begin()[I]))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Invalid template argument kind");
|
2010-02-16 06:01:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determine structural equivalence for the common part of array
|
|
|
|
/// types.
|
|
|
|
static bool IsArrayStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
const ArrayType *Array1,
|
|
|
|
const ArrayType *Array2) {
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Array1->getElementType(),
|
|
|
|
Array2->getElementType()))
|
|
|
|
return false;
|
|
|
|
if (Array1->getSizeModifier() != Array2->getSizeModifier())
|
|
|
|
return false;
|
|
|
|
if (Array1->getIndexTypeQualifiers() != Array2->getIndexTypeQualifiers())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determine structural equivalence of two types.
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
QualType T1, QualType T2) {
|
|
|
|
if (T1.isNull() || T2.isNull())
|
|
|
|
return T1.isNull() && T2.isNull();
|
|
|
|
|
|
|
|
if (!Context.StrictTypeSpelling) {
|
|
|
|
// We aren't being strict about token-to-token equivalence of types,
|
|
|
|
// so map down to the canonical type.
|
|
|
|
T1 = Context.C1.getCanonicalType(T1);
|
|
|
|
T2 = Context.C2.getCanonicalType(T2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (T1.getQualifiers() != T2.getQualifiers())
|
|
|
|
return false;
|
|
|
|
|
2010-02-16 07:54:17 +08:00
|
|
|
Type::TypeClass TC = T1->getTypeClass();
|
|
|
|
|
|
|
|
if (T1->getTypeClass() != T2->getTypeClass()) {
|
|
|
|
// Compare function types with prototypes vs. without prototypes as if
|
|
|
|
// both did not have prototypes.
|
|
|
|
if (T1->getTypeClass() == Type::FunctionProto &&
|
|
|
|
T2->getTypeClass() == Type::FunctionNoProto)
|
|
|
|
TC = Type::FunctionNoProto;
|
|
|
|
else if (T1->getTypeClass() == Type::FunctionNoProto &&
|
|
|
|
T2->getTypeClass() == Type::FunctionProto)
|
|
|
|
TC = Type::FunctionNoProto;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-16 06:01:00 +08:00
|
|
|
|
2010-02-16 07:54:17 +08:00
|
|
|
switch (TC) {
|
|
|
|
case Type::Builtin:
|
2010-02-16 06:01:00 +08:00
|
|
|
// FIXME: Deal with Char_S/Char_U.
|
|
|
|
if (cast<BuiltinType>(T1)->getKind() != cast<BuiltinType>(T2)->getKind())
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::Complex:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<ComplexType>(T1)->getElementType(),
|
|
|
|
cast<ComplexType>(T2)->getElementType()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
2013-12-05 09:23:43 +08:00
|
|
|
case Type::Adjusted:
|
2013-06-25 01:51:48 +08:00
|
|
|
case Type::Decayed:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
2013-12-05 09:23:43 +08:00
|
|
|
cast<AdjustedType>(T1)->getOriginalType(),
|
|
|
|
cast<AdjustedType>(T2)->getOriginalType()))
|
2013-06-25 01:51:48 +08:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
case Type::Pointer:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<PointerType>(T1)->getPointeeType(),
|
|
|
|
cast<PointerType>(T2)->getPointeeType()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::BlockPointer:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<BlockPointerType>(T1)->getPointeeType(),
|
|
|
|
cast<BlockPointerType>(T2)->getPointeeType()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::LValueReference:
|
|
|
|
case Type::RValueReference: {
|
|
|
|
const ReferenceType *Ref1 = cast<ReferenceType>(T1);
|
|
|
|
const ReferenceType *Ref2 = cast<ReferenceType>(T2);
|
|
|
|
if (Ref1->isSpelledAsLValue() != Ref2->isSpelledAsLValue())
|
|
|
|
return false;
|
|
|
|
if (Ref1->isInnerRef() != Ref2->isInnerRef())
|
|
|
|
return false;
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Ref1->getPointeeTypeAsWritten(),
|
|
|
|
Ref2->getPointeeTypeAsWritten()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Type::MemberPointer: {
|
|
|
|
const MemberPointerType *MemPtr1 = cast<MemberPointerType>(T1);
|
|
|
|
const MemberPointerType *MemPtr2 = cast<MemberPointerType>(T2);
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
MemPtr1->getPointeeType(),
|
|
|
|
MemPtr2->getPointeeType()))
|
|
|
|
return false;
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
QualType(MemPtr1->getClass(), 0),
|
|
|
|
QualType(MemPtr2->getClass(), 0)))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Type::ConstantArray: {
|
|
|
|
const ConstantArrayType *Array1 = cast<ConstantArrayType>(T1);
|
|
|
|
const ConstantArrayType *Array2 = cast<ConstantArrayType>(T2);
|
2012-07-15 08:23:57 +08:00
|
|
|
if (!llvm::APInt::isSameValue(Array1->getSize(), Array2->getSize()))
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Type::IncompleteArray:
|
|
|
|
if (!IsArrayStructurallyEquivalent(Context,
|
|
|
|
cast<ArrayType>(T1),
|
|
|
|
cast<ArrayType>(T2)))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::VariableArray: {
|
|
|
|
const VariableArrayType *Array1 = cast<VariableArrayType>(T1);
|
|
|
|
const VariableArrayType *Array2 = cast<VariableArrayType>(T2);
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Array1->getSizeExpr(), Array2->getSizeExpr()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Type::DependentSizedArray: {
|
|
|
|
const DependentSizedArrayType *Array1 = cast<DependentSizedArrayType>(T1);
|
|
|
|
const DependentSizedArrayType *Array2 = cast<DependentSizedArrayType>(T2);
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Array1->getSizeExpr(), Array2->getSizeExpr()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!IsArrayStructurallyEquivalent(Context, Array1, Array2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Type::DependentSizedExtVector: {
|
|
|
|
const DependentSizedExtVectorType *Vec1
|
|
|
|
= cast<DependentSizedExtVectorType>(T1);
|
|
|
|
const DependentSizedExtVectorType *Vec2
|
|
|
|
= cast<DependentSizedExtVectorType>(T2);
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Vec1->getSizeExpr(), Vec2->getSizeExpr()))
|
|
|
|
return false;
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Vec1->getElementType(),
|
|
|
|
Vec2->getElementType()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Type::Vector:
|
|
|
|
case Type::ExtVector: {
|
|
|
|
const VectorType *Vec1 = cast<VectorType>(T1);
|
|
|
|
const VectorType *Vec2 = cast<VectorType>(T2);
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Vec1->getElementType(),
|
|
|
|
Vec2->getElementType()))
|
|
|
|
return false;
|
|
|
|
if (Vec1->getNumElements() != Vec2->getNumElements())
|
|
|
|
return false;
|
2010-11-11 05:56:12 +08:00
|
|
|
if (Vec1->getVectorKind() != Vec2->getVectorKind())
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
2010-02-19 09:36:36 +08:00
|
|
|
break;
|
2010-02-16 06:01:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case Type::FunctionProto: {
|
|
|
|
const FunctionProtoType *Proto1 = cast<FunctionProtoType>(T1);
|
|
|
|
const FunctionProtoType *Proto2 = cast<FunctionProtoType>(T2);
|
2014-01-21 04:26:09 +08:00
|
|
|
if (Proto1->getNumParams() != Proto2->getNumParams())
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
2014-01-21 04:26:09 +08:00
|
|
|
for (unsigned I = 0, N = Proto1->getNumParams(); I != N; ++I) {
|
|
|
|
if (!IsStructurallyEquivalent(Context, Proto1->getParamType(I),
|
|
|
|
Proto2->getParamType(I)))
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Proto1->isVariadic() != Proto2->isVariadic())
|
|
|
|
return false;
|
2011-03-12 19:50:43 +08:00
|
|
|
if (Proto1->getExceptionSpecType() != Proto2->getExceptionSpecType())
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
2011-03-12 19:50:43 +08:00
|
|
|
if (Proto1->getExceptionSpecType() == EST_Dynamic) {
|
|
|
|
if (Proto1->getNumExceptions() != Proto2->getNumExceptions())
|
|
|
|
return false;
|
|
|
|
for (unsigned I = 0, N = Proto1->getNumExceptions(); I != N; ++I) {
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Proto1->getExceptionType(I),
|
|
|
|
Proto2->getExceptionType(I)))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (Proto1->getExceptionSpecType() == EST_ComputedNoexcept) {
|
2010-02-16 06:01:00 +08:00
|
|
|
if (!IsStructurallyEquivalent(Context,
|
2011-03-12 19:50:43 +08:00
|
|
|
Proto1->getNoexceptExpr(),
|
|
|
|
Proto2->getNoexceptExpr()))
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Proto1->getTypeQuals() != Proto2->getTypeQuals())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Fall through to check the bits common with FunctionNoProtoType.
|
|
|
|
}
|
|
|
|
|
|
|
|
case Type::FunctionNoProto: {
|
|
|
|
const FunctionType *Function1 = cast<FunctionType>(T1);
|
|
|
|
const FunctionType *Function2 = cast<FunctionType>(T2);
|
2014-01-26 00:55:45 +08:00
|
|
|
if (!IsStructurallyEquivalent(Context, Function1->getReturnType(),
|
|
|
|
Function2->getReturnType()))
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
2016-03-21 00:58:03 +08:00
|
|
|
if (Function1->getExtInfo() != Function2->getExtInfo())
|
|
|
|
return false;
|
2010-02-16 06:01:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Type::UnresolvedUsing:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<UnresolvedUsingType>(T1)->getDecl(),
|
|
|
|
cast<UnresolvedUsingType>(T2)->getDecl()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
2011-01-06 09:58:22 +08:00
|
|
|
|
|
|
|
case Type::Attributed:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<AttributedType>(T1)->getModifiedType(),
|
|
|
|
cast<AttributedType>(T2)->getModifiedType()))
|
|
|
|
return false;
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<AttributedType>(T1)->getEquivalentType(),
|
|
|
|
cast<AttributedType>(T2)->getEquivalentType()))
|
|
|
|
return false;
|
|
|
|
break;
|
2010-02-16 06:01:00 +08:00
|
|
|
|
2010-12-11 00:29:40 +08:00
|
|
|
case Type::Paren:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<ParenType>(T1)->getInnerType(),
|
|
|
|
cast<ParenType>(T2)->getInnerType()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
case Type::Typedef:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<TypedefType>(T1)->getDecl(),
|
|
|
|
cast<TypedefType>(T2)->getDecl()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::TypeOfExpr:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<TypeOfExprType>(T1)->getUnderlyingExpr(),
|
|
|
|
cast<TypeOfExprType>(T2)->getUnderlyingExpr()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::TypeOf:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<TypeOfType>(T1)->getUnderlyingType(),
|
|
|
|
cast<TypeOfType>(T2)->getUnderlyingType()))
|
|
|
|
return false;
|
|
|
|
break;
|
2011-05-25 06:41:36 +08:00
|
|
|
|
|
|
|
case Type::UnaryTransform:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<UnaryTransformType>(T1)->getUnderlyingType(),
|
|
|
|
cast<UnaryTransformType>(T1)->getUnderlyingType()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
case Type::Decltype:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<DecltypeType>(T1)->getUnderlyingExpr(),
|
|
|
|
cast<DecltypeType>(T2)->getUnderlyingExpr()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
2011-02-20 11:19:35 +08:00
|
|
|
case Type::Auto:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<AutoType>(T1)->getDeducedType(),
|
|
|
|
cast<AutoType>(T2)->getDeducedType()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
case Type::Record:
|
|
|
|
case Type::Enum:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<TagType>(T1)->getDecl(),
|
|
|
|
cast<TagType>(T2)->getDecl()))
|
|
|
|
return false;
|
|
|
|
break;
|
2010-05-12 05:36:43 +08:00
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
case Type::TemplateTypeParm: {
|
|
|
|
const TemplateTypeParmType *Parm1 = cast<TemplateTypeParmType>(T1);
|
|
|
|
const TemplateTypeParmType *Parm2 = cast<TemplateTypeParmType>(T2);
|
|
|
|
if (Parm1->getDepth() != Parm2->getDepth())
|
|
|
|
return false;
|
|
|
|
if (Parm1->getIndex() != Parm2->getIndex())
|
|
|
|
return false;
|
|
|
|
if (Parm1->isParameterPack() != Parm2->isParameterPack())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Names of template type parameters are never significant.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Type::SubstTemplateTypeParm: {
|
|
|
|
const SubstTemplateTypeParmType *Subst1
|
|
|
|
= cast<SubstTemplateTypeParmType>(T1);
|
|
|
|
const SubstTemplateTypeParmType *Subst2
|
|
|
|
= cast<SubstTemplateTypeParmType>(T2);
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
QualType(Subst1->getReplacedParameter(), 0),
|
|
|
|
QualType(Subst2->getReplacedParameter(), 0)))
|
|
|
|
return false;
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Subst1->getReplacementType(),
|
|
|
|
Subst2->getReplacementType()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-01-14 13:11:40 +08:00
|
|
|
case Type::SubstTemplateTypeParmPack: {
|
|
|
|
const SubstTemplateTypeParmPackType *Subst1
|
|
|
|
= cast<SubstTemplateTypeParmPackType>(T1);
|
|
|
|
const SubstTemplateTypeParmPackType *Subst2
|
|
|
|
= cast<SubstTemplateTypeParmPackType>(T2);
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
QualType(Subst1->getReplacedParameter(), 0),
|
|
|
|
QualType(Subst2->getReplacedParameter(), 0)))
|
|
|
|
return false;
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Subst1->getArgumentPack(),
|
|
|
|
Subst2->getArgumentPack()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2010-02-16 06:01:00 +08:00
|
|
|
case Type::TemplateSpecialization: {
|
|
|
|
const TemplateSpecializationType *Spec1
|
|
|
|
= cast<TemplateSpecializationType>(T1);
|
|
|
|
const TemplateSpecializationType *Spec2
|
|
|
|
= cast<TemplateSpecializationType>(T2);
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Spec1->getTemplateName(),
|
|
|
|
Spec2->getTemplateName()))
|
|
|
|
return false;
|
|
|
|
if (Spec1->getNumArgs() != Spec2->getNumArgs())
|
|
|
|
return false;
|
|
|
|
for (unsigned I = 0, N = Spec1->getNumArgs(); I != N; ++I) {
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Spec1->getArg(I), Spec2->getArg(I)))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-12 05:36:43 +08:00
|
|
|
case Type::Elaborated: {
|
|
|
|
const ElaboratedType *Elab1 = cast<ElaboratedType>(T1);
|
|
|
|
const ElaboratedType *Elab2 = cast<ElaboratedType>(T2);
|
|
|
|
// CHECKME: what if a keyword is ETK_None or ETK_typename ?
|
|
|
|
if (Elab1->getKeyword() != Elab2->getKeyword())
|
|
|
|
return false;
|
2010-02-16 06:01:00 +08:00
|
|
|
if (!IsStructurallyEquivalent(Context,
|
2010-05-12 05:36:43 +08:00
|
|
|
Elab1->getQualifier(),
|
|
|
|
Elab2->getQualifier()))
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
2010-05-12 05:36:43 +08:00
|
|
|
Elab1->getNamedType(),
|
|
|
|
Elab2->getNamedType()))
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-03-10 11:28:59 +08:00
|
|
|
case Type::InjectedClassName: {
|
|
|
|
const InjectedClassNameType *Inj1 = cast<InjectedClassNameType>(T1);
|
|
|
|
const InjectedClassNameType *Inj2 = cast<InjectedClassNameType>(T2);
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
2010-04-27 08:57:59 +08:00
|
|
|
Inj1->getInjectedSpecializationType(),
|
|
|
|
Inj2->getInjectedSpecializationType()))
|
2010-03-10 11:28:59 +08:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-01 01:34:00 +08:00
|
|
|
case Type::DependentName: {
|
|
|
|
const DependentNameType *Typename1 = cast<DependentNameType>(T1);
|
|
|
|
const DependentNameType *Typename2 = cast<DependentNameType>(T2);
|
2010-02-16 06:01:00 +08:00
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Typename1->getQualifier(),
|
|
|
|
Typename2->getQualifier()))
|
|
|
|
return false;
|
|
|
|
if (!IsStructurallyEquivalent(Typename1->getIdentifier(),
|
|
|
|
Typename2->getIdentifier()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-11 08:33:02 +08:00
|
|
|
case Type::DependentTemplateSpecialization: {
|
|
|
|
const DependentTemplateSpecializationType *Spec1 =
|
|
|
|
cast<DependentTemplateSpecializationType>(T1);
|
|
|
|
const DependentTemplateSpecializationType *Spec2 =
|
|
|
|
cast<DependentTemplateSpecializationType>(T2);
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Spec1->getQualifier(),
|
|
|
|
Spec2->getQualifier()))
|
|
|
|
return false;
|
|
|
|
if (!IsStructurallyEquivalent(Spec1->getIdentifier(),
|
|
|
|
Spec2->getIdentifier()))
|
|
|
|
return false;
|
|
|
|
if (Spec1->getNumArgs() != Spec2->getNumArgs())
|
|
|
|
return false;
|
|
|
|
for (unsigned I = 0, N = Spec1->getNumArgs(); I != N; ++I) {
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Spec1->getArg(I), Spec2->getArg(I)))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-12-20 10:24:11 +08:00
|
|
|
|
|
|
|
case Type::PackExpansion:
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<PackExpansionType>(T1)->getPattern(),
|
|
|
|
cast<PackExpansionType>(T2)->getPattern()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
case Type::ObjCInterface: {
|
|
|
|
const ObjCInterfaceType *Iface1 = cast<ObjCInterfaceType>(T1);
|
|
|
|
const ObjCInterfaceType *Iface2 = cast<ObjCInterfaceType>(T2);
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Iface1->getDecl(), Iface2->getDecl()))
|
|
|
|
return false;
|
2010-05-15 19:32:37 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Type::ObjCObject: {
|
|
|
|
const ObjCObjectType *Obj1 = cast<ObjCObjectType>(T1);
|
|
|
|
const ObjCObjectType *Obj2 = cast<ObjCObjectType>(T2);
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Obj1->getBaseType(),
|
|
|
|
Obj2->getBaseType()))
|
|
|
|
return false;
|
|
|
|
if (Obj1->getNumProtocols() != Obj2->getNumProtocols())
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
2010-05-15 19:32:37 +08:00
|
|
|
for (unsigned I = 0, N = Obj1->getNumProtocols(); I != N; ++I) {
|
2010-02-16 06:01:00 +08:00
|
|
|
if (!IsStructurallyEquivalent(Context,
|
2010-05-15 19:32:37 +08:00
|
|
|
Obj1->getProtocol(I),
|
|
|
|
Obj2->getProtocol(I)))
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Type::ObjCObjectPointer: {
|
|
|
|
const ObjCObjectPointerType *Ptr1 = cast<ObjCObjectPointerType>(T1);
|
|
|
|
const ObjCObjectPointerType *Ptr2 = cast<ObjCObjectPointerType>(T2);
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Ptr1->getPointeeType(),
|
|
|
|
Ptr2->getPointeeType()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2011-10-07 07:00:33 +08:00
|
|
|
|
|
|
|
case Type::Atomic: {
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<AtomicType>(T1)->getValueType(),
|
|
|
|
cast<AtomicType>(T2)->getValueType()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-09 20:53:17 +08:00
|
|
|
case Type::Pipe: {
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
cast<PipeType>(T1)->getElementType(),
|
|
|
|
cast<PipeType>(T2)->getElementType()))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
} // end switch
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-15 05:54:42 +08:00
|
|
|
/// \brief Determine structural equivalence of two fields.
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
FieldDecl *Field1, FieldDecl *Field2) {
|
|
|
|
RecordDecl *Owner2 = cast<RecordDecl>(Field2->getDeclContext());
|
2012-10-27 00:45:11 +08:00
|
|
|
|
|
|
|
// For anonymous structs/unions, match up the anonymous struct/union type
|
|
|
|
// declarations directly, so that we don't go off searching for anonymous
|
|
|
|
// types
|
|
|
|
if (Field1->isAnonymousStructOrUnion() &&
|
|
|
|
Field2->isAnonymousStructOrUnion()) {
|
|
|
|
RecordDecl *D1 = Field1->getType()->castAs<RecordType>()->getDecl();
|
|
|
|
RecordDecl *D2 = Field2->getType()->castAs<RecordType>()->getDecl();
|
|
|
|
return IsStructurallyEquivalent(Context, D1, D2);
|
|
|
|
}
|
2013-04-27 06:49:25 +08:00
|
|
|
|
|
|
|
// Check for equivalent field names.
|
|
|
|
IdentifierInfo *Name1 = Field1->getIdentifier();
|
|
|
|
IdentifierInfo *Name2 = Field2->getIdentifier();
|
|
|
|
if (!::IsStructurallyEquivalent(Name1, Name2))
|
|
|
|
return false;
|
2012-10-27 00:45:11 +08:00
|
|
|
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
2011-10-15 05:54:42 +08:00
|
|
|
Field1->getType(), Field2->getType())) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent)
|
|
|
|
<< Context.C2.getTypeDeclType(Owner2);
|
|
|
|
Context.Diag2(Field2->getLocation(), diag::note_odr_field)
|
|
|
|
<< Field2->getDeclName() << Field2->getType();
|
|
|
|
Context.Diag1(Field1->getLocation(), diag::note_odr_field)
|
|
|
|
<< Field1->getDeclName() << Field1->getType();
|
|
|
|
}
|
2011-10-15 05:54:42 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Field1->isBitField() != Field2->isBitField()) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent)
|
|
|
|
<< Context.C2.getTypeDeclType(Owner2);
|
|
|
|
if (Field1->isBitField()) {
|
|
|
|
Context.Diag1(Field1->getLocation(), diag::note_odr_bit_field)
|
|
|
|
<< Field1->getDeclName() << Field1->getType()
|
|
|
|
<< Field1->getBitWidthValue(Context.C1);
|
|
|
|
Context.Diag2(Field2->getLocation(), diag::note_odr_not_bit_field)
|
|
|
|
<< Field2->getDeclName();
|
|
|
|
} else {
|
|
|
|
Context.Diag2(Field2->getLocation(), diag::note_odr_bit_field)
|
|
|
|
<< Field2->getDeclName() << Field2->getType()
|
|
|
|
<< Field2->getBitWidthValue(Context.C2);
|
|
|
|
Context.Diag1(Field1->getLocation(), diag::note_odr_not_bit_field)
|
|
|
|
<< Field1->getDeclName();
|
|
|
|
}
|
2011-10-15 05:54:42 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Field1->isBitField()) {
|
|
|
|
// Make sure that the bit-fields are the same length.
|
|
|
|
unsigned Bits1 = Field1->getBitWidthValue(Context.C1);
|
|
|
|
unsigned Bits2 = Field2->getBitWidthValue(Context.C2);
|
|
|
|
|
|
|
|
if (Bits1 != Bits2) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(Owner2->getLocation(), diag::warn_odr_tag_type_inconsistent)
|
|
|
|
<< Context.C2.getTypeDeclType(Owner2);
|
|
|
|
Context.Diag2(Field2->getLocation(), diag::note_odr_bit_field)
|
|
|
|
<< Field2->getDeclName() << Field2->getType() << Bits2;
|
|
|
|
Context.Diag1(Field1->getLocation(), diag::note_odr_bit_field)
|
|
|
|
<< Field1->getDeclName() << Field1->getType() << Bits1;
|
|
|
|
}
|
2011-10-15 05:54:42 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-27 00:45:11 +08:00
|
|
|
/// \brief Find the index of the given anonymous struct/union within its
|
|
|
|
/// context.
|
|
|
|
///
|
|
|
|
/// \returns Returns the index of this anonymous struct/union in its context,
|
|
|
|
/// including the next assigned index (if none of them match). Returns an
|
|
|
|
/// empty option if the context is not a record, i.e.. if the anonymous
|
|
|
|
/// struct/union is at namespace or block scope.
|
2013-02-21 06:23:23 +08:00
|
|
|
static Optional<unsigned> findAnonymousStructOrUnionIndex(RecordDecl *Anon) {
|
2012-10-27 00:45:11 +08:00
|
|
|
ASTContext &Context = Anon->getASTContext();
|
|
|
|
QualType AnonTy = Context.getRecordType(Anon);
|
|
|
|
|
|
|
|
RecordDecl *Owner = dyn_cast<RecordDecl>(Anon->getDeclContext());
|
|
|
|
if (!Owner)
|
2013-02-21 09:47:18 +08:00
|
|
|
return None;
|
2012-10-27 00:45:11 +08:00
|
|
|
|
|
|
|
unsigned Index = 0;
|
2014-03-08 03:56:05 +08:00
|
|
|
for (const auto *D : Owner->noload_decls()) {
|
|
|
|
const auto *F = dyn_cast<FieldDecl>(D);
|
2012-10-27 00:45:11 +08:00
|
|
|
if (!F || !F->isAnonymousStructOrUnion())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Context.hasSameType(F->getType(), AnonTy))
|
|
|
|
break;
|
|
|
|
|
|
|
|
++Index;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Index;
|
|
|
|
}
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
/// \brief Determine structural equivalence of two records.
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
RecordDecl *D1, RecordDecl *D2) {
|
|
|
|
if (D1->isUnion() != D2->isUnion()) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
|
|
|
|
<< Context.C2.getTypeDeclType(D2);
|
|
|
|
Context.Diag1(D1->getLocation(), diag::note_odr_tag_kind_here)
|
|
|
|
<< D1->getDeclName() << (unsigned)D1->getTagKind();
|
|
|
|
}
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-27 00:45:11 +08:00
|
|
|
|
|
|
|
if (D1->isAnonymousStructOrUnion() && D2->isAnonymousStructOrUnion()) {
|
|
|
|
// If both anonymous structs/unions are in a record context, make sure
|
|
|
|
// they occur in the same location in the context records.
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<unsigned> Index1 = findAnonymousStructOrUnionIndex(D1)) {
|
|
|
|
if (Optional<unsigned> Index2 = findAnonymousStructOrUnionIndex(D2)) {
|
2012-10-27 00:45:11 +08:00
|
|
|
if (*Index1 != *Index2)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
// If both declarations are class template specializations, we know
|
|
|
|
// the ODR applies, so check the template and template arguments.
|
|
|
|
ClassTemplateSpecializationDecl *Spec1
|
|
|
|
= dyn_cast<ClassTemplateSpecializationDecl>(D1);
|
|
|
|
ClassTemplateSpecializationDecl *Spec2
|
|
|
|
= dyn_cast<ClassTemplateSpecializationDecl>(D2);
|
|
|
|
if (Spec1 && Spec2) {
|
|
|
|
// Check that the specialized templates are the same.
|
|
|
|
if (!IsStructurallyEquivalent(Context, Spec1->getSpecializedTemplate(),
|
|
|
|
Spec2->getSpecializedTemplate()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check that the template arguments are the same.
|
|
|
|
if (Spec1->getTemplateArgs().size() != Spec2->getTemplateArgs().size())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (unsigned I = 0, N = Spec1->getTemplateArgs().size(); I != N; ++I)
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Spec1->getTemplateArgs().get(I),
|
|
|
|
Spec2->getTemplateArgs().get(I)))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// If one is a class template specialization and the other is not, these
|
2011-04-15 13:22:18 +08:00
|
|
|
// structures are different.
|
2010-12-01 09:36:18 +08:00
|
|
|
else if (Spec1 || Spec2)
|
|
|
|
return false;
|
|
|
|
|
2010-02-16 07:54:17 +08:00
|
|
|
// Compare the definitions of these two records. If either or both are
|
|
|
|
// incomplete, we assume that they are equivalent.
|
|
|
|
D1 = D1->getDefinition();
|
|
|
|
D2 = D2->getDefinition();
|
|
|
|
if (!D1 || !D2)
|
|
|
|
return true;
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
if (CXXRecordDecl *D1CXX = dyn_cast<CXXRecordDecl>(D1)) {
|
|
|
|
if (CXXRecordDecl *D2CXX = dyn_cast<CXXRecordDecl>(D2)) {
|
|
|
|
if (D1CXX->getNumBases() != D2CXX->getNumBases()) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
|
|
|
|
<< Context.C2.getTypeDeclType(D2);
|
|
|
|
Context.Diag2(D2->getLocation(), diag::note_odr_number_of_bases)
|
|
|
|
<< D2CXX->getNumBases();
|
|
|
|
Context.Diag1(D1->getLocation(), diag::note_odr_number_of_bases)
|
|
|
|
<< D1CXX->getNumBases();
|
|
|
|
}
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the base classes.
|
|
|
|
for (CXXRecordDecl::base_class_iterator Base1 = D1CXX->bases_begin(),
|
|
|
|
BaseEnd1 = D1CXX->bases_end(),
|
|
|
|
Base2 = D2CXX->bases_begin();
|
|
|
|
Base1 != BaseEnd1;
|
|
|
|
++Base1, ++Base2) {
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
Base1->getType(), Base2->getType())) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
|
|
|
|
<< Context.C2.getTypeDeclType(D2);
|
|
|
|
Context.Diag2(Base2->getLocStart(), diag::note_odr_base)
|
|
|
|
<< Base2->getType()
|
|
|
|
<< Base2->getSourceRange();
|
|
|
|
Context.Diag1(Base1->getLocStart(), diag::note_odr_base)
|
|
|
|
<< Base1->getType()
|
|
|
|
<< Base1->getSourceRange();
|
|
|
|
}
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check virtual vs. non-virtual inheritance mismatch.
|
|
|
|
if (Base1->isVirtual() != Base2->isVirtual()) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
|
|
|
|
<< Context.C2.getTypeDeclType(D2);
|
|
|
|
Context.Diag2(Base2->getLocStart(),
|
|
|
|
diag::note_odr_virtual_base)
|
|
|
|
<< Base2->isVirtual() << Base2->getSourceRange();
|
|
|
|
Context.Diag1(Base1->getLocStart(), diag::note_odr_base)
|
|
|
|
<< Base1->isVirtual()
|
|
|
|
<< Base1->getSourceRange();
|
|
|
|
}
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (D1CXX->getNumBases() > 0) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
|
|
|
|
<< Context.C2.getTypeDeclType(D2);
|
|
|
|
const CXXBaseSpecifier *Base1 = D1CXX->bases_begin();
|
|
|
|
Context.Diag1(Base1->getLocStart(), diag::note_odr_base)
|
|
|
|
<< Base1->getType()
|
|
|
|
<< Base1->getSourceRange();
|
|
|
|
Context.Diag2(D2->getLocation(), diag::note_odr_missing_base);
|
|
|
|
}
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the fields for consistency.
|
2012-05-20 01:17:26 +08:00
|
|
|
RecordDecl::field_iterator Field2 = D2->field_begin(),
|
2010-02-16 06:01:00 +08:00
|
|
|
Field2End = D2->field_end();
|
2012-05-20 01:17:26 +08:00
|
|
|
for (RecordDecl::field_iterator Field1 = D1->field_begin(),
|
2010-02-16 06:01:00 +08:00
|
|
|
Field1End = D1->field_end();
|
|
|
|
Field1 != Field1End;
|
|
|
|
++Field1, ++Field2) {
|
|
|
|
if (Field2 == Field2End) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
|
|
|
|
<< Context.C2.getTypeDeclType(D2);
|
|
|
|
Context.Diag1(Field1->getLocation(), diag::note_odr_field)
|
|
|
|
<< Field1->getDeclName() << Field1->getType();
|
|
|
|
Context.Diag2(D2->getLocation(), diag::note_odr_missing_field);
|
|
|
|
}
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-07 04:45:41 +08:00
|
|
|
if (!IsStructurallyEquivalent(Context, *Field1, *Field2))
|
2011-10-15 05:54:42 +08:00
|
|
|
return false;
|
2010-02-16 06:01:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Field2 != Field2End) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
|
|
|
|
<< Context.C2.getTypeDeclType(D2);
|
|
|
|
Context.Diag2(Field2->getLocation(), diag::note_odr_field)
|
|
|
|
<< Field2->getDeclName() << Field2->getType();
|
|
|
|
Context.Diag1(D1->getLocation(), diag::note_odr_missing_field);
|
|
|
|
}
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determine structural equivalence of two enums.
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
EnumDecl *D1, EnumDecl *D2) {
|
|
|
|
EnumDecl::enumerator_iterator EC2 = D2->enumerator_begin(),
|
|
|
|
EC2End = D2->enumerator_end();
|
|
|
|
for (EnumDecl::enumerator_iterator EC1 = D1->enumerator_begin(),
|
|
|
|
EC1End = D1->enumerator_end();
|
|
|
|
EC1 != EC1End; ++EC1, ++EC2) {
|
|
|
|
if (EC2 == EC2End) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
|
|
|
|
<< Context.C2.getTypeDeclType(D2);
|
|
|
|
Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator)
|
|
|
|
<< EC1->getDeclName()
|
|
|
|
<< EC1->getInitVal().toString(10);
|
|
|
|
Context.Diag2(D2->getLocation(), diag::note_odr_missing_enumerator);
|
|
|
|
}
|
2010-02-16 06:01:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::APSInt Val1 = EC1->getInitVal();
|
|
|
|
llvm::APSInt Val2 = EC2->getInitVal();
|
2012-07-15 08:23:57 +08:00
|
|
|
if (!llvm::APSInt::isSameValue(Val1, Val2) ||
|
2010-02-16 06:01:00 +08:00
|
|
|
!IsStructurallyEquivalent(EC1->getIdentifier(), EC2->getIdentifier())) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
|
|
|
|
<< Context.C2.getTypeDeclType(D2);
|
|
|
|
Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator)
|
|
|
|
<< EC2->getDeclName()
|
|
|
|
<< EC2->getInitVal().toString(10);
|
|
|
|
Context.Diag1(EC1->getLocation(), diag::note_odr_enumerator)
|
|
|
|
<< EC1->getDeclName()
|
|
|
|
<< EC1->getInitVal().toString(10);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EC2 != EC2End) {
|
|
|
|
if (Context.Complain) {
|
2010-02-16 06:01:00 +08:00
|
|
|
Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent)
|
|
|
|
<< Context.C2.getTypeDeclType(D2);
|
|
|
|
Context.Diag2(EC2->getLocation(), diag::note_odr_enumerator)
|
|
|
|
<< EC2->getDeclName()
|
|
|
|
<< EC2->getInitVal().toString(10);
|
2012-10-26 23:34:11 +08:00
|
|
|
Context.Diag1(D1->getLocation(), diag::note_odr_missing_enumerator);
|
2010-02-16 06:01:00 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-12-01 03:14:50 +08:00
|
|
|
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
TemplateParameterList *Params1,
|
|
|
|
TemplateParameterList *Params2) {
|
|
|
|
if (Params1->size() != Params2->size()) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(Params2->getTemplateLoc(),
|
|
|
|
diag::err_odr_different_num_template_parameters)
|
|
|
|
<< Params1->size() << Params2->size();
|
|
|
|
Context.Diag1(Params1->getTemplateLoc(),
|
|
|
|
diag::note_odr_template_parameter_list);
|
|
|
|
}
|
2010-12-01 03:14:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned I = 0, N = Params1->size(); I != N; ++I) {
|
|
|
|
if (Params1->getParam(I)->getKind() != Params2->getParam(I)->getKind()) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(Params2->getParam(I)->getLocation(),
|
|
|
|
diag::err_odr_different_template_parameter_kind);
|
|
|
|
Context.Diag1(Params1->getParam(I)->getLocation(),
|
|
|
|
diag::note_odr_template_parameter_here);
|
|
|
|
}
|
2010-12-01 03:14:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Context.IsStructurallyEquivalent(Params1->getParam(I),
|
|
|
|
Params2->getParam(I))) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
TemplateTypeParmDecl *D1,
|
|
|
|
TemplateTypeParmDecl *D2) {
|
|
|
|
if (D1->isParameterPack() != D2->isParameterPack()) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack)
|
|
|
|
<< D2->isParameterPack();
|
|
|
|
Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
|
|
|
|
<< D1->isParameterPack();
|
|
|
|
}
|
2010-12-01 03:14:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
NonTypeTemplateParmDecl *D1,
|
|
|
|
NonTypeTemplateParmDecl *D2) {
|
|
|
|
if (D1->isParameterPack() != D2->isParameterPack()) {
|
2012-10-26 23:36:15 +08:00
|
|
|
if (Context.Complain) {
|
2012-10-26 23:34:11 +08:00
|
|
|
Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack)
|
|
|
|
<< D2->isParameterPack();
|
|
|
|
Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
|
|
|
|
<< D1->isParameterPack();
|
|
|
|
}
|
2010-12-01 03:14:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check types.
|
|
|
|
if (!Context.IsStructurallyEquivalent(D1->getType(), D2->getType())) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(D2->getLocation(),
|
|
|
|
diag::err_odr_non_type_parameter_type_inconsistent)
|
|
|
|
<< D2->getType() << D1->getType();
|
|
|
|
Context.Diag1(D1->getLocation(), diag::note_odr_value_here)
|
|
|
|
<< D1->getType();
|
|
|
|
}
|
2010-12-01 03:14:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
TemplateTemplateParmDecl *D1,
|
|
|
|
TemplateTemplateParmDecl *D2) {
|
|
|
|
if (D1->isParameterPack() != D2->isParameterPack()) {
|
2012-10-26 23:34:11 +08:00
|
|
|
if (Context.Complain) {
|
|
|
|
Context.Diag2(D2->getLocation(), diag::err_odr_parameter_pack_non_pack)
|
|
|
|
<< D2->isParameterPack();
|
|
|
|
Context.Diag1(D1->getLocation(), diag::note_odr_parameter_pack_non_pack)
|
|
|
|
<< D1->isParameterPack();
|
|
|
|
}
|
2010-12-01 03:14:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-26 23:36:15 +08:00
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
// Check template parameter lists.
|
|
|
|
return IsStructurallyEquivalent(Context, D1->getTemplateParameters(),
|
|
|
|
D2->getTemplateParameters());
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
ClassTemplateDecl *D1,
|
|
|
|
ClassTemplateDecl *D2) {
|
|
|
|
// Check template parameters.
|
|
|
|
if (!IsStructurallyEquivalent(Context,
|
|
|
|
D1->getTemplateParameters(),
|
|
|
|
D2->getTemplateParameters()))
|
|
|
|
return false;
|
2010-02-16 06:01:00 +08:00
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
// Check the templated declaration.
|
|
|
|
return Context.IsStructurallyEquivalent(D1->getTemplatedDecl(),
|
|
|
|
D2->getTemplatedDecl());
|
|
|
|
}
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
/// \brief Determine structural equivalence of two declarations.
|
|
|
|
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
|
|
|
|
Decl *D1, Decl *D2) {
|
|
|
|
// FIXME: Check for known structural equivalences via a callback of some sort.
|
|
|
|
|
2010-02-16 07:54:17 +08:00
|
|
|
// Check whether we already know that these two declarations are not
|
|
|
|
// structurally equivalent.
|
|
|
|
if (Context.NonEquivalentDecls.count(std::make_pair(D1->getCanonicalDecl(),
|
|
|
|
D2->getCanonicalDecl())))
|
|
|
|
return false;
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
// Determine whether we've already produced a tentative equivalence for D1.
|
|
|
|
Decl *&EquivToD1 = Context.TentativeEquivalences[D1->getCanonicalDecl()];
|
|
|
|
if (EquivToD1)
|
|
|
|
return EquivToD1 == D2->getCanonicalDecl();
|
|
|
|
|
|
|
|
// Produce a tentative equivalence D1 <-> D2, which will be checked later.
|
|
|
|
EquivToD1 = D2->getCanonicalDecl();
|
|
|
|
Context.DeclsToCheck.push_back(D1->getCanonicalDecl());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StructuralEquivalenceContext::IsStructurallyEquivalent(Decl *D1,
|
|
|
|
Decl *D2) {
|
|
|
|
if (!::IsStructurallyEquivalent(*this, D1, D2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StructuralEquivalenceContext::IsStructurallyEquivalent(QualType T1,
|
|
|
|
QualType T2) {
|
|
|
|
if (!::IsStructurallyEquivalent(*this, T1, T2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StructuralEquivalenceContext::Finish() {
|
|
|
|
while (!DeclsToCheck.empty()) {
|
|
|
|
// Check the next declaration.
|
|
|
|
Decl *D1 = DeclsToCheck.front();
|
|
|
|
DeclsToCheck.pop_front();
|
|
|
|
|
|
|
|
Decl *D2 = TentativeEquivalences[D1];
|
|
|
|
assert(D2 && "Unrecorded tentative equivalence?");
|
|
|
|
|
2010-02-16 07:54:17 +08:00
|
|
|
bool Equivalent = true;
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
// FIXME: Switch on all declaration kinds. For now, we're just going to
|
|
|
|
// check the obvious ones.
|
|
|
|
if (RecordDecl *Record1 = dyn_cast<RecordDecl>(D1)) {
|
|
|
|
if (RecordDecl *Record2 = dyn_cast<RecordDecl>(D2)) {
|
|
|
|
// Check for equivalent structure names.
|
|
|
|
IdentifierInfo *Name1 = Record1->getIdentifier();
|
2011-04-15 22:24:37 +08:00
|
|
|
if (!Name1 && Record1->getTypedefNameForAnonDecl())
|
|
|
|
Name1 = Record1->getTypedefNameForAnonDecl()->getIdentifier();
|
2010-02-16 06:01:00 +08:00
|
|
|
IdentifierInfo *Name2 = Record2->getIdentifier();
|
2011-04-15 22:24:37 +08:00
|
|
|
if (!Name2 && Record2->getTypedefNameForAnonDecl())
|
|
|
|
Name2 = Record2->getTypedefNameForAnonDecl()->getIdentifier();
|
2010-02-16 07:54:17 +08:00
|
|
|
if (!::IsStructurallyEquivalent(Name1, Name2) ||
|
|
|
|
!::IsStructurallyEquivalent(*this, Record1, Record2))
|
|
|
|
Equivalent = false;
|
2010-02-16 06:01:00 +08:00
|
|
|
} else {
|
|
|
|
// Record/non-record mismatch.
|
2010-02-16 07:54:17 +08:00
|
|
|
Equivalent = false;
|
2010-02-16 06:01:00 +08:00
|
|
|
}
|
2010-02-16 07:54:17 +08:00
|
|
|
} else if (EnumDecl *Enum1 = dyn_cast<EnumDecl>(D1)) {
|
2010-02-16 06:01:00 +08:00
|
|
|
if (EnumDecl *Enum2 = dyn_cast<EnumDecl>(D2)) {
|
|
|
|
// Check for equivalent enum names.
|
|
|
|
IdentifierInfo *Name1 = Enum1->getIdentifier();
|
2011-04-15 22:24:37 +08:00
|
|
|
if (!Name1 && Enum1->getTypedefNameForAnonDecl())
|
|
|
|
Name1 = Enum1->getTypedefNameForAnonDecl()->getIdentifier();
|
2010-02-16 06:01:00 +08:00
|
|
|
IdentifierInfo *Name2 = Enum2->getIdentifier();
|
2011-04-15 22:24:37 +08:00
|
|
|
if (!Name2 && Enum2->getTypedefNameForAnonDecl())
|
|
|
|
Name2 = Enum2->getTypedefNameForAnonDecl()->getIdentifier();
|
2010-02-16 07:54:17 +08:00
|
|
|
if (!::IsStructurallyEquivalent(Name1, Name2) ||
|
|
|
|
!::IsStructurallyEquivalent(*this, Enum1, Enum2))
|
|
|
|
Equivalent = false;
|
2010-02-16 06:01:00 +08:00
|
|
|
} else {
|
|
|
|
// Enum/non-enum mismatch
|
2010-02-16 07:54:17 +08:00
|
|
|
Equivalent = false;
|
2010-02-16 06:01:00 +08:00
|
|
|
}
|
2011-04-15 22:24:37 +08:00
|
|
|
} else if (TypedefNameDecl *Typedef1 = dyn_cast<TypedefNameDecl>(D1)) {
|
|
|
|
if (TypedefNameDecl *Typedef2 = dyn_cast<TypedefNameDecl>(D2)) {
|
2010-02-16 06:01:00 +08:00
|
|
|
if (!::IsStructurallyEquivalent(Typedef1->getIdentifier(),
|
2010-02-16 07:54:17 +08:00
|
|
|
Typedef2->getIdentifier()) ||
|
|
|
|
!::IsStructurallyEquivalent(*this,
|
2010-02-16 06:01:00 +08:00
|
|
|
Typedef1->getUnderlyingType(),
|
|
|
|
Typedef2->getUnderlyingType()))
|
2010-02-16 07:54:17 +08:00
|
|
|
Equivalent = false;
|
2010-02-16 06:01:00 +08:00
|
|
|
} else {
|
|
|
|
// Typedef/non-typedef mismatch.
|
2010-02-16 07:54:17 +08:00
|
|
|
Equivalent = false;
|
2010-02-16 06:01:00 +08:00
|
|
|
}
|
2010-12-01 03:14:50 +08:00
|
|
|
} else if (ClassTemplateDecl *ClassTemplate1
|
|
|
|
= dyn_cast<ClassTemplateDecl>(D1)) {
|
|
|
|
if (ClassTemplateDecl *ClassTemplate2 = dyn_cast<ClassTemplateDecl>(D2)) {
|
|
|
|
if (!::IsStructurallyEquivalent(ClassTemplate1->getIdentifier(),
|
|
|
|
ClassTemplate2->getIdentifier()) ||
|
|
|
|
!::IsStructurallyEquivalent(*this, ClassTemplate1, ClassTemplate2))
|
|
|
|
Equivalent = false;
|
|
|
|
} else {
|
|
|
|
// Class template/non-class-template mismatch.
|
|
|
|
Equivalent = false;
|
|
|
|
}
|
|
|
|
} else if (TemplateTypeParmDecl *TTP1= dyn_cast<TemplateTypeParmDecl>(D1)) {
|
|
|
|
if (TemplateTypeParmDecl *TTP2 = dyn_cast<TemplateTypeParmDecl>(D2)) {
|
|
|
|
if (!::IsStructurallyEquivalent(*this, TTP1, TTP2))
|
|
|
|
Equivalent = false;
|
|
|
|
} else {
|
|
|
|
// Kind mismatch.
|
|
|
|
Equivalent = false;
|
|
|
|
}
|
|
|
|
} else if (NonTypeTemplateParmDecl *NTTP1
|
|
|
|
= dyn_cast<NonTypeTemplateParmDecl>(D1)) {
|
|
|
|
if (NonTypeTemplateParmDecl *NTTP2
|
|
|
|
= dyn_cast<NonTypeTemplateParmDecl>(D2)) {
|
|
|
|
if (!::IsStructurallyEquivalent(*this, NTTP1, NTTP2))
|
|
|
|
Equivalent = false;
|
|
|
|
} else {
|
|
|
|
// Kind mismatch.
|
|
|
|
Equivalent = false;
|
|
|
|
}
|
|
|
|
} else if (TemplateTemplateParmDecl *TTP1
|
|
|
|
= dyn_cast<TemplateTemplateParmDecl>(D1)) {
|
|
|
|
if (TemplateTemplateParmDecl *TTP2
|
|
|
|
= dyn_cast<TemplateTemplateParmDecl>(D2)) {
|
|
|
|
if (!::IsStructurallyEquivalent(*this, TTP1, TTP2))
|
|
|
|
Equivalent = false;
|
|
|
|
} else {
|
|
|
|
// Kind mismatch.
|
|
|
|
Equivalent = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-16 07:54:17 +08:00
|
|
|
if (!Equivalent) {
|
|
|
|
// Note that these two declarations are not equivalent (and we already
|
|
|
|
// know about it).
|
|
|
|
NonEquivalentDecls.insert(std::make_pair(D1->getCanonicalDecl(),
|
|
|
|
D2->getCanonicalDecl()));
|
|
|
|
return true;
|
|
|
|
}
|
2010-02-16 06:01:00 +08:00
|
|
|
// FIXME: Check other declaration kinds!
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-06 01:54:41 +08:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Import Types
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitType(const Type *T) {
|
2010-02-10 06:48:33 +08:00
|
|
|
Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
|
|
|
|
<< T->getTypeClassName();
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
switch (T->getKind()) {
|
2016-04-08 21:40:33 +08:00
|
|
|
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
|
|
|
|
case BuiltinType::Id: \
|
|
|
|
return Importer.getToContext().SingletonId;
|
2016-04-13 16:33:41 +08:00
|
|
|
#include "clang/Basic/OpenCLImageTypes.def"
|
2011-10-19 05:02:43 +08:00
|
|
|
#define SHARED_SINGLETON_TYPE(Expansion)
|
|
|
|
#define BUILTIN_TYPE(Id, SingletonId) \
|
|
|
|
case BuiltinType::Id: return Importer.getToContext().SingletonId;
|
|
|
|
#include "clang/AST/BuiltinTypes.def"
|
|
|
|
|
|
|
|
// FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
|
|
|
|
// context supports C++.
|
|
|
|
|
|
|
|
// FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
|
|
|
|
// context supports ObjC.
|
|
|
|
|
2010-02-06 01:54:41 +08:00
|
|
|
case BuiltinType::Char_U:
|
|
|
|
// The context we're importing from has an unsigned 'char'. If we're
|
|
|
|
// importing into a context with a signed 'char', translate to
|
|
|
|
// 'unsigned char' instead.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (Importer.getToContext().getLangOpts().CharIsSigned)
|
2010-02-06 01:54:41 +08:00
|
|
|
return Importer.getToContext().UnsignedCharTy;
|
|
|
|
|
|
|
|
return Importer.getToContext().CharTy;
|
|
|
|
|
|
|
|
case BuiltinType::Char_S:
|
|
|
|
// The context we're importing from has an unsigned 'char'. If we're
|
|
|
|
// importing into a context with a signed 'char', translate to
|
|
|
|
// 'unsigned char' instead.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!Importer.getToContext().getLangOpts().CharIsSigned)
|
2010-02-06 01:54:41 +08:00
|
|
|
return Importer.getToContext().SignedCharTy;
|
|
|
|
|
|
|
|
return Importer.getToContext().CharTy;
|
|
|
|
|
2010-12-26 07:25:43 +08:00
|
|
|
case BuiltinType::WChar_S:
|
|
|
|
case BuiltinType::WChar_U:
|
2010-02-06 01:54:41 +08:00
|
|
|
// FIXME: If not in C++, shall we translate to the C equivalent of
|
|
|
|
// wchar_t?
|
|
|
|
return Importer.getToContext().WCharTy;
|
|
|
|
}
|
2012-01-21 05:50:17 +08:00
|
|
|
|
|
|
|
llvm_unreachable("Invalid BuiltinType Kind!");
|
2010-02-06 01:54:41 +08:00
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
QualType ToElementType = Importer.Import(T->getElementType());
|
|
|
|
if (ToElementType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getComplexType(ToElementType);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitPointerType(const PointerType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
QualType ToPointeeType = Importer.Import(T->getPointeeType());
|
|
|
|
if (ToPointeeType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getPointerType(ToPointeeType);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
// FIXME: Check for blocks support in "to" context.
|
|
|
|
QualType ToPointeeType = Importer.Import(T->getPointeeType());
|
|
|
|
if (ToPointeeType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getBlockPointerType(ToPointeeType);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType
|
|
|
|
ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
// FIXME: Check for C++ support in "to" context.
|
|
|
|
QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten());
|
|
|
|
if (ToPointeeType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getLValueReferenceType(ToPointeeType);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType
|
|
|
|
ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
// FIXME: Check for C++0x support in "to" context.
|
|
|
|
QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten());
|
|
|
|
if (ToPointeeType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getRValueReferenceType(ToPointeeType);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
// FIXME: Check for C++ support in "to" context.
|
|
|
|
QualType ToPointeeType = Importer.Import(T->getPointeeType());
|
|
|
|
if (ToPointeeType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
QualType ClassType = Importer.Import(QualType(T->getClass(), 0));
|
|
|
|
return Importer.getToContext().getMemberPointerType(ToPointeeType,
|
|
|
|
ClassType.getTypePtr());
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
QualType ToElementType = Importer.Import(T->getElementType());
|
|
|
|
if (ToElementType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getConstantArrayType(ToElementType,
|
|
|
|
T->getSize(),
|
|
|
|
T->getSizeModifier(),
|
|
|
|
T->getIndexTypeCVRQualifiers());
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType
|
|
|
|
ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
QualType ToElementType = Importer.Import(T->getElementType());
|
|
|
|
if (ToElementType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getIncompleteArrayType(ToElementType,
|
|
|
|
T->getSizeModifier(),
|
|
|
|
T->getIndexTypeCVRQualifiers());
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
QualType ToElementType = Importer.Import(T->getElementType());
|
|
|
|
if (ToElementType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
Expr *Size = Importer.Import(T->getSizeExpr());
|
|
|
|
if (!Size)
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
SourceRange Brackets = Importer.Import(T->getBracketsRange());
|
|
|
|
return Importer.getToContext().getVariableArrayType(ToElementType, Size,
|
|
|
|
T->getSizeModifier(),
|
|
|
|
T->getIndexTypeCVRQualifiers(),
|
|
|
|
Brackets);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitVectorType(const VectorType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
QualType ToElementType = Importer.Import(T->getElementType());
|
|
|
|
if (ToElementType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getVectorType(ToElementType,
|
|
|
|
T->getNumElements(),
|
2010-11-11 05:56:12 +08:00
|
|
|
T->getVectorKind());
|
2010-02-06 01:54:41 +08:00
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
QualType ToElementType = Importer.Import(T->getElementType());
|
|
|
|
if (ToElementType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getExtVectorType(ToElementType,
|
|
|
|
T->getNumElements());
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType
|
|
|
|
ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
// FIXME: What happens if we're importing a function without a prototype
|
|
|
|
// into C++? Should we make it variadic?
|
2014-01-26 00:55:45 +08:00
|
|
|
QualType ToResultType = Importer.Import(T->getReturnType());
|
2010-02-06 01:54:41 +08:00
|
|
|
if (ToResultType.isNull())
|
|
|
|
return QualType();
|
2010-03-31 04:24:48 +08:00
|
|
|
|
2010-02-06 01:54:41 +08:00
|
|
|
return Importer.getToContext().getFunctionNoProtoType(ToResultType,
|
2010-03-31 04:24:48 +08:00
|
|
|
T->getExtInfo());
|
2010-02-06 01:54:41 +08:00
|
|
|
}
|
|
|
|
|
2012-09-26 03:26:39 +08:00
|
|
|
QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
|
2014-01-26 00:55:45 +08:00
|
|
|
QualType ToResultType = Importer.Import(T->getReturnType());
|
2010-02-06 01:54:41 +08:00
|
|
|
if (ToResultType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
// Import argument types
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<QualType, 4> ArgTypes;
|
2014-03-17 23:23:01 +08:00
|
|
|
for (const auto &A : T->param_types()) {
|
|
|
|
QualType ArgType = Importer.Import(A);
|
2010-02-06 01:54:41 +08:00
|
|
|
if (ArgType.isNull())
|
|
|
|
return QualType();
|
|
|
|
ArgTypes.push_back(ArgType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import exception types
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<QualType, 4> ExceptionTypes;
|
2014-03-17 23:38:09 +08:00
|
|
|
for (const auto &E : T->exceptions()) {
|
|
|
|
QualType ExceptionType = Importer.Import(E);
|
2010-02-06 01:54:41 +08:00
|
|
|
if (ExceptionType.isNull())
|
|
|
|
return QualType();
|
|
|
|
ExceptionTypes.push_back(ExceptionType);
|
|
|
|
}
|
2010-12-14 16:05:40 +08:00
|
|
|
|
2012-09-22 09:58:06 +08:00
|
|
|
FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo();
|
|
|
|
FunctionProtoType::ExtProtoInfo ToEPI;
|
|
|
|
|
|
|
|
ToEPI.ExtInfo = FromEPI.ExtInfo;
|
|
|
|
ToEPI.Variadic = FromEPI.Variadic;
|
|
|
|
ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
|
|
|
|
ToEPI.TypeQuals = FromEPI.TypeQuals;
|
|
|
|
ToEPI.RefQualifier = FromEPI.RefQualifier;
|
2014-08-01 05:57:55 +08:00
|
|
|
ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
|
|
|
|
ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
|
|
|
|
ToEPI.ExceptionSpec.NoexceptExpr =
|
|
|
|
Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr);
|
|
|
|
ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>(
|
|
|
|
Importer.Import(FromEPI.ExceptionSpec.SourceDecl));
|
|
|
|
ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>(
|
|
|
|
Importer.Import(FromEPI.ExceptionSpec.SourceTemplate));
|
2012-09-22 09:58:06 +08:00
|
|
|
|
2013-03-09 05:51:21 +08:00
|
|
|
return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI);
|
2012-09-22 09:58:06 +08:00
|
|
|
}
|
|
|
|
|
2011-08-12 00:56:07 +08:00
|
|
|
QualType ASTNodeImporter::VisitParenType(const ParenType *T) {
|
|
|
|
QualType ToInnerType = Importer.Import(T->getInnerType());
|
|
|
|
if (ToInnerType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getParenType(ToInnerType);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
|
2011-04-15 22:24:37 +08:00
|
|
|
TypedefNameDecl *ToDecl
|
|
|
|
= dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl()));
|
2010-02-06 01:54:41 +08:00
|
|
|
if (!ToDecl)
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getTypeDeclType(ToDecl);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
Expr *ToExpr = Importer.Import(T->getUnderlyingExpr());
|
|
|
|
if (!ToExpr)
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getTypeOfExprType(ToExpr);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType());
|
|
|
|
if (ToUnderlyingType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getTypeOfType(ToUnderlyingType);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
|
2011-02-20 11:19:35 +08:00
|
|
|
// FIXME: Make sure that the "to" context supports C++0x!
|
2010-02-06 01:54:41 +08:00
|
|
|
Expr *ToExpr = Importer.Import(T->getUnderlyingExpr());
|
|
|
|
if (!ToExpr)
|
|
|
|
return QualType();
|
|
|
|
|
2012-02-13 02:42:33 +08:00
|
|
|
QualType UnderlyingType = Importer.Import(T->getUnderlyingType());
|
|
|
|
if (UnderlyingType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType);
|
2010-02-06 01:54:41 +08:00
|
|
|
}
|
|
|
|
|
2011-05-25 06:41:36 +08:00
|
|
|
QualType ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
|
|
|
|
QualType ToBaseType = Importer.Import(T->getBaseType());
|
|
|
|
QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType());
|
|
|
|
if (ToBaseType.isNull() || ToUnderlyingType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getUnaryTransformType(ToBaseType,
|
|
|
|
ToUnderlyingType,
|
|
|
|
T->getUTTKind());
|
|
|
|
}
|
|
|
|
|
2011-02-20 11:19:35 +08:00
|
|
|
QualType ASTNodeImporter::VisitAutoType(const AutoType *T) {
|
2013-04-27 00:15:35 +08:00
|
|
|
// FIXME: Make sure that the "to" context supports C++11!
|
2011-02-20 11:19:35 +08:00
|
|
|
QualType FromDeduced = T->getDeducedType();
|
|
|
|
QualType ToDeduced;
|
|
|
|
if (!FromDeduced.isNull()) {
|
|
|
|
ToDeduced = Importer.Import(FromDeduced);
|
|
|
|
if (ToDeduced.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
2015-11-11 10:02:15 +08:00
|
|
|
return Importer.getToContext().getAutoType(ToDeduced, T->getKeyword(),
|
Implement a rudimentary form of generic lambdas.
Specifically, the following features are not included in this commit:
- any sort of capturing within generic lambdas
- generic lambdas within template functions and nested
within other generic lambdas
- conversion operator for captureless lambdas
- ensuring all visitors are generic lambda aware
(Although I have gotten some useful feedback on my patches of the above and will be incorporating that as I submit those patches for commit)
As an example of what compiles through this commit:
template <class F1, class F2>
struct overload : F1, F2 {
using F1::operator();
using F2::operator();
overload(F1 f1, F2 f2) : F1(f1), F2(f2) { }
};
auto Recursive = [](auto Self, auto h, auto ... rest) {
return 1 + Self(Self, rest...);
};
auto Base = [](auto Self, auto h) {
return 1;
};
overload<decltype(Base), decltype(Recursive)> O(Base, Recursive);
int num_params = O(O, 5, 3, "abc", 3.14, 'a');
Please see attached tests for more examples.
This patch has been reviewed by Doug and Richard. Minor changes (non-functionality affecting) have been made since both of them formally looked at it, but the changes involve removal of supernumerary return type deduction changes (since they are now redundant, with richard having committed a recent patch to address return type deduction for C++11 lambdas using C++14 semantics).
Some implementation notes:
- Add a new Declarator context => LambdaExprParameterContext to
clang::Declarator to allow the use of 'auto' in declaring generic
lambda parameters
- Add various helpers to CXXRecordDecl to facilitate identifying
and querying a closure class
- LambdaScopeInfo (which maintains the current lambda's Sema state)
was augmented to house the current depth of the template being
parsed (id est the Parser calls Sema::RecordParsingTemplateParameterDepth)
so that SemaType.cpp::ConvertDeclSpecToType may use it to immediately
generate a template-parameter-type when 'auto' is parsed in a generic
lambda parameter context. (i.e we do NOT use AutoType deduced to
a template parameter type - Richard seemed ok with this approach).
We encode that this template type was generated from an auto by simply
adding $auto to the name which can be used for better diagnostics if needed.
- SemaLambda.h was added to hold some common lambda utility
functions (this file is likely to grow ...)
- Teach Sema::ActOnStartOfFunctionDef to check whether it
is being called to instantiate a generic lambda's call
operator, and if so, push an appropriately prepared
LambdaScopeInfo object on the stack.
- various tests were added - but much more will be needed.
There is obviously more work to be done, and both Richard (weakly) and Doug (strongly)
have requested that LambdaExpr be removed form the CXXRecordDecl LambdaDefinitionaData
in a future patch which is forthcoming.
A greatful thanks to all reviewers including Eli Friedman, James Dennett,
and especially the two gracious wizards (Richard Smith and Doug Gregor)
who spent hours providing feedback (in person in Chicago and on the mailing lists).
And yet I am certain that I have allowed unidentified bugs to creep in; bugs, that I will do my best to slay, once identified!
Thanks!
llvm-svn: 191453
2013-09-27 03:54:12 +08:00
|
|
|
/*IsDependent*/false);
|
2011-02-20 11:19:35 +08:00
|
|
|
}
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
QualType ASTNodeImporter::VisitInjectedClassNameType(
|
|
|
|
const InjectedClassNameType *T) {
|
|
|
|
CXXRecordDecl *D = cast_or_null<CXXRecordDecl>(Importer.Import(T->getDecl()));
|
|
|
|
if (!D)
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
QualType InjType = Importer.Import(T->getInjectedSpecializationType());
|
|
|
|
if (InjType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
// FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading
|
|
|
|
// See comments in InjectedClassNameType definition for details
|
|
|
|
// return Importer.getToContext().getInjectedClassNameType(D, InjType);
|
|
|
|
enum {
|
|
|
|
TypeAlignmentInBits = 4,
|
|
|
|
TypeAlignment = 1 << TypeAlignmentInBits
|
|
|
|
};
|
|
|
|
|
|
|
|
return QualType(new (Importer.getToContext(), TypeAlignment)
|
|
|
|
InjectedClassNameType(D, InjType), 0);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitRecordType(const RecordType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
RecordDecl *ToDecl
|
|
|
|
= dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl()));
|
|
|
|
if (!ToDecl)
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getTagDeclType(ToDecl);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitEnumType(const EnumType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
EnumDecl *ToDecl
|
|
|
|
= dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl()));
|
|
|
|
if (!ToDecl)
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getTagDeclType(ToDecl);
|
|
|
|
}
|
|
|
|
|
2015-04-03 07:50:08 +08:00
|
|
|
QualType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
|
|
|
|
QualType FromModifiedType = T->getModifiedType();
|
|
|
|
QualType FromEquivalentType = T->getEquivalentType();
|
|
|
|
QualType ToModifiedType;
|
|
|
|
QualType ToEquivalentType;
|
|
|
|
|
|
|
|
if (!FromModifiedType.isNull()) {
|
|
|
|
ToModifiedType = Importer.Import(FromModifiedType);
|
|
|
|
if (ToModifiedType.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
if (!FromEquivalentType.isNull()) {
|
|
|
|
ToEquivalentType = Importer.Import(FromEquivalentType);
|
|
|
|
if (ToEquivalentType.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Importer.getToContext().getAttributedType(T->getAttrKind(),
|
|
|
|
ToModifiedType, ToEquivalentType);
|
|
|
|
}
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
|
|
|
|
QualType ASTNodeImporter::VisitTemplateTypeParmType(
|
|
|
|
const TemplateTypeParmType *T) {
|
|
|
|
TemplateTypeParmDecl *ParmDecl =
|
|
|
|
cast_or_null<TemplateTypeParmDecl>(Importer.Import(T->getDecl()));
|
|
|
|
if (!ParmDecl && T->getDecl())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
return Importer.getToContext().getTemplateTypeParmType(
|
|
|
|
T->getDepth(), T->getIndex(), T->isParameterPack(), ParmDecl);
|
|
|
|
}
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
QualType ASTNodeImporter::VisitTemplateSpecializationType(
|
2011-01-19 14:33:43 +08:00
|
|
|
const TemplateSpecializationType *T) {
|
2010-12-01 09:36:18 +08:00
|
|
|
TemplateName ToTemplate = Importer.Import(T->getTemplateName());
|
|
|
|
if (ToTemplate.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<TemplateArgument, 2> ToTemplateArgs;
|
2010-12-01 09:36:18 +08:00
|
|
|
if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs))
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
QualType ToCanonType;
|
|
|
|
if (!QualType(T, 0).isCanonical()) {
|
|
|
|
QualType FromCanonType
|
|
|
|
= Importer.getFromContext().getCanonicalType(QualType(T, 0));
|
|
|
|
ToCanonType =Importer.Import(FromCanonType);
|
|
|
|
if (ToCanonType.isNull())
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
return Importer.getToContext().getTemplateSpecializationType(ToTemplate,
|
|
|
|
ToTemplateArgs.data(),
|
|
|
|
ToTemplateArgs.size(),
|
|
|
|
ToCanonType);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) {
|
2014-05-12 13:36:57 +08:00
|
|
|
NestedNameSpecifier *ToQualifier = nullptr;
|
2010-05-12 05:36:43 +08:00
|
|
|
// Note: the qualifier in an ElaboratedType is optional.
|
|
|
|
if (T->getQualifier()) {
|
|
|
|
ToQualifier = Importer.Import(T->getQualifier());
|
|
|
|
if (!ToQualifier)
|
|
|
|
return QualType();
|
|
|
|
}
|
2010-02-06 01:54:41 +08:00
|
|
|
|
|
|
|
QualType ToNamedType = Importer.Import(T->getNamedType());
|
|
|
|
if (ToNamedType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
2010-05-12 05:36:43 +08:00
|
|
|
return Importer.getToContext().getElaboratedType(T->getKeyword(),
|
|
|
|
ToQualifier, ToNamedType);
|
2010-02-06 01:54:41 +08:00
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
ObjCInterfaceDecl *Class
|
|
|
|
= dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl()));
|
|
|
|
if (!Class)
|
|
|
|
return QualType();
|
|
|
|
|
2010-05-15 19:32:37 +08:00
|
|
|
return Importer.getToContext().getObjCInterfaceType(Class);
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
|
2010-05-15 19:32:37 +08:00
|
|
|
QualType ToBaseType = Importer.Import(T->getBaseType());
|
|
|
|
if (ToBaseType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
2015-07-07 11:57:35 +08:00
|
|
|
SmallVector<QualType, 4> TypeArgs;
|
Substitute type arguments into uses of Objective-C interface members.
When messaging a method that was defined in an Objective-C class (or
category or extension thereof) that has type parameters, substitute
the type arguments for those type parameters. Similarly, substitute
into property accesses, instance variables, and other references.
This includes general infrastructure for substituting the type
arguments associated with an ObjCObject(Pointer)Type into a type
referenced within a particular context, handling all of the
substitutions required to deal with (e.g.) inheritance involving
parameterized classes. In cases where no type arguments are available
(e.g., because we're messaging via some unspecialized type, id, etc.),
we substitute in the type bounds for the type parameters instead.
Example:
@interface NSSet<T : id<NSCopying>> : NSObject <NSCopying>
- (T)firstObject;
@end
void f(NSSet<NSString *> *stringSet, NSSet *anySet) {
[stringSet firstObject]; // produces NSString*
[anySet firstObject]; // produces id<NSCopying> (the bound)
}
When substituting for the type parameters given an unspecialized
context (i.e., no specific type arguments were given), substituting
the type bounds unconditionally produces type signatures that are too
strong compared to the pre-generics signatures. Instead, use the
following rule:
- In covariant positions, such as method return types, replace type
parameters with “id” or “Class” (the latter only when the type
parameter bound is “Class” or qualified class, e.g,
“Class<NSCopying>”)
- In other positions (e.g., parameter types), replace type
parameters with their type bounds.
- When a specialized Objective-C object or object pointer type
contains a type parameter in its type arguments (e.g.,
NSArray<T>*, but not NSArray<NSString *> *), replace the entire
object/object pointer type with its unspecialized version (e.g.,
NSArray *).
llvm-svn: 241543
2015-07-07 11:57:53 +08:00
|
|
|
for (auto TypeArg : T->getTypeArgsAsWritten()) {
|
2015-07-07 11:57:35 +08:00
|
|
|
QualType ImportedTypeArg = Importer.Import(TypeArg);
|
|
|
|
if (ImportedTypeArg.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
|
|
|
TypeArgs.push_back(ImportedTypeArg);
|
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<ObjCProtocolDecl *, 4> Protocols;
|
2014-03-17 23:55:30 +08:00
|
|
|
for (auto *P : T->quals()) {
|
2010-02-06 01:54:41 +08:00
|
|
|
ObjCProtocolDecl *Protocol
|
2014-03-17 23:55:30 +08:00
|
|
|
= dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P));
|
2010-02-06 01:54:41 +08:00
|
|
|
if (!Protocol)
|
|
|
|
return QualType();
|
|
|
|
Protocols.push_back(Protocol);
|
|
|
|
}
|
|
|
|
|
2015-07-07 11:57:35 +08:00
|
|
|
return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs,
|
2015-07-07 11:58:42 +08:00
|
|
|
Protocols,
|
|
|
|
T->isKindOfTypeAsWritten());
|
2010-02-06 01:54:41 +08:00
|
|
|
}
|
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType
|
|
|
|
ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
|
2010-02-06 01:54:41 +08:00
|
|
|
QualType ToPointeeType = Importer.Import(T->getPointeeType());
|
|
|
|
if (ToPointeeType.isNull())
|
|
|
|
return QualType();
|
|
|
|
|
2010-05-15 19:32:37 +08:00
|
|
|
return Importer.getToContext().getObjCObjectPointerType(ToPointeeType);
|
2010-02-06 01:54:41 +08:00
|
|
|
}
|
|
|
|
|
2010-02-09 05:09:39 +08:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Import Declarations
|
|
|
|
//----------------------------------------------------------------------------
|
2010-02-11 03:54:31 +08:00
|
|
|
bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC,
|
|
|
|
DeclContext *&LexicalDC,
|
|
|
|
DeclarationName &Name,
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *&ToD,
|
2010-02-11 03:54:31 +08:00
|
|
|
SourceLocation &Loc) {
|
2010-02-09 05:09:39 +08:00
|
|
|
// Import the context of this declaration.
|
2010-02-11 03:54:31 +08:00
|
|
|
DC = Importer.ImportContext(D->getDeclContext());
|
2010-02-09 05:09:39 +08:00
|
|
|
if (!DC)
|
2010-02-11 03:54:31 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
LexicalDC = DC;
|
2010-02-10 03:21:46 +08:00
|
|
|
if (D->getDeclContext() != D->getLexicalDeclContext()) {
|
|
|
|
LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
|
|
|
|
if (!LexicalDC)
|
2010-02-11 03:54:31 +08:00
|
|
|
return true;
|
2010-02-10 03:21:46 +08:00
|
|
|
}
|
2010-02-11 03:54:31 +08:00
|
|
|
|
2010-02-09 05:09:39 +08:00
|
|
|
// Import the name of this declaration.
|
2010-02-11 03:54:31 +08:00
|
|
|
Name = Importer.Import(D->getDeclName());
|
2010-02-09 05:09:39 +08:00
|
|
|
if (D->getDeclName() && !Name)
|
2010-02-11 03:54:31 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Import the location of this declaration.
|
|
|
|
Loc = Importer.Import(D->getLocation());
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
|
2010-02-11 03:54:31 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-30 07:31:30 +08:00
|
|
|
void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) {
|
|
|
|
if (!FromD)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ToD) {
|
|
|
|
ToD = Importer.Import(FromD);
|
|
|
|
if (!ToD)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
|
|
|
|
if (RecordDecl *ToRecord = cast_or_null<RecordDecl>(ToD)) {
|
2013-01-12 07:17:47 +08:00
|
|
|
if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) {
|
2011-07-30 07:31:30 +08:00
|
|
|
ImportDefinition(FromRecord, ToRecord);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
|
|
|
|
if (EnumDecl *ToEnum = cast_or_null<EnumDecl>(ToD)) {
|
|
|
|
if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
|
|
|
|
ImportDefinition(FromEnum, ToEnum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-12 06:01:17 +08:00
|
|
|
void
|
|
|
|
ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From,
|
|
|
|
DeclarationNameInfo& To) {
|
|
|
|
// NOTE: To.Name and To.Loc are already imported.
|
|
|
|
// We only have to import To.LocInfo.
|
|
|
|
switch (To.getName().getNameKind()) {
|
|
|
|
case DeclarationName::Identifier:
|
|
|
|
case DeclarationName::ObjCZeroArgSelector:
|
|
|
|
case DeclarationName::ObjCOneArgSelector:
|
|
|
|
case DeclarationName::ObjCMultiArgSelector:
|
|
|
|
case DeclarationName::CXXUsingDirective:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case DeclarationName::CXXOperatorName: {
|
|
|
|
SourceRange Range = From.getCXXOperatorNameRange();
|
|
|
|
To.setCXXOperatorNameRange(Importer.Import(Range));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case DeclarationName::CXXLiteralOperatorName: {
|
|
|
|
SourceLocation Loc = From.getCXXLiteralOperatorNameLoc();
|
|
|
|
To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case DeclarationName::CXXConstructorName:
|
|
|
|
case DeclarationName::CXXDestructorName:
|
|
|
|
case DeclarationName::CXXConversionFunctionName: {
|
|
|
|
TypeSourceInfo *FromTInfo = From.getNamedTypeInfo();
|
|
|
|
To.setNamedTypeInfo(Importer.Import(FromTInfo));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-11-03 04:52:01 +08:00
|
|
|
llvm_unreachable("Unknown name kind.");
|
2010-08-12 06:01:17 +08:00
|
|
|
}
|
|
|
|
|
2012-02-02 05:00:38 +08:00
|
|
|
void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
|
2011-01-18 11:11:38 +08:00
|
|
|
if (Importer.isMinimalImport() && !ForceImport) {
|
2011-07-23 07:46:03 +08:00
|
|
|
Importer.ImportContext(FromDC);
|
2011-01-18 11:11:38 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-08 03:56:05 +08:00
|
|
|
for (auto *From : FromDC->decls())
|
|
|
|
Importer.Import(From);
|
2010-02-22 02:24:45 +08:00
|
|
|
}
|
|
|
|
|
2011-07-30 07:31:30 +08:00
|
|
|
bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To,
|
2012-01-25 02:36:04 +08:00
|
|
|
ImportDefinitionKind Kind) {
|
|
|
|
if (To->getDefinition() || To->isBeingDefined()) {
|
|
|
|
if (Kind == IDK_Everything)
|
|
|
|
ImportDeclContext(From, /*ForceImport=*/true);
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
return false;
|
2012-01-25 02:36:04 +08:00
|
|
|
}
|
2010-12-01 09:36:18 +08:00
|
|
|
|
|
|
|
To->startDefinition();
|
|
|
|
|
|
|
|
// Add base classes.
|
|
|
|
if (CXXRecordDecl *ToCXX = dyn_cast<CXXRecordDecl>(To)) {
|
|
|
|
CXXRecordDecl *FromCXX = cast<CXXRecordDecl>(From);
|
2011-11-04 02:07:07 +08:00
|
|
|
|
|
|
|
struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
|
|
|
|
struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
|
|
|
|
ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor;
|
2012-11-30 13:11:39 +08:00
|
|
|
ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers;
|
2011-11-04 02:07:07 +08:00
|
|
|
ToData.Aggregate = FromData.Aggregate;
|
|
|
|
ToData.PlainOldData = FromData.PlainOldData;
|
|
|
|
ToData.Empty = FromData.Empty;
|
|
|
|
ToData.Polymorphic = FromData.Polymorphic;
|
|
|
|
ToData.Abstract = FromData.Abstract;
|
|
|
|
ToData.IsStandardLayout = FromData.IsStandardLayout;
|
|
|
|
ToData.HasNoNonEmptyBases = FromData.HasNoNonEmptyBases;
|
|
|
|
ToData.HasPrivateFields = FromData.HasPrivateFields;
|
|
|
|
ToData.HasProtectedFields = FromData.HasProtectedFields;
|
|
|
|
ToData.HasPublicFields = FromData.HasPublicFields;
|
|
|
|
ToData.HasMutableFields = FromData.HasMutableFields;
|
2013-12-10 16:25:00 +08:00
|
|
|
ToData.HasVariantMembers = FromData.HasVariantMembers;
|
2012-02-25 15:33:38 +08:00
|
|
|
ToData.HasOnlyCMembers = FromData.HasOnlyCMembers;
|
2012-05-07 09:07:30 +08:00
|
|
|
ToData.HasInClassInitializer = FromData.HasInClassInitializer;
|
2012-12-08 10:01:17 +08:00
|
|
|
ToData.HasUninitializedReferenceMember
|
|
|
|
= FromData.HasUninitializedReferenceMember;
|
2016-02-19 09:52:46 +08:00
|
|
|
ToData.HasUninitializedFields = FromData.HasUninitializedFields;
|
2016-05-13 14:47:56 +08:00
|
|
|
ToData.HasInheritedConstructor = FromData.HasInheritedConstructor;
|
|
|
|
ToData.HasInheritedAssignment = FromData.HasInheritedAssignment;
|
2012-12-08 16:32:28 +08:00
|
|
|
ToData.NeedOverloadResolutionForMoveConstructor
|
|
|
|
= FromData.NeedOverloadResolutionForMoveConstructor;
|
|
|
|
ToData.NeedOverloadResolutionForMoveAssignment
|
|
|
|
= FromData.NeedOverloadResolutionForMoveAssignment;
|
|
|
|
ToData.NeedOverloadResolutionForDestructor
|
|
|
|
= FromData.NeedOverloadResolutionForDestructor;
|
|
|
|
ToData.DefaultedMoveConstructorIsDeleted
|
|
|
|
= FromData.DefaultedMoveConstructorIsDeleted;
|
|
|
|
ToData.DefaultedMoveAssignmentIsDeleted
|
|
|
|
= FromData.DefaultedMoveAssignmentIsDeleted;
|
|
|
|
ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted;
|
2012-11-30 13:11:39 +08:00
|
|
|
ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers;
|
|
|
|
ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor;
|
2011-11-04 02:07:07 +08:00
|
|
|
ToData.HasConstexprNonCopyMoveConstructor
|
|
|
|
= FromData.HasConstexprNonCopyMoveConstructor;
|
2016-02-25 04:58:14 +08:00
|
|
|
ToData.HasDefaultedDefaultConstructor
|
|
|
|
= FromData.HasDefaultedDefaultConstructor;
|
2012-02-25 15:33:38 +08:00
|
|
|
ToData.DefaultedDefaultConstructorIsConstexpr
|
|
|
|
= FromData.DefaultedDefaultConstructorIsConstexpr;
|
|
|
|
ToData.HasConstexprDefaultConstructor
|
|
|
|
= FromData.HasConstexprDefaultConstructor;
|
2011-11-04 02:07:07 +08:00
|
|
|
ToData.HasNonLiteralTypeFieldsOrBases
|
|
|
|
= FromData.HasNonLiteralTypeFieldsOrBases;
|
2012-02-25 15:33:38 +08:00
|
|
|
// ComputedVisibleConversions not imported.
|
2011-11-04 02:07:07 +08:00
|
|
|
ToData.UserProvidedDefaultConstructor
|
|
|
|
= FromData.UserProvidedDefaultConstructor;
|
2012-11-30 13:11:39 +08:00
|
|
|
ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers;
|
2012-11-28 14:23:12 +08:00
|
|
|
ToData.ImplicitCopyConstructorHasConstParam
|
|
|
|
= FromData.ImplicitCopyConstructorHasConstParam;
|
|
|
|
ToData.ImplicitCopyAssignmentHasConstParam
|
|
|
|
= FromData.ImplicitCopyAssignmentHasConstParam;
|
|
|
|
ToData.HasDeclaredCopyConstructorWithConstParam
|
|
|
|
= FromData.HasDeclaredCopyConstructorWithConstParam;
|
|
|
|
ToData.HasDeclaredCopyAssignmentWithConstParam
|
|
|
|
= FromData.HasDeclaredCopyAssignmentWithConstParam;
|
2012-02-25 15:33:38 +08:00
|
|
|
ToData.IsLambda = FromData.IsLambda;
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<CXXBaseSpecifier *, 4> Bases;
|
2014-03-13 23:41:46 +08:00
|
|
|
for (const auto &Base1 : FromCXX->bases()) {
|
|
|
|
QualType T = Importer.Import(Base1.getType());
|
2010-12-01 09:36:18 +08:00
|
|
|
if (T.isNull())
|
2010-12-03 03:33:37 +08:00
|
|
|
return true;
|
2011-01-04 06:36:02 +08:00
|
|
|
|
|
|
|
SourceLocation EllipsisLoc;
|
2014-03-13 23:41:46 +08:00
|
|
|
if (Base1.isPackExpansion())
|
|
|
|
EllipsisLoc = Importer.Import(Base1.getEllipsisLoc());
|
2011-07-30 07:31:30 +08:00
|
|
|
|
|
|
|
// Ensure that we have a definition for the base.
|
2014-03-13 23:41:46 +08:00
|
|
|
ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl());
|
2011-07-30 07:31:30 +08:00
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
Bases.push_back(
|
|
|
|
new (Importer.getToContext())
|
2014-03-13 23:41:46 +08:00
|
|
|
CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()),
|
|
|
|
Base1.isVirtual(),
|
|
|
|
Base1.isBaseOfClass(),
|
|
|
|
Base1.getAccessSpecifierAsWritten(),
|
|
|
|
Importer.Import(Base1.getTypeSourceInfo()),
|
2011-01-04 06:36:02 +08:00
|
|
|
EllipsisLoc));
|
2010-12-01 09:36:18 +08:00
|
|
|
}
|
|
|
|
if (!Bases.empty())
|
2015-12-25 08:36:02 +08:00
|
|
|
ToCXX->setBases(Bases.data(), Bases.size());
|
2010-12-01 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2012-02-02 05:00:38 +08:00
|
|
|
if (shouldForceImportDeclContext(Kind))
|
2012-01-25 02:36:04 +08:00
|
|
|
ImportDeclContext(From, /*ForceImport=*/true);
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
To->completeDefinition();
|
2010-12-03 03:33:37 +08:00
|
|
|
return false;
|
2010-12-01 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
bool ASTNodeImporter::ImportDefinition(VarDecl *From, VarDecl *To,
|
|
|
|
ImportDefinitionKind Kind) {
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (To->getAnyInitializer())
|
2013-08-06 09:03:05 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// FIXME: Can we really import any initializer? Alternatively, we could force
|
|
|
|
// ourselves to import every declaration of a variable and then only use
|
|
|
|
// getInit() here.
|
|
|
|
To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer())));
|
|
|
|
|
|
|
|
// FIXME: Other bits to merge?
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-30 07:31:30 +08:00
|
|
|
bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To,
|
2012-02-02 05:00:38 +08:00
|
|
|
ImportDefinitionKind Kind) {
|
|
|
|
if (To->getDefinition() || To->isBeingDefined()) {
|
|
|
|
if (Kind == IDK_Everything)
|
|
|
|
ImportDeclContext(From, /*ForceImport=*/true);
|
2011-07-30 07:31:30 +08:00
|
|
|
return false;
|
2012-02-02 05:00:38 +08:00
|
|
|
}
|
2011-07-30 07:31:30 +08:00
|
|
|
|
|
|
|
To->startDefinition();
|
|
|
|
|
|
|
|
QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From));
|
|
|
|
if (T.isNull())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
QualType ToPromotionType = Importer.Import(From->getPromotionType());
|
|
|
|
if (ToPromotionType.isNull())
|
|
|
|
return true;
|
2012-02-02 05:00:38 +08:00
|
|
|
|
|
|
|
if (shouldForceImportDeclContext(Kind))
|
|
|
|
ImportDeclContext(From, /*ForceImport=*/true);
|
2011-07-30 07:31:30 +08:00
|
|
|
|
|
|
|
// FIXME: we might need to merge the number of positive or negative bits
|
|
|
|
// if the enumerator lists don't match.
|
|
|
|
To->completeDefinition(T, ToPromotionType,
|
|
|
|
From->getNumPositiveBits(),
|
|
|
|
From->getNumNegativeBits());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList(
|
|
|
|
TemplateParameterList *Params) {
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<NamedDecl *, 4> ToParams;
|
2010-12-01 03:14:50 +08:00
|
|
|
ToParams.reserve(Params->size());
|
|
|
|
for (TemplateParameterList::iterator P = Params->begin(),
|
|
|
|
PEnd = Params->end();
|
|
|
|
P != PEnd; ++P) {
|
|
|
|
Decl *To = Importer.Import(*P);
|
|
|
|
if (!To)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
ToParams.push_back(cast<NamedDecl>(To));
|
|
|
|
}
|
|
|
|
|
|
|
|
return TemplateParameterList::Create(Importer.getToContext(),
|
|
|
|
Importer.Import(Params->getTemplateLoc()),
|
|
|
|
Importer.Import(Params->getLAngleLoc()),
|
2015-12-27 15:16:27 +08:00
|
|
|
ToParams,
|
2010-12-01 03:14:50 +08:00
|
|
|
Importer.Import(Params->getRAngleLoc()));
|
|
|
|
}
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
TemplateArgument
|
|
|
|
ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) {
|
|
|
|
switch (From.getKind()) {
|
|
|
|
case TemplateArgument::Null:
|
|
|
|
return TemplateArgument();
|
|
|
|
|
|
|
|
case TemplateArgument::Type: {
|
|
|
|
QualType ToType = Importer.Import(From.getAsType());
|
|
|
|
if (ToType.isNull())
|
|
|
|
return TemplateArgument();
|
|
|
|
return TemplateArgument(ToType);
|
|
|
|
}
|
|
|
|
|
|
|
|
case TemplateArgument::Integral: {
|
|
|
|
QualType ToType = Importer.Import(From.getIntegralType());
|
|
|
|
if (ToType.isNull())
|
|
|
|
return TemplateArgument();
|
2012-06-07 23:09:51 +08:00
|
|
|
return TemplateArgument(From, ToType);
|
2010-12-01 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2012-09-26 10:36:12 +08:00
|
|
|
case TemplateArgument::Declaration: {
|
2014-10-23 03:54:16 +08:00
|
|
|
ValueDecl *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl()));
|
|
|
|
QualType ToType = Importer.Import(From.getParamTypeForDecl());
|
|
|
|
if (!To || ToType.isNull())
|
|
|
|
return TemplateArgument();
|
|
|
|
return TemplateArgument(To, ToType);
|
2012-09-26 10:36:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case TemplateArgument::NullPtr: {
|
|
|
|
QualType ToType = Importer.Import(From.getNullPtrType());
|
|
|
|
if (ToType.isNull())
|
|
|
|
return TemplateArgument();
|
|
|
|
return TemplateArgument(ToType, /*isNullPtr*/true);
|
|
|
|
}
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
case TemplateArgument::Template: {
|
|
|
|
TemplateName ToTemplate = Importer.Import(From.getAsTemplate());
|
|
|
|
if (ToTemplate.isNull())
|
|
|
|
return TemplateArgument();
|
|
|
|
|
|
|
|
return TemplateArgument(ToTemplate);
|
|
|
|
}
|
2011-01-06 02:58:31 +08:00
|
|
|
|
|
|
|
case TemplateArgument::TemplateExpansion: {
|
|
|
|
TemplateName ToTemplate
|
|
|
|
= Importer.Import(From.getAsTemplateOrTemplatePattern());
|
|
|
|
if (ToTemplate.isNull())
|
|
|
|
return TemplateArgument();
|
|
|
|
|
2011-01-15 07:41:42 +08:00
|
|
|
return TemplateArgument(ToTemplate, From.getNumTemplateExpansions());
|
2011-01-06 02:58:31 +08:00
|
|
|
}
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
case TemplateArgument::Expression:
|
|
|
|
if (Expr *ToExpr = Importer.Import(From.getAsExpr()))
|
|
|
|
return TemplateArgument(ToExpr);
|
|
|
|
return TemplateArgument();
|
|
|
|
|
|
|
|
case TemplateArgument::Pack: {
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<TemplateArgument, 2> ToPack;
|
2010-12-01 09:36:18 +08:00
|
|
|
ToPack.reserve(From.pack_size());
|
|
|
|
if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack))
|
|
|
|
return TemplateArgument();
|
2015-08-05 17:40:22 +08:00
|
|
|
|
|
|
|
return TemplateArgument(
|
|
|
|
llvm::makeArrayRef(ToPack).copy(Importer.getToContext()));
|
2010-12-01 09:36:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Invalid template argument kind");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs,
|
|
|
|
unsigned NumFromArgs,
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVectorImpl<TemplateArgument> &ToArgs) {
|
2010-12-01 09:36:18 +08:00
|
|
|
for (unsigned I = 0; I != NumFromArgs; ++I) {
|
|
|
|
TemplateArgument To = ImportTemplateArgument(FromArgs[I]);
|
|
|
|
if (To.isNull() && !FromArgs[I].isNull())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
ToArgs.push_back(To);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-11 08:48:18 +08:00
|
|
|
bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord,
|
2012-07-18 05:16:27 +08:00
|
|
|
RecordDecl *ToRecord, bool Complain) {
|
This patch addresses a problem encountered by the
ASTImporter when importing the following types:
typedef struct {
} A;
typedef struct {
A a;
} B;
Suppose we have imported B, but we did not at that
time need to complete it. Then later we want to
import A. The struct is anonymous, so the first
thing we want to do is make sure no other anonymous
struct already matches it. So we set up an
StructuralEquivalenceContext and compare B with A.
This happens at ASTImporter.cpp:2179.
Now, in this scenario, B is not complete. So we go
and import its fields, including a, which causes A
to be imported. The ASTImporter doesn’t yet have A
in its list of already-imported things, so we
import A.
After the StructuralEquivalenceContext is finished
determining that A and B are different, the
ASTImporter concludes that A must be imported
because no equivalent exists, so it imports a second
copy of A. Now we have two different structs
representing A. This is really bad news.
The patch allows the StructuralEquivalenceContext to
use the original version of B when making its
comparison, obviating the need for an import and
cutting this loop.
llvm-svn: 192324
2013-10-10 05:45:11 +08:00
|
|
|
// Eliminate a potential failure point where we attempt to re-import
|
|
|
|
// something we're trying to import while completing ToRecord.
|
|
|
|
Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord);
|
|
|
|
if (ToOrigin) {
|
|
|
|
RecordDecl *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin);
|
|
|
|
if (ToOriginRecord)
|
|
|
|
ToRecord = ToOriginRecord;
|
|
|
|
}
|
|
|
|
|
2010-02-18 21:02:13 +08:00
|
|
|
StructuralEquivalenceContext Ctx(Importer.getFromContext(),
|
This patch addresses a problem encountered by the
ASTImporter when importing the following types:
typedef struct {
} A;
typedef struct {
A a;
} B;
Suppose we have imported B, but we did not at that
time need to complete it. Then later we want to
import A. The struct is anonymous, so the first
thing we want to do is make sure no other anonymous
struct already matches it. So we set up an
StructuralEquivalenceContext and compare B with A.
This happens at ASTImporter.cpp:2179.
Now, in this scenario, B is not complete. So we go
and import its fields, including a, which causes A
to be imported. The ASTImporter doesn’t yet have A
in its list of already-imported things, so we
import A.
After the StructuralEquivalenceContext is finished
determining that A and B are different, the
ASTImporter concludes that A must be imported
because no equivalent exists, so it imports a second
copy of A. Now we have two different structs
representing A. This is really bad news.
The patch allows the StructuralEquivalenceContext to
use the original version of B when making its
comparison, obviating the need for an import and
cutting this loop.
llvm-svn: 192324
2013-10-10 05:45:11 +08:00
|
|
|
ToRecord->getASTContext(),
|
2012-07-18 05:16:27 +08:00
|
|
|
Importer.getNonEquivalentDecls(),
|
|
|
|
false, Complain);
|
2010-02-18 21:02:13 +08:00
|
|
|
return Ctx.IsStructurallyEquivalent(FromRecord, ToRecord);
|
2010-02-11 08:48:18 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar,
|
|
|
|
bool Complain) {
|
|
|
|
StructuralEquivalenceContext Ctx(
|
|
|
|
Importer.getFromContext(), Importer.getToContext(),
|
|
|
|
Importer.getNonEquivalentDecls(), false, Complain);
|
|
|
|
return Ctx.IsStructurallyEquivalent(FromVar, ToVar);
|
|
|
|
}
|
|
|
|
|
2010-02-13 06:17:39 +08:00
|
|
|
bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) {
|
2010-02-18 21:02:13 +08:00
|
|
|
StructuralEquivalenceContext Ctx(Importer.getFromContext(),
|
2010-02-16 06:01:00 +08:00
|
|
|
Importer.getToContext(),
|
2010-02-16 07:54:17 +08:00
|
|
|
Importer.getNonEquivalentDecls());
|
2010-02-18 21:02:13 +08:00
|
|
|
return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum);
|
2010-02-13 06:17:39 +08:00
|
|
|
}
|
|
|
|
|
2012-11-15 06:29:20 +08:00
|
|
|
bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC,
|
|
|
|
EnumConstantDecl *ToEC)
|
|
|
|
{
|
|
|
|
const llvm::APSInt &FromVal = FromEC->getInitVal();
|
|
|
|
const llvm::APSInt &ToVal = ToEC->getInitVal();
|
|
|
|
|
|
|
|
return FromVal.isSigned() == ToVal.isSigned() &&
|
|
|
|
FromVal.getBitWidth() == ToVal.getBitWidth() &&
|
|
|
|
FromVal == ToVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From,
|
2010-12-01 03:14:50 +08:00
|
|
|
ClassTemplateDecl *To) {
|
|
|
|
StructuralEquivalenceContext Ctx(Importer.getFromContext(),
|
|
|
|
Importer.getToContext(),
|
|
|
|
Importer.getNonEquivalentDecls());
|
|
|
|
return Ctx.IsStructurallyEquivalent(From, To);
|
|
|
|
}
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From,
|
|
|
|
VarTemplateDecl *To) {
|
|
|
|
StructuralEquivalenceContext Ctx(Importer.getFromContext(),
|
|
|
|
Importer.getToContext(),
|
|
|
|
Importer.getNonEquivalentDecls());
|
|
|
|
return Ctx.IsStructurallyEquivalent(From, To);
|
|
|
|
}
|
|
|
|
|
2010-02-11 03:54:31 +08:00
|
|
|
Decl *ASTNodeImporter::VisitDecl(Decl *D) {
|
|
|
|
Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
|
|
|
|
<< D->getDeclKindName();
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-11 03:54:31 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 07:20:56 +08:00
|
|
|
Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
|
|
|
|
TranslationUnitDecl *ToD =
|
|
|
|
Importer.getToContext().getTranslationUnitDecl();
|
|
|
|
|
|
|
|
Importer.Imported(D, ToD);
|
|
|
|
|
|
|
|
return ToD;
|
|
|
|
}
|
|
|
|
|
2016-02-19 07:08:36 +08:00
|
|
|
Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) {
|
|
|
|
|
|
|
|
SourceLocation Loc = Importer.Import(D->getLocation());
|
|
|
|
SourceLocation ColonLoc = Importer.Import(D->getColonLoc());
|
|
|
|
|
|
|
|
// Import the context of this declaration.
|
|
|
|
DeclContext *DC = Importer.ImportContext(D->getDeclContext());
|
|
|
|
if (!DC)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
AccessSpecDecl *accessSpecDecl
|
|
|
|
= AccessSpecDecl::Create(Importer.getToContext(), D->getAccess(),
|
|
|
|
DC, Loc, ColonLoc);
|
|
|
|
|
|
|
|
if (!accessSpecDecl)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// Lexical DeclContext and Semantic DeclContext
|
|
|
|
// is always the same for the accessSpec.
|
|
|
|
accessSpecDecl->setLexicalDeclContext(DC);
|
|
|
|
DC->addDeclInternal(accessSpecDecl);
|
|
|
|
|
|
|
|
return accessSpecDecl;
|
|
|
|
}
|
|
|
|
|
2010-02-22 02:26:36 +08:00
|
|
|
Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) {
|
|
|
|
// Import the major distinguishing characteristics of this namespace.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2014-05-12 13:36:57 +08:00
|
|
|
|
|
|
|
NamespaceDecl *MergeWithNamespace = nullptr;
|
2010-02-22 02:26:36 +08:00
|
|
|
if (!Name) {
|
|
|
|
// This is an anonymous namespace. Adopt an existing anonymous
|
|
|
|
// namespace if we can.
|
|
|
|
// FIXME: Not testable.
|
|
|
|
if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC))
|
|
|
|
MergeWithNamespace = TU->getAnonymousNamespace();
|
|
|
|
else
|
|
|
|
MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace();
|
|
|
|
} else {
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<NamedDecl *, 4> ConflictingDecls;
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Namespace))
|
2010-02-22 02:26:36 +08:00
|
|
|
continue;
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
if (NamespaceDecl *FoundNS = dyn_cast<NamespaceDecl>(FoundDecls[I])) {
|
2010-02-22 02:26:36 +08:00
|
|
|
MergeWithNamespace = FoundNS;
|
|
|
|
ConflictingDecls.clear();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
ConflictingDecls.push_back(FoundDecls[I]);
|
2010-02-22 02:26:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ConflictingDecls.empty()) {
|
2010-04-24 02:46:30 +08:00
|
|
|
Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace,
|
2010-02-22 02:26:36 +08:00
|
|
|
ConflictingDecls.data(),
|
|
|
|
ConflictingDecls.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the "to" namespace, if needed.
|
|
|
|
NamespaceDecl *ToNamespace = MergeWithNamespace;
|
|
|
|
if (!ToNamespace) {
|
2011-03-08 20:38:20 +08:00
|
|
|
ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC,
|
2012-01-07 17:11:48 +08:00
|
|
|
D->isInline(),
|
2011-03-08 20:38:20 +08:00
|
|
|
Importer.Import(D->getLocStart()),
|
2012-01-07 17:11:48 +08:00
|
|
|
Loc, Name.getAsIdentifierInfo(),
|
2014-05-12 13:36:57 +08:00
|
|
|
/*PrevDecl=*/nullptr);
|
2010-02-22 02:26:36 +08:00
|
|
|
ToNamespace->setLexicalDeclContext(LexicalDC);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(ToNamespace);
|
2010-02-22 02:26:36 +08:00
|
|
|
|
|
|
|
// If this is an anonymous namespace, register it as the anonymous
|
|
|
|
// namespace within its context.
|
|
|
|
if (!Name) {
|
|
|
|
if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(DC))
|
|
|
|
TU->setAnonymousNamespace(ToNamespace);
|
|
|
|
else
|
|
|
|
cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Importer.Imported(D, ToNamespace);
|
|
|
|
|
|
|
|
ImportDeclContext(D);
|
|
|
|
|
|
|
|
return ToNamespace;
|
|
|
|
}
|
|
|
|
|
2011-04-15 22:24:37 +08:00
|
|
|
Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) {
|
2010-02-11 05:10:29 +08:00
|
|
|
// Import the major distinguishing characteristics of this typedef.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2014-05-12 13:36:57 +08:00
|
|
|
|
2010-02-11 05:10:29 +08:00
|
|
|
// If this typedef is not in block scope, determine whether we've
|
|
|
|
// seen a typedef with the same name (that we can merge with) or any
|
|
|
|
// other entity by that name (which name lookup could conflict with).
|
|
|
|
if (!DC->isFunctionOrMethod()) {
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<NamedDecl *, 4> ConflictingDecls;
|
2010-02-11 05:10:29 +08:00
|
|
|
unsigned IDNS = Decl::IDNS_Ordinary;
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
|
2010-02-11 05:10:29 +08:00
|
|
|
continue;
|
2011-04-15 22:24:37 +08:00
|
|
|
if (TypedefNameDecl *FoundTypedef =
|
2011-10-15 08:10:27 +08:00
|
|
|
dyn_cast<TypedefNameDecl>(FoundDecls[I])) {
|
2010-02-16 07:54:17 +08:00
|
|
|
if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(),
|
|
|
|
FoundTypedef->getUnderlyingType()))
|
2010-02-13 07:44:20 +08:00
|
|
|
return Importer.Imported(D, FoundTypedef);
|
2010-02-11 05:10:29 +08:00
|
|
|
}
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
ConflictingDecls.push_back(FoundDecls[I]);
|
2010-02-11 05:10:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ConflictingDecls.empty()) {
|
|
|
|
Name = Importer.HandleNameConflict(Name, DC, IDNS,
|
|
|
|
ConflictingDecls.data(),
|
|
|
|
ConflictingDecls.size());
|
|
|
|
if (!Name)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-11 05:10:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-16 07:54:17 +08:00
|
|
|
// Import the underlying type of this typedef;
|
|
|
|
QualType T = Importer.Import(D->getUnderlyingType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-11 05:10:29 +08:00
|
|
|
// Create the new typedef node.
|
|
|
|
TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
|
2011-03-06 23:48:19 +08:00
|
|
|
SourceLocation StartL = Importer.Import(D->getLocStart());
|
2011-04-15 22:24:37 +08:00
|
|
|
TypedefNameDecl *ToTypedef;
|
|
|
|
if (IsAlias)
|
2011-10-15 05:54:42 +08:00
|
|
|
ToTypedef = TypeAliasDecl::Create(Importer.getToContext(), DC,
|
|
|
|
StartL, Loc,
|
|
|
|
Name.getAsIdentifierInfo(),
|
|
|
|
TInfo);
|
|
|
|
else
|
2011-04-15 22:24:37 +08:00
|
|
|
ToTypedef = TypedefDecl::Create(Importer.getToContext(), DC,
|
|
|
|
StartL, Loc,
|
|
|
|
Name.getAsIdentifierInfo(),
|
|
|
|
TInfo);
|
2011-10-15 05:54:42 +08:00
|
|
|
|
2010-02-23 01:42:47 +08:00
|
|
|
ToTypedef->setAccess(D->getAccess());
|
2010-02-11 05:10:29 +08:00
|
|
|
ToTypedef->setLexicalDeclContext(LexicalDC);
|
2010-02-13 07:44:20 +08:00
|
|
|
Importer.Imported(D, ToTypedef);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(ToTypedef);
|
2010-02-16 07:54:17 +08:00
|
|
|
|
2010-02-11 05:10:29 +08:00
|
|
|
return ToTypedef;
|
|
|
|
}
|
|
|
|
|
2011-04-15 22:24:37 +08:00
|
|
|
Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) {
|
|
|
|
return VisitTypedefNameDecl(D, /*IsAlias=*/false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) {
|
|
|
|
return VisitTypedefNameDecl(D, /*IsAlias=*/true);
|
|
|
|
}
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
Decl *ASTNodeImporter::VisitLabelDecl(LabelDecl *D) {
|
|
|
|
// Import the major distinguishing characteristics of this label.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
|
|
|
return nullptr;
|
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
|
|
|
|
|
|
|
assert(LexicalDC->isFunctionOrMethod());
|
|
|
|
|
|
|
|
LabelDecl *ToLabel = D->isGnuLocal()
|
|
|
|
? LabelDecl::Create(Importer.getToContext(),
|
|
|
|
DC, Importer.Import(D->getLocation()),
|
|
|
|
Name.getAsIdentifierInfo(),
|
|
|
|
Importer.Import(D->getLocStart()))
|
|
|
|
: LabelDecl::Create(Importer.getToContext(),
|
|
|
|
DC, Importer.Import(D->getLocation()),
|
|
|
|
Name.getAsIdentifierInfo());
|
|
|
|
Importer.Imported(D, ToLabel);
|
|
|
|
|
|
|
|
LabelStmt *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt()));
|
|
|
|
if (!Label)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
ToLabel->setStmt(Label);
|
|
|
|
ToLabel->setLexicalDeclContext(LexicalDC);
|
|
|
|
LexicalDC->addDeclInternal(ToLabel);
|
|
|
|
return ToLabel;
|
|
|
|
}
|
|
|
|
|
2010-02-13 06:17:39 +08:00
|
|
|
Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) {
|
|
|
|
// Import the major distinguishing characteristics of this enum.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2014-05-12 13:36:57 +08:00
|
|
|
|
2010-02-13 06:17:39 +08:00
|
|
|
// Figure out what enum name we're looking for.
|
|
|
|
unsigned IDNS = Decl::IDNS_Tag;
|
|
|
|
DeclarationName SearchName = Name;
|
2011-04-15 22:24:37 +08:00
|
|
|
if (!SearchName && D->getTypedefNameForAnonDecl()) {
|
|
|
|
SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName());
|
2010-02-13 06:17:39 +08:00
|
|
|
IDNS = Decl::IDNS_Ordinary;
|
2012-03-11 15:00:24 +08:00
|
|
|
} else if (Importer.getToContext().getLangOpts().CPlusPlus)
|
2010-02-13 06:17:39 +08:00
|
|
|
IDNS |= Decl::IDNS_Ordinary;
|
|
|
|
|
|
|
|
// We may already have an enum of the same name; try to find and match it.
|
|
|
|
if (!DC->isFunctionOrMethod() && SearchName) {
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<NamedDecl *, 4> ConflictingDecls;
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
|
2010-02-13 06:17:39 +08:00
|
|
|
continue;
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
Decl *Found = FoundDecls[I];
|
2011-04-15 22:24:37 +08:00
|
|
|
if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
|
2010-02-13 06:17:39 +08:00
|
|
|
if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
|
|
|
|
Found = Tag->getDecl();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EnumDecl *FoundEnum = dyn_cast<EnumDecl>(Found)) {
|
2010-02-13 07:44:20 +08:00
|
|
|
if (IsStructuralMatch(D, FoundEnum))
|
|
|
|
return Importer.Imported(D, FoundEnum);
|
2010-02-13 06:17:39 +08:00
|
|
|
}
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
ConflictingDecls.push_back(FoundDecls[I]);
|
2010-02-13 06:17:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ConflictingDecls.empty()) {
|
|
|
|
Name = Importer.HandleNameConflict(Name, DC, IDNS,
|
|
|
|
ConflictingDecls.data(),
|
|
|
|
ConflictingDecls.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the enum declaration.
|
2011-03-09 22:09:51 +08:00
|
|
|
EnumDecl *D2 = EnumDecl::Create(Importer.getToContext(), DC,
|
|
|
|
Importer.Import(D->getLocStart()),
|
2014-05-12 13:36:57 +08:00
|
|
|
Loc, Name.getAsIdentifierInfo(), nullptr,
|
2010-12-04 02:54:17 +08:00
|
|
|
D->isScoped(), D->isScopedUsingClassTag(),
|
|
|
|
D->isFixed());
|
2010-03-15 18:12:16 +08:00
|
|
|
// Import the qualifier, if any.
|
2011-02-25 10:25:35 +08:00
|
|
|
D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
|
2010-02-23 01:42:47 +08:00
|
|
|
D2->setAccess(D->getAccess());
|
2010-02-16 06:01:00 +08:00
|
|
|
D2->setLexicalDeclContext(LexicalDC);
|
|
|
|
Importer.Imported(D, D2);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(D2);
|
2010-02-13 06:17:39 +08:00
|
|
|
|
|
|
|
// Import the integer type.
|
|
|
|
QualType ToIntegerType = Importer.Import(D->getIntegerType());
|
|
|
|
if (ToIntegerType.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-16 06:01:00 +08:00
|
|
|
D2->setIntegerType(ToIntegerType);
|
2010-02-13 06:17:39 +08:00
|
|
|
|
|
|
|
// Import the definition
|
2011-10-07 14:10:15 +08:00
|
|
|
if (D->isCompleteDefinition() && ImportDefinition(D, D2))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-13 06:17:39 +08:00
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
return D2;
|
2010-02-13 06:17:39 +08:00
|
|
|
}
|
|
|
|
|
2010-02-11 08:48:18 +08:00
|
|
|
Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
|
|
|
|
// If this record has a definition in the translation unit we're coming from,
|
|
|
|
// but this particular declaration is not that definition, import the
|
|
|
|
// definition and map to that.
|
2010-02-11 09:04:33 +08:00
|
|
|
TagDecl *Definition = D->getDefinition();
|
2010-02-11 08:48:18 +08:00
|
|
|
if (Definition && Definition != D) {
|
|
|
|
Decl *ImportedDef = Importer.Import(Definition);
|
2010-02-13 07:44:20 +08:00
|
|
|
if (!ImportedDef)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-13 07:44:20 +08:00
|
|
|
return Importer.Imported(D, ImportedDef);
|
2010-02-11 08:48:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Import the major distinguishing characteristics of this record.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2014-05-12 13:36:57 +08:00
|
|
|
|
2010-02-11 08:48:18 +08:00
|
|
|
// Figure out what structure name we're looking for.
|
|
|
|
unsigned IDNS = Decl::IDNS_Tag;
|
|
|
|
DeclarationName SearchName = Name;
|
2011-04-15 22:24:37 +08:00
|
|
|
if (!SearchName && D->getTypedefNameForAnonDecl()) {
|
|
|
|
SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName());
|
2010-02-11 08:48:18 +08:00
|
|
|
IDNS = Decl::IDNS_Ordinary;
|
2012-03-11 15:00:24 +08:00
|
|
|
} else if (Importer.getToContext().getLangOpts().CPlusPlus)
|
2010-02-11 08:48:18 +08:00
|
|
|
IDNS |= Decl::IDNS_Ordinary;
|
|
|
|
|
|
|
|
// We may already have a record of the same name; try to find and match it.
|
2014-05-12 13:36:57 +08:00
|
|
|
RecordDecl *AdoptDecl = nullptr;
|
2012-07-18 05:16:27 +08:00
|
|
|
if (!DC->isFunctionOrMethod()) {
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<NamedDecl *, 4> ConflictingDecls;
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
|
2010-02-11 08:48:18 +08:00
|
|
|
continue;
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
Decl *Found = FoundDecls[I];
|
2011-04-15 22:24:37 +08:00
|
|
|
if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
|
2010-02-11 08:48:18 +08:00
|
|
|
if (const TagType *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
|
|
|
|
Found = Tag->getDecl();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RecordDecl *FoundRecord = dyn_cast<RecordDecl>(Found)) {
|
2012-10-27 00:45:11 +08:00
|
|
|
if (D->isAnonymousStructOrUnion() &&
|
|
|
|
FoundRecord->isAnonymousStructOrUnion()) {
|
|
|
|
// If both anonymous structs/unions are in a record context, make sure
|
|
|
|
// they occur in the same location in the context records.
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<unsigned> Index1
|
2012-10-27 00:45:11 +08:00
|
|
|
= findAnonymousStructOrUnionIndex(D)) {
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<unsigned> Index2 =
|
|
|
|
findAnonymousStructOrUnionIndex(FoundRecord)) {
|
2012-10-27 00:45:11 +08:00
|
|
|
if (*Index1 != *Index2)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-12 08:09:27 +08:00
|
|
|
if (RecordDecl *FoundDef = FoundRecord->getDefinition()) {
|
2012-07-18 05:16:27 +08:00
|
|
|
if ((SearchName && !D->isCompleteDefinition())
|
|
|
|
|| (D->isCompleteDefinition() &&
|
|
|
|
D->isAnonymousStructOrUnion()
|
|
|
|
== FoundDef->isAnonymousStructOrUnion() &&
|
|
|
|
IsStructuralMatch(D, FoundDef))) {
|
2010-02-12 08:09:27 +08:00
|
|
|
// The record types structurally match, or the "from" translation
|
|
|
|
// unit only had a forward declaration anyway; call it the same
|
|
|
|
// function.
|
|
|
|
// FIXME: For C++, we should also merge methods here.
|
2010-02-13 07:44:20 +08:00
|
|
|
return Importer.Imported(D, FoundDef);
|
2010-02-12 08:09:27 +08:00
|
|
|
}
|
2012-07-18 05:16:27 +08:00
|
|
|
} else if (!D->isCompleteDefinition()) {
|
2010-02-12 08:09:27 +08:00
|
|
|
// We have a forward declaration of this type, so adopt that forward
|
|
|
|
// declaration rather than building a new one.
|
2014-03-05 02:11:50 +08:00
|
|
|
|
|
|
|
// If one or both can be completed from external storage then try one
|
|
|
|
// last time to complete and compare them before doing this.
|
|
|
|
|
|
|
|
if (FoundRecord->hasExternalLexicalStorage() &&
|
|
|
|
!FoundRecord->isCompleteDefinition())
|
|
|
|
FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord);
|
|
|
|
if (D->hasExternalLexicalStorage())
|
|
|
|
D->getASTContext().getExternalSource()->CompleteType(D);
|
|
|
|
|
|
|
|
if (FoundRecord->isCompleteDefinition() &&
|
|
|
|
D->isCompleteDefinition() &&
|
|
|
|
!IsStructuralMatch(D, FoundRecord))
|
|
|
|
continue;
|
|
|
|
|
2010-02-12 08:09:27 +08:00
|
|
|
AdoptDecl = FoundRecord;
|
|
|
|
continue;
|
2012-07-18 05:16:27 +08:00
|
|
|
} else if (!SearchName) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-02-11 08:48:18 +08:00
|
|
|
}
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
ConflictingDecls.push_back(FoundDecls[I]);
|
2010-02-11 08:48:18 +08:00
|
|
|
}
|
|
|
|
|
2012-07-18 05:16:27 +08:00
|
|
|
if (!ConflictingDecls.empty() && SearchName) {
|
2010-02-11 08:48:18 +08:00
|
|
|
Name = Importer.HandleNameConflict(Name, DC, IDNS,
|
|
|
|
ConflictingDecls.data(),
|
|
|
|
ConflictingDecls.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the record declaration.
|
2010-02-16 06:01:00 +08:00
|
|
|
RecordDecl *D2 = AdoptDecl;
|
2011-03-09 22:09:51 +08:00
|
|
|
SourceLocation StartLoc = Importer.Import(D->getLocStart());
|
2010-02-16 06:01:00 +08:00
|
|
|
if (!D2) {
|
2016-03-29 05:43:01 +08:00
|
|
|
CXXRecordDecl *D2CXX = nullptr;
|
|
|
|
if (CXXRecordDecl *DCXX = llvm::dyn_cast<CXXRecordDecl>(D)) {
|
|
|
|
if (DCXX->isLambda()) {
|
|
|
|
TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo());
|
|
|
|
D2CXX = CXXRecordDecl::CreateLambda(Importer.getToContext(),
|
|
|
|
DC, TInfo, Loc,
|
|
|
|
DCXX->isDependentLambda(),
|
|
|
|
DCXX->isGenericLambda(),
|
|
|
|
DCXX->getLambdaCaptureDefault());
|
|
|
|
Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl());
|
|
|
|
if (DCXX->getLambdaContextDecl() && !CDecl)
|
|
|
|
return nullptr;
|
2016-05-14 13:43:57 +08:00
|
|
|
D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl);
|
|
|
|
} else if (DCXX->isInjectedClassName()) {
|
|
|
|
// We have to be careful to do a similar dance to the one in
|
|
|
|
// Sema::ActOnStartCXXMemberDeclarations
|
|
|
|
CXXRecordDecl *const PrevDecl = nullptr;
|
|
|
|
const bool DelayTypeCreation = true;
|
|
|
|
D2CXX = CXXRecordDecl::Create(
|
|
|
|
Importer.getToContext(), D->getTagKind(), DC, StartLoc, Loc,
|
|
|
|
Name.getAsIdentifierInfo(), PrevDecl, DelayTypeCreation);
|
|
|
|
Importer.getToContext().getTypeDeclType(
|
|
|
|
D2CXX, llvm::dyn_cast<CXXRecordDecl>(DC));
|
2016-03-29 05:43:01 +08:00
|
|
|
} else {
|
|
|
|
D2CXX = CXXRecordDecl::Create(Importer.getToContext(),
|
|
|
|
D->getTagKind(),
|
|
|
|
DC, StartLoc, Loc,
|
|
|
|
Name.getAsIdentifierInfo());
|
|
|
|
}
|
2010-02-16 06:01:00 +08:00
|
|
|
D2 = D2CXX;
|
2010-02-23 01:42:47 +08:00
|
|
|
D2->setAccess(D->getAccess());
|
2010-02-12 08:09:27 +08:00
|
|
|
} else {
|
2010-02-16 06:01:00 +08:00
|
|
|
D2 = RecordDecl::Create(Importer.getToContext(), D->getTagKind(),
|
2011-03-09 22:09:51 +08:00
|
|
|
DC, StartLoc, Loc, Name.getAsIdentifierInfo());
|
2010-02-11 08:48:18 +08:00
|
|
|
}
|
2011-02-25 10:25:35 +08:00
|
|
|
|
|
|
|
D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
|
2010-02-16 06:01:00 +08:00
|
|
|
D2->setLexicalDeclContext(LexicalDC);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(D2);
|
2012-07-18 05:16:27 +08:00
|
|
|
if (D->isAnonymousStructOrUnion())
|
|
|
|
D2->setAnonymousStructOrUnion(true);
|
2010-02-11 08:48:18 +08:00
|
|
|
}
|
2010-02-13 07:44:20 +08:00
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
Importer.Imported(D, D2);
|
2010-02-12 08:09:27 +08:00
|
|
|
|
2012-01-25 02:36:04 +08:00
|
|
|
if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-16 06:01:00 +08:00
|
|
|
return D2;
|
2010-02-11 08:48:18 +08:00
|
|
|
}
|
|
|
|
|
2010-02-13 06:17:39 +08:00
|
|
|
Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) {
|
|
|
|
// Import the major distinguishing characteristics of this enumerator.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2010-02-16 07:54:17 +08:00
|
|
|
|
|
|
|
QualType T = Importer.Import(D->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-16 07:54:17 +08:00
|
|
|
|
2010-02-13 06:17:39 +08:00
|
|
|
// Determine whether there are any other declarations with the same name and
|
|
|
|
// in the same context.
|
|
|
|
if (!LexicalDC->isFunctionOrMethod()) {
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<NamedDecl *, 4> ConflictingDecls;
|
2010-02-13 06:17:39 +08:00
|
|
|
unsigned IDNS = Decl::IDNS_Ordinary;
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
|
2010-02-13 06:17:39 +08:00
|
|
|
continue;
|
2012-11-15 06:29:20 +08:00
|
|
|
|
|
|
|
if (EnumConstantDecl *FoundEnumConstant
|
|
|
|
= dyn_cast<EnumConstantDecl>(FoundDecls[I])) {
|
|
|
|
if (IsStructuralMatch(D, FoundEnumConstant))
|
|
|
|
return Importer.Imported(D, FoundEnumConstant);
|
|
|
|
}
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
ConflictingDecls.push_back(FoundDecls[I]);
|
2010-02-13 06:17:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ConflictingDecls.empty()) {
|
|
|
|
Name = Importer.HandleNameConflict(Name, DC, IDNS,
|
|
|
|
ConflictingDecls.data(),
|
|
|
|
ConflictingDecls.size());
|
|
|
|
if (!Name)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-13 06:17:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *Init = Importer.Import(D->getInitExpr());
|
|
|
|
if (D->getInitExpr() && !Init)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-13 06:17:39 +08:00
|
|
|
EnumConstantDecl *ToEnumerator
|
|
|
|
= EnumConstantDecl::Create(Importer.getToContext(), cast<EnumDecl>(DC), Loc,
|
|
|
|
Name.getAsIdentifierInfo(), T,
|
|
|
|
Init, D->getInitVal());
|
2010-02-23 01:42:47 +08:00
|
|
|
ToEnumerator->setAccess(D->getAccess());
|
2010-02-13 06:17:39 +08:00
|
|
|
ToEnumerator->setLexicalDeclContext(LexicalDC);
|
2010-02-13 07:44:20 +08:00
|
|
|
Importer.Imported(D, ToEnumerator);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(ToEnumerator);
|
2010-02-13 06:17:39 +08:00
|
|
|
return ToEnumerator;
|
|
|
|
}
|
2010-02-11 08:48:18 +08:00
|
|
|
|
2010-02-11 03:54:31 +08:00
|
|
|
Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
|
|
|
|
// Import the major distinguishing characteristics of this function.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2010-08-12 06:01:17 +08:00
|
|
|
|
2010-02-11 03:54:31 +08:00
|
|
|
// Try to find a function in our own ("to") context with the same name, same
|
|
|
|
// type, and in the same context as the function we're importing.
|
|
|
|
if (!LexicalDC->isFunctionOrMethod()) {
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<NamedDecl *, 4> ConflictingDecls;
|
2010-02-11 03:54:31 +08:00
|
|
|
unsigned IDNS = Decl::IDNS_Ordinary;
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
|
2010-02-11 03:54:31 +08:00
|
|
|
continue;
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
if (FunctionDecl *FoundFunction = dyn_cast<FunctionDecl>(FoundDecls[I])) {
|
2013-05-13 08:12:11 +08:00
|
|
|
if (FoundFunction->hasExternalFormalLinkage() &&
|
|
|
|
D->hasExternalFormalLinkage()) {
|
2010-02-16 07:54:17 +08:00
|
|
|
if (Importer.IsStructurallyEquivalent(D->getType(),
|
|
|
|
FoundFunction->getType())) {
|
2010-02-11 03:54:31 +08:00
|
|
|
// FIXME: Actually try to merge the body and other attributes.
|
2010-02-13 07:44:20 +08:00
|
|
|
return Importer.Imported(D, FoundFunction);
|
2010-02-11 03:54:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Check for overloading more carefully, e.g., by boosting
|
|
|
|
// Sema::IsOverload out to the AST library.
|
|
|
|
|
|
|
|
// Function overloading is okay in C++.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (Importer.getToContext().getLangOpts().CPlusPlus)
|
2010-02-11 03:54:31 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Complain about inconsistent function types.
|
|
|
|
Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent)
|
2010-02-16 07:54:17 +08:00
|
|
|
<< Name << D->getType() << FoundFunction->getType();
|
2010-02-11 03:54:31 +08:00
|
|
|
Importer.ToDiag(FoundFunction->getLocation(),
|
|
|
|
diag::note_odr_value_here)
|
|
|
|
<< FoundFunction->getType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
ConflictingDecls.push_back(FoundDecls[I]);
|
2010-02-11 03:54:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ConflictingDecls.empty()) {
|
|
|
|
Name = Importer.HandleNameConflict(Name, DC, IDNS,
|
|
|
|
ConflictingDecls.data(),
|
|
|
|
ConflictingDecls.size());
|
|
|
|
if (!Name)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-11 03:54:31 +08:00
|
|
|
}
|
|
|
|
}
|
2010-02-16 07:54:17 +08:00
|
|
|
|
2010-08-12 06:01:17 +08:00
|
|
|
DeclarationNameInfo NameInfo(Name, Loc);
|
|
|
|
// Import additional name location/type info.
|
|
|
|
ImportDeclarationNameLoc(D->getNameInfo(), NameInfo);
|
|
|
|
|
2012-09-26 03:26:39 +08:00
|
|
|
QualType FromTy = D->getType();
|
|
|
|
bool usedDifferentExceptionSpec = false;
|
|
|
|
|
|
|
|
if (const FunctionProtoType *
|
|
|
|
FromFPT = D->getType()->getAs<FunctionProtoType>()) {
|
|
|
|
FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
|
|
|
|
// FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
|
|
|
|
// FunctionDecl that we are importing the FunctionProtoType for.
|
|
|
|
// To avoid an infinite recursion when importing, create the FunctionDecl
|
|
|
|
// with a simplified function type and update it afterwards.
|
2014-08-01 05:57:55 +08:00
|
|
|
if (FromEPI.ExceptionSpec.SourceDecl ||
|
|
|
|
FromEPI.ExceptionSpec.SourceTemplate ||
|
|
|
|
FromEPI.ExceptionSpec.NoexceptExpr) {
|
2012-09-26 03:26:39 +08:00
|
|
|
FunctionProtoType::ExtProtoInfo DefaultEPI;
|
|
|
|
FromTy = Importer.getFromContext().getFunctionType(
|
2014-01-26 00:55:45 +08:00
|
|
|
FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI);
|
2012-09-26 03:26:39 +08:00
|
|
|
usedDifferentExceptionSpec = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-16 07:54:17 +08:00
|
|
|
// Import the type.
|
2012-09-26 03:26:39 +08:00
|
|
|
QualType T = Importer.Import(FromTy);
|
2010-02-16 07:54:17 +08:00
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-11 03:54:31 +08:00
|
|
|
// Import the function parameters.
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<ParmVarDecl *, 8> Parameters;
|
2016-06-24 12:05:48 +08:00
|
|
|
for (auto P : D->parameters()) {
|
2014-03-07 23:12:56 +08:00
|
|
|
ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P));
|
2010-02-11 03:54:31 +08:00
|
|
|
if (!ToP)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-11 03:54:31 +08:00
|
|
|
Parameters.push_back(ToP);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the imported function.
|
|
|
|
TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
|
2014-05-12 13:36:57 +08:00
|
|
|
FunctionDecl *ToFunction = nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart());
|
2010-02-22 02:29:16 +08:00
|
|
|
if (CXXConstructorDecl *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
|
|
|
|
ToFunction = CXXConstructorDecl::Create(Importer.getToContext(),
|
|
|
|
cast<CXXRecordDecl>(DC),
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
InnerLocStart,
|
2010-08-12 06:01:17 +08:00
|
|
|
NameInfo, T, TInfo,
|
2010-02-22 02:29:16 +08:00
|
|
|
FromConstructor->isExplicit(),
|
|
|
|
D->isInlineSpecified(),
|
2011-08-16 05:04:07 +08:00
|
|
|
D->isImplicit(),
|
|
|
|
D->isConstexpr());
|
2016-05-17 04:48:03 +08:00
|
|
|
if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
|
|
|
|
SmallVector<CXXCtorInitializer *, 4> CtorInitializers;
|
|
|
|
for (CXXCtorInitializer *I : FromConstructor->inits()) {
|
|
|
|
CXXCtorInitializer *ToI =
|
|
|
|
cast_or_null<CXXCtorInitializer>(Importer.Import(I));
|
|
|
|
if (!ToI && I)
|
|
|
|
return nullptr;
|
|
|
|
CtorInitializers.push_back(ToI);
|
|
|
|
}
|
|
|
|
CXXCtorInitializer **Memory =
|
|
|
|
new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
|
|
|
|
std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
|
|
|
|
CXXConstructorDecl *ToCtor = llvm::cast<CXXConstructorDecl>(ToFunction);
|
|
|
|
ToCtor->setCtorInitializers(Memory);
|
|
|
|
ToCtor->setNumCtorInitializers(NumInitializers);
|
|
|
|
}
|
2010-02-22 02:29:16 +08:00
|
|
|
} else if (isa<CXXDestructorDecl>(D)) {
|
|
|
|
ToFunction = CXXDestructorDecl::Create(Importer.getToContext(),
|
|
|
|
cast<CXXRecordDecl>(DC),
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
InnerLocStart,
|
2010-10-21 08:44:50 +08:00
|
|
|
NameInfo, T, TInfo,
|
2010-02-22 02:29:16 +08:00
|
|
|
D->isInlineSpecified(),
|
|
|
|
D->isImplicit());
|
|
|
|
} else if (CXXConversionDecl *FromConversion
|
|
|
|
= dyn_cast<CXXConversionDecl>(D)) {
|
|
|
|
ToFunction = CXXConversionDecl::Create(Importer.getToContext(),
|
|
|
|
cast<CXXRecordDecl>(DC),
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
InnerLocStart,
|
2010-08-12 06:01:17 +08:00
|
|
|
NameInfo, T, TInfo,
|
2010-02-22 02:29:16 +08:00
|
|
|
D->isInlineSpecified(),
|
2011-03-09 01:10:18 +08:00
|
|
|
FromConversion->isExplicit(),
|
2011-08-16 05:04:07 +08:00
|
|
|
D->isConstexpr(),
|
2011-03-09 01:10:18 +08:00
|
|
|
Importer.Import(D->getLocEnd()));
|
2010-11-30 00:04:58 +08:00
|
|
|
} else if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) {
|
|
|
|
ToFunction = CXXMethodDecl::Create(Importer.getToContext(),
|
|
|
|
cast<CXXRecordDecl>(DC),
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
InnerLocStart,
|
2010-11-30 00:04:58 +08:00
|
|
|
NameInfo, T, TInfo,
|
2013-04-04 03:27:57 +08:00
|
|
|
Method->getStorageClass(),
|
2011-03-09 01:10:18 +08:00
|
|
|
Method->isInlineSpecified(),
|
2011-08-16 05:04:07 +08:00
|
|
|
D->isConstexpr(),
|
2011-03-09 01:10:18 +08:00
|
|
|
Importer.Import(D->getLocEnd()));
|
2010-02-22 02:29:16 +08:00
|
|
|
} else {
|
2010-08-12 06:01:17 +08:00
|
|
|
ToFunction = FunctionDecl::Create(Importer.getToContext(), DC,
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
InnerLocStart,
|
2010-08-12 06:01:17 +08:00
|
|
|
NameInfo, T, TInfo, D->getStorageClass(),
|
2010-02-22 02:29:16 +08:00
|
|
|
D->isInlineSpecified(),
|
2011-08-16 05:04:07 +08:00
|
|
|
D->hasWrittenPrototype(),
|
|
|
|
D->isConstexpr());
|
2010-02-22 02:29:16 +08:00
|
|
|
}
|
2010-03-15 18:12:16 +08:00
|
|
|
|
|
|
|
// Import the qualifier, if any.
|
2011-02-25 10:25:35 +08:00
|
|
|
ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
|
2010-02-23 01:42:47 +08:00
|
|
|
ToFunction->setAccess(D->getAccess());
|
2010-02-17 10:12:47 +08:00
|
|
|
ToFunction->setLexicalDeclContext(LexicalDC);
|
2011-01-27 10:37:01 +08:00
|
|
|
ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
|
|
|
|
ToFunction->setTrivial(D->isTrivial());
|
|
|
|
ToFunction->setPure(D->isPure());
|
2010-02-17 10:12:47 +08:00
|
|
|
Importer.Imported(D, ToFunction);
|
2010-02-11 03:54:31 +08:00
|
|
|
|
|
|
|
// Set the parameters.
|
|
|
|
for (unsigned I = 0, N = Parameters.size(); I != N; ++I) {
|
2010-02-17 10:12:47 +08:00
|
|
|
Parameters[I]->setOwningFunction(ToFunction);
|
2011-10-21 10:57:43 +08:00
|
|
|
ToFunction->addDeclInternal(Parameters[I]);
|
2010-02-11 03:54:31 +08:00
|
|
|
}
|
2011-09-22 02:16:56 +08:00
|
|
|
ToFunction->setParams(Parameters);
|
2010-02-11 03:54:31 +08:00
|
|
|
|
2012-09-26 03:26:39 +08:00
|
|
|
if (usedDifferentExceptionSpec) {
|
|
|
|
// Update FunctionProtoType::ExtProtoInfo.
|
|
|
|
QualType T = Importer.Import(D->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2012-09-26 03:26:39 +08:00
|
|
|
ToFunction->setType(T);
|
2012-09-22 09:58:06 +08:00
|
|
|
}
|
|
|
|
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
// Import the body, if any.
|
|
|
|
if (Stmt *FromBody = D->getBody()) {
|
|
|
|
if (Stmt *ToBody = Importer.Import(FromBody)) {
|
|
|
|
ToFunction->setBody(ToBody);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-11 03:54:31 +08:00
|
|
|
// FIXME: Other bits to merge?
|
2010-10-02 07:55:07 +08:00
|
|
|
|
|
|
|
// Add this function to the lexical context.
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(ToFunction);
|
2010-10-02 07:55:07 +08:00
|
|
|
|
2010-02-17 10:12:47 +08:00
|
|
|
return ToFunction;
|
2010-02-11 03:54:31 +08:00
|
|
|
}
|
|
|
|
|
2010-02-22 02:29:16 +08:00
|
|
|
Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) {
|
|
|
|
return VisitFunctionDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
|
|
|
|
return VisitCXXMethodDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
|
|
|
|
return VisitCXXMethodDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) {
|
|
|
|
return VisitCXXMethodDecl(D);
|
|
|
|
}
|
|
|
|
|
2012-10-27 00:45:11 +08:00
|
|
|
static unsigned getFieldIndex(Decl *F) {
|
|
|
|
RecordDecl *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
|
|
|
|
if (!Owner)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
unsigned Index = 1;
|
2014-03-08 03:56:05 +08:00
|
|
|
for (const auto *D : Owner->noload_decls()) {
|
|
|
|
if (D == F)
|
2012-10-27 00:45:11 +08:00
|
|
|
return Index;
|
|
|
|
|
|
|
|
if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D))
|
|
|
|
++Index;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Index;
|
|
|
|
}
|
|
|
|
|
2010-02-11 08:48:18 +08:00
|
|
|
Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {
|
|
|
|
// Import the major distinguishing characteristics of a variable.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2014-05-12 13:36:57 +08:00
|
|
|
|
2011-10-15 05:54:42 +08:00
|
|
|
// Determine whether we've already imported this field.
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecls[I])) {
|
2012-10-27 00:45:11 +08:00
|
|
|
// For anonymous fields, match up by index.
|
|
|
|
if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
|
|
|
|
continue;
|
|
|
|
|
2011-10-15 05:54:42 +08:00
|
|
|
if (Importer.IsStructurallyEquivalent(D->getType(),
|
|
|
|
FoundField->getType())) {
|
|
|
|
Importer.Imported(D, FoundField);
|
|
|
|
return FoundField;
|
|
|
|
}
|
|
|
|
|
|
|
|
Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent)
|
|
|
|
<< Name << D->getType() << FoundField->getType();
|
|
|
|
Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
|
|
|
|
<< FoundField->getType();
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2011-10-15 05:54:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-16 07:54:17 +08:00
|
|
|
// Import the type.
|
|
|
|
QualType T = Importer.Import(D->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-11 08:48:18 +08:00
|
|
|
TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
|
|
|
|
Expr *BitWidth = Importer.Import(D->getBitWidth());
|
|
|
|
if (!BitWidth && D->getBitWidth())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2011-03-08 16:55:46 +08:00
|
|
|
FieldDecl *ToField = FieldDecl::Create(Importer.getToContext(), DC,
|
|
|
|
Importer.Import(D->getInnerLocStart()),
|
2010-02-11 08:48:18 +08:00
|
|
|
Loc, Name.getAsIdentifierInfo(),
|
2011-06-12 01:19:42 +08:00
|
|
|
T, TInfo, BitWidth, D->isMutable(),
|
2012-06-10 11:12:00 +08:00
|
|
|
D->getInClassInitStyle());
|
2010-02-23 01:42:47 +08:00
|
|
|
ToField->setAccess(D->getAccess());
|
2010-02-11 08:48:18 +08:00
|
|
|
ToField->setLexicalDeclContext(LexicalDC);
|
2016-03-03 10:22:05 +08:00
|
|
|
if (Expr *FromInitializer = D->getInClassInitializer()) {
|
2016-03-03 09:21:28 +08:00
|
|
|
Expr *ToInitializer = Importer.Import(FromInitializer);
|
|
|
|
if (ToInitializer)
|
|
|
|
ToField->setInClassInitializer(ToInitializer);
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-10-27 00:45:11 +08:00
|
|
|
ToField->setImplicit(D->isImplicit());
|
2010-02-13 07:44:20 +08:00
|
|
|
Importer.Imported(D, ToField);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(ToField);
|
2010-02-11 08:48:18 +08:00
|
|
|
return ToField;
|
|
|
|
}
|
|
|
|
|
2010-11-21 14:08:52 +08:00
|
|
|
Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
|
|
|
|
// Import the major distinguishing characteristics of a variable.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2010-11-21 14:08:52 +08:00
|
|
|
|
2011-10-15 05:54:42 +08:00
|
|
|
// Determine whether we've already imported this field.
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
2011-10-15 05:54:42 +08:00
|
|
|
if (IndirectFieldDecl *FoundField
|
2011-10-15 08:10:27 +08:00
|
|
|
= dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
|
2012-10-27 00:45:11 +08:00
|
|
|
// For anonymous indirect fields, match up by index.
|
|
|
|
if (!Name && getFieldIndex(D) != getFieldIndex(FoundField))
|
|
|
|
continue;
|
|
|
|
|
2011-10-15 05:54:42 +08:00
|
|
|
if (Importer.IsStructurallyEquivalent(D->getType(),
|
2012-07-18 05:16:27 +08:00
|
|
|
FoundField->getType(),
|
2013-05-15 15:37:26 +08:00
|
|
|
!Name.isEmpty())) {
|
2011-10-15 05:54:42 +08:00
|
|
|
Importer.Imported(D, FoundField);
|
|
|
|
return FoundField;
|
|
|
|
}
|
2012-07-18 05:16:27 +08:00
|
|
|
|
|
|
|
// If there are more anonymous fields to check, continue.
|
|
|
|
if (!Name && I < N-1)
|
|
|
|
continue;
|
|
|
|
|
2011-10-15 05:54:42 +08:00
|
|
|
Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent)
|
|
|
|
<< Name << D->getType() << FoundField->getType();
|
|
|
|
Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
|
|
|
|
<< FoundField->getType();
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2011-10-15 05:54:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-21 14:08:52 +08:00
|
|
|
// Import the type.
|
|
|
|
QualType T = Importer.Import(D->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-11-21 14:08:52 +08:00
|
|
|
|
|
|
|
NamedDecl **NamedChain =
|
|
|
|
new (Importer.getToContext())NamedDecl*[D->getChainingSize()];
|
|
|
|
|
|
|
|
unsigned i = 0;
|
2014-03-08 02:36:15 +08:00
|
|
|
for (auto *PI : D->chain()) {
|
2014-03-08 02:11:58 +08:00
|
|
|
Decl *D = Importer.Import(PI);
|
2010-11-21 14:08:52 +08:00
|
|
|
if (!D)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-11-21 14:08:52 +08:00
|
|
|
NamedChain[i++] = cast<NamedDecl>(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create(
|
2014-10-16 00:58:18 +08:00
|
|
|
Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T,
|
2016-06-24 12:05:48 +08:00
|
|
|
{NamedChain, D->getChainingSize()});
|
2014-10-16 00:58:18 +08:00
|
|
|
|
|
|
|
for (const auto *Attr : D->attrs())
|
|
|
|
ToIndirectField->addAttr(Attr->clone(Importer.getToContext()));
|
|
|
|
|
2010-11-21 14:08:52 +08:00
|
|
|
ToIndirectField->setAccess(D->getAccess());
|
|
|
|
ToIndirectField->setLexicalDeclContext(LexicalDC);
|
|
|
|
Importer.Imported(D, ToIndirectField);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(ToIndirectField);
|
2010-11-21 14:08:52 +08:00
|
|
|
return ToIndirectField;
|
|
|
|
}
|
|
|
|
|
2010-02-17 08:34:30 +08:00
|
|
|
Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
|
|
|
|
// Import the major distinguishing characteristics of an ivar.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2014-05-12 13:36:57 +08:00
|
|
|
|
2010-02-17 08:34:30 +08:00
|
|
|
// Determine whether we've already imported this ivar
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecls[I])) {
|
2010-02-17 08:34:30 +08:00
|
|
|
if (Importer.IsStructurallyEquivalent(D->getType(),
|
|
|
|
FoundIvar->getType())) {
|
|
|
|
Importer.Imported(D, FoundIvar);
|
|
|
|
return FoundIvar;
|
|
|
|
}
|
|
|
|
|
|
|
|
Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent)
|
|
|
|
<< Name << D->getType() << FoundIvar->getType();
|
|
|
|
Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
|
|
|
|
<< FoundIvar->getType();
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-17 08:34:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import the type.
|
|
|
|
QualType T = Importer.Import(D->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-17 08:34:30 +08:00
|
|
|
TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
|
|
|
|
Expr *BitWidth = Importer.Import(D->getBitWidth());
|
|
|
|
if (!BitWidth && D->getBitWidth())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-04-03 04:10:03 +08:00
|
|
|
ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(),
|
|
|
|
cast<ObjCContainerDecl>(DC),
|
2011-03-08 16:55:46 +08:00
|
|
|
Importer.Import(D->getInnerLocStart()),
|
2010-02-17 08:34:30 +08:00
|
|
|
Loc, Name.getAsIdentifierInfo(),
|
|
|
|
T, TInfo, D->getAccessControl(),
|
2014-01-04 02:32:18 +08:00
|
|
|
BitWidth, D->getSynthesize());
|
2010-02-17 08:34:30 +08:00
|
|
|
ToIvar->setLexicalDeclContext(LexicalDC);
|
|
|
|
Importer.Imported(D, ToIvar);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(ToIvar);
|
2010-02-17 08:34:30 +08:00
|
|
|
return ToIvar;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-02-11 03:54:31 +08:00
|
|
|
Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) {
|
|
|
|
// Import the major distinguishing characteristics of a variable.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2014-05-12 13:36:57 +08:00
|
|
|
|
2010-02-09 05:09:39 +08:00
|
|
|
// Try to find a variable in our own ("to") context with the same name and
|
|
|
|
// in the same context as the variable we're importing.
|
2010-02-10 03:21:46 +08:00
|
|
|
if (D->isFileVarDecl()) {
|
2014-05-12 13:36:57 +08:00
|
|
|
VarDecl *MergeWithVar = nullptr;
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<NamedDecl *, 4> ConflictingDecls;
|
2010-02-09 05:09:39 +08:00
|
|
|
unsigned IDNS = Decl::IDNS_Ordinary;
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (!FoundDecls[I]->isInIdentifierNamespace(IDNS))
|
2010-02-09 05:09:39 +08:00
|
|
|
continue;
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
if (VarDecl *FoundVar = dyn_cast<VarDecl>(FoundDecls[I])) {
|
2010-02-09 05:09:39 +08:00
|
|
|
// We have found a variable that we may need to merge with. Check it.
|
2013-05-13 08:12:11 +08:00
|
|
|
if (FoundVar->hasExternalFormalLinkage() &&
|
|
|
|
D->hasExternalFormalLinkage()) {
|
2010-02-16 07:54:17 +08:00
|
|
|
if (Importer.IsStructurallyEquivalent(D->getType(),
|
|
|
|
FoundVar->getType())) {
|
2010-02-09 05:09:39 +08:00
|
|
|
MergeWithVar = FoundVar;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-13 01:23:39 +08:00
|
|
|
const ArrayType *FoundArray
|
|
|
|
= Importer.getToContext().getAsArrayType(FoundVar->getType());
|
|
|
|
const ArrayType *TArray
|
2010-02-16 07:54:17 +08:00
|
|
|
= Importer.getToContext().getAsArrayType(D->getType());
|
2010-02-13 01:23:39 +08:00
|
|
|
if (FoundArray && TArray) {
|
|
|
|
if (isa<IncompleteArrayType>(FoundArray) &&
|
|
|
|
isa<ConstantArrayType>(TArray)) {
|
2010-02-16 07:54:17 +08:00
|
|
|
// Import the type.
|
|
|
|
QualType T = Importer.Import(D->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-13 01:23:39 +08:00
|
|
|
FoundVar->setType(T);
|
|
|
|
MergeWithVar = FoundVar;
|
|
|
|
break;
|
|
|
|
} else if (isa<IncompleteArrayType>(TArray) &&
|
|
|
|
isa<ConstantArrayType>(FoundArray)) {
|
|
|
|
MergeWithVar = FoundVar;
|
|
|
|
break;
|
2010-02-11 01:16:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-09 05:09:39 +08:00
|
|
|
Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent)
|
2010-02-16 07:54:17 +08:00
|
|
|
<< Name << D->getType() << FoundVar->getType();
|
2010-02-09 05:09:39 +08:00
|
|
|
Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
|
|
|
|
<< FoundVar->getType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
ConflictingDecls.push_back(FoundDecls[I]);
|
2010-02-09 05:09:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (MergeWithVar) {
|
|
|
|
// An equivalent variable with external linkage has been found. Link
|
|
|
|
// the two declarations, then merge them.
|
2010-02-13 07:44:20 +08:00
|
|
|
Importer.Imported(D, MergeWithVar);
|
2010-02-09 05:09:39 +08:00
|
|
|
|
|
|
|
if (VarDecl *DDef = D->getDefinition()) {
|
|
|
|
if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) {
|
|
|
|
Importer.ToDiag(ExistingDef->getLocation(),
|
|
|
|
diag::err_odr_variable_multiple_def)
|
|
|
|
<< Name;
|
|
|
|
Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here);
|
|
|
|
} else {
|
|
|
|
Expr *Init = Importer.Import(DDef->getInit());
|
2010-02-11 09:19:42 +08:00
|
|
|
MergeWithVar->setInit(Init);
|
2011-12-19 14:19:21 +08:00
|
|
|
if (DDef->isInitKnownICE()) {
|
|
|
|
EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt();
|
|
|
|
Eval->CheckedICE = true;
|
|
|
|
Eval->IsICE = DDef->isInitICE();
|
|
|
|
}
|
2010-02-09 05:09:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return MergeWithVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ConflictingDecls.empty()) {
|
|
|
|
Name = Importer.HandleNameConflict(Name, DC, IDNS,
|
|
|
|
ConflictingDecls.data(),
|
|
|
|
ConflictingDecls.size());
|
|
|
|
if (!Name)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-09 05:09:39 +08:00
|
|
|
}
|
|
|
|
}
|
2010-02-11 01:47:19 +08:00
|
|
|
|
2010-02-16 07:54:17 +08:00
|
|
|
// Import the type.
|
|
|
|
QualType T = Importer.Import(D->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-09 05:09:39 +08:00
|
|
|
// Create the imported variable.
|
2010-02-11 01:47:19 +08:00
|
|
|
TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
|
2011-03-08 16:55:46 +08:00
|
|
|
VarDecl *ToVar = VarDecl::Create(Importer.getToContext(), DC,
|
|
|
|
Importer.Import(D->getInnerLocStart()),
|
|
|
|
Loc, Name.getAsIdentifierInfo(),
|
|
|
|
T, TInfo,
|
2013-04-04 03:27:57 +08:00
|
|
|
D->getStorageClass());
|
2011-02-25 10:25:35 +08:00
|
|
|
ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
|
2010-02-23 01:42:47 +08:00
|
|
|
ToVar->setAccess(D->getAccess());
|
2010-02-10 03:21:46 +08:00
|
|
|
ToVar->setLexicalDeclContext(LexicalDC);
|
2010-02-13 07:44:20 +08:00
|
|
|
Importer.Imported(D, ToVar);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(ToVar);
|
2010-02-10 03:21:46 +08:00
|
|
|
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (!D->isFileVarDecl() &&
|
|
|
|
D->isUsed())
|
|
|
|
ToVar->setIsUsed();
|
|
|
|
|
2010-02-09 05:09:39 +08:00
|
|
|
// Merge the initializer.
|
2013-08-06 09:03:05 +08:00
|
|
|
if (ImportDefinition(D, ToVar))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-09 05:09:39 +08:00
|
|
|
|
|
|
|
return ToVar;
|
|
|
|
}
|
|
|
|
|
2010-02-18 05:22:52 +08:00
|
|
|
Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
|
|
|
|
// Parameters are created in the translation unit's context, then moved
|
|
|
|
// into the function declaration's context afterward.
|
|
|
|
DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
|
|
|
|
|
|
|
|
// Import the name of this declaration.
|
|
|
|
DeclarationName Name = Importer.Import(D->getDeclName());
|
|
|
|
if (D->getDeclName() && !Name)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-18 05:22:52 +08:00
|
|
|
// Import the location of this declaration.
|
|
|
|
SourceLocation Loc = Importer.Import(D->getLocation());
|
|
|
|
|
|
|
|
// Import the parameter's type.
|
|
|
|
QualType T = Importer.Import(D->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-18 05:22:52 +08:00
|
|
|
// Create the imported parameter.
|
|
|
|
ImplicitParamDecl *ToParm
|
|
|
|
= ImplicitParamDecl::Create(Importer.getToContext(), DC,
|
|
|
|
Loc, Name.getAsIdentifierInfo(),
|
|
|
|
T);
|
|
|
|
return Importer.Imported(D, ToParm);
|
|
|
|
}
|
|
|
|
|
2010-02-11 03:54:31 +08:00
|
|
|
Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) {
|
|
|
|
// Parameters are created in the translation unit's context, then moved
|
|
|
|
// into the function declaration's context afterward.
|
|
|
|
DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
|
|
|
|
|
2010-02-11 01:47:19 +08:00
|
|
|
// Import the name of this declaration.
|
|
|
|
DeclarationName Name = Importer.Import(D->getDeclName());
|
|
|
|
if (D->getDeclName() && !Name)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-11 03:54:31 +08:00
|
|
|
// Import the location of this declaration.
|
|
|
|
SourceLocation Loc = Importer.Import(D->getLocation());
|
|
|
|
|
|
|
|
// Import the parameter's type.
|
|
|
|
QualType T = Importer.Import(D->getType());
|
2010-02-11 01:47:19 +08:00
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-11 03:54:31 +08:00
|
|
|
// Create the imported parameter.
|
|
|
|
TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
|
|
|
|
ParmVarDecl *ToParm = ParmVarDecl::Create(Importer.getToContext(), DC,
|
2011-03-08 16:55:46 +08:00
|
|
|
Importer.Import(D->getInnerLocStart()),
|
2010-02-11 03:54:31 +08:00
|
|
|
Loc, Name.getAsIdentifierInfo(),
|
|
|
|
T, TInfo, D->getStorageClass(),
|
2014-05-12 13:36:57 +08:00
|
|
|
/*FIXME: Default argument*/nullptr);
|
2010-03-13 02:31:32 +08:00
|
|
|
ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg());
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
|
|
|
|
if (D->isUsed())
|
|
|
|
ToParm->setIsUsed();
|
|
|
|
|
2010-02-13 07:44:20 +08:00
|
|
|
return Importer.Imported(D, ToParm);
|
2010-02-11 03:54:31 +08:00
|
|
|
}
|
2010-02-11 01:47:19 +08:00
|
|
|
|
2010-02-17 10:12:47 +08:00
|
|
|
Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
|
|
|
|
// Import the major distinguishing characteristics of a method.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2014-05-12 13:36:57 +08:00
|
|
|
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (ObjCMethodDecl *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecls[I])) {
|
2010-02-17 10:12:47 +08:00
|
|
|
if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Check return types.
|
2014-01-26 00:55:45 +08:00
|
|
|
if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
|
|
|
|
FoundMethod->getReturnType())) {
|
2010-02-17 10:12:47 +08:00
|
|
|
Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent)
|
2014-01-26 00:55:45 +08:00
|
|
|
<< D->isInstanceMethod() << Name << D->getReturnType()
|
|
|
|
<< FoundMethod->getReturnType();
|
2010-02-17 10:12:47 +08:00
|
|
|
Importer.ToDiag(FoundMethod->getLocation(),
|
|
|
|
diag::note_odr_objc_method_here)
|
|
|
|
<< D->isInstanceMethod() << Name;
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-17 10:12:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check the number of parameters.
|
|
|
|
if (D->param_size() != FoundMethod->param_size()) {
|
|
|
|
Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent)
|
|
|
|
<< D->isInstanceMethod() << Name
|
|
|
|
<< D->param_size() << FoundMethod->param_size();
|
|
|
|
Importer.ToDiag(FoundMethod->getLocation(),
|
|
|
|
diag::note_odr_objc_method_here)
|
|
|
|
<< D->isInstanceMethod() << Name;
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-17 10:12:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check parameter types.
|
|
|
|
for (ObjCMethodDecl::param_iterator P = D->param_begin(),
|
|
|
|
PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
|
|
|
|
P != PEnd; ++P, ++FoundP) {
|
|
|
|
if (!Importer.IsStructurallyEquivalent((*P)->getType(),
|
|
|
|
(*FoundP)->getType())) {
|
|
|
|
Importer.FromDiag((*P)->getLocation(),
|
|
|
|
diag::err_odr_objc_method_param_type_inconsistent)
|
|
|
|
<< D->isInstanceMethod() << Name
|
|
|
|
<< (*P)->getType() << (*FoundP)->getType();
|
|
|
|
Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
|
|
|
|
<< (*FoundP)->getType();
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-17 10:12:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check variadic/non-variadic.
|
|
|
|
// Check the number of parameters.
|
|
|
|
if (D->isVariadic() != FoundMethod->isVariadic()) {
|
|
|
|
Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent)
|
|
|
|
<< D->isInstanceMethod() << Name;
|
|
|
|
Importer.ToDiag(FoundMethod->getLocation(),
|
|
|
|
diag::note_odr_objc_method_here)
|
|
|
|
<< D->isInstanceMethod() << Name;
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-17 10:12:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Any other bits we need to merge?
|
|
|
|
return Importer.Imported(D, FoundMethod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import the result type.
|
2014-01-26 00:55:45 +08:00
|
|
|
QualType ResultTy = Importer.Import(D->getReturnType());
|
2010-02-17 10:12:47 +08:00
|
|
|
if (ResultTy.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-17 10:12:47 +08:00
|
|
|
|
2014-01-26 00:55:45 +08:00
|
|
|
TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo());
|
|
|
|
|
|
|
|
ObjCMethodDecl *ToMethod = ObjCMethodDecl::Create(
|
|
|
|
Importer.getToContext(), Loc, Importer.Import(D->getLocEnd()),
|
|
|
|
Name.getObjCSelector(), ResultTy, ReturnTInfo, DC, D->isInstanceMethod(),
|
|
|
|
D->isVariadic(), D->isPropertyAccessor(), D->isImplicit(), D->isDefined(),
|
|
|
|
D->getImplementationControl(), D->hasRelatedResultType());
|
2010-02-17 10:12:47 +08:00
|
|
|
|
|
|
|
// FIXME: When we decide to merge method definitions, we'll need to
|
|
|
|
// deal with implicit parameters.
|
|
|
|
|
|
|
|
// Import the parameters
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<ParmVarDecl *, 5> ToParams;
|
2016-06-24 12:05:48 +08:00
|
|
|
for (auto *FromP : D->parameters()) {
|
2014-03-08 01:50:17 +08:00
|
|
|
ParmVarDecl *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP));
|
2010-02-17 10:12:47 +08:00
|
|
|
if (!ToP)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-17 10:12:47 +08:00
|
|
|
ToParams.push_back(ToP);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the parameters.
|
|
|
|
for (unsigned I = 0, N = ToParams.size(); I != N; ++I) {
|
|
|
|
ToParams[I]->setOwningFunction(ToMethod);
|
2011-10-21 10:57:43 +08:00
|
|
|
ToMethod->addDeclInternal(ToParams[I]);
|
2010-02-17 10:12:47 +08:00
|
|
|
}
|
2011-10-03 14:37:04 +08:00
|
|
|
SmallVector<SourceLocation, 12> SelLocs;
|
|
|
|
D->getSelectorLocs(SelLocs);
|
|
|
|
ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs);
|
2010-02-17 10:12:47 +08:00
|
|
|
|
|
|
|
ToMethod->setLexicalDeclContext(LexicalDC);
|
|
|
|
Importer.Imported(D, ToMethod);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(ToMethod);
|
2010-02-17 10:12:47 +08:00
|
|
|
return ToMethod;
|
|
|
|
}
|
|
|
|
|
Parsing, semantic analysis, and AST for Objective-C type parameters.
Produce type parameter declarations for Objective-C type parameters,
and attach lists of type parameters to Objective-C classes,
categories, forward declarations, and extensions as
appropriate. Perform semantic analysis of type bounds for type
parameters, both in isolation and across classes/categories/extensions
to ensure consistency.
Also handle (de-)serialization of Objective-C type parameter lists,
along with sundry other things one must do to add a new declaration to
Clang.
Note that Objective-C type parameters are typedef name declarations,
like typedefs and C++11 type aliases, in support of type erasure.
Part of rdar://problem/6294649.
llvm-svn: 241541
2015-07-07 11:57:15 +08:00
|
|
|
Decl *ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
|
|
|
|
// Import the major distinguishing characteristics of a category.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
|
|
|
return nullptr;
|
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
|
|
|
|
|
|
|
TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo());
|
|
|
|
if (!BoundInfo)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
ObjCTypeParamDecl *Result = ObjCTypeParamDecl::Create(
|
|
|
|
Importer.getToContext(), DC,
|
2015-07-07 11:58:54 +08:00
|
|
|
D->getVariance(),
|
|
|
|
Importer.Import(D->getVarianceLoc()),
|
Substitute type arguments into uses of Objective-C interface members.
When messaging a method that was defined in an Objective-C class (or
category or extension thereof) that has type parameters, substitute
the type arguments for those type parameters. Similarly, substitute
into property accesses, instance variables, and other references.
This includes general infrastructure for substituting the type
arguments associated with an ObjCObject(Pointer)Type into a type
referenced within a particular context, handling all of the
substitutions required to deal with (e.g.) inheritance involving
parameterized classes. In cases where no type arguments are available
(e.g., because we're messaging via some unspecialized type, id, etc.),
we substitute in the type bounds for the type parameters instead.
Example:
@interface NSSet<T : id<NSCopying>> : NSObject <NSCopying>
- (T)firstObject;
@end
void f(NSSet<NSString *> *stringSet, NSSet *anySet) {
[stringSet firstObject]; // produces NSString*
[anySet firstObject]; // produces id<NSCopying> (the bound)
}
When substituting for the type parameters given an unspecialized
context (i.e., no specific type arguments were given), substituting
the type bounds unconditionally produces type signatures that are too
strong compared to the pre-generics signatures. Instead, use the
following rule:
- In covariant positions, such as method return types, replace type
parameters with “id” or “Class” (the latter only when the type
parameter bound is “Class” or qualified class, e.g,
“Class<NSCopying>”)
- In other positions (e.g., parameter types), replace type
parameters with their type bounds.
- When a specialized Objective-C object or object pointer type
contains a type parameter in its type arguments (e.g.,
NSArray<T>*, but not NSArray<NSString *> *), replace the entire
object/object pointer type with its unspecialized version (e.g.,
NSArray *).
llvm-svn: 241543
2015-07-07 11:57:53 +08:00
|
|
|
D->getIndex(),
|
Parsing, semantic analysis, and AST for Objective-C type parameters.
Produce type parameter declarations for Objective-C type parameters,
and attach lists of type parameters to Objective-C classes,
categories, forward declarations, and extensions as
appropriate. Perform semantic analysis of type bounds for type
parameters, both in isolation and across classes/categories/extensions
to ensure consistency.
Also handle (de-)serialization of Objective-C type parameter lists,
along with sundry other things one must do to add a new declaration to
Clang.
Note that Objective-C type parameters are typedef name declarations,
like typedefs and C++11 type aliases, in support of type erasure.
Part of rdar://problem/6294649.
llvm-svn: 241541
2015-07-07 11:57:15 +08:00
|
|
|
Importer.Import(D->getLocation()),
|
|
|
|
Name.getAsIdentifierInfo(),
|
|
|
|
Importer.Import(D->getColonLoc()),
|
|
|
|
BoundInfo);
|
|
|
|
Importer.Imported(D, Result);
|
|
|
|
Result->setLexicalDeclContext(LexicalDC);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-02-18 09:47:50 +08:00
|
|
|
Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
|
|
|
|
// Import the major distinguishing characteristics of a category.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2014-05-12 13:36:57 +08:00
|
|
|
|
2010-02-18 09:47:50 +08:00
|
|
|
ObjCInterfaceDecl *ToInterface
|
|
|
|
= cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface()));
|
|
|
|
if (!ToInterface)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-18 09:47:50 +08:00
|
|
|
// Determine if we've already encountered this category.
|
|
|
|
ObjCCategoryDecl *MergeWithCategory
|
|
|
|
= ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
|
|
|
|
ObjCCategoryDecl *ToCategory = MergeWithCategory;
|
|
|
|
if (!ToCategory) {
|
|
|
|
ToCategory = ObjCCategoryDecl::Create(Importer.getToContext(), DC,
|
2011-10-04 12:48:02 +08:00
|
|
|
Importer.Import(D->getAtStartLoc()),
|
2010-02-18 09:47:50 +08:00
|
|
|
Loc,
|
|
|
|
Importer.Import(D->getCategoryNameLoc()),
|
2011-08-31 03:43:26 +08:00
|
|
|
Name.getAsIdentifierInfo(),
|
2012-02-21 04:09:20 +08:00
|
|
|
ToInterface,
|
2015-07-07 14:20:12 +08:00
|
|
|
/*TypeParamList=*/nullptr,
|
2012-02-21 04:09:20 +08:00
|
|
|
Importer.Import(D->getIvarLBraceLoc()),
|
|
|
|
Importer.Import(D->getIvarRBraceLoc()));
|
2010-02-18 09:47:50 +08:00
|
|
|
ToCategory->setLexicalDeclContext(LexicalDC);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(ToCategory);
|
2010-02-18 09:47:50 +08:00
|
|
|
Importer.Imported(D, ToCategory);
|
2015-07-07 14:20:12 +08:00
|
|
|
// Import the type parameter list after calling Imported, to avoid
|
|
|
|
// loops when bringing in their DeclContext.
|
|
|
|
ToCategory->setTypeParamList(ImportObjCTypeParamList(
|
|
|
|
D->getTypeParamList()));
|
2010-02-18 09:47:50 +08:00
|
|
|
|
|
|
|
// Import protocols
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<ObjCProtocolDecl *, 4> Protocols;
|
|
|
|
SmallVector<SourceLocation, 4> ProtocolLocs;
|
2010-02-18 09:47:50 +08:00
|
|
|
ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc
|
|
|
|
= D->protocol_loc_begin();
|
|
|
|
for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(),
|
|
|
|
FromProtoEnd = D->protocol_end();
|
|
|
|
FromProto != FromProtoEnd;
|
|
|
|
++FromProto, ++FromProtoLoc) {
|
|
|
|
ObjCProtocolDecl *ToProto
|
|
|
|
= cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto));
|
|
|
|
if (!ToProto)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-18 09:47:50 +08:00
|
|
|
Protocols.push_back(ToProto);
|
|
|
|
ProtocolLocs.push_back(Importer.Import(*FromProtoLoc));
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: If we're merging, make sure that the protocol list is the same.
|
|
|
|
ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
|
|
|
|
ProtocolLocs.data(), Importer.getToContext());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Importer.Imported(D, ToCategory);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import all of the members of this category.
|
2010-02-22 02:24:45 +08:00
|
|
|
ImportDeclContext(D);
|
2010-02-18 09:47:50 +08:00
|
|
|
|
|
|
|
// If we have an implementation, import it as well.
|
|
|
|
if (D->getImplementation()) {
|
|
|
|
ObjCCategoryImplDecl *Impl
|
2010-12-09 00:41:55 +08:00
|
|
|
= cast_or_null<ObjCCategoryImplDecl>(
|
|
|
|
Importer.Import(D->getImplementation()));
|
2010-02-18 09:47:50 +08:00
|
|
|
if (!Impl)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-18 09:47:50 +08:00
|
|
|
ToCategory->setImplementation(Impl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ToCategory;
|
|
|
|
}
|
|
|
|
|
2012-01-25 01:42:07 +08:00
|
|
|
bool ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From,
|
|
|
|
ObjCProtocolDecl *To,
|
2012-02-02 05:00:38 +08:00
|
|
|
ImportDefinitionKind Kind) {
|
2012-01-25 01:42:07 +08:00
|
|
|
if (To->getDefinition()) {
|
2012-02-02 05:00:38 +08:00
|
|
|
if (shouldForceImportDeclContext(Kind))
|
|
|
|
ImportDeclContext(From);
|
2012-01-25 01:42:07 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the protocol definition
|
|
|
|
To->startDefinition();
|
|
|
|
|
|
|
|
// Import protocols
|
|
|
|
SmallVector<ObjCProtocolDecl *, 4> Protocols;
|
|
|
|
SmallVector<SourceLocation, 4> ProtocolLocs;
|
|
|
|
ObjCProtocolDecl::protocol_loc_iterator
|
|
|
|
FromProtoLoc = From->protocol_loc_begin();
|
|
|
|
for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
|
|
|
|
FromProtoEnd = From->protocol_end();
|
|
|
|
FromProto != FromProtoEnd;
|
|
|
|
++FromProto, ++FromProtoLoc) {
|
|
|
|
ObjCProtocolDecl *ToProto
|
|
|
|
= cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto));
|
|
|
|
if (!ToProto)
|
|
|
|
return true;
|
|
|
|
Protocols.push_back(ToProto);
|
|
|
|
ProtocolLocs.push_back(Importer.Import(*FromProtoLoc));
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: If we're merging, make sure that the protocol list is the same.
|
|
|
|
To->setProtocolList(Protocols.data(), Protocols.size(),
|
|
|
|
ProtocolLocs.data(), Importer.getToContext());
|
|
|
|
|
2012-02-02 05:00:38 +08:00
|
|
|
if (shouldForceImportDeclContext(Kind)) {
|
|
|
|
// Import all of the members of this protocol.
|
|
|
|
ImportDeclContext(From, /*ForceImport=*/true);
|
|
|
|
}
|
2012-01-25 01:42:07 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-18 00:12:00 +08:00
|
|
|
Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
|
2012-01-25 01:42:07 +08:00
|
|
|
// If this protocol has a definition in the translation unit we're coming
|
|
|
|
// from, but this particular declaration is not that definition, import the
|
|
|
|
// definition and map to that.
|
|
|
|
ObjCProtocolDecl *Definition = D->getDefinition();
|
|
|
|
if (Definition && Definition != D) {
|
|
|
|
Decl *ImportedDef = Importer.Import(Definition);
|
|
|
|
if (!ImportedDef)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2012-01-25 01:42:07 +08:00
|
|
|
return Importer.Imported(D, ImportedDef);
|
|
|
|
}
|
|
|
|
|
2010-02-18 09:47:50 +08:00
|
|
|
// Import the major distinguishing characteristics of a protocol.
|
2010-02-18 00:12:00 +08:00
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2010-02-18 00:12:00 +08:00
|
|
|
|
2014-05-12 13:36:57 +08:00
|
|
|
ObjCProtocolDecl *MergeWithProtocol = nullptr;
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
|
2010-02-18 00:12:00 +08:00
|
|
|
continue;
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecls[I])))
|
2010-02-18 00:12:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjCProtocolDecl *ToProto = MergeWithProtocol;
|
2012-01-25 01:42:07 +08:00
|
|
|
if (!ToProto) {
|
|
|
|
ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC,
|
|
|
|
Name.getAsIdentifierInfo(), Loc,
|
|
|
|
Importer.Import(D->getAtStartLoc()),
|
2014-05-12 13:36:57 +08:00
|
|
|
/*PrevDecl=*/nullptr);
|
2012-01-25 01:42:07 +08:00
|
|
|
ToProto->setLexicalDeclContext(LexicalDC);
|
|
|
|
LexicalDC->addDeclInternal(ToProto);
|
|
|
|
}
|
2012-01-02 03:29:29 +08:00
|
|
|
|
2012-01-25 01:42:07 +08:00
|
|
|
Importer.Imported(D, ToProto);
|
2010-02-18 00:12:00 +08:00
|
|
|
|
2012-01-25 01:42:07 +08:00
|
|
|
if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2012-01-25 01:42:07 +08:00
|
|
|
return ToProto;
|
|
|
|
}
|
|
|
|
|
2014-12-10 08:00:37 +08:00
|
|
|
Decl *ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
|
|
|
|
DeclContext *DC = Importer.ImportContext(D->getDeclContext());
|
|
|
|
DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
|
|
|
|
|
|
|
|
SourceLocation ExternLoc = Importer.Import(D->getExternLoc());
|
|
|
|
SourceLocation LangLoc = Importer.Import(D->getLocation());
|
|
|
|
|
|
|
|
bool HasBraces = D->hasBraces();
|
|
|
|
|
2014-12-11 05:22:20 +08:00
|
|
|
LinkageSpecDecl *ToLinkageSpec =
|
|
|
|
LinkageSpecDecl::Create(Importer.getToContext(),
|
|
|
|
DC,
|
|
|
|
ExternLoc,
|
|
|
|
LangLoc,
|
|
|
|
D->getLanguage(),
|
|
|
|
HasBraces);
|
2014-12-10 08:00:37 +08:00
|
|
|
|
|
|
|
if (HasBraces) {
|
|
|
|
SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc());
|
|
|
|
ToLinkageSpec->setRBraceLoc(RBraceLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
ToLinkageSpec->setLexicalDeclContext(LexicalDC);
|
|
|
|
LexicalDC->addDeclInternal(ToLinkageSpec);
|
|
|
|
|
|
|
|
Importer.Imported(D, ToLinkageSpec);
|
|
|
|
|
|
|
|
return ToLinkageSpec;
|
|
|
|
}
|
|
|
|
|
2012-01-25 01:42:07 +08:00
|
|
|
bool ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From,
|
|
|
|
ObjCInterfaceDecl *To,
|
2012-02-02 05:00:38 +08:00
|
|
|
ImportDefinitionKind Kind) {
|
2012-01-25 01:42:07 +08:00
|
|
|
if (To->getDefinition()) {
|
|
|
|
// Check consistency of superclass.
|
|
|
|
ObjCInterfaceDecl *FromSuper = From->getSuperClass();
|
|
|
|
if (FromSuper) {
|
|
|
|
FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper));
|
|
|
|
if (!FromSuper)
|
|
|
|
return true;
|
2010-02-18 00:12:00 +08:00
|
|
|
}
|
|
|
|
|
2012-01-25 01:42:07 +08:00
|
|
|
ObjCInterfaceDecl *ToSuper = To->getSuperClass();
|
|
|
|
if ((bool)FromSuper != (bool)ToSuper ||
|
|
|
|
(FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
|
|
|
|
Importer.ToDiag(To->getLocation(),
|
|
|
|
diag::err_odr_objc_superclass_inconsistent)
|
|
|
|
<< To->getDeclName();
|
|
|
|
if (ToSuper)
|
|
|
|
Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
|
|
|
|
<< To->getSuperClass()->getDeclName();
|
|
|
|
else
|
|
|
|
Importer.ToDiag(To->getLocation(),
|
|
|
|
diag::note_odr_objc_missing_superclass);
|
|
|
|
if (From->getSuperClass())
|
|
|
|
Importer.FromDiag(From->getSuperClassLoc(),
|
|
|
|
diag::note_odr_objc_superclass)
|
|
|
|
<< From->getSuperClass()->getDeclName();
|
|
|
|
else
|
|
|
|
Importer.FromDiag(From->getLocation(),
|
|
|
|
diag::note_odr_objc_missing_superclass);
|
|
|
|
}
|
|
|
|
|
2012-02-02 05:00:38 +08:00
|
|
|
if (shouldForceImportDeclContext(Kind))
|
|
|
|
ImportDeclContext(From);
|
2012-01-25 01:42:07 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the definition.
|
|
|
|
To->startDefinition();
|
|
|
|
|
|
|
|
// If this class has a superclass, import it.
|
|
|
|
if (From->getSuperClass()) {
|
2015-07-07 11:57:35 +08:00
|
|
|
TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo());
|
|
|
|
if (!SuperTInfo)
|
2012-01-25 01:42:07 +08:00
|
|
|
return true;
|
2015-07-07 11:57:35 +08:00
|
|
|
|
|
|
|
To->setSuperClass(SuperTInfo);
|
2012-01-25 01:42:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Import protocols
|
|
|
|
SmallVector<ObjCProtocolDecl *, 4> Protocols;
|
|
|
|
SmallVector<SourceLocation, 4> ProtocolLocs;
|
|
|
|
ObjCInterfaceDecl::protocol_loc_iterator
|
|
|
|
FromProtoLoc = From->protocol_loc_begin();
|
|
|
|
|
|
|
|
for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(),
|
|
|
|
FromProtoEnd = From->protocol_end();
|
|
|
|
FromProto != FromProtoEnd;
|
|
|
|
++FromProto, ++FromProtoLoc) {
|
|
|
|
ObjCProtocolDecl *ToProto
|
|
|
|
= cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto));
|
|
|
|
if (!ToProto)
|
|
|
|
return true;
|
|
|
|
Protocols.push_back(ToProto);
|
|
|
|
ProtocolLocs.push_back(Importer.Import(*FromProtoLoc));
|
2010-02-18 00:12:00 +08:00
|
|
|
}
|
2012-01-25 01:42:07 +08:00
|
|
|
|
|
|
|
// FIXME: If we're merging, make sure that the protocol list is the same.
|
|
|
|
To->setProtocolList(Protocols.data(), Protocols.size(),
|
|
|
|
ProtocolLocs.data(), Importer.getToContext());
|
|
|
|
|
|
|
|
// Import categories. When the categories themselves are imported, they'll
|
|
|
|
// hook themselves into this interface.
|
2014-03-14 05:35:02 +08:00
|
|
|
for (auto *Cat : From->known_categories())
|
|
|
|
Importer.Import(Cat);
|
2013-01-17 07:00:23 +08:00
|
|
|
|
2012-01-25 01:42:07 +08:00
|
|
|
// If we have an @implementation, import it as well.
|
|
|
|
if (From->getImplementation()) {
|
|
|
|
ObjCImplementationDecl *Impl = cast_or_null<ObjCImplementationDecl>(
|
|
|
|
Importer.Import(From->getImplementation()));
|
|
|
|
if (!Impl)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
To->setImplementation(Impl);
|
|
|
|
}
|
2010-02-18 00:12:00 +08:00
|
|
|
|
2012-02-02 05:00:38 +08:00
|
|
|
if (shouldForceImportDeclContext(Kind)) {
|
|
|
|
// Import all of the members of this class.
|
|
|
|
ImportDeclContext(From, /*ForceImport=*/true);
|
|
|
|
}
|
2012-01-25 01:42:07 +08:00
|
|
|
return false;
|
2010-02-18 00:12:00 +08:00
|
|
|
}
|
|
|
|
|
Parsing, semantic analysis, and AST for Objective-C type parameters.
Produce type parameter declarations for Objective-C type parameters,
and attach lists of type parameters to Objective-C classes,
categories, forward declarations, and extensions as
appropriate. Perform semantic analysis of type bounds for type
parameters, both in isolation and across classes/categories/extensions
to ensure consistency.
Also handle (de-)serialization of Objective-C type parameter lists,
along with sundry other things one must do to add a new declaration to
Clang.
Note that Objective-C type parameters are typedef name declarations,
like typedefs and C++11 type aliases, in support of type erasure.
Part of rdar://problem/6294649.
llvm-svn: 241541
2015-07-07 11:57:15 +08:00
|
|
|
ObjCTypeParamList *
|
|
|
|
ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) {
|
|
|
|
if (!list)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
SmallVector<ObjCTypeParamDecl *, 4> toTypeParams;
|
|
|
|
for (auto fromTypeParam : *list) {
|
|
|
|
auto toTypeParam = cast_or_null<ObjCTypeParamDecl>(
|
|
|
|
Importer.Import(fromTypeParam));
|
|
|
|
if (!toTypeParam)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
toTypeParams.push_back(toTypeParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ObjCTypeParamList::create(Importer.getToContext(),
|
|
|
|
Importer.Import(list->getLAngleLoc()),
|
|
|
|
toTypeParams,
|
|
|
|
Importer.Import(list->getRAngleLoc()));
|
|
|
|
}
|
|
|
|
|
2010-02-16 09:20:57 +08:00
|
|
|
Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
|
2012-01-25 01:42:07 +08:00
|
|
|
// If this class has a definition in the translation unit we're coming from,
|
|
|
|
// but this particular declaration is not that definition, import the
|
|
|
|
// definition and map to that.
|
|
|
|
ObjCInterfaceDecl *Definition = D->getDefinition();
|
|
|
|
if (Definition && Definition != D) {
|
|
|
|
Decl *ImportedDef = Importer.Import(Definition);
|
|
|
|
if (!ImportedDef)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2012-01-25 01:42:07 +08:00
|
|
|
return Importer.Imported(D, ImportedDef);
|
|
|
|
}
|
|
|
|
|
2010-02-16 09:20:57 +08:00
|
|
|
// Import the major distinguishing characteristics of an @interface.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2010-02-16 09:20:57 +08:00
|
|
|
|
2012-01-25 01:42:07 +08:00
|
|
|
// Look for an existing interface with the same name.
|
2014-05-12 13:36:57 +08:00
|
|
|
ObjCInterfaceDecl *MergeWithIface = nullptr;
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary))
|
2010-02-16 09:20:57 +08:00
|
|
|
continue;
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecls[I])))
|
2010-02-16 09:20:57 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-25 01:42:07 +08:00
|
|
|
// Create an interface declaration, if one does not already exist.
|
2010-02-16 09:20:57 +08:00
|
|
|
ObjCInterfaceDecl *ToIface = MergeWithIface;
|
2012-01-25 01:42:07 +08:00
|
|
|
if (!ToIface) {
|
|
|
|
ToIface = ObjCInterfaceDecl::Create(Importer.getToContext(), DC,
|
|
|
|
Importer.Import(D->getAtStartLoc()),
|
Parsing, semantic analysis, and AST for Objective-C type parameters.
Produce type parameter declarations for Objective-C type parameters,
and attach lists of type parameters to Objective-C classes,
categories, forward declarations, and extensions as
appropriate. Perform semantic analysis of type bounds for type
parameters, both in isolation and across classes/categories/extensions
to ensure consistency.
Also handle (de-)serialization of Objective-C type parameter lists,
along with sundry other things one must do to add a new declaration to
Clang.
Note that Objective-C type parameters are typedef name declarations,
like typedefs and C++11 type aliases, in support of type erasure.
Part of rdar://problem/6294649.
llvm-svn: 241541
2015-07-07 11:57:15 +08:00
|
|
|
Name.getAsIdentifierInfo(),
|
2015-07-07 14:20:12 +08:00
|
|
|
/*TypeParamList=*/nullptr,
|
2014-05-12 13:36:57 +08:00
|
|
|
/*PrevDecl=*/nullptr, Loc,
|
2012-01-25 01:42:07 +08:00
|
|
|
D->isImplicitInterfaceDecl());
|
|
|
|
ToIface->setLexicalDeclContext(LexicalDC);
|
|
|
|
LexicalDC->addDeclInternal(ToIface);
|
2010-02-16 09:20:57 +08:00
|
|
|
}
|
2012-01-25 01:42:07 +08:00
|
|
|
Importer.Imported(D, ToIface);
|
2015-07-07 14:20:12 +08:00
|
|
|
// Import the type parameter list after calling Imported, to avoid
|
|
|
|
// loops when bringing in their DeclContext.
|
|
|
|
ToIface->setTypeParamList(ImportObjCTypeParamList(
|
|
|
|
D->getTypeParamListAsWritten()));
|
2010-02-16 09:20:57 +08:00
|
|
|
|
2012-01-25 01:42:07 +08:00
|
|
|
if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-18 00:12:00 +08:00
|
|
|
return ToIface;
|
2010-02-16 09:20:57 +08:00
|
|
|
}
|
|
|
|
|
2010-12-07 23:32:12 +08:00
|
|
|
Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
|
|
|
|
ObjCCategoryDecl *Category = cast_or_null<ObjCCategoryDecl>(
|
|
|
|
Importer.Import(D->getCategoryDecl()));
|
|
|
|
if (!Category)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-07 23:32:12 +08:00
|
|
|
ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
|
|
|
|
if (!ToImpl) {
|
|
|
|
DeclContext *DC = Importer.ImportContext(D->getDeclContext());
|
|
|
|
if (!DC)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2011-12-09 08:31:40 +08:00
|
|
|
SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc());
|
2010-12-07 23:32:12 +08:00
|
|
|
ToImpl = ObjCCategoryImplDecl::Create(Importer.getToContext(), DC,
|
|
|
|
Importer.Import(D->getIdentifier()),
|
2011-10-04 12:48:02 +08:00
|
|
|
Category->getClassInterface(),
|
|
|
|
Importer.Import(D->getLocation()),
|
2011-12-09 08:31:40 +08:00
|
|
|
Importer.Import(D->getAtStartLoc()),
|
|
|
|
CategoryNameLoc);
|
2010-12-07 23:32:12 +08:00
|
|
|
|
|
|
|
DeclContext *LexicalDC = DC;
|
|
|
|
if (D->getDeclContext() != D->getLexicalDeclContext()) {
|
|
|
|
LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
|
|
|
|
if (!LexicalDC)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-07 23:32:12 +08:00
|
|
|
ToImpl->setLexicalDeclContext(LexicalDC);
|
|
|
|
}
|
|
|
|
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(ToImpl);
|
2010-12-07 23:32:12 +08:00
|
|
|
Category->setImplementation(ToImpl);
|
|
|
|
}
|
|
|
|
|
|
|
|
Importer.Imported(D, ToImpl);
|
2010-12-09 00:41:55 +08:00
|
|
|
ImportDeclContext(D);
|
2010-12-07 23:32:12 +08:00
|
|
|
return ToImpl;
|
|
|
|
}
|
|
|
|
|
2010-12-07 09:26:03 +08:00
|
|
|
Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
|
|
|
|
// Find the corresponding interface.
|
|
|
|
ObjCInterfaceDecl *Iface = cast_or_null<ObjCInterfaceDecl>(
|
|
|
|
Importer.Import(D->getClassInterface()));
|
|
|
|
if (!Iface)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-12-07 09:26:03 +08:00
|
|
|
|
|
|
|
// Import the superclass, if any.
|
2014-05-12 13:36:57 +08:00
|
|
|
ObjCInterfaceDecl *Super = nullptr;
|
2010-12-07 09:26:03 +08:00
|
|
|
if (D->getSuperClass()) {
|
|
|
|
Super = cast_or_null<ObjCInterfaceDecl>(
|
|
|
|
Importer.Import(D->getSuperClass()));
|
|
|
|
if (!Super)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-12-07 09:26:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjCImplementationDecl *Impl = Iface->getImplementation();
|
|
|
|
if (!Impl) {
|
|
|
|
// We haven't imported an implementation yet. Create a new @implementation
|
|
|
|
// now.
|
|
|
|
Impl = ObjCImplementationDecl::Create(Importer.getToContext(),
|
|
|
|
Importer.ImportContext(D->getDeclContext()),
|
2011-10-04 12:48:02 +08:00
|
|
|
Iface, Super,
|
2010-12-07 09:26:03 +08:00
|
|
|
Importer.Import(D->getLocation()),
|
2012-02-21 04:09:20 +08:00
|
|
|
Importer.Import(D->getAtStartLoc()),
|
2013-05-04 06:31:26 +08:00
|
|
|
Importer.Import(D->getSuperClassLoc()),
|
2012-02-21 04:09:20 +08:00
|
|
|
Importer.Import(D->getIvarLBraceLoc()),
|
|
|
|
Importer.Import(D->getIvarRBraceLoc()));
|
2010-12-07 09:26:03 +08:00
|
|
|
|
|
|
|
if (D->getDeclContext() != D->getLexicalDeclContext()) {
|
|
|
|
DeclContext *LexicalDC
|
|
|
|
= Importer.ImportContext(D->getLexicalDeclContext());
|
|
|
|
if (!LexicalDC)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-12-07 09:26:03 +08:00
|
|
|
Impl->setLexicalDeclContext(LexicalDC);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Associate the implementation with the class it implements.
|
|
|
|
Iface->setImplementation(Impl);
|
|
|
|
Importer.Imported(D, Iface->getImplementation());
|
|
|
|
} else {
|
|
|
|
Importer.Imported(D, Iface->getImplementation());
|
|
|
|
|
|
|
|
// Verify that the existing @implementation has the same superclass.
|
|
|
|
if ((Super && !Impl->getSuperClass()) ||
|
|
|
|
(!Super && Impl->getSuperClass()) ||
|
2014-05-07 14:57:44 +08:00
|
|
|
(Super && Impl->getSuperClass() &&
|
|
|
|
!declaresSameEntity(Super->getCanonicalDecl(),
|
|
|
|
Impl->getSuperClass()))) {
|
|
|
|
Importer.ToDiag(Impl->getLocation(),
|
|
|
|
diag::err_odr_objc_superclass_inconsistent)
|
|
|
|
<< Iface->getDeclName();
|
|
|
|
// FIXME: It would be nice to have the location of the superclass
|
|
|
|
// below.
|
|
|
|
if (Impl->getSuperClass())
|
|
|
|
Importer.ToDiag(Impl->getLocation(),
|
|
|
|
diag::note_odr_objc_superclass)
|
|
|
|
<< Impl->getSuperClass()->getDeclName();
|
|
|
|
else
|
|
|
|
Importer.ToDiag(Impl->getLocation(),
|
|
|
|
diag::note_odr_objc_missing_superclass);
|
|
|
|
if (D->getSuperClass())
|
|
|
|
Importer.FromDiag(D->getLocation(),
|
2010-12-07 09:26:03 +08:00
|
|
|
diag::note_odr_objc_superclass)
|
2014-05-07 14:57:44 +08:00
|
|
|
<< D->getSuperClass()->getDeclName();
|
|
|
|
else
|
|
|
|
Importer.FromDiag(D->getLocation(),
|
2010-12-07 09:26:03 +08:00
|
|
|
diag::note_odr_objc_missing_superclass);
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-12-07 09:26:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import all of the members of this @implementation.
|
|
|
|
ImportDeclContext(D);
|
|
|
|
|
|
|
|
return Impl;
|
|
|
|
}
|
|
|
|
|
2010-02-18 02:02:10 +08:00
|
|
|
Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
|
|
|
|
// Import the major distinguishing characteristics of an @property.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2010-02-18 02:02:10 +08:00
|
|
|
|
|
|
|
// Check whether we have already imported this property.
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
2010-02-18 02:02:10 +08:00
|
|
|
if (ObjCPropertyDecl *FoundProp
|
2011-10-15 08:10:27 +08:00
|
|
|
= dyn_cast<ObjCPropertyDecl>(FoundDecls[I])) {
|
2010-02-18 02:02:10 +08:00
|
|
|
// Check property types.
|
|
|
|
if (!Importer.IsStructurallyEquivalent(D->getType(),
|
|
|
|
FoundProp->getType())) {
|
|
|
|
Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent)
|
|
|
|
<< Name << D->getType() << FoundProp->getType();
|
|
|
|
Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
|
|
|
|
<< FoundProp->getType();
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-18 02:02:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Check property attributes, getters, setters, etc.?
|
|
|
|
|
|
|
|
// Consider these properties to be equivalent.
|
|
|
|
Importer.Imported(D, FoundProp);
|
|
|
|
return FoundProp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import the type.
|
2015-06-20 02:14:38 +08:00
|
|
|
TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo());
|
|
|
|
if (!TSI)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-18 02:02:10 +08:00
|
|
|
|
|
|
|
// Create the new property.
|
|
|
|
ObjCPropertyDecl *ToProperty
|
|
|
|
= ObjCPropertyDecl::Create(Importer.getToContext(), DC, Loc,
|
|
|
|
Name.getAsIdentifierInfo(),
|
|
|
|
Importer.Import(D->getAtLoc()),
|
2012-03-01 06:18:55 +08:00
|
|
|
Importer.Import(D->getLParenLoc()),
|
2015-06-20 02:14:38 +08:00
|
|
|
Importer.Import(D->getType()),
|
|
|
|
TSI,
|
2010-02-18 02:02:10 +08:00
|
|
|
D->getPropertyImplementation());
|
|
|
|
Importer.Imported(D, ToProperty);
|
|
|
|
ToProperty->setLexicalDeclContext(LexicalDC);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(ToProperty);
|
2010-02-18 02:02:10 +08:00
|
|
|
|
|
|
|
ToProperty->setPropertyAttributes(D->getPropertyAttributes());
|
2010-06-23 07:20:40 +08:00
|
|
|
ToProperty->setPropertyAttributesAsWritten(
|
|
|
|
D->getPropertyAttributesAsWritten());
|
2010-02-18 02:02:10 +08:00
|
|
|
ToProperty->setGetterName(Importer.Import(D->getGetterName()));
|
|
|
|
ToProperty->setSetterName(Importer.Import(D->getSetterName()));
|
|
|
|
ToProperty->setGetterMethodDecl(
|
|
|
|
cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl())));
|
|
|
|
ToProperty->setSetterMethodDecl(
|
|
|
|
cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl())));
|
|
|
|
ToProperty->setPropertyIvarDecl(
|
|
|
|
cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl())));
|
|
|
|
return ToProperty;
|
|
|
|
}
|
|
|
|
|
2010-12-08 02:32:03 +08:00
|
|
|
Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
|
|
|
|
ObjCPropertyDecl *Property = cast_or_null<ObjCPropertyDecl>(
|
|
|
|
Importer.Import(D->getPropertyDecl()));
|
|
|
|
if (!Property)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-12-08 02:32:03 +08:00
|
|
|
|
|
|
|
DeclContext *DC = Importer.ImportContext(D->getDeclContext());
|
|
|
|
if (!DC)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-08 02:32:03 +08:00
|
|
|
// Import the lexical declaration context.
|
|
|
|
DeclContext *LexicalDC = DC;
|
|
|
|
if (D->getDeclContext() != D->getLexicalDeclContext()) {
|
|
|
|
LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
|
|
|
|
if (!LexicalDC)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-12-08 02:32:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjCImplDecl *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC);
|
|
|
|
if (!InImpl)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-12-08 02:32:03 +08:00
|
|
|
|
|
|
|
// Import the ivar (for an @synthesize).
|
2014-05-12 13:36:57 +08:00
|
|
|
ObjCIvarDecl *Ivar = nullptr;
|
2010-12-08 02:32:03 +08:00
|
|
|
if (D->getPropertyIvarDecl()) {
|
|
|
|
Ivar = cast_or_null<ObjCIvarDecl>(
|
|
|
|
Importer.Import(D->getPropertyIvarDecl()));
|
|
|
|
if (!Ivar)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-12-08 02:32:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjCPropertyImplDecl *ToImpl
|
2016-01-29 02:49:28 +08:00
|
|
|
= InImpl->FindPropertyImplDecl(Property->getIdentifier(),
|
|
|
|
Property->getQueryKind());
|
2010-12-08 02:32:03 +08:00
|
|
|
if (!ToImpl) {
|
|
|
|
ToImpl = ObjCPropertyImplDecl::Create(Importer.getToContext(), DC,
|
|
|
|
Importer.Import(D->getLocStart()),
|
|
|
|
Importer.Import(D->getLocation()),
|
|
|
|
Property,
|
|
|
|
D->getPropertyImplementation(),
|
|
|
|
Ivar,
|
|
|
|
Importer.Import(D->getPropertyIvarDeclLoc()));
|
|
|
|
ToImpl->setLexicalDeclContext(LexicalDC);
|
|
|
|
Importer.Imported(D, ToImpl);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(ToImpl);
|
2010-12-08 02:32:03 +08:00
|
|
|
} else {
|
|
|
|
// Check that we have the same kind of property implementation (@synthesize
|
|
|
|
// vs. @dynamic).
|
|
|
|
if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) {
|
|
|
|
Importer.ToDiag(ToImpl->getLocation(),
|
|
|
|
diag::err_odr_objc_property_impl_kind_inconsistent)
|
|
|
|
<< Property->getDeclName()
|
|
|
|
<< (ToImpl->getPropertyImplementation()
|
|
|
|
== ObjCPropertyImplDecl::Dynamic);
|
|
|
|
Importer.FromDiag(D->getLocation(),
|
|
|
|
diag::note_odr_objc_property_impl_kind)
|
|
|
|
<< D->getPropertyDecl()->getDeclName()
|
|
|
|
<< (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic);
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-12-08 02:32:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// For @synthesize, check that we have the same
|
|
|
|
if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize &&
|
|
|
|
Ivar != ToImpl->getPropertyIvarDecl()) {
|
|
|
|
Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
|
|
|
|
diag::err_odr_objc_synthesize_ivar_inconsistent)
|
|
|
|
<< Property->getDeclName()
|
|
|
|
<< ToImpl->getPropertyIvarDecl()->getDeclName()
|
|
|
|
<< Ivar->getDeclName();
|
|
|
|
Importer.FromDiag(D->getPropertyIvarDeclLoc(),
|
|
|
|
diag::note_odr_objc_synthesize_ivar_here)
|
|
|
|
<< D->getPropertyIvarDecl()->getDeclName();
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-12-08 02:32:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Merge the existing implementation with the new implementation.
|
|
|
|
Importer.Imported(D, ToImpl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ToImpl;
|
|
|
|
}
|
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
|
|
|
|
// For template arguments, we adopt the translation unit as our declaration
|
|
|
|
// context. This context will be fixed when the actual template declaration
|
|
|
|
// is created.
|
|
|
|
|
|
|
|
// FIXME: Import default argument.
|
|
|
|
return TemplateTypeParmDecl::Create(Importer.getToContext(),
|
|
|
|
Importer.getToContext().getTranslationUnitDecl(),
|
2011-03-06 23:48:19 +08:00
|
|
|
Importer.Import(D->getLocStart()),
|
2010-12-01 03:14:50 +08:00
|
|
|
Importer.Import(D->getLocation()),
|
|
|
|
D->getDepth(),
|
|
|
|
D->getIndex(),
|
|
|
|
Importer.Import(D->getIdentifier()),
|
|
|
|
D->wasDeclaredWithTypename(),
|
|
|
|
D->isParameterPack());
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *
|
|
|
|
ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
|
|
|
|
// Import the name of this declaration.
|
|
|
|
DeclarationName Name = Importer.Import(D->getDeclName());
|
|
|
|
if (D->getDeclName() && !Name)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
// Import the location of this declaration.
|
|
|
|
SourceLocation Loc = Importer.Import(D->getLocation());
|
|
|
|
|
|
|
|
// Import the type of this declaration.
|
|
|
|
QualType T = Importer.Import(D->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
// Import type-source information.
|
|
|
|
TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
|
|
|
|
if (D->getTypeSourceInfo() && !TInfo)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
// FIXME: Import default argument.
|
|
|
|
|
|
|
|
return NonTypeTemplateParmDecl::Create(Importer.getToContext(),
|
|
|
|
Importer.getToContext().getTranslationUnitDecl(),
|
2011-03-08 16:55:46 +08:00
|
|
|
Importer.Import(D->getInnerLocStart()),
|
2010-12-01 03:14:50 +08:00
|
|
|
Loc, D->getDepth(), D->getPosition(),
|
|
|
|
Name.getAsIdentifierInfo(),
|
2010-12-24 07:51:58 +08:00
|
|
|
T, D->isParameterPack(), TInfo);
|
2010-12-01 03:14:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Decl *
|
|
|
|
ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
|
|
|
|
// Import the name of this declaration.
|
|
|
|
DeclarationName Name = Importer.Import(D->getDeclName());
|
|
|
|
if (D->getDeclName() && !Name)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
// Import the location of this declaration.
|
|
|
|
SourceLocation Loc = Importer.Import(D->getLocation());
|
|
|
|
|
|
|
|
// Import template parameters.
|
|
|
|
TemplateParameterList *TemplateParams
|
|
|
|
= ImportTemplateParameterList(D->getTemplateParameters());
|
|
|
|
if (!TemplateParams)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
// FIXME: Import default argument.
|
|
|
|
|
|
|
|
return TemplateTemplateParmDecl::Create(Importer.getToContext(),
|
|
|
|
Importer.getToContext().getTranslationUnitDecl(),
|
|
|
|
Loc, D->getDepth(), D->getPosition(),
|
2011-01-05 23:48:55 +08:00
|
|
|
D->isParameterPack(),
|
2010-12-01 03:14:50 +08:00
|
|
|
Name.getAsIdentifierInfo(),
|
|
|
|
TemplateParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
|
|
|
|
// If this record has a definition in the translation unit we're coming from,
|
|
|
|
// but this particular declaration is not that definition, import the
|
|
|
|
// definition and map to that.
|
|
|
|
CXXRecordDecl *Definition
|
|
|
|
= cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition());
|
|
|
|
if (Definition && Definition != D->getTemplatedDecl()) {
|
|
|
|
Decl *ImportedDef
|
|
|
|
= Importer.Import(Definition->getDescribedClassTemplate());
|
|
|
|
if (!ImportedDef)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
return Importer.Imported(D, ImportedDef);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import the major distinguishing characteristics of this class template.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2014-05-12 13:36:57 +08:00
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
// We may already have a template of the same name; try to find and match it.
|
|
|
|
if (!DC->isFunctionOrMethod()) {
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<NamedDecl *, 4> ConflictingDecls;
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2011-10-15 08:10:27 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary))
|
2010-12-01 03:14:50 +08:00
|
|
|
continue;
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
Decl *Found = FoundDecls[I];
|
2010-12-01 03:14:50 +08:00
|
|
|
if (ClassTemplateDecl *FoundTemplate
|
|
|
|
= dyn_cast<ClassTemplateDecl>(Found)) {
|
|
|
|
if (IsStructuralMatch(D, FoundTemplate)) {
|
|
|
|
// The class templates structurally match; call it the same template.
|
|
|
|
// FIXME: We may be filling in a forward declaration here. Handle
|
|
|
|
// this case!
|
|
|
|
Importer.Imported(D->getTemplatedDecl(),
|
|
|
|
FoundTemplate->getTemplatedDecl());
|
|
|
|
return Importer.Imported(D, FoundTemplate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
ConflictingDecls.push_back(FoundDecls[I]);
|
2010-12-01 03:14:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ConflictingDecls.empty()) {
|
|
|
|
Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary,
|
|
|
|
ConflictingDecls.data(),
|
|
|
|
ConflictingDecls.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Name)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-12-01 03:14:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXXRecordDecl *DTemplated = D->getTemplatedDecl();
|
|
|
|
|
|
|
|
// Create the declaration that is being templated.
|
2016-04-14 19:51:27 +08:00
|
|
|
// Create the declaration that is being templated.
|
|
|
|
CXXRecordDecl *D2Templated = cast_or_null<CXXRecordDecl>(
|
|
|
|
Importer.Import(DTemplated));
|
|
|
|
if (!D2Templated)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// Resolve possible cyclic import.
|
|
|
|
if (Decl *AlreadyImported = Importer.GetAlreadyImportedOrNull(D))
|
|
|
|
return AlreadyImported;
|
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
// Create the class template declaration itself.
|
|
|
|
TemplateParameterList *TemplateParams
|
|
|
|
= ImportTemplateParameterList(D->getTemplateParameters());
|
|
|
|
if (!TemplateParams)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-01 03:14:50 +08:00
|
|
|
ClassTemplateDecl *D2 = ClassTemplateDecl::Create(Importer.getToContext(), DC,
|
|
|
|
Loc, Name, TemplateParams,
|
|
|
|
D2Templated,
|
2014-05-12 13:36:57 +08:00
|
|
|
/*PrevDecl=*/nullptr);
|
2010-12-01 03:14:50 +08:00
|
|
|
D2Templated->setDescribedClassTemplate(D2);
|
|
|
|
|
|
|
|
D2->setAccess(D->getAccess());
|
|
|
|
D2->setLexicalDeclContext(LexicalDC);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(D2);
|
2010-12-01 03:14:50 +08:00
|
|
|
|
|
|
|
// Note the relationship between the class templates.
|
|
|
|
Importer.Imported(D, D2);
|
|
|
|
Importer.Imported(DTemplated, D2Templated);
|
|
|
|
|
2011-10-07 14:10:15 +08:00
|
|
|
if (DTemplated->isCompleteDefinition() &&
|
|
|
|
!D2Templated->isCompleteDefinition()) {
|
2010-12-01 03:14:50 +08:00
|
|
|
// FIXME: Import definition!
|
|
|
|
}
|
|
|
|
|
|
|
|
return D2;
|
|
|
|
}
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl(
|
|
|
|
ClassTemplateSpecializationDecl *D) {
|
|
|
|
// If this record has a definition in the translation unit we're coming from,
|
|
|
|
// but this particular declaration is not that definition, import the
|
|
|
|
// definition and map to that.
|
|
|
|
TagDecl *Definition = D->getDefinition();
|
|
|
|
if (Definition && Definition != D) {
|
|
|
|
Decl *ImportedDef = Importer.Import(Definition);
|
|
|
|
if (!ImportedDef)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
return Importer.Imported(D, ImportedDef);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassTemplateDecl *ClassTemplate
|
|
|
|
= cast_or_null<ClassTemplateDecl>(Importer.Import(
|
|
|
|
D->getSpecializedTemplate()));
|
|
|
|
if (!ClassTemplate)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
// Import the context of this declaration.
|
|
|
|
DeclContext *DC = ClassTemplate->getDeclContext();
|
|
|
|
if (!DC)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
DeclContext *LexicalDC = DC;
|
|
|
|
if (D->getDeclContext() != D->getLexicalDeclContext()) {
|
|
|
|
LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
|
|
|
|
if (!LexicalDC)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-12-01 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Import the location of this declaration.
|
2011-03-09 22:09:51 +08:00
|
|
|
SourceLocation StartLoc = Importer.Import(D->getLocStart());
|
|
|
|
SourceLocation IdLoc = Importer.Import(D->getLocation());
|
2010-12-01 09:36:18 +08:00
|
|
|
|
|
|
|
// Import template arguments.
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<TemplateArgument, 2> TemplateArgs;
|
2010-12-01 09:36:18 +08:00
|
|
|
if (ImportTemplateArguments(D->getTemplateArgs().data(),
|
|
|
|
D->getTemplateArgs().size(),
|
|
|
|
TemplateArgs))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
// Try to find an existing specialization with these template arguments.
|
2014-05-12 13:36:57 +08:00
|
|
|
void *InsertPos = nullptr;
|
2010-12-01 09:36:18 +08:00
|
|
|
ClassTemplateSpecializationDecl *D2
|
2014-06-26 12:58:53 +08:00
|
|
|
= ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
|
2010-12-01 09:36:18 +08:00
|
|
|
if (D2) {
|
|
|
|
// We already have a class template specialization with these template
|
|
|
|
// arguments.
|
|
|
|
|
|
|
|
// FIXME: Check for specialization vs. instantiation errors.
|
|
|
|
|
|
|
|
if (RecordDecl *FoundDef = D2->getDefinition()) {
|
2011-10-07 14:10:15 +08:00
|
|
|
if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) {
|
2010-12-01 09:36:18 +08:00
|
|
|
// The record types structurally match, or the "from" translation
|
|
|
|
// unit only had a forward declaration anyway; call it the same
|
|
|
|
// function.
|
|
|
|
return Importer.Imported(D, FoundDef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Create a new specialization.
|
|
|
|
D2 = ClassTemplateSpecializationDecl::Create(Importer.getToContext(),
|
|
|
|
D->getTagKind(), DC,
|
2011-03-09 22:09:51 +08:00
|
|
|
StartLoc, IdLoc,
|
|
|
|
ClassTemplate,
|
2010-12-01 09:36:18 +08:00
|
|
|
TemplateArgs.data(),
|
|
|
|
TemplateArgs.size(),
|
2014-05-12 13:36:57 +08:00
|
|
|
/*PrevDecl=*/nullptr);
|
2010-12-01 09:36:18 +08:00
|
|
|
D2->setSpecializationKind(D->getSpecializationKind());
|
|
|
|
|
|
|
|
// Add this specialization to the class template.
|
|
|
|
ClassTemplate->AddSpecialization(D2, InsertPos);
|
|
|
|
|
|
|
|
// Import the qualifier, if any.
|
2011-02-25 10:25:35 +08:00
|
|
|
D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
|
2010-12-01 09:36:18 +08:00
|
|
|
|
|
|
|
// Add the specialization to this context.
|
|
|
|
D2->setLexicalDeclContext(LexicalDC);
|
2011-10-21 10:57:43 +08:00
|
|
|
LexicalDC->addDeclInternal(D2);
|
2010-12-01 09:36:18 +08:00
|
|
|
}
|
|
|
|
Importer.Imported(D, D2);
|
|
|
|
|
2011-10-07 14:10:15 +08:00
|
|
|
if (D->isCompleteDefinition() && ImportDefinition(D, D2))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
return D2;
|
|
|
|
}
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
Decl *ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) {
|
|
|
|
// If this variable has a definition in the translation unit we're coming
|
|
|
|
// from,
|
|
|
|
// but this particular declaration is not that definition, import the
|
|
|
|
// definition and map to that.
|
|
|
|
VarDecl *Definition =
|
|
|
|
cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition());
|
|
|
|
if (Definition && Definition != D->getTemplatedDecl()) {
|
|
|
|
Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate());
|
|
|
|
if (!ImportedDef)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
return Importer.Imported(D, ImportedDef);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import the major distinguishing characteristics of this variable template.
|
|
|
|
DeclContext *DC, *LexicalDC;
|
|
|
|
DeclarationName Name;
|
|
|
|
SourceLocation Loc;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
NamedDecl *ToD;
|
|
|
|
if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
if (ToD)
|
|
|
|
return ToD;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// We may already have a template of the same name; try to find and match it.
|
|
|
|
assert(!DC->isFunctionOrMethod() &&
|
|
|
|
"Variable templates cannot be declared at function scope");
|
|
|
|
SmallVector<NamedDecl *, 4> ConflictingDecls;
|
|
|
|
SmallVector<NamedDecl *, 2> FoundDecls;
|
2014-12-10 11:09:41 +08:00
|
|
|
DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls);
|
2013-08-06 09:03:05 +08:00
|
|
|
for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
|
|
|
|
if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Ordinary))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Decl *Found = FoundDecls[I];
|
|
|
|
if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) {
|
|
|
|
if (IsStructuralMatch(D, FoundTemplate)) {
|
|
|
|
// The variable templates structurally match; call it the same template.
|
|
|
|
Importer.Imported(D->getTemplatedDecl(),
|
|
|
|
FoundTemplate->getTemplatedDecl());
|
|
|
|
return Importer.Imported(D, FoundTemplate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConflictingDecls.push_back(FoundDecls[I]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ConflictingDecls.empty()) {
|
|
|
|
Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary,
|
|
|
|
ConflictingDecls.data(),
|
|
|
|
ConflictingDecls.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Name)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
VarDecl *DTemplated = D->getTemplatedDecl();
|
|
|
|
|
|
|
|
// Import the type.
|
|
|
|
QualType T = Importer.Import(DTemplated->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Create the declaration that is being templated.
|
|
|
|
SourceLocation StartLoc = Importer.Import(DTemplated->getLocStart());
|
|
|
|
SourceLocation IdLoc = Importer.Import(DTemplated->getLocation());
|
|
|
|
TypeSourceInfo *TInfo = Importer.Import(DTemplated->getTypeSourceInfo());
|
|
|
|
VarDecl *D2Templated = VarDecl::Create(Importer.getToContext(), DC, StartLoc,
|
|
|
|
IdLoc, Name.getAsIdentifierInfo(), T,
|
|
|
|
TInfo, DTemplated->getStorageClass());
|
|
|
|
D2Templated->setAccess(DTemplated->getAccess());
|
|
|
|
D2Templated->setQualifierInfo(Importer.Import(DTemplated->getQualifierLoc()));
|
|
|
|
D2Templated->setLexicalDeclContext(LexicalDC);
|
|
|
|
|
|
|
|
// Importer.Imported(DTemplated, D2Templated);
|
|
|
|
// LexicalDC->addDeclInternal(D2Templated);
|
|
|
|
|
|
|
|
// Merge the initializer.
|
|
|
|
if (ImportDefinition(DTemplated, D2Templated))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Create the variable template declaration itself.
|
|
|
|
TemplateParameterList *TemplateParams =
|
|
|
|
ImportTemplateParameterList(D->getTemplateParameters());
|
|
|
|
if (!TemplateParams)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
VarTemplateDecl *D2 = VarTemplateDecl::Create(
|
2014-01-17 07:39:20 +08:00
|
|
|
Importer.getToContext(), DC, Loc, Name, TemplateParams, D2Templated);
|
2013-08-06 09:03:05 +08:00
|
|
|
D2Templated->setDescribedVarTemplate(D2);
|
|
|
|
|
|
|
|
D2->setAccess(D->getAccess());
|
|
|
|
D2->setLexicalDeclContext(LexicalDC);
|
|
|
|
LexicalDC->addDeclInternal(D2);
|
|
|
|
|
|
|
|
// Note the relationship between the variable templates.
|
|
|
|
Importer.Imported(D, D2);
|
|
|
|
Importer.Imported(DTemplated, D2Templated);
|
|
|
|
|
|
|
|
if (DTemplated->isThisDeclarationADefinition() &&
|
|
|
|
!D2Templated->isThisDeclarationADefinition()) {
|
|
|
|
// FIXME: Import definition!
|
|
|
|
}
|
|
|
|
|
|
|
|
return D2;
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl(
|
|
|
|
VarTemplateSpecializationDecl *D) {
|
|
|
|
// If this record has a definition in the translation unit we're coming from,
|
|
|
|
// but this particular declaration is not that definition, import the
|
|
|
|
// definition and map to that.
|
|
|
|
VarDecl *Definition = D->getDefinition();
|
|
|
|
if (Definition && Definition != D) {
|
|
|
|
Decl *ImportedDef = Importer.Import(Definition);
|
|
|
|
if (!ImportedDef)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
return Importer.Imported(D, ImportedDef);
|
|
|
|
}
|
|
|
|
|
|
|
|
VarTemplateDecl *VarTemplate = cast_or_null<VarTemplateDecl>(
|
|
|
|
Importer.Import(D->getSpecializedTemplate()));
|
|
|
|
if (!VarTemplate)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Import the context of this declaration.
|
|
|
|
DeclContext *DC = VarTemplate->getDeclContext();
|
|
|
|
if (!DC)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
DeclContext *LexicalDC = DC;
|
|
|
|
if (D->getDeclContext() != D->getLexicalDeclContext()) {
|
|
|
|
LexicalDC = Importer.ImportContext(D->getLexicalDeclContext());
|
|
|
|
if (!LexicalDC)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Import the location of this declaration.
|
|
|
|
SourceLocation StartLoc = Importer.Import(D->getLocStart());
|
|
|
|
SourceLocation IdLoc = Importer.Import(D->getLocation());
|
|
|
|
|
|
|
|
// Import template arguments.
|
|
|
|
SmallVector<TemplateArgument, 2> TemplateArgs;
|
|
|
|
if (ImportTemplateArguments(D->getTemplateArgs().data(),
|
|
|
|
D->getTemplateArgs().size(), TemplateArgs))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
// Try to find an existing specialization with these template arguments.
|
2014-05-12 13:36:57 +08:00
|
|
|
void *InsertPos = nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization(
|
2014-06-26 12:58:53 +08:00
|
|
|
TemplateArgs, InsertPos);
|
2013-08-06 09:03:05 +08:00
|
|
|
if (D2) {
|
|
|
|
// We already have a variable template specialization with these template
|
|
|
|
// arguments.
|
|
|
|
|
|
|
|
// FIXME: Check for specialization vs. instantiation errors.
|
|
|
|
|
|
|
|
if (VarDecl *FoundDef = D2->getDefinition()) {
|
|
|
|
if (!D->isThisDeclarationADefinition() ||
|
|
|
|
IsStructuralMatch(D, FoundDef)) {
|
|
|
|
// The record types structurally match, or the "from" translation
|
|
|
|
// unit only had a forward declaration anyway; call it the same
|
|
|
|
// variable.
|
|
|
|
return Importer.Imported(D, FoundDef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Import the type.
|
|
|
|
QualType T = Importer.Import(D->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());
|
|
|
|
|
|
|
|
// Create a new specialization.
|
|
|
|
D2 = VarTemplateSpecializationDecl::Create(
|
|
|
|
Importer.getToContext(), DC, StartLoc, IdLoc, VarTemplate, T, TInfo,
|
|
|
|
D->getStorageClass(), TemplateArgs.data(), TemplateArgs.size());
|
|
|
|
D2->setSpecializationKind(D->getSpecializationKind());
|
|
|
|
D2->setTemplateArgsInfo(D->getTemplateArgsInfo());
|
|
|
|
|
|
|
|
// Add this specialization to the class template.
|
|
|
|
VarTemplate->AddSpecialization(D2, InsertPos);
|
|
|
|
|
|
|
|
// Import the qualifier, if any.
|
|
|
|
D2->setQualifierInfo(Importer.Import(D->getQualifierLoc()));
|
|
|
|
|
|
|
|
// Add the specialization to this context.
|
|
|
|
D2->setLexicalDeclContext(LexicalDC);
|
|
|
|
LexicalDC->addDeclInternal(D2);
|
|
|
|
}
|
|
|
|
Importer.Imported(D, D2);
|
|
|
|
|
|
|
|
if (D->isThisDeclarationADefinition() && ImportDefinition(D, D2))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
return D2;
|
|
|
|
}
|
|
|
|
|
2010-02-12 03:21:55 +08:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Import Statements
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
DeclGroupRef ASTNodeImporter::ImportDeclGroup(DeclGroupRef DG) {
|
|
|
|
if (DG.isNull())
|
|
|
|
return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
|
|
|
|
size_t NumDecls = DG.end() - DG.begin();
|
|
|
|
SmallVector<Decl *, 1> ToDecls(NumDecls);
|
|
|
|
auto &_Importer = this->Importer;
|
|
|
|
std::transform(DG.begin(), DG.end(), ToDecls.begin(),
|
|
|
|
[&_Importer](Decl *D) -> Decl * {
|
|
|
|
return _Importer.Import(D);
|
|
|
|
});
|
|
|
|
return DeclGroupRef::Create(Importer.getToContext(),
|
|
|
|
ToDecls.begin(),
|
|
|
|
NumDecls);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitStmt(Stmt *S) {
|
|
|
|
Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node)
|
|
|
|
<< S->getStmtClassName();
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-04-14 19:51:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) {
|
|
|
|
SmallVector<IdentifierInfo *, 4> Names;
|
|
|
|
for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
|
|
|
|
IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
|
|
|
|
if (!ToII)
|
|
|
|
return nullptr;
|
|
|
|
Names.push_back(ToII);
|
|
|
|
}
|
|
|
|
for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
|
|
|
|
IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
|
|
|
|
if (!ToII)
|
|
|
|
return nullptr;
|
|
|
|
Names.push_back(ToII);
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<StringLiteral *, 4> Clobbers;
|
|
|
|
for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
|
|
|
|
StringLiteral *Clobber = cast_or_null<StringLiteral>(
|
|
|
|
Importer.Import(S->getClobberStringLiteral(I)));
|
|
|
|
if (!Clobber)
|
|
|
|
return nullptr;
|
|
|
|
Clobbers.push_back(Clobber);
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<StringLiteral *, 4> Constraints;
|
|
|
|
for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
|
|
|
|
StringLiteral *Output = cast_or_null<StringLiteral>(
|
|
|
|
Importer.Import(S->getOutputConstraintLiteral(I)));
|
|
|
|
if (!Output)
|
|
|
|
return nullptr;
|
|
|
|
Constraints.push_back(Output);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
|
|
|
|
StringLiteral *Input = cast_or_null<StringLiteral>(
|
|
|
|
Importer.Import(S->getInputConstraintLiteral(I)));
|
|
|
|
if (!Input)
|
|
|
|
return nullptr;
|
|
|
|
Constraints.push_back(Input);
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs());
|
|
|
|
if (ImportArrayChecked(S->begin_outputs(), S->end_outputs(), Exprs.begin()))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if (ImportArrayChecked(S->begin_inputs(), S->end_inputs(),
|
|
|
|
Exprs.begin() + S->getNumOutputs()))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
StringLiteral *AsmStr = cast_or_null<StringLiteral>(
|
|
|
|
Importer.Import(S->getAsmString()));
|
|
|
|
if (!AsmStr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext()) GCCAsmStmt(
|
|
|
|
Importer.getToContext(),
|
|
|
|
Importer.Import(S->getAsmLoc()),
|
|
|
|
S->isSimple(),
|
|
|
|
S->isVolatile(),
|
|
|
|
S->getNumOutputs(),
|
|
|
|
S->getNumInputs(),
|
|
|
|
Names.data(),
|
|
|
|
Constraints.data(),
|
|
|
|
Exprs.data(),
|
|
|
|
AsmStr,
|
|
|
|
S->getNumClobbers(),
|
|
|
|
Clobbers.data(),
|
|
|
|
Importer.Import(S->getRParenLoc()));
|
|
|
|
}
|
|
|
|
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
Stmt *ASTNodeImporter::VisitDeclStmt(DeclStmt *S) {
|
|
|
|
DeclGroupRef ToDG = ImportDeclGroup(S->getDeclGroup());
|
|
|
|
for (Decl *ToD : ToDG) {
|
|
|
|
if (!ToD)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
SourceLocation ToStartLoc = Importer.Import(S->getStartLoc());
|
|
|
|
SourceLocation ToEndLoc = Importer.Import(S->getEndLoc());
|
|
|
|
return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitNullStmt(NullStmt *S) {
|
|
|
|
SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc());
|
|
|
|
return new (Importer.getToContext()) NullStmt(ToSemiLoc,
|
|
|
|
S->hasLeadingEmptyMacro());
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) {
|
2016-04-14 19:51:27 +08:00
|
|
|
llvm::SmallVector<Stmt *, 8> ToStmts(S->size());
|
2016-03-29 05:43:01 +08:00
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
if (ImportArrayChecked(S->body_begin(), S->body_end(), ToStmts.begin()))
|
2016-03-29 05:43:01 +08:00
|
|
|
return nullptr;
|
|
|
|
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc());
|
|
|
|
SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc());
|
|
|
|
return new (Importer.getToContext()) CompoundStmt(Importer.getToContext(),
|
|
|
|
ToStmts,
|
|
|
|
ToLBraceLoc, ToRBraceLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) {
|
|
|
|
Expr *ToLHS = Importer.Import(S->getLHS());
|
|
|
|
if (!ToLHS)
|
|
|
|
return nullptr;
|
|
|
|
Expr *ToRHS = Importer.Import(S->getRHS());
|
|
|
|
if (!ToRHS && S->getRHS())
|
|
|
|
return nullptr;
|
|
|
|
SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc());
|
|
|
|
SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc());
|
|
|
|
SourceLocation ToColonLoc = Importer.Import(S->getColonLoc());
|
|
|
|
return new (Importer.getToContext()) CaseStmt(ToLHS, ToRHS,
|
|
|
|
ToCaseLoc, ToEllipsisLoc,
|
|
|
|
ToColonLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) {
|
|
|
|
SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc());
|
|
|
|
SourceLocation ToColonLoc = Importer.Import(S->getColonLoc());
|
|
|
|
Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
|
|
|
|
if (!ToSubStmt && S->getSubStmt())
|
|
|
|
return nullptr;
|
|
|
|
return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc,
|
|
|
|
ToSubStmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) {
|
|
|
|
SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc());
|
|
|
|
LabelDecl *ToLabelDecl =
|
|
|
|
cast_or_null<LabelDecl>(Importer.Import(S->getDecl()));
|
|
|
|
if (!ToLabelDecl && S->getDecl())
|
|
|
|
return nullptr;
|
|
|
|
Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
|
|
|
|
if (!ToSubStmt && S->getSubStmt())
|
|
|
|
return nullptr;
|
|
|
|
return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl,
|
|
|
|
ToSubStmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) {
|
|
|
|
SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc());
|
|
|
|
ArrayRef<const Attr*> FromAttrs(S->getAttrs());
|
|
|
|
SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
|
|
|
|
ASTContext &_ToContext = Importer.getToContext();
|
|
|
|
std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(),
|
|
|
|
[&_ToContext](const Attr *A) -> const Attr * {
|
|
|
|
return A->clone(_ToContext);
|
|
|
|
});
|
|
|
|
for (const Attr *ToA : ToAttrs) {
|
|
|
|
if (!ToA)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
|
|
|
|
if (!ToSubStmt && S->getSubStmt())
|
|
|
|
return nullptr;
|
|
|
|
return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc,
|
|
|
|
ToAttrs, ToSubStmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitIfStmt(IfStmt *S) {
|
|
|
|
SourceLocation ToIfLoc = Importer.Import(S->getIfLoc());
|
|
|
|
VarDecl *ToConditionVariable = nullptr;
|
|
|
|
if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
|
|
|
|
ToConditionVariable =
|
|
|
|
dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
|
|
|
|
if (!ToConditionVariable)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Expr *ToCondition = Importer.Import(S->getCond());
|
|
|
|
if (!ToCondition && S->getCond())
|
|
|
|
return nullptr;
|
|
|
|
Stmt *ToThenStmt = Importer.Import(S->getThen());
|
|
|
|
if (!ToThenStmt && S->getThen())
|
|
|
|
return nullptr;
|
|
|
|
SourceLocation ToElseLoc = Importer.Import(S->getElseLoc());
|
|
|
|
Stmt *ToElseStmt = Importer.Import(S->getElse());
|
|
|
|
if (!ToElseStmt && S->getElse())
|
|
|
|
return nullptr;
|
|
|
|
return new (Importer.getToContext()) IfStmt(Importer.getToContext(),
|
2016-06-24 03:16:49 +08:00
|
|
|
ToIfLoc, S->isConstexpr(),
|
|
|
|
ToConditionVariable,
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
ToCondition, ToThenStmt,
|
|
|
|
ToElseLoc, ToElseStmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) {
|
|
|
|
VarDecl *ToConditionVariable = nullptr;
|
|
|
|
if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
|
|
|
|
ToConditionVariable =
|
|
|
|
dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
|
|
|
|
if (!ToConditionVariable)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Expr *ToCondition = Importer.Import(S->getCond());
|
|
|
|
if (!ToCondition && S->getCond())
|
|
|
|
return nullptr;
|
|
|
|
SwitchStmt *ToStmt = new (Importer.getToContext()) SwitchStmt(
|
|
|
|
Importer.getToContext(), ToConditionVariable,
|
|
|
|
ToCondition);
|
|
|
|
Stmt *ToBody = Importer.Import(S->getBody());
|
|
|
|
if (!ToBody && S->getBody())
|
|
|
|
return nullptr;
|
|
|
|
ToStmt->setBody(ToBody);
|
|
|
|
ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc()));
|
|
|
|
// Now we have to re-chain the cases.
|
|
|
|
SwitchCase *LastChainedSwitchCase = nullptr;
|
|
|
|
for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
|
|
|
|
SC = SC->getNextSwitchCase()) {
|
|
|
|
SwitchCase *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC));
|
|
|
|
if (!ToSC)
|
|
|
|
return nullptr;
|
|
|
|
if (LastChainedSwitchCase)
|
|
|
|
LastChainedSwitchCase->setNextSwitchCase(ToSC);
|
|
|
|
else
|
|
|
|
ToStmt->setSwitchCaseList(ToSC);
|
|
|
|
LastChainedSwitchCase = ToSC;
|
|
|
|
}
|
|
|
|
return ToStmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitWhileStmt(WhileStmt *S) {
|
|
|
|
VarDecl *ToConditionVariable = nullptr;
|
|
|
|
if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
|
|
|
|
ToConditionVariable =
|
|
|
|
dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
|
|
|
|
if (!ToConditionVariable)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Expr *ToCondition = Importer.Import(S->getCond());
|
|
|
|
if (!ToCondition && S->getCond())
|
|
|
|
return nullptr;
|
|
|
|
Stmt *ToBody = Importer.Import(S->getBody());
|
|
|
|
if (!ToBody && S->getBody())
|
|
|
|
return nullptr;
|
|
|
|
SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc());
|
|
|
|
return new (Importer.getToContext()) WhileStmt(Importer.getToContext(),
|
|
|
|
ToConditionVariable,
|
|
|
|
ToCondition, ToBody,
|
|
|
|
ToWhileLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitDoStmt(DoStmt *S) {
|
|
|
|
Stmt *ToBody = Importer.Import(S->getBody());
|
|
|
|
if (!ToBody && S->getBody())
|
|
|
|
return nullptr;
|
|
|
|
Expr *ToCondition = Importer.Import(S->getCond());
|
|
|
|
if (!ToCondition && S->getCond())
|
|
|
|
return nullptr;
|
|
|
|
SourceLocation ToDoLoc = Importer.Import(S->getDoLoc());
|
|
|
|
SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc());
|
|
|
|
SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
|
|
|
|
return new (Importer.getToContext()) DoStmt(ToBody, ToCondition,
|
|
|
|
ToDoLoc, ToWhileLoc,
|
|
|
|
ToRParenLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitForStmt(ForStmt *S) {
|
|
|
|
Stmt *ToInit = Importer.Import(S->getInit());
|
|
|
|
if (!ToInit && S->getInit())
|
|
|
|
return nullptr;
|
|
|
|
Expr *ToCondition = Importer.Import(S->getCond());
|
|
|
|
if (!ToCondition && S->getCond())
|
|
|
|
return nullptr;
|
|
|
|
VarDecl *ToConditionVariable = nullptr;
|
|
|
|
if (VarDecl *FromConditionVariable = S->getConditionVariable()) {
|
|
|
|
ToConditionVariable =
|
|
|
|
dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable));
|
|
|
|
if (!ToConditionVariable)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Expr *ToInc = Importer.Import(S->getInc());
|
|
|
|
if (!ToInc && S->getInc())
|
|
|
|
return nullptr;
|
|
|
|
Stmt *ToBody = Importer.Import(S->getBody());
|
|
|
|
if (!ToBody && S->getBody())
|
|
|
|
return nullptr;
|
|
|
|
SourceLocation ToForLoc = Importer.Import(S->getForLoc());
|
|
|
|
SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc());
|
|
|
|
SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
|
|
|
|
return new (Importer.getToContext()) ForStmt(Importer.getToContext(),
|
|
|
|
ToInit, ToCondition,
|
|
|
|
ToConditionVariable,
|
|
|
|
ToInc, ToBody,
|
|
|
|
ToForLoc, ToLParenLoc,
|
|
|
|
ToRParenLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitGotoStmt(GotoStmt *S) {
|
|
|
|
LabelDecl *ToLabel = nullptr;
|
|
|
|
if (LabelDecl *FromLabel = S->getLabel()) {
|
|
|
|
ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel));
|
|
|
|
if (!ToLabel)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc());
|
|
|
|
SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc());
|
|
|
|
return new (Importer.getToContext()) GotoStmt(ToLabel,
|
|
|
|
ToGotoLoc, ToLabelLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
|
|
|
|
SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc());
|
|
|
|
SourceLocation ToStarLoc = Importer.Import(S->getStarLoc());
|
|
|
|
Expr *ToTarget = Importer.Import(S->getTarget());
|
|
|
|
if (!ToTarget && S->getTarget())
|
|
|
|
return nullptr;
|
|
|
|
return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc,
|
|
|
|
ToTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) {
|
|
|
|
SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc());
|
|
|
|
return new (Importer.getToContext()) ContinueStmt(ToContinueLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitBreakStmt(BreakStmt *S) {
|
|
|
|
SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc());
|
|
|
|
return new (Importer.getToContext()) BreakStmt(ToBreakLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) {
|
|
|
|
SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc());
|
|
|
|
Expr *ToRetExpr = Importer.Import(S->getRetValue());
|
|
|
|
if (!ToRetExpr && S->getRetValue())
|
|
|
|
return nullptr;
|
|
|
|
VarDecl *NRVOCandidate = const_cast<VarDecl*>(S->getNRVOCandidate());
|
|
|
|
VarDecl *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate));
|
|
|
|
if (!ToNRVOCandidate && NRVOCandidate)
|
|
|
|
return nullptr;
|
|
|
|
return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr,
|
|
|
|
ToNRVOCandidate);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) {
|
|
|
|
SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc());
|
|
|
|
VarDecl *ToExceptionDecl = nullptr;
|
|
|
|
if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) {
|
|
|
|
ToExceptionDecl =
|
|
|
|
dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl));
|
|
|
|
if (!ToExceptionDecl)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock());
|
|
|
|
if (!ToHandlerBlock && S->getHandlerBlock())
|
|
|
|
return nullptr;
|
|
|
|
return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc,
|
|
|
|
ToExceptionDecl,
|
|
|
|
ToHandlerBlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) {
|
|
|
|
SourceLocation ToTryLoc = Importer.Import(S->getTryLoc());
|
|
|
|
Stmt *ToTryBlock = Importer.Import(S->getTryBlock());
|
|
|
|
if (!ToTryBlock && S->getTryBlock())
|
|
|
|
return nullptr;
|
|
|
|
SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
|
|
|
|
for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
|
|
|
|
CXXCatchStmt *FromHandler = S->getHandler(HI);
|
|
|
|
if (Stmt *ToHandler = Importer.Import(FromHandler))
|
|
|
|
ToHandlers[HI] = ToHandler;
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock,
|
|
|
|
ToHandlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
|
|
|
|
DeclStmt *ToRange =
|
|
|
|
dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt()));
|
|
|
|
if (!ToRange && S->getRangeStmt())
|
|
|
|
return nullptr;
|
2016-03-20 18:33:40 +08:00
|
|
|
DeclStmt *ToBegin =
|
|
|
|
dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt()));
|
|
|
|
if (!ToBegin && S->getBeginStmt())
|
|
|
|
return nullptr;
|
|
|
|
DeclStmt *ToEnd =
|
|
|
|
dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt()));
|
|
|
|
if (!ToEnd && S->getEndStmt())
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
return nullptr;
|
|
|
|
Expr *ToCond = Importer.Import(S->getCond());
|
|
|
|
if (!ToCond && S->getCond())
|
|
|
|
return nullptr;
|
|
|
|
Expr *ToInc = Importer.Import(S->getInc());
|
|
|
|
if (!ToInc && S->getInc())
|
|
|
|
return nullptr;
|
|
|
|
DeclStmt *ToLoopVar =
|
|
|
|
dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt()));
|
|
|
|
if (!ToLoopVar && S->getLoopVarStmt())
|
|
|
|
return nullptr;
|
|
|
|
Stmt *ToBody = Importer.Import(S->getBody());
|
|
|
|
if (!ToBody && S->getBody())
|
|
|
|
return nullptr;
|
|
|
|
SourceLocation ToForLoc = Importer.Import(S->getForLoc());
|
2015-10-27 14:02:45 +08:00
|
|
|
SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc());
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
SourceLocation ToColonLoc = Importer.Import(S->getColonLoc());
|
|
|
|
SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
|
2016-03-20 18:33:40 +08:00
|
|
|
return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd,
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
ToCond, ToInc,
|
|
|
|
ToLoopVar, ToBody,
|
2015-10-27 14:02:45 +08:00
|
|
|
ToForLoc, ToCoawaitLoc,
|
|
|
|
ToColonLoc, ToRParenLoc);
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
|
|
|
|
Stmt *ToElem = Importer.Import(S->getElement());
|
|
|
|
if (!ToElem && S->getElement())
|
|
|
|
return nullptr;
|
|
|
|
Expr *ToCollect = Importer.Import(S->getCollection());
|
|
|
|
if (!ToCollect && S->getCollection())
|
|
|
|
return nullptr;
|
|
|
|
Stmt *ToBody = Importer.Import(S->getBody());
|
|
|
|
if (!ToBody && S->getBody())
|
|
|
|
return nullptr;
|
|
|
|
SourceLocation ToForLoc = Importer.Import(S->getForLoc());
|
|
|
|
SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
|
|
|
|
return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem,
|
|
|
|
ToCollect,
|
|
|
|
ToBody, ToForLoc,
|
|
|
|
ToRParenLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
|
|
|
|
SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc());
|
|
|
|
SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc());
|
|
|
|
VarDecl *ToExceptionDecl = nullptr;
|
|
|
|
if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) {
|
|
|
|
ToExceptionDecl =
|
|
|
|
dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl));
|
|
|
|
if (!ToExceptionDecl)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Stmt *ToBody = Importer.Import(S->getCatchBody());
|
|
|
|
if (!ToBody && S->getCatchBody())
|
|
|
|
return nullptr;
|
|
|
|
return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc,
|
|
|
|
ToRParenLoc,
|
|
|
|
ToExceptionDecl,
|
|
|
|
ToBody);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
|
|
|
|
SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc());
|
|
|
|
Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody());
|
|
|
|
if (!ToAtFinallyStmt && S->getFinallyBody())
|
|
|
|
return nullptr;
|
|
|
|
return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc,
|
|
|
|
ToAtFinallyStmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
|
|
|
|
SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc());
|
|
|
|
Stmt *ToAtTryStmt = Importer.Import(S->getTryBody());
|
|
|
|
if (!ToAtTryStmt && S->getTryBody())
|
|
|
|
return nullptr;
|
|
|
|
SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
|
|
|
|
for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
|
|
|
|
ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
|
|
|
|
if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt))
|
|
|
|
ToCatchStmts[CI] = ToCatchStmt;
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt());
|
|
|
|
if (!ToAtFinallyStmt && S->getFinallyStmt())
|
|
|
|
return nullptr;
|
|
|
|
return ObjCAtTryStmt::Create(Importer.getToContext(),
|
|
|
|
ToAtTryLoc, ToAtTryStmt,
|
|
|
|
ToCatchStmts.begin(), ToCatchStmts.size(),
|
|
|
|
ToAtFinallyStmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitObjCAtSynchronizedStmt
|
|
|
|
(ObjCAtSynchronizedStmt *S) {
|
|
|
|
SourceLocation ToAtSynchronizedLoc =
|
|
|
|
Importer.Import(S->getAtSynchronizedLoc());
|
|
|
|
Expr *ToSynchExpr = Importer.Import(S->getSynchExpr());
|
|
|
|
if (!ToSynchExpr && S->getSynchExpr())
|
|
|
|
return nullptr;
|
|
|
|
Stmt *ToSynchBody = Importer.Import(S->getSynchBody());
|
|
|
|
if (!ToSynchBody && S->getSynchBody())
|
|
|
|
return nullptr;
|
|
|
|
return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
|
|
|
|
ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
|
|
|
|
SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc());
|
|
|
|
Expr *ToThrow = Importer.Import(S->getThrowExpr());
|
|
|
|
if (!ToThrow && S->getThrowExpr())
|
|
|
|
return nullptr;
|
|
|
|
return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTNodeImporter::VisitObjCAutoreleasePoolStmt
|
|
|
|
(ObjCAutoreleasePoolStmt *S) {
|
|
|
|
SourceLocation ToAtLoc = Importer.Import(S->getAtLoc());
|
|
|
|
Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
|
|
|
|
if (!ToSubStmt && S->getSubStmt())
|
|
|
|
return nullptr;
|
|
|
|
return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc,
|
|
|
|
ToSubStmt);
|
2010-02-12 03:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Import Expressions
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
Expr *ASTNodeImporter::VisitExpr(Expr *E) {
|
|
|
|
Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node)
|
|
|
|
<< E->getStmtClassName();
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-12 03:21:55 +08:00
|
|
|
}
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
Expr *ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Expr *SubExpr = Importer.Import(E->getSubExpr());
|
|
|
|
if (!SubExpr && E->getSubExpr())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo());
|
|
|
|
if (!TInfo)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext()) VAArgExpr(
|
|
|
|
Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo,
|
|
|
|
Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext()) GNUNullExpr(
|
|
|
|
T, Importer.Import(E->getExprLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
StringLiteral *SL = cast_or_null<StringLiteral>(
|
|
|
|
Importer.Import(E->getFunctionName()));
|
|
|
|
if (!SL && E->getFunctionName())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext()) PredefinedExpr(
|
|
|
|
Importer.Import(E->getExprLoc()), T, E->getIdentType(), SL);
|
|
|
|
}
|
|
|
|
|
2010-02-19 09:17:02 +08:00
|
|
|
Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) {
|
|
|
|
ValueDecl *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl()));
|
|
|
|
if (!ToD)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Add an optional field attached to a DeclRefExpr which points back to the
Decl actually found via name lookup & overload resolution when that Decl
is different from the ValueDecl which is actually referenced by the
expression.
This can be used by AST consumers to correctly attribute references to
the spelling location of a using declaration, and otherwise gain insight
into the name resolution performed by Clang.
The public interface to DRE is kept as narrow as possible: we provide
a getFoundDecl() which always returns a NamedDecl, either the ValueDecl
referenced or the new, more precise NamedDecl if present. This way AST
clients can code against getFoundDecl without know when exactly the AST
has a split representation.
For an example of the data this provides consider:
% cat x.cc
namespace N1 {
struct S {};
void f(const S&);
}
void test(N1::S s) {
f(s);
using N1::f;
f(s);
}
% ./bin/clang -fsyntax-only -Xclang -ast-dump x.cc
[...]
void test(N1::S s) (CompoundStmt 0x5b02010 <x.cc:5:20, line:9:1>
(CallExpr 0x5b01df0 <line:6:3, col:6> 'void'
(ImplicitCastExpr 0x5b01dd8 <col:3> 'void (*)(const struct N1::S &)' <FunctionToPointerDecay>
(DeclRefExpr 0x5b01d80 <col:3> 'void (const struct N1::S &)' lvalue Function 0x5b01a20 'f' 'void (const struct N1::S &)'))
(ImplicitCastExpr 0x5b01e20 <col:5> 'const struct N1::S' lvalue <NoOp>
(DeclRefExpr 0x5b01d58 <col:5> 'N1::S':'struct N1::S' lvalue ParmVar 0x5b01b60 's' 'N1::S':'struct N1::S')))
(DeclStmt 0x5b01ee0 <line:7:3, col:14>
0x5b01e40 "UsingN1::;")
(CallExpr 0x5b01fc8 <line:8:3, col:6> 'void'
(ImplicitCastExpr 0x5b01fb0 <col:3> 'void (*)(const struct N1::S &)' <FunctionToPointerDecay>
(DeclRefExpr 0x5b01f80 <col:3> 'void (const struct N1::S &)' lvalue Function 0x5b01a20 'f' 'void (const struct N1::S &)' (UsingShadow 0x5b01ea0 'f')))
(ImplicitCastExpr 0x5b01ff8 <col:5> 'const struct N1::S' lvalue <NoOp>
(DeclRefExpr 0x5b01f58 <col:5> 'N1::S':'struct N1::S' lvalue ParmVar 0x5b01b60 's' 'N1::S':'struct N1::S'))))
Now we can tell that the second call is 'using' (no pun intended) the using
declaration, and *which* using declaration it sees. Without this, we can
mistake calls that go through using declarations for ADL calls, and have no way
to attribute names looked up with using declarations to the appropriate
UsingDecl.
llvm-svn: 130670
2011-05-02 07:48:14 +08:00
|
|
|
|
2014-05-12 13:36:57 +08:00
|
|
|
NamedDecl *FoundD = nullptr;
|
Add an optional field attached to a DeclRefExpr which points back to the
Decl actually found via name lookup & overload resolution when that Decl
is different from the ValueDecl which is actually referenced by the
expression.
This can be used by AST consumers to correctly attribute references to
the spelling location of a using declaration, and otherwise gain insight
into the name resolution performed by Clang.
The public interface to DRE is kept as narrow as possible: we provide
a getFoundDecl() which always returns a NamedDecl, either the ValueDecl
referenced or the new, more precise NamedDecl if present. This way AST
clients can code against getFoundDecl without know when exactly the AST
has a split representation.
For an example of the data this provides consider:
% cat x.cc
namespace N1 {
struct S {};
void f(const S&);
}
void test(N1::S s) {
f(s);
using N1::f;
f(s);
}
% ./bin/clang -fsyntax-only -Xclang -ast-dump x.cc
[...]
void test(N1::S s) (CompoundStmt 0x5b02010 <x.cc:5:20, line:9:1>
(CallExpr 0x5b01df0 <line:6:3, col:6> 'void'
(ImplicitCastExpr 0x5b01dd8 <col:3> 'void (*)(const struct N1::S &)' <FunctionToPointerDecay>
(DeclRefExpr 0x5b01d80 <col:3> 'void (const struct N1::S &)' lvalue Function 0x5b01a20 'f' 'void (const struct N1::S &)'))
(ImplicitCastExpr 0x5b01e20 <col:5> 'const struct N1::S' lvalue <NoOp>
(DeclRefExpr 0x5b01d58 <col:5> 'N1::S':'struct N1::S' lvalue ParmVar 0x5b01b60 's' 'N1::S':'struct N1::S')))
(DeclStmt 0x5b01ee0 <line:7:3, col:14>
0x5b01e40 "UsingN1::;")
(CallExpr 0x5b01fc8 <line:8:3, col:6> 'void'
(ImplicitCastExpr 0x5b01fb0 <col:3> 'void (*)(const struct N1::S &)' <FunctionToPointerDecay>
(DeclRefExpr 0x5b01f80 <col:3> 'void (const struct N1::S &)' lvalue Function 0x5b01a20 'f' 'void (const struct N1::S &)' (UsingShadow 0x5b01ea0 'f')))
(ImplicitCastExpr 0x5b01ff8 <col:5> 'const struct N1::S' lvalue <NoOp>
(DeclRefExpr 0x5b01f58 <col:5> 'N1::S':'struct N1::S' lvalue ParmVar 0x5b01b60 's' 'N1::S':'struct N1::S'))))
Now we can tell that the second call is 'using' (no pun intended) the using
declaration, and *which* using declaration it sees. Without this, we can
mistake calls that go through using declarations for ADL calls, and have no way
to attribute names looked up with using declarations to the appropriate
UsingDecl.
llvm-svn: 130670
2011-05-02 07:48:14 +08:00
|
|
|
if (E->getDecl() != E->getFoundDecl()) {
|
|
|
|
FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl()));
|
|
|
|
if (!FoundD)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
Add an optional field attached to a DeclRefExpr which points back to the
Decl actually found via name lookup & overload resolution when that Decl
is different from the ValueDecl which is actually referenced by the
expression.
This can be used by AST consumers to correctly attribute references to
the spelling location of a using declaration, and otherwise gain insight
into the name resolution performed by Clang.
The public interface to DRE is kept as narrow as possible: we provide
a getFoundDecl() which always returns a NamedDecl, either the ValueDecl
referenced or the new, more precise NamedDecl if present. This way AST
clients can code against getFoundDecl without know when exactly the AST
has a split representation.
For an example of the data this provides consider:
% cat x.cc
namespace N1 {
struct S {};
void f(const S&);
}
void test(N1::S s) {
f(s);
using N1::f;
f(s);
}
% ./bin/clang -fsyntax-only -Xclang -ast-dump x.cc
[...]
void test(N1::S s) (CompoundStmt 0x5b02010 <x.cc:5:20, line:9:1>
(CallExpr 0x5b01df0 <line:6:3, col:6> 'void'
(ImplicitCastExpr 0x5b01dd8 <col:3> 'void (*)(const struct N1::S &)' <FunctionToPointerDecay>
(DeclRefExpr 0x5b01d80 <col:3> 'void (const struct N1::S &)' lvalue Function 0x5b01a20 'f' 'void (const struct N1::S &)'))
(ImplicitCastExpr 0x5b01e20 <col:5> 'const struct N1::S' lvalue <NoOp>
(DeclRefExpr 0x5b01d58 <col:5> 'N1::S':'struct N1::S' lvalue ParmVar 0x5b01b60 's' 'N1::S':'struct N1::S')))
(DeclStmt 0x5b01ee0 <line:7:3, col:14>
0x5b01e40 "UsingN1::;")
(CallExpr 0x5b01fc8 <line:8:3, col:6> 'void'
(ImplicitCastExpr 0x5b01fb0 <col:3> 'void (*)(const struct N1::S &)' <FunctionToPointerDecay>
(DeclRefExpr 0x5b01f80 <col:3> 'void (const struct N1::S &)' lvalue Function 0x5b01a20 'f' 'void (const struct N1::S &)' (UsingShadow 0x5b01ea0 'f')))
(ImplicitCastExpr 0x5b01ff8 <col:5> 'const struct N1::S' lvalue <NoOp>
(DeclRefExpr 0x5b01f58 <col:5> 'N1::S':'struct N1::S' lvalue ParmVar 0x5b01b60 's' 'N1::S':'struct N1::S'))))
Now we can tell that the second call is 'using' (no pun intended) the using
declaration, and *which* using declaration it sees. Without this, we can
mistake calls that go through using declarations for ADL calls, and have no way
to attribute names looked up with using declarations to the appropriate
UsingDecl.
llvm-svn: 130670
2011-05-02 07:48:14 +08:00
|
|
|
}
|
2010-02-19 09:17:02 +08:00
|
|
|
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2011-10-05 15:56:41 +08:00
|
|
|
|
|
|
|
DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(),
|
|
|
|
Importer.Import(E->getQualifierLoc()),
|
2012-01-27 17:46:47 +08:00
|
|
|
Importer.Import(E->getTemplateKeywordLoc()),
|
2011-10-05 15:56:41 +08:00
|
|
|
ToD,
|
2015-01-12 18:17:46 +08:00
|
|
|
E->refersToEnclosingVariableOrCapture(),
|
2011-10-05 15:56:41 +08:00
|
|
|
Importer.Import(E->getLocation()),
|
|
|
|
T, E->getValueKind(),
|
|
|
|
FoundD,
|
2014-05-12 13:36:57 +08:00
|
|
|
/*FIXME:TemplateArgs=*/nullptr);
|
2011-10-05 15:56:41 +08:00
|
|
|
if (E->hadMultipleCandidates())
|
|
|
|
DRE->setHadMultipleCandidates(true);
|
|
|
|
return DRE;
|
2010-02-19 09:17:02 +08:00
|
|
|
}
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return new (Importer.getToContext()) ImplicitValueInitExpr(T);
|
|
|
|
}
|
|
|
|
|
|
|
|
ASTNodeImporter::Designator
|
|
|
|
ASTNodeImporter::ImportDesignator(const Designator &D) {
|
|
|
|
if (D.isFieldDesignator()) {
|
|
|
|
IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
|
|
|
|
// Caller checks for import error
|
|
|
|
return Designator(ToFieldName, Importer.Import(D.getDotLoc()),
|
|
|
|
Importer.Import(D.getFieldLoc()));
|
|
|
|
}
|
|
|
|
if (D.isArrayDesignator())
|
|
|
|
return Designator(D.getFirstExprIndex(),
|
|
|
|
Importer.Import(D.getLBracketLoc()),
|
|
|
|
Importer.Import(D.getRBracketLoc()));
|
|
|
|
|
|
|
|
assert(D.isArrayRangeDesignator());
|
|
|
|
return Designator(D.getFirstExprIndex(),
|
|
|
|
Importer.Import(D.getLBracketLoc()),
|
|
|
|
Importer.Import(D.getEllipsisLoc()),
|
|
|
|
Importer.Import(D.getRBracketLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) {
|
|
|
|
Expr *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit()));
|
|
|
|
if (!Init)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1);
|
|
|
|
// List elements from the second, the first is Init itself
|
|
|
|
for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) {
|
|
|
|
if (Expr *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I))))
|
|
|
|
IndexExprs[I - 1] = Arg;
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<Designator, 4> Designators(DIE->size());
|
2016-06-23 08:15:04 +08:00
|
|
|
llvm::transform(DIE->designators(), Designators.begin(),
|
|
|
|
[this](const Designator &D) -> Designator {
|
|
|
|
return ImportDesignator(D);
|
|
|
|
});
|
2016-04-14 19:51:27 +08:00
|
|
|
|
2016-06-23 08:15:04 +08:00
|
|
|
for (const Designator &D : DIE->designators())
|
|
|
|
if (D.isFieldDesignator() && !D.getFieldName())
|
2016-04-14 19:51:27 +08:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return DesignatedInitExpr::Create(
|
2016-06-23 08:15:04 +08:00
|
|
|
Importer.getToContext(), Designators,
|
2016-04-14 19:51:27 +08:00
|
|
|
IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()),
|
|
|
|
DIE->usesGNUSyntax(), Init);
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext())
|
|
|
|
CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation()));
|
|
|
|
}
|
|
|
|
|
2010-02-12 03:21:55 +08:00
|
|
|
Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-12 03:21:55 +08:00
|
|
|
|
2010-08-28 17:06:06 +08:00
|
|
|
return IntegerLiteral::Create(Importer.getToContext(),
|
|
|
|
E->getValue(), T,
|
|
|
|
Importer.Import(E->getLocation()));
|
2010-02-12 03:21:55 +08:00
|
|
|
}
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return FloatingLiteral::Create(Importer.getToContext(),
|
|
|
|
E->getValue(), E->isExact(), T,
|
|
|
|
Importer.Import(E->getLocation()));
|
|
|
|
}
|
|
|
|
|
2010-02-18 10:21:22 +08:00
|
|
|
Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2011-07-27 13:40:30 +08:00
|
|
|
return new (Importer.getToContext()) CharacterLiteral(E->getValue(),
|
|
|
|
E->getKind(), T,
|
2010-02-18 10:21:22 +08:00
|
|
|
Importer.Import(E->getLocation()));
|
|
|
|
}
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
SmallVector<SourceLocation, 4> Locations(E->getNumConcatenated());
|
|
|
|
ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin());
|
|
|
|
|
|
|
|
return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
|
|
|
|
E->getKind(), E->isPascal(), T,
|
|
|
|
Locations.data(), Locations.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo());
|
|
|
|
if (!TInfo)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Expr *Init = Importer.Import(E->getInitializer());
|
|
|
|
if (!Init)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext()) CompoundLiteralExpr(
|
|
|
|
Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(),
|
|
|
|
Init, E->isFileScope());
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
SmallVector<Expr *, 6> Exprs(E->getNumSubExprs());
|
|
|
|
if (ImportArrayChecked(
|
|
|
|
E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
|
|
|
|
Exprs.begin()))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext()) AtomicExpr(
|
|
|
|
Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(),
|
|
|
|
Importer.Import(E->getRParenLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
LabelDecl *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel()));
|
|
|
|
if (!ToLabel)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext()) AddrLabelExpr(
|
|
|
|
Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()),
|
|
|
|
ToLabel, T);
|
|
|
|
}
|
|
|
|
|
2010-02-19 09:07:06 +08:00
|
|
|
Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) {
|
|
|
|
Expr *SubExpr = Importer.Import(E->getSubExpr());
|
|
|
|
if (!SubExpr)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-19 09:07:06 +08:00
|
|
|
return new (Importer.getToContext())
|
|
|
|
ParenExpr(Importer.Import(E->getLParen()),
|
|
|
|
Importer.Import(E->getRParen()),
|
|
|
|
SubExpr);
|
|
|
|
}
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
Expr *ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) {
|
|
|
|
SmallVector<Expr *, 4> Exprs(E->getNumExprs());
|
|
|
|
if (ImportArrayChecked(
|
|
|
|
E->getExprs(), E->getExprs() + E->getNumExprs(), Exprs.begin()))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext()) ParenListExpr(
|
|
|
|
Importer.getToContext(), Importer.Import(E->getLParenLoc()),
|
|
|
|
Exprs, Importer.Import(E->getLParenLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitStmtExpr(StmtExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
CompoundStmt *ToSubStmt = cast_or_null<CompoundStmt>(
|
|
|
|
Importer.Import(E->getSubStmt()));
|
|
|
|
if (!ToSubStmt && E->getSubStmt())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext()) StmtExpr(ToSubStmt, T,
|
|
|
|
Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc()));
|
|
|
|
}
|
|
|
|
|
2010-02-19 09:07:06 +08:00
|
|
|
Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-19 09:07:06 +08:00
|
|
|
|
|
|
|
Expr *SubExpr = Importer.Import(E->getSubExpr());
|
|
|
|
if (!SubExpr)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-19 09:07:06 +08:00
|
|
|
return new (Importer.getToContext()) UnaryOperator(SubExpr, E->getOpcode(),
|
2010-11-18 14:31:45 +08:00
|
|
|
T, E->getValueKind(),
|
|
|
|
E->getObjectKind(),
|
2010-02-19 09:07:06 +08:00
|
|
|
Importer.Import(E->getOperatorLoc()));
|
|
|
|
}
|
|
|
|
|
2011-03-12 03:24:49 +08:00
|
|
|
Expr *ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(
|
|
|
|
UnaryExprOrTypeTraitExpr *E) {
|
2010-02-19 09:24:23 +08:00
|
|
|
QualType ResultType = Importer.Import(E->getType());
|
|
|
|
|
|
|
|
if (E->isArgumentType()) {
|
|
|
|
TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo());
|
|
|
|
if (!TInfo)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2011-03-12 03:24:49 +08:00
|
|
|
return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(),
|
|
|
|
TInfo, ResultType,
|
2010-02-19 09:24:23 +08:00
|
|
|
Importer.Import(E->getOperatorLoc()),
|
|
|
|
Importer.Import(E->getRParenLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *SubExpr = Importer.Import(E->getArgumentExpr());
|
|
|
|
if (!SubExpr)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2011-03-12 03:24:49 +08:00
|
|
|
return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(),
|
|
|
|
SubExpr, ResultType,
|
2010-02-19 09:24:23 +08:00
|
|
|
Importer.Import(E->getOperatorLoc()),
|
|
|
|
Importer.Import(E->getRParenLoc()));
|
|
|
|
}
|
|
|
|
|
2010-02-19 09:07:06 +08:00
|
|
|
Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-19 09:07:06 +08:00
|
|
|
|
|
|
|
Expr *LHS = Importer.Import(E->getLHS());
|
|
|
|
if (!LHS)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-19 09:07:06 +08:00
|
|
|
Expr *RHS = Importer.Import(E->getRHS());
|
|
|
|
if (!RHS)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-19 09:07:06 +08:00
|
|
|
return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(),
|
2010-11-18 14:31:45 +08:00
|
|
|
T, E->getValueKind(),
|
|
|
|
E->getObjectKind(),
|
2012-10-02 12:45:10 +08:00
|
|
|
Importer.Import(E->getOperatorLoc()),
|
|
|
|
E->isFPContractable());
|
2010-02-19 09:07:06 +08:00
|
|
|
}
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Expr *ToLHS = Importer.Import(E->getLHS());
|
|
|
|
if (!ToLHS)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Expr *ToRHS = Importer.Import(E->getRHS());
|
|
|
|
if (!ToRHS)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Expr *ToCond = Importer.Import(E->getCond());
|
|
|
|
if (!ToCond)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext()) ConditionalOperator(
|
|
|
|
ToCond, Importer.Import(E->getQuestionLoc()),
|
|
|
|
ToLHS, Importer.Import(E->getColonLoc()),
|
|
|
|
ToRHS, T, E->getValueKind(), E->getObjectKind());
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitBinaryConditionalOperator(
|
|
|
|
BinaryConditionalOperator *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Expr *Common = Importer.Import(E->getCommon());
|
|
|
|
if (!Common)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Expr *Cond = Importer.Import(E->getCond());
|
|
|
|
if (!Cond)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
OpaqueValueExpr *OpaqueValue = cast_or_null<OpaqueValueExpr>(
|
|
|
|
Importer.Import(E->getOpaqueValue()));
|
|
|
|
if (!OpaqueValue)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Expr *TrueExpr = Importer.Import(E->getTrueExpr());
|
|
|
|
if (!TrueExpr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Expr *FalseExpr = Importer.Import(E->getFalseExpr());
|
|
|
|
if (!FalseExpr)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext()) BinaryConditionalOperator(
|
|
|
|
Common, OpaqueValue, Cond, TrueExpr, FalseExpr,
|
|
|
|
Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()),
|
|
|
|
T, E->getValueKind(), E->getObjectKind());
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Expr *SourceExpr = Importer.Import(E->getSourceExpr());
|
|
|
|
if (!SourceExpr && E->getSourceExpr())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext()) OpaqueValueExpr(
|
|
|
|
Importer.Import(E->getExprLoc()), T, E->getValueKind(),
|
|
|
|
E->getObjectKind(), SourceExpr);
|
|
|
|
}
|
|
|
|
|
2010-02-19 09:07:06 +08:00
|
|
|
Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-19 09:07:06 +08:00
|
|
|
QualType CompLHSType = Importer.Import(E->getComputationLHSType());
|
|
|
|
if (CompLHSType.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-19 09:07:06 +08:00
|
|
|
QualType CompResultType = Importer.Import(E->getComputationResultType());
|
|
|
|
if (CompResultType.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-19 09:07:06 +08:00
|
|
|
Expr *LHS = Importer.Import(E->getLHS());
|
|
|
|
if (!LHS)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-19 09:07:06 +08:00
|
|
|
Expr *RHS = Importer.Import(E->getRHS());
|
|
|
|
if (!RHS)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-19 09:07:06 +08:00
|
|
|
return new (Importer.getToContext())
|
|
|
|
CompoundAssignOperator(LHS, RHS, E->getOpcode(),
|
2010-11-18 14:31:45 +08:00
|
|
|
T, E->getValueKind(),
|
|
|
|
E->getObjectKind(),
|
|
|
|
CompLHSType, CompResultType,
|
2012-10-02 12:45:10 +08:00
|
|
|
Importer.Import(E->getOperatorLoc()),
|
|
|
|
E->isFPContractable());
|
2010-02-19 09:07:06 +08:00
|
|
|
}
|
|
|
|
|
2011-03-26 20:38:21 +08:00
|
|
|
static bool ImportCastPath(CastExpr *E, CXXCastPath &Path) {
|
2010-08-07 14:22:56 +08:00
|
|
|
if (E->path_empty()) return false;
|
|
|
|
|
|
|
|
// TODO: import cast paths
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-13 06:17:39 +08:00
|
|
|
Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-13 06:17:39 +08:00
|
|
|
|
|
|
|
Expr *SubExpr = Importer.Import(E->getSubExpr());
|
|
|
|
if (!SubExpr)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-08-07 14:22:56 +08:00
|
|
|
|
|
|
|
CXXCastPath BasePath;
|
|
|
|
if (ImportCastPath(E, BasePath))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-08-07 14:22:56 +08:00
|
|
|
|
|
|
|
return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(),
|
2010-08-25 18:28:54 +08:00
|
|
|
SubExpr, &BasePath, E->getValueKind());
|
2010-02-13 06:17:39 +08:00
|
|
|
}
|
|
|
|
|
2010-02-19 09:32:14 +08:00
|
|
|
Expr *ASTNodeImporter::VisitCStyleCastExpr(CStyleCastExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-19 09:32:14 +08:00
|
|
|
Expr *SubExpr = Importer.Import(E->getSubExpr());
|
|
|
|
if (!SubExpr)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-19 09:32:14 +08:00
|
|
|
|
|
|
|
TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten());
|
|
|
|
if (!TInfo && E->getTypeInfoAsWritten())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-08-07 14:22:56 +08:00
|
|
|
CXXCastPath BasePath;
|
|
|
|
if (ImportCastPath(E, BasePath))
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-08-07 14:22:56 +08:00
|
|
|
|
2010-11-18 14:31:45 +08:00
|
|
|
return CStyleCastExpr::Create(Importer.getToContext(), T,
|
|
|
|
E->getValueKind(), E->getCastKind(),
|
2010-08-07 14:22:56 +08:00
|
|
|
SubExpr, &BasePath, TInfo,
|
|
|
|
Importer.Import(E->getLParenLoc()),
|
|
|
|
Importer.Import(E->getRParenLoc()));
|
2010-02-19 09:32:14 +08:00
|
|
|
}
|
|
|
|
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
CXXConstructorDecl *ToCCD =
|
2016-05-17 04:48:03 +08:00
|
|
|
dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor()));
|
2016-05-12 04:37:46 +08:00
|
|
|
if (!ToCCD)
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
SmallVector<Expr *, 6> ToArgs(E->getNumArgs());
|
|
|
|
if (ImportArrayChecked(E->getArgs(), E->getArgs() + E->getNumArgs(),
|
|
|
|
ToArgs.begin()))
|
2016-03-29 05:43:01 +08:00
|
|
|
return nullptr;
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
|
|
|
|
return CXXConstructExpr::Create(Importer.getToContext(), T,
|
|
|
|
Importer.Import(E->getLocation()),
|
2016-06-10 08:58:19 +08:00
|
|
|
ToCCD, E->isElidable(),
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
ToArgs, E->hadMultipleCandidates(),
|
|
|
|
E->isListInitialization(),
|
|
|
|
E->isStdInitListInitialization(),
|
|
|
|
E->requiresZeroInitialization(),
|
|
|
|
E->getConstructionKind(),
|
|
|
|
Importer.Import(E->getParenOrBraceRange()));
|
|
|
|
}
|
|
|
|
|
2016-03-29 05:43:01 +08:00
|
|
|
Expr *ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Expr *ToFn = Importer.Import(E->getCallee());
|
|
|
|
if (!ToFn)
|
|
|
|
return nullptr;
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
SmallVector<Expr *, 4> ToArgs(E->getNumArgs());
|
2016-03-29 05:43:01 +08:00
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
if (ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
|
2016-03-29 05:43:01 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
return new (Importer.getToContext()) CXXMemberCallExpr(
|
|
|
|
Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(),
|
|
|
|
Importer.Import(E->getRParenLoc()));
|
2016-03-29 05:43:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext())
|
|
|
|
CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit());
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (Importer.getToContext())
|
|
|
|
CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Expr *ToBase = Importer.Import(E->getBase());
|
|
|
|
if (!ToBase && E->getBase())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
ValueDecl *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl()));
|
|
|
|
if (!ToMember && E->getMemberDecl())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
DeclAccessPair ToFoundDecl = DeclAccessPair::make(
|
|
|
|
dyn_cast<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())),
|
|
|
|
E->getFoundDecl().getAccess());
|
|
|
|
|
|
|
|
DeclarationNameInfo ToMemberNameInfo(
|
|
|
|
Importer.Import(E->getMemberNameInfo().getName()),
|
|
|
|
Importer.Import(E->getMemberNameInfo().getLoc()));
|
|
|
|
|
|
|
|
if (E->hasExplicitTemplateArgs()) {
|
|
|
|
return nullptr; // FIXME: handle template arguments
|
|
|
|
}
|
|
|
|
|
|
|
|
return MemberExpr::Create(Importer.getToContext(), ToBase,
|
|
|
|
E->isArrow(),
|
|
|
|
Importer.Import(E->getOperatorLoc()),
|
|
|
|
Importer.Import(E->getQualifierLoc()),
|
|
|
|
Importer.Import(E->getTemplateKeywordLoc()),
|
|
|
|
ToMember, ToFoundDecl, ToMemberNameInfo,
|
|
|
|
nullptr, T, E->getValueKind(),
|
|
|
|
E->getObjectKind());
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) {
|
|
|
|
QualType T = Importer.Import(E->getType());
|
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
Expr *ToCallee = Importer.Import(E->getCallee());
|
|
|
|
if (!ToCallee && E->getCallee())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
unsigned NumArgs = E->getNumArgs();
|
|
|
|
|
|
|
|
llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
|
|
|
|
|
|
|
|
for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) {
|
|
|
|
Expr *FromArg = E->getArg(ai);
|
|
|
|
Expr *ToArg = Importer.Import(FromArg);
|
|
|
|
if (!ToArg)
|
|
|
|
return nullptr;
|
|
|
|
ToArgs[ai] = ToArg;
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr **ToArgs_Copied = new (Importer.getToContext())
|
|
|
|
Expr*[NumArgs];
|
|
|
|
|
|
|
|
for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai)
|
|
|
|
ToArgs_Copied[ai] = ToArgs[ai];
|
|
|
|
|
|
|
|
return new (Importer.getToContext())
|
|
|
|
CallExpr(Importer.getToContext(), ToCallee,
|
2015-09-27 11:44:08 +08:00
|
|
|
llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(),
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
Importer.Import(E->getRParenLoc()));
|
|
|
|
}
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *ILE) {
|
|
|
|
QualType T = Importer.Import(ILE->getType());
|
2016-03-29 05:43:01 +08:00
|
|
|
if (T.isNull())
|
|
|
|
return nullptr;
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
llvm::SmallVector<Expr *, 4> Exprs(ILE->getNumInits());
|
|
|
|
if (ImportArrayChecked(
|
|
|
|
ILE->getInits(), ILE->getInits() + ILE->getNumInits(), Exprs.begin()))
|
2016-03-29 05:43:01 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2016-04-14 19:51:27 +08:00
|
|
|
ASTContext &ToCtx = Importer.getToContext();
|
|
|
|
InitListExpr *To = new (ToCtx) InitListExpr(
|
|
|
|
ToCtx, Importer.Import(ILE->getLBraceLoc()),
|
|
|
|
Exprs, Importer.Import(ILE->getLBraceLoc()));
|
|
|
|
To->setType(T);
|
|
|
|
|
|
|
|
if (ILE->hasArrayFiller()) {
|
|
|
|
Expr *Filler = Importer.Import(ILE->getArrayFiller());
|
|
|
|
if (!Filler)
|
|
|
|
return nullptr;
|
|
|
|
To->setArrayFiller(Filler);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) {
|
|
|
|
FieldDecl *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD));
|
|
|
|
if (!ToFD)
|
|
|
|
return nullptr;
|
|
|
|
To->setInitializedFieldInUnion(ToFD);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (InitListExpr *SyntForm = ILE->getSyntacticForm()) {
|
|
|
|
InitListExpr *ToSyntForm = cast_or_null<InitListExpr>(
|
|
|
|
Importer.Import(SyntForm));
|
|
|
|
if (!ToSyntForm)
|
|
|
|
return nullptr;
|
|
|
|
To->setSyntacticForm(ToSyntForm);
|
|
|
|
}
|
|
|
|
|
|
|
|
To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator());
|
|
|
|
To->setValueDependent(ILE->isValueDependent());
|
|
|
|
To->setInstantiationDependent(ILE->isInstantiationDependent());
|
|
|
|
|
|
|
|
return To;
|
2016-03-29 05:43:01 +08:00
|
|
|
}
|
|
|
|
|
2016-05-17 04:48:03 +08:00
|
|
|
Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {
|
|
|
|
FieldDecl *ToField = llvm::dyn_cast_or_null<FieldDecl>(
|
|
|
|
Importer.Import(DIE->getField()));
|
|
|
|
if (!ToField && DIE->getField())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return CXXDefaultInitExpr::Create(
|
|
|
|
Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField);
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
|
|
|
|
QualType ToType = Importer.Import(E->getType());
|
|
|
|
if (ToType.isNull() && !E->getType().isNull())
|
|
|
|
return nullptr;
|
|
|
|
ExprValueKind VK = E->getValueKind();
|
|
|
|
CastKind CK = E->getCastKind();
|
|
|
|
Expr *ToOp = Importer.Import(E->getSubExpr());
|
|
|
|
if (!ToOp && E->getSubExpr())
|
|
|
|
return nullptr;
|
|
|
|
CXXCastPath BasePath;
|
|
|
|
if (ImportCastPath(E, BasePath))
|
|
|
|
return nullptr;
|
|
|
|
TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten());
|
|
|
|
SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc());
|
|
|
|
SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc());
|
|
|
|
SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets());
|
|
|
|
|
|
|
|
if (isa<CXXStaticCastExpr>(E)) {
|
|
|
|
return CXXStaticCastExpr::Create(
|
|
|
|
Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath,
|
|
|
|
ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
|
|
|
|
} else if (isa<CXXDynamicCastExpr>(E)) {
|
|
|
|
return CXXDynamicCastExpr::Create(
|
|
|
|
Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath,
|
|
|
|
ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
|
|
|
|
} else if (isa<CXXReinterpretCastExpr>(E)) {
|
|
|
|
return CXXReinterpretCastExpr::Create(
|
|
|
|
Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath,
|
|
|
|
ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-19 04:06:41 +08:00
|
|
|
ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
|
2011-01-18 11:11:38 +08:00
|
|
|
ASTContext &FromContext, FileManager &FromFileManager,
|
|
|
|
bool MinimalImport)
|
2010-02-06 01:54:41 +08:00
|
|
|
: ToContext(ToContext), FromContext(FromContext),
|
2011-01-18 11:11:38 +08:00
|
|
|
ToFileManager(ToFileManager), FromFileManager(FromFileManager),
|
2012-12-20 10:22:15 +08:00
|
|
|
Minimal(MinimalImport), LastDiagFromFrom(false)
|
2011-01-18 11:11:38 +08:00
|
|
|
{
|
2010-02-10 03:21:46 +08:00
|
|
|
ImportedDecls[FromContext.getTranslationUnitDecl()]
|
|
|
|
= ToContext.getTranslationUnitDecl();
|
|
|
|
}
|
|
|
|
|
2015-10-20 21:23:58 +08:00
|
|
|
ASTImporter::~ASTImporter() { }
|
2010-02-06 01:54:41 +08:00
|
|
|
|
|
|
|
QualType ASTImporter::Import(QualType FromT) {
|
|
|
|
if (FromT.isNull())
|
|
|
|
return QualType();
|
2011-01-19 14:33:43 +08:00
|
|
|
|
|
|
|
const Type *fromTy = FromT.getTypePtr();
|
2010-02-06 01:54:41 +08:00
|
|
|
|
2010-02-08 23:18:58 +08:00
|
|
|
// Check whether we've already imported this type.
|
2011-01-19 14:33:43 +08:00
|
|
|
llvm::DenseMap<const Type *, const Type *>::iterator Pos
|
|
|
|
= ImportedTypes.find(fromTy);
|
2010-02-08 23:18:58 +08:00
|
|
|
if (Pos != ImportedTypes.end())
|
2011-01-19 14:33:43 +08:00
|
|
|
return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers());
|
2010-02-06 01:54:41 +08:00
|
|
|
|
2010-02-08 23:18:58 +08:00
|
|
|
// Import the type
|
2010-02-06 01:54:41 +08:00
|
|
|
ASTNodeImporter Importer(*this);
|
2011-01-19 14:33:43 +08:00
|
|
|
QualType ToT = Importer.Visit(fromTy);
|
2010-02-06 01:54:41 +08:00
|
|
|
if (ToT.isNull())
|
|
|
|
return ToT;
|
|
|
|
|
2010-02-08 23:18:58 +08:00
|
|
|
// Record the imported type.
|
2011-01-19 14:33:43 +08:00
|
|
|
ImportedTypes[fromTy] = ToT.getTypePtr();
|
2010-02-08 23:18:58 +08:00
|
|
|
|
2011-01-19 14:33:43 +08:00
|
|
|
return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers());
|
2010-02-06 01:54:41 +08:00
|
|
|
}
|
|
|
|
|
2010-02-10 03:21:46 +08:00
|
|
|
TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) {
|
2010-02-11 01:47:19 +08:00
|
|
|
if (!FromTSI)
|
|
|
|
return FromTSI;
|
|
|
|
|
|
|
|
// FIXME: For now we just create a "trivial" type source info based
|
2010-07-27 00:56:01 +08:00
|
|
|
// on the type and a single location. Implement a real version of this.
|
2010-02-11 01:47:19 +08:00
|
|
|
QualType T = Import(FromTSI->getType());
|
|
|
|
if (T.isNull())
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-11 01:47:19 +08:00
|
|
|
|
|
|
|
return ToContext.getTrivialTypeSourceInfo(T,
|
2015-07-07 11:57:35 +08:00
|
|
|
Import(FromTSI->getTypeLoc().getLocStart()));
|
2010-02-10 03:21:46 +08:00
|
|
|
}
|
|
|
|
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) {
|
|
|
|
llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD);
|
|
|
|
if (Pos != ImportedDecls.end()) {
|
|
|
|
Decl *ToD = Pos->second;
|
|
|
|
ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD);
|
|
|
|
return ToD;
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-10 03:21:46 +08:00
|
|
|
Decl *ASTImporter::Import(Decl *FromD) {
|
|
|
|
if (!FromD)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-10 03:21:46 +08:00
|
|
|
|
2011-07-30 07:31:30 +08:00
|
|
|
ASTNodeImporter Importer(*this);
|
|
|
|
|
2010-02-10 03:21:46 +08:00
|
|
|
// Check whether we've already imported this declaration.
|
|
|
|
llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD);
|
2011-07-30 07:31:30 +08:00
|
|
|
if (Pos != ImportedDecls.end()) {
|
|
|
|
Decl *ToD = Pos->second;
|
|
|
|
Importer.ImportDefinitionIfNeeded(FromD, ToD);
|
|
|
|
return ToD;
|
|
|
|
}
|
2010-02-10 03:21:46 +08:00
|
|
|
|
|
|
|
// Import the type
|
|
|
|
Decl *ToD = Importer.Visit(FromD);
|
|
|
|
if (!ToD)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-10 03:21:46 +08:00
|
|
|
// Record the imported declaration.
|
|
|
|
ImportedDecls[FromD] = ToD;
|
2010-02-16 07:54:17 +08:00
|
|
|
|
|
|
|
if (TagDecl *FromTag = dyn_cast<TagDecl>(FromD)) {
|
|
|
|
// Keep track of anonymous tags that have an associated typedef.
|
2011-04-15 22:24:37 +08:00
|
|
|
if (FromTag->getTypedefNameForAnonDecl())
|
2010-02-16 07:54:17 +08:00
|
|
|
AnonTagsWithPendingTypedefs.push_back(FromTag);
|
2011-04-15 22:24:37 +08:00
|
|
|
} else if (TypedefNameDecl *FromTypedef = dyn_cast<TypedefNameDecl>(FromD)) {
|
2010-02-16 07:54:17 +08:00
|
|
|
// When we've finished transforming a typedef, see whether it was the
|
|
|
|
// typedef for an anonymous tag.
|
2013-07-04 11:08:24 +08:00
|
|
|
for (SmallVectorImpl<TagDecl *>::iterator
|
2010-02-16 07:54:17 +08:00
|
|
|
FromTag = AnonTagsWithPendingTypedefs.begin(),
|
|
|
|
FromTagEnd = AnonTagsWithPendingTypedefs.end();
|
|
|
|
FromTag != FromTagEnd; ++FromTag) {
|
2011-04-15 22:24:37 +08:00
|
|
|
if ((*FromTag)->getTypedefNameForAnonDecl() == FromTypedef) {
|
2010-02-16 07:54:17 +08:00
|
|
|
if (TagDecl *ToTag = cast_or_null<TagDecl>(Import(*FromTag))) {
|
|
|
|
// We found the typedef for an anonymous tag; link them.
|
2011-04-15 22:24:37 +08:00
|
|
|
ToTag->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(ToD));
|
2010-02-16 07:54:17 +08:00
|
|
|
AnonTagsWithPendingTypedefs.erase(FromTag);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-10 03:21:46 +08:00
|
|
|
return ToD;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) {
|
|
|
|
if (!FromDC)
|
|
|
|
return FromDC;
|
|
|
|
|
2012-01-25 02:36:04 +08:00
|
|
|
DeclContext *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC)));
|
2012-02-02 05:00:38 +08:00
|
|
|
if (!ToDC)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2012-02-02 05:00:38 +08:00
|
|
|
// When we're using a record/enum/Objective-C class/protocol as a context, we
|
|
|
|
// need it to have a definition.
|
|
|
|
if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
|
2012-01-25 09:13:20 +08:00
|
|
|
RecordDecl *FromRecord = cast<RecordDecl>(FromDC);
|
2012-02-02 05:00:38 +08:00
|
|
|
if (ToRecord->isCompleteDefinition()) {
|
|
|
|
// Do nothing.
|
|
|
|
} else if (FromRecord->isCompleteDefinition()) {
|
|
|
|
ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord,
|
|
|
|
ASTNodeImporter::IDK_Basic);
|
|
|
|
} else {
|
|
|
|
CompleteDecl(ToRecord);
|
|
|
|
}
|
|
|
|
} else if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
|
|
|
|
EnumDecl *FromEnum = cast<EnumDecl>(FromDC);
|
|
|
|
if (ToEnum->isCompleteDefinition()) {
|
|
|
|
// Do nothing.
|
|
|
|
} else if (FromEnum->isCompleteDefinition()) {
|
|
|
|
ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum,
|
|
|
|
ASTNodeImporter::IDK_Basic);
|
|
|
|
} else {
|
|
|
|
CompleteDecl(ToEnum);
|
|
|
|
}
|
|
|
|
} else if (ObjCInterfaceDecl *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
|
|
|
|
ObjCInterfaceDecl *FromClass = cast<ObjCInterfaceDecl>(FromDC);
|
|
|
|
if (ToClass->getDefinition()) {
|
|
|
|
// Do nothing.
|
|
|
|
} else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
|
|
|
|
ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass,
|
|
|
|
ASTNodeImporter::IDK_Basic);
|
|
|
|
} else {
|
|
|
|
CompleteDecl(ToClass);
|
|
|
|
}
|
|
|
|
} else if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
|
|
|
|
ObjCProtocolDecl *FromProto = cast<ObjCProtocolDecl>(FromDC);
|
|
|
|
if (ToProto->getDefinition()) {
|
|
|
|
// Do nothing.
|
|
|
|
} else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
|
|
|
|
ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto,
|
|
|
|
ASTNodeImporter::IDK_Basic);
|
|
|
|
} else {
|
|
|
|
CompleteDecl(ToProto);
|
|
|
|
}
|
2012-01-25 02:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ToDC;
|
2010-02-10 03:21:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Expr *ASTImporter::Import(Expr *FromE) {
|
|
|
|
if (!FromE)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-10 03:21:46 +08:00
|
|
|
|
|
|
|
return cast_or_null<Expr>(Import(cast<Stmt>(FromE)));
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ASTImporter::Import(Stmt *FromS) {
|
|
|
|
if (!FromS)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-10 03:21:46 +08:00
|
|
|
|
2010-02-12 03:21:55 +08:00
|
|
|
// Check whether we've already imported this declaration.
|
|
|
|
llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
|
|
|
|
if (Pos != ImportedStmts.end())
|
|
|
|
return Pos->second;
|
|
|
|
|
|
|
|
// Import the type
|
|
|
|
ASTNodeImporter Importer(*this);
|
|
|
|
Stmt *ToS = Importer.Visit(FromS);
|
|
|
|
if (!ToS)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2010-02-12 03:21:55 +08:00
|
|
|
// Record the imported declaration.
|
|
|
|
ImportedStmts[FromS] = ToS;
|
|
|
|
return ToS;
|
2010-02-10 03:21:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) {
|
|
|
|
if (!FromNNS)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-10 03:21:46 +08:00
|
|
|
|
2011-04-28 00:48:40 +08:00
|
|
|
NestedNameSpecifier *prefix = Import(FromNNS->getPrefix());
|
|
|
|
|
|
|
|
switch (FromNNS->getKind()) {
|
|
|
|
case NestedNameSpecifier::Identifier:
|
|
|
|
if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) {
|
|
|
|
return NestedNameSpecifier::Create(ToContext, prefix, II);
|
|
|
|
}
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2011-04-28 00:48:40 +08:00
|
|
|
|
|
|
|
case NestedNameSpecifier::Namespace:
|
|
|
|
if (NamespaceDecl *NS =
|
|
|
|
cast<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) {
|
|
|
|
return NestedNameSpecifier::Create(ToContext, prefix, NS);
|
|
|
|
}
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2011-04-28 00:48:40 +08:00
|
|
|
|
|
|
|
case NestedNameSpecifier::NamespaceAlias:
|
|
|
|
if (NamespaceAliasDecl *NSAD =
|
|
|
|
cast<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) {
|
|
|
|
return NestedNameSpecifier::Create(ToContext, prefix, NSAD);
|
|
|
|
}
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2011-04-28 00:48:40 +08:00
|
|
|
|
|
|
|
case NestedNameSpecifier::Global:
|
|
|
|
return NestedNameSpecifier::GlobalSpecifier(ToContext);
|
|
|
|
|
2014-09-26 08:28:20 +08:00
|
|
|
case NestedNameSpecifier::Super:
|
|
|
|
if (CXXRecordDecl *RD =
|
|
|
|
cast<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) {
|
|
|
|
return NestedNameSpecifier::SuperSpecifier(ToContext, RD);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
|
2011-04-28 00:48:40 +08:00
|
|
|
case NestedNameSpecifier::TypeSpec:
|
|
|
|
case NestedNameSpecifier::TypeSpecWithTemplate: {
|
|
|
|
QualType T = Import(QualType(FromNNS->getAsType(), 0u));
|
|
|
|
if (!T.isNull()) {
|
|
|
|
bool bTemplate = FromNNS->getKind() ==
|
|
|
|
NestedNameSpecifier::TypeSpecWithTemplate;
|
|
|
|
return NestedNameSpecifier::Create(ToContext, prefix,
|
|
|
|
bTemplate, T.getTypePtr());
|
|
|
|
}
|
|
|
|
}
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2011-04-28 00:48:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Invalid nested name specifier kind");
|
2010-02-10 03:21:46 +08:00
|
|
|
}
|
|
|
|
|
2011-02-25 10:25:35 +08:00
|
|
|
NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) {
|
|
|
|
// FIXME: Implement!
|
|
|
|
return NestedNameSpecifierLoc();
|
|
|
|
}
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
TemplateName ASTImporter::Import(TemplateName From) {
|
|
|
|
switch (From.getKind()) {
|
|
|
|
case TemplateName::Template:
|
|
|
|
if (TemplateDecl *ToTemplate
|
|
|
|
= cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl())))
|
|
|
|
return TemplateName(ToTemplate);
|
|
|
|
|
|
|
|
return TemplateName();
|
|
|
|
|
|
|
|
case TemplateName::OverloadedTemplate: {
|
|
|
|
OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate();
|
|
|
|
UnresolvedSet<2> ToTemplates;
|
|
|
|
for (OverloadedTemplateStorage::iterator I = FromStorage->begin(),
|
|
|
|
E = FromStorage->end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if (NamedDecl *To = cast_or_null<NamedDecl>(Import(*I)))
|
|
|
|
ToTemplates.addDecl(To);
|
|
|
|
else
|
|
|
|
return TemplateName();
|
|
|
|
}
|
|
|
|
return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
|
|
|
|
ToTemplates.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
case TemplateName::QualifiedTemplate: {
|
|
|
|
QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName();
|
|
|
|
NestedNameSpecifier *Qualifier = Import(QTN->getQualifier());
|
|
|
|
if (!Qualifier)
|
|
|
|
return TemplateName();
|
|
|
|
|
|
|
|
if (TemplateDecl *ToTemplate
|
|
|
|
= cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl())))
|
|
|
|
return ToContext.getQualifiedTemplateName(Qualifier,
|
|
|
|
QTN->hasTemplateKeyword(),
|
|
|
|
ToTemplate);
|
|
|
|
|
|
|
|
return TemplateName();
|
|
|
|
}
|
|
|
|
|
|
|
|
case TemplateName::DependentTemplate: {
|
|
|
|
DependentTemplateName *DTN = From.getAsDependentTemplateName();
|
|
|
|
NestedNameSpecifier *Qualifier = Import(DTN->getQualifier());
|
|
|
|
if (!Qualifier)
|
|
|
|
return TemplateName();
|
|
|
|
|
|
|
|
if (DTN->isIdentifier()) {
|
|
|
|
return ToContext.getDependentTemplateName(Qualifier,
|
|
|
|
Import(DTN->getIdentifier()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator());
|
|
|
|
}
|
2011-06-30 16:33:18 +08:00
|
|
|
|
|
|
|
case TemplateName::SubstTemplateTemplateParm: {
|
|
|
|
SubstTemplateTemplateParmStorage *subst
|
|
|
|
= From.getAsSubstTemplateTemplateParm();
|
|
|
|
TemplateTemplateParmDecl *param
|
|
|
|
= cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter()));
|
|
|
|
if (!param)
|
|
|
|
return TemplateName();
|
|
|
|
|
|
|
|
TemplateName replacement = Import(subst->getReplacement());
|
|
|
|
if (replacement.isNull()) return TemplateName();
|
|
|
|
|
|
|
|
return ToContext.getSubstTemplateTemplateParm(param, replacement);
|
|
|
|
}
|
2011-01-15 14:45:20 +08:00
|
|
|
|
|
|
|
case TemplateName::SubstTemplateTemplateParmPack: {
|
|
|
|
SubstTemplateTemplateParmPackStorage *SubstPack
|
|
|
|
= From.getAsSubstTemplateTemplateParmPack();
|
|
|
|
TemplateTemplateParmDecl *Param
|
|
|
|
= cast_or_null<TemplateTemplateParmDecl>(
|
|
|
|
Import(SubstPack->getParameterPack()));
|
|
|
|
if (!Param)
|
|
|
|
return TemplateName();
|
|
|
|
|
|
|
|
ASTNodeImporter Importer(*this);
|
|
|
|
TemplateArgument ArgPack
|
|
|
|
= Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
|
|
|
|
if (ArgPack.isNull())
|
|
|
|
return TemplateName();
|
|
|
|
|
|
|
|
return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack);
|
|
|
|
}
|
2010-12-01 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Invalid template name kind");
|
|
|
|
}
|
|
|
|
|
2010-02-10 03:21:46 +08:00
|
|
|
SourceLocation ASTImporter::Import(SourceLocation FromLoc) {
|
|
|
|
if (FromLoc.isInvalid())
|
|
|
|
return SourceLocation();
|
|
|
|
|
2010-02-10 08:15:17 +08:00
|
|
|
SourceManager &FromSM = FromContext.getSourceManager();
|
|
|
|
|
|
|
|
// For now, map everything down to its spelling location, so that we
|
2011-07-15 08:04:35 +08:00
|
|
|
// don't have to import macro expansions.
|
|
|
|
// FIXME: Import macro expansions!
|
2010-02-10 08:15:17 +08:00
|
|
|
FromLoc = FromSM.getSpellingLoc(FromLoc);
|
|
|
|
std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
|
|
|
|
SourceManager &ToSM = ToContext.getSourceManager();
|
2014-12-10 09:26:39 +08:00
|
|
|
FileID ToFileID = Import(Decomposed.first);
|
|
|
|
if (ToFileID.isInvalid())
|
|
|
|
return SourceLocation();
|
Implemented ASTImporter support for Stmts and fixed
some bugs in the ASTImporter that this exposed:
- When importing functions, the body (if any) was
previously ignored. This patch ensures that the
body is imported also.
- When a function-local Decl is imported, the first
thing the ASTImporter does is import its context
(via ImportDeclParts()). This can trigger
importing the Decl again as part of the body of
the function (but only once, since the function's
Decl has been added to ImportedDecls). This patch
fixes that problem by extending ImportDeclParts()
to return the imported Decl if it was imported as
part of importing its context, and the patch adds
ASTImporter::GetAlreadyImportedOrNull() to support
this query. All callers of ImportDeclParts return
the imported version of the Decl if ImportDeclParts()
returns it.
- When creating functions, InnerLocStart of the source
function was re-used without importing. This is a
straight up bug, and this patch makes ASTImporter
import the InnerLocStart and use the imported version.
- When importing FileIDs, the ASTImporter previously
always tried to re-load the file for the corresponding
CacheEntry from disk. This doesn't work if the
CacheEntry corresponds to a named memory buffer. This
patch changes the code so that if the UniqueID for the
cache entry is invalid (i.e., it is not a disk file)
the whole entry is treated as if it were invalid, which
forces an in-memory copy of the buffer.
Also added test cases, using the new support committed in
236011.
llvm-svn: 236012
2015-04-29 02:41:46 +08:00
|
|
|
SourceLocation ret = ToSM.getLocForStartOfFile(ToFileID)
|
|
|
|
.getLocWithOffset(Decomposed.second);
|
|
|
|
return ret;
|
2010-02-10 03:21:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SourceRange ASTImporter::Import(SourceRange FromRange) {
|
|
|
|
return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd()));
|
|
|
|
}
|
|
|
|
|
2010-02-10 08:15:17 +08:00
|
|
|
FileID ASTImporter::Import(FileID FromID) {
|
2010-09-30 09:03:06 +08:00
|
|
|
llvm::DenseMap<FileID, FileID>::iterator Pos
|
|
|
|
= ImportedFileIDs.find(FromID);
|
2010-02-10 08:15:17 +08:00
|
|
|
if (Pos != ImportedFileIDs.end())
|
|
|
|
return Pos->second;
|
|
|
|
|
|
|
|
SourceManager &FromSM = FromContext.getSourceManager();
|
|
|
|
SourceManager &ToSM = ToContext.getSourceManager();
|
|
|
|
const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
|
2011-07-15 08:04:35 +08:00
|
|
|
assert(FromSLoc.isFile() && "Cannot handle macro expansions yet");
|
2010-02-10 08:15:17 +08:00
|
|
|
|
|
|
|
// Include location of this file.
|
|
|
|
SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
|
|
|
|
|
|
|
|
// Map the FileID for to the "to" source manager.
|
|
|
|
FileID ToID;
|
|
|
|
const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache();
|
2015-04-30 08:44:21 +08:00
|
|
|
if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
|
2010-02-10 08:15:17 +08:00
|
|
|
// FIXME: We probably want to use getVirtualFile(), so we don't hit the
|
|
|
|
// disk again
|
|
|
|
// FIXME: We definitely want to re-use the existing MemoryBuffer, rather
|
|
|
|
// than mmap the files several times.
|
2011-03-05 09:03:53 +08:00
|
|
|
const FileEntry *Entry = ToFileManager.getFile(Cache->OrigEntry->getName());
|
2014-12-10 09:26:39 +08:00
|
|
|
if (!Entry)
|
|
|
|
return FileID();
|
2010-02-10 08:15:17 +08:00
|
|
|
ToID = ToSM.createFileID(Entry, ToIncludeLoc,
|
|
|
|
FromSLoc.getFile().getFileCharacteristic());
|
|
|
|
} else {
|
|
|
|
// FIXME: We want to re-use the existing MemoryBuffer!
|
2010-11-19 04:06:41 +08:00
|
|
|
const llvm::MemoryBuffer *
|
|
|
|
FromBuf = Cache->getBuffer(FromContext.getDiagnostics(), FromSM);
|
2014-08-28 04:03:29 +08:00
|
|
|
std::unique_ptr<llvm::MemoryBuffer> ToBuf
|
2010-04-06 06:42:27 +08:00
|
|
|
= llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
|
2010-02-10 08:15:17 +08:00
|
|
|
FromBuf->getBufferIdentifier());
|
2014-08-29 15:59:55 +08:00
|
|
|
ToID = ToSM.createFileID(std::move(ToBuf),
|
2014-08-28 04:03:29 +08:00
|
|
|
FromSLoc.getFile().getFileCharacteristic());
|
2010-02-10 08:15:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-30 09:03:06 +08:00
|
|
|
ImportedFileIDs[FromID] = ToID;
|
2010-02-10 08:15:17 +08:00
|
|
|
return ToID;
|
|
|
|
}
|
|
|
|
|
2016-05-17 04:48:03 +08:00
|
|
|
CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) {
|
|
|
|
Expr *ToExpr = Import(From->getInit());
|
|
|
|
if (!ToExpr && From->getInit())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if (From->isBaseInitializer()) {
|
|
|
|
TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo());
|
|
|
|
if (!ToTInfo && From->getTypeSourceInfo())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (ToContext) CXXCtorInitializer(
|
|
|
|
ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()),
|
|
|
|
ToExpr, Import(From->getRParenLoc()),
|
|
|
|
From->isPackExpansion() ? Import(From->getEllipsisLoc())
|
|
|
|
: SourceLocation());
|
|
|
|
} else if (From->isMemberInitializer()) {
|
|
|
|
FieldDecl *ToField =
|
|
|
|
llvm::cast_or_null<FieldDecl>(Import(From->getMember()));
|
|
|
|
if (!ToField && From->getMember())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (ToContext) CXXCtorInitializer(
|
|
|
|
ToContext, ToField, Import(From->getMemberLocation()),
|
|
|
|
Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc()));
|
|
|
|
} else if (From->isIndirectMemberInitializer()) {
|
|
|
|
IndirectFieldDecl *ToIField = llvm::cast_or_null<IndirectFieldDecl>(
|
|
|
|
Import(From->getIndirectMember()));
|
|
|
|
if (!ToIField && From->getIndirectMember())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (ToContext) CXXCtorInitializer(
|
|
|
|
ToContext, ToIField, Import(From->getMemberLocation()),
|
|
|
|
Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc()));
|
|
|
|
} else if (From->isDelegatingInitializer()) {
|
|
|
|
TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo());
|
|
|
|
if (!ToTInfo && From->getTypeSourceInfo())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return new (ToContext)
|
|
|
|
CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()),
|
|
|
|
ToExpr, Import(From->getRParenLoc()));
|
|
|
|
} else if (unsigned NumArrayIndices = From->getNumArrayIndices()) {
|
|
|
|
FieldDecl *ToField =
|
|
|
|
llvm::cast_or_null<FieldDecl>(Import(From->getMember()));
|
|
|
|
if (!ToField && From->getMember())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
SmallVector<VarDecl *, 4> ToAIs(NumArrayIndices);
|
|
|
|
|
|
|
|
for (unsigned AII = 0; AII < NumArrayIndices; ++AII) {
|
|
|
|
VarDecl *ToArrayIndex =
|
|
|
|
dyn_cast_or_null<VarDecl>(Import(From->getArrayIndex(AII)));
|
|
|
|
if (!ToArrayIndex && From->getArrayIndex(AII))
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CXXCtorInitializer::Create(
|
|
|
|
ToContext, ToField, Import(From->getMemberLocation()),
|
|
|
|
Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc()),
|
|
|
|
ToAIs.data(), NumArrayIndices);
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-18 11:11:38 +08:00
|
|
|
void ASTImporter::ImportDefinition(Decl *From) {
|
|
|
|
Decl *To = Import(From);
|
|
|
|
if (!To)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (DeclContext *FromDC = cast<DeclContext>(From)) {
|
|
|
|
ASTNodeImporter Importer(*this);
|
2011-07-20 06:38:25 +08:00
|
|
|
|
|
|
|
if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(To)) {
|
|
|
|
if (!ToRecord->getDefinition()) {
|
|
|
|
Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord,
|
2012-01-25 02:36:04 +08:00
|
|
|
ASTNodeImporter::IDK_Everything);
|
2011-07-20 06:38:25 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-07-30 07:31:30 +08:00
|
|
|
|
|
|
|
if (EnumDecl *ToEnum = dyn_cast<EnumDecl>(To)) {
|
|
|
|
if (!ToEnum->getDefinition()) {
|
|
|
|
Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum,
|
2012-02-02 05:00:38 +08:00
|
|
|
ASTNodeImporter::IDK_Everything);
|
2011-07-30 07:31:30 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-01-25 01:42:07 +08:00
|
|
|
|
|
|
|
if (ObjCInterfaceDecl *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
|
|
|
|
if (!ToIFace->getDefinition()) {
|
|
|
|
Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace,
|
2012-02-02 05:00:38 +08:00
|
|
|
ASTNodeImporter::IDK_Everything);
|
2012-01-25 01:42:07 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-07-30 07:31:30 +08:00
|
|
|
|
2012-01-25 01:42:07 +08:00
|
|
|
if (ObjCProtocolDecl *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
|
|
|
|
if (!ToProto->getDefinition()) {
|
|
|
|
Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto,
|
2012-02-02 05:00:38 +08:00
|
|
|
ASTNodeImporter::IDK_Everything);
|
2012-01-25 01:42:07 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-18 11:11:38 +08:00
|
|
|
Importer.ImportDeclContext(FromDC, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-06 01:54:41 +08:00
|
|
|
DeclarationName ASTImporter::Import(DeclarationName FromName) {
|
|
|
|
if (!FromName)
|
|
|
|
return DeclarationName();
|
|
|
|
|
|
|
|
switch (FromName.getNameKind()) {
|
|
|
|
case DeclarationName::Identifier:
|
|
|
|
return Import(FromName.getAsIdentifierInfo());
|
|
|
|
|
|
|
|
case DeclarationName::ObjCZeroArgSelector:
|
|
|
|
case DeclarationName::ObjCOneArgSelector:
|
|
|
|
case DeclarationName::ObjCMultiArgSelector:
|
|
|
|
return Import(FromName.getObjCSelector());
|
|
|
|
|
|
|
|
case DeclarationName::CXXConstructorName: {
|
|
|
|
QualType T = Import(FromName.getCXXNameType());
|
|
|
|
if (T.isNull())
|
|
|
|
return DeclarationName();
|
|
|
|
|
|
|
|
return ToContext.DeclarationNames.getCXXConstructorName(
|
|
|
|
ToContext.getCanonicalType(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeclarationName::CXXDestructorName: {
|
|
|
|
QualType T = Import(FromName.getCXXNameType());
|
|
|
|
if (T.isNull())
|
|
|
|
return DeclarationName();
|
|
|
|
|
|
|
|
return ToContext.DeclarationNames.getCXXDestructorName(
|
|
|
|
ToContext.getCanonicalType(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeclarationName::CXXConversionFunctionName: {
|
|
|
|
QualType T = Import(FromName.getCXXNameType());
|
|
|
|
if (T.isNull())
|
|
|
|
return DeclarationName();
|
|
|
|
|
|
|
|
return ToContext.DeclarationNames.getCXXConversionFunctionName(
|
|
|
|
ToContext.getCanonicalType(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
case DeclarationName::CXXOperatorName:
|
|
|
|
return ToContext.DeclarationNames.getCXXOperatorName(
|
|
|
|
FromName.getCXXOverloadedOperator());
|
|
|
|
|
|
|
|
case DeclarationName::CXXLiteralOperatorName:
|
|
|
|
return ToContext.DeclarationNames.getCXXLiteralOperatorName(
|
|
|
|
Import(FromName.getCXXLiteralIdentifier()));
|
|
|
|
|
|
|
|
case DeclarationName::CXXUsingDirective:
|
|
|
|
// FIXME: STATICS!
|
|
|
|
return DeclarationName::getUsingDirectiveName();
|
|
|
|
}
|
|
|
|
|
2012-01-21 05:50:17 +08:00
|
|
|
llvm_unreachable("Invalid DeclarationName Kind!");
|
2010-02-06 01:54:41 +08:00
|
|
|
}
|
|
|
|
|
2010-12-01 09:36:18 +08:00
|
|
|
IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) {
|
2010-02-06 01:54:41 +08:00
|
|
|
if (!FromId)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-02-06 01:54:41 +08:00
|
|
|
|
2016-05-14 14:11:19 +08:00
|
|
|
IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
|
|
|
|
|
|
|
|
if (!ToId->getBuiltinID() && FromId->getBuiltinID())
|
|
|
|
ToId->setBuiltinID(FromId->getBuiltinID());
|
|
|
|
|
|
|
|
return ToId;
|
2010-02-06 01:54:41 +08:00
|
|
|
}
|
2010-02-09 05:09:39 +08:00
|
|
|
|
2010-02-17 10:12:47 +08:00
|
|
|
Selector ASTImporter::Import(Selector FromSel) {
|
|
|
|
if (FromSel.isNull())
|
|
|
|
return Selector();
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<IdentifierInfo *, 4> Idents;
|
2010-02-17 10:12:47 +08:00
|
|
|
Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
|
|
|
|
for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
|
|
|
|
Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
|
|
|
|
return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
|
|
|
|
}
|
|
|
|
|
2010-02-09 05:09:39 +08:00
|
|
|
DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name,
|
|
|
|
DeclContext *DC,
|
|
|
|
unsigned IDNS,
|
|
|
|
NamedDecl **Decls,
|
|
|
|
unsigned NumDecls) {
|
|
|
|
return Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) {
|
2012-12-20 10:22:15 +08:00
|
|
|
if (LastDiagFromFrom)
|
|
|
|
ToContext.getDiagnostics().notePriorDiagnosticFrom(
|
|
|
|
FromContext.getDiagnostics());
|
|
|
|
LastDiagFromFrom = false;
|
2010-11-19 04:06:41 +08:00
|
|
|
return ToContext.getDiagnostics().Report(Loc, DiagID);
|
2010-02-09 05:09:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) {
|
2012-12-20 10:22:15 +08:00
|
|
|
if (!LastDiagFromFrom)
|
|
|
|
FromContext.getDiagnostics().notePriorDiagnosticFrom(
|
|
|
|
ToContext.getDiagnostics());
|
|
|
|
LastDiagFromFrom = true;
|
2010-11-19 04:06:41 +08:00
|
|
|
return FromContext.getDiagnostics().Report(Loc, DiagID);
|
2010-02-09 05:09:39 +08:00
|
|
|
}
|
2010-02-13 07:44:20 +08:00
|
|
|
|
2012-02-02 05:00:38 +08:00
|
|
|
void ASTImporter::CompleteDecl (Decl *D) {
|
|
|
|
if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
|
|
|
|
if (!ID->getDefinition())
|
|
|
|
ID->startDefinition();
|
|
|
|
}
|
|
|
|
else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) {
|
|
|
|
if (!PD->getDefinition())
|
|
|
|
PD->startDefinition();
|
|
|
|
}
|
|
|
|
else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
|
|
|
|
if (!TD->getDefinition() && !TD->isBeingDefined()) {
|
|
|
|
TD->startDefinition();
|
|
|
|
TD->setCompleteDefinition(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
assert (0 && "CompleteDecl called on a Decl that can't be completed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-13 07:44:20 +08:00
|
|
|
Decl *ASTImporter::Imported(Decl *From, Decl *To) {
|
2016-03-29 05:43:01 +08:00
|
|
|
if (From->hasAttrs()) {
|
|
|
|
for (Attr *FromAttr : From->getAttrs())
|
|
|
|
To->addAttr(FromAttr->clone(To->getASTContext()));
|
|
|
|
}
|
|
|
|
if (From->isUsed()) {
|
|
|
|
To->setIsUsed();
|
|
|
|
}
|
2016-05-17 04:48:03 +08:00
|
|
|
if (From->isImplicit()) {
|
|
|
|
To->setImplicit();
|
|
|
|
}
|
2010-02-13 07:44:20 +08:00
|
|
|
ImportedDecls[From] = To;
|
|
|
|
return To;
|
2010-02-14 04:24:39 +08:00
|
|
|
}
|
2010-02-16 07:54:17 +08:00
|
|
|
|
2012-07-18 05:16:27 +08:00
|
|
|
bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To,
|
|
|
|
bool Complain) {
|
2011-01-19 14:33:43 +08:00
|
|
|
llvm::DenseMap<const Type *, const Type *>::iterator Pos
|
2010-02-16 07:54:17 +08:00
|
|
|
= ImportedTypes.find(From.getTypePtr());
|
|
|
|
if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To))
|
|
|
|
return true;
|
|
|
|
|
2012-07-18 05:16:27 +08:00
|
|
|
StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
|
|
|
|
false, Complain);
|
2010-02-18 21:02:13 +08:00
|
|
|
return Ctx.IsStructurallyEquivalent(From, To);
|
2010-02-16 07:54:17 +08:00
|
|
|
}
|