Newer
Older
//===--- 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"
#include "clang/AST/ASTDiagnostic.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclVisitor.h"
Douglas Gregor
committed
#include "clang/AST/TypeLoc.h"
#include "clang/AST/TypeVisitor.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/Support/MemoryBuffer.h"
using namespace clang;
namespace {
class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, QualType>,
public DeclVisitor<ASTNodeImporter, Decl *> {
ASTImporter &Importer;
public:
explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) { }
using TypeVisitor<ASTNodeImporter, QualType>::Visit;
using DeclVisitor<ASTNodeImporter, Decl *>::Visit;
// Importing types
QualType VisitType(Type *T);
QualType VisitBuiltinType(BuiltinType *T);
QualType VisitComplexType(ComplexType *T);
QualType VisitPointerType(PointerType *T);
QualType VisitBlockPointerType(BlockPointerType *T);
QualType VisitLValueReferenceType(LValueReferenceType *T);
QualType VisitRValueReferenceType(RValueReferenceType *T);
QualType VisitMemberPointerType(MemberPointerType *T);
QualType VisitConstantArrayType(ConstantArrayType *T);
QualType VisitIncompleteArrayType(IncompleteArrayType *T);
QualType VisitVariableArrayType(VariableArrayType *T);
// FIXME: DependentSizedArrayType
// FIXME: DependentSizedExtVectorType
QualType VisitVectorType(VectorType *T);
QualType VisitExtVectorType(ExtVectorType *T);
QualType VisitFunctionNoProtoType(FunctionNoProtoType *T);
QualType VisitFunctionProtoType(FunctionProtoType *T);
// FIXME: UnresolvedUsingType
QualType VisitTypedefType(TypedefType *T);
QualType VisitTypeOfExprType(TypeOfExprType *T);
// FIXME: DependentTypeOfExprType
QualType VisitTypeOfType(TypeOfType *T);
QualType VisitDecltypeType(DecltypeType *T);
// FIXME: DependentDecltypeType
QualType VisitRecordType(RecordType *T);
QualType VisitEnumType(EnumType *T);
QualType VisitElaboratedType(ElaboratedType *T);
// FIXME: TemplateTypeParmType
// FIXME: SubstTemplateTypeParmType
// FIXME: TemplateSpecializationType
QualType VisitQualifiedNameType(QualifiedNameType *T);
// FIXME: TypenameType
QualType VisitObjCInterfaceType(ObjCInterfaceType *T);
QualType VisitObjCObjectPointerType(ObjCObjectPointerType *T);
// Importing declarations
bool ImportDeclParts(NamedDecl *D, DeclContext *&DC,
DeclContext *&LexicalDC, DeclarationName &Name,
SourceLocation &Loc);
bool ImportDeclParts(DeclaratorDecl *D,
DeclContext *&DC, DeclContext *&LexicalDC,
DeclarationName &Name, SourceLocation &Loc,
QualType &T);
Decl *VisitDecl(Decl *D);
Douglas Gregor
committed
Decl *VisitTypedefDecl(TypedefDecl *D);
Decl *VisitFunctionDecl(FunctionDecl *D);
Decl *VisitVarDecl(VarDecl *D);
Decl *VisitParmVarDecl(ParmVarDecl *D);
};
}
//----------------------------------------------------------------------------
// Import Types
//----------------------------------------------------------------------------
QualType ASTNodeImporter::VisitType(Type *T) {
Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
<< T->getTypeClassName();
return QualType();
}
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
QualType ASTNodeImporter::VisitBuiltinType(BuiltinType *T) {
switch (T->getKind()) {
case BuiltinType::Void: return Importer.getToContext().VoidTy;
case BuiltinType::Bool: return Importer.getToContext().BoolTy;
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.
if (Importer.getToContext().getLangOptions().CharIsSigned)
return Importer.getToContext().UnsignedCharTy;
return Importer.getToContext().CharTy;
case BuiltinType::UChar: return Importer.getToContext().UnsignedCharTy;
case BuiltinType::Char16:
// FIXME: Make sure that the "to" context supports C++!
return Importer.getToContext().Char16Ty;
case BuiltinType::Char32:
// FIXME: Make sure that the "to" context supports C++!
return Importer.getToContext().Char32Ty;
case BuiltinType::UShort: return Importer.getToContext().UnsignedShortTy;
case BuiltinType::UInt: return Importer.getToContext().UnsignedIntTy;
case BuiltinType::ULong: return Importer.getToContext().UnsignedLongTy;
case BuiltinType::ULongLong:
return Importer.getToContext().UnsignedLongLongTy;
case BuiltinType::UInt128: return Importer.getToContext().UnsignedInt128Ty;
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.
if (!Importer.getToContext().getLangOptions().CharIsSigned)
return Importer.getToContext().SignedCharTy;
return Importer.getToContext().CharTy;
case BuiltinType::SChar: return Importer.getToContext().SignedCharTy;
case BuiltinType::WChar:
// FIXME: If not in C++, shall we translate to the C equivalent of
// wchar_t?
return Importer.getToContext().WCharTy;
case BuiltinType::Short : return Importer.getToContext().ShortTy;
case BuiltinType::Int : return Importer.getToContext().IntTy;
case BuiltinType::Long : return Importer.getToContext().LongTy;
case BuiltinType::LongLong : return Importer.getToContext().LongLongTy;
case BuiltinType::Int128 : return Importer.getToContext().Int128Ty;
case BuiltinType::Float: return Importer.getToContext().FloatTy;
case BuiltinType::Double: return Importer.getToContext().DoubleTy;
case BuiltinType::LongDouble: return Importer.getToContext().LongDoubleTy;
case BuiltinType::NullPtr:
// FIXME: Make sure that the "to" context supports C++0x!
return Importer.getToContext().NullPtrTy;
case BuiltinType::Overload: return Importer.getToContext().OverloadTy;
case BuiltinType::Dependent: return Importer.getToContext().DependentTy;
case BuiltinType::UndeducedAuto:
// FIXME: Make sure that the "to" context supports C++0x!
return Importer.getToContext().UndeducedAutoTy;
case BuiltinType::ObjCId:
// FIXME: Make sure that the "to" context supports Objective-C!
return Importer.getToContext().ObjCBuiltinIdTy;
case BuiltinType::ObjCClass:
return Importer.getToContext().ObjCBuiltinClassTy;
case BuiltinType::ObjCSel:
return Importer.getToContext().ObjCBuiltinSelTy;
}
return QualType();
}
QualType ASTNodeImporter::VisitComplexType(ComplexType *T) {
QualType ToElementType = Importer.Import(T->getElementType());
if (ToElementType.isNull())
return QualType();
return Importer.getToContext().getComplexType(ToElementType);
}
QualType ASTNodeImporter::VisitPointerType(PointerType *T) {
QualType ToPointeeType = Importer.Import(T->getPointeeType());
if (ToPointeeType.isNull())
return QualType();
return Importer.getToContext().getPointerType(ToPointeeType);
}
QualType ASTNodeImporter::VisitBlockPointerType(BlockPointerType *T) {
// FIXME: Check for blocks support in "to" context.
QualType ToPointeeType = Importer.Import(T->getPointeeType());
if (ToPointeeType.isNull())
return QualType();
Loading
Loading full blame...