summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-27 21:45:14 +0000
committerChris Lattner <sabre@nondot.org>2009-04-27 21:45:14 +0000
commitd1d64a027554b635d644957ef071ec04ea1f7063 (patch)
treed090e124fe1fc3ce7f5f4b63196eeae0fd72ad35
parent13e8854b186265a601545ca88f8f495fb3fb5654 (diff)
downloadclang-d1d64a027554b635d644957ef071ec04ea1f7063.tar.gz
Teach PCH that ASTContext is optional. Move -parse-noop and -Eonly (so far)
processing to after PCH is loaded. -Eonly and -parse-noop are close to working with PCH now but are not quite there yet. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70257 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Frontend/PCHReader.h6
-rw-r--r--lib/Frontend/PCHReader.cpp151
-rw-r--r--lib/Frontend/PCHReaderDecl.cpp88
-rw-r--r--lib/Frontend/PCHReaderStmt.cpp14
-rw-r--r--tools/clang-cc/clang-cc.cpp112
5 files changed, 190 insertions, 181 deletions
diff --git a/include/clang/Frontend/PCHReader.h b/include/clang/Frontend/PCHReader.h
index 6795e2adf4..81f18432ee 100644
--- a/include/clang/Frontend/PCHReader.h
+++ b/include/clang/Frontend/PCHReader.h
@@ -83,7 +83,7 @@ private:
Preprocessor &PP;
/// \brief The AST context into which we'll read the PCH file.
- ASTContext &Context;
+ ASTContext *Context;
/// \brief The AST consumer.
ASTConsumer *Consumer;
@@ -298,7 +298,7 @@ private:
public:
typedef llvm::SmallVector<uint64_t, 64> RecordData;
- explicit PCHReader(Preprocessor &PP, ASTContext &Context);
+ explicit PCHReader(Preprocessor &PP, ASTContext *Context);
~PCHReader();
PCHReadResult ReadPCH(const std::string &FileName);
@@ -453,7 +453,7 @@ public:
/// \brief Retrieve the AST context that this PCH reader
/// supplements.
- ASTContext &getContext() { return Context; }
+ ASTContext *getContext() { return Context; }
// \brief Contains declarations that were loaded before we have
// access to a Sema object.
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index d36d8361fd..7483f7854c 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -38,7 +38,7 @@ using namespace clang;
// PCH reader implementation
//===----------------------------------------------------------------------===//
-PCHReader::PCHReader(Preprocessor &PP, ASTContext &Context)
+PCHReader::PCHReader(Preprocessor &PP, ASTContext *Context)
: SemaObj(0), PP(PP), Context(Context), Consumer(0),
IdentifierTableData(0), IdentifierLookupTable(0),
IdentifierOffsets(0),
@@ -102,7 +102,7 @@ public:
internal_key_type ReadKey(const unsigned char* d, unsigned) {
using namespace clang::io;
- SelectorTable &SelTable = Reader.getContext().Selectors;
+ SelectorTable &SelTable = Reader.getContext()->Selectors;
unsigned N = ReadUnalignedLE16(d);
IdentifierInfo *FirstII
= Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d));
@@ -557,7 +557,7 @@ PCHReader::PCHReadResult PCHReader::ReadSourceManagerBlock() {
return Failure;
}
- SourceManager &SourceMgr = Context.getSourceManager();
+ SourceManager &SourceMgr = PP.getSourceManager();
RecordData Record;
unsigned NumHeaderInfos = 0;
while (true) {
@@ -637,7 +637,7 @@ PCHReader::PCHReadResult PCHReader::ReadSLocEntryRecord(unsigned ID) {
return Failure;
}
- SourceManager &SourceMgr = Context.getSourceManager();
+ SourceManager &SourceMgr = PP.getSourceManager();
RecordData Record;
const char *BlobStart;
unsigned BlobLen;
@@ -928,9 +928,9 @@ PCHReader::ReadPCHBlock() {
case pch::TARGET_TRIPLE: {
std::string TargetTriple(BlobStart, BlobLen);
- if (TargetTriple != Context.Target.getTargetTriple()) {
+ if (TargetTriple != PP.getTargetInfo().getTargetTriple()) {
Diag(diag::warn_pch_target_triple)
- << TargetTriple << Context.Target.getTargetTriple();
+ << TargetTriple << PP.getTargetInfo().getTargetTriple();
Diag(diag::note_ignoring_pch) << FileName;
return IgnorePCH;
}
@@ -1137,7 +1137,8 @@ PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) {
}
// Load the translation unit declaration
- ReadDeclRecord(DeclOffsets[0], 0);
+ if (Context)
+ ReadDeclRecord(DeclOffsets[0], 0);
// Initialization of builtins and library builtins occurs before the
// PCH file is read, so there may be some identifiers that were
@@ -1173,21 +1174,23 @@ PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) {
}
// Load the special types.
- Context.setBuiltinVaListType(
- GetType(SpecialTypes[pch::SPECIAL_TYPE_BUILTIN_VA_LIST]));
- if (unsigned Id = SpecialTypes[pch::SPECIAL_TYPE_OBJC_ID])
- Context.setObjCIdType(GetType(Id));
- if (unsigned Sel = SpecialTypes[pch::SPECIAL_TYPE_OBJC_SELECTOR])
- Context.setObjCSelType(GetType(Sel));
- if (unsigned Proto = SpecialTypes[pch::SPECIAL_TYPE_OBJC_PROTOCOL])
- Context.setObjCProtoType(GetType(Proto));
- if (unsigned Class = SpecialTypes[pch::SPECIAL_TYPE_OBJC_CLASS])
- Context.setObjCClassType(GetType(Class));
- if (unsigned String = SpecialTypes[pch::SPECIAL_TYPE_CF_CONSTANT_STRING])
- Context.setCFConstantStringType(GetType(String));
- if (unsigned FastEnum
- = SpecialTypes[pch::SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE])
- Context.setObjCFastEnumerationStateType(GetType(FastEnum));
+ if (Context) {
+ Context->setBuiltinVaListType(
+ GetType(SpecialTypes[pch::SPECIAL_TYPE_BUILTIN_VA_LIST]));
+ if (unsigned Id = SpecialTypes[pch::SPECIAL_TYPE_OBJC_ID])
+ Context->setObjCIdType(GetType(Id));
+ if (unsigned Sel = SpecialTypes[pch::SPECIAL_TYPE_OBJC_SELECTOR])
+ Context->setObjCSelType(GetType(Sel));
+ if (unsigned Proto = SpecialTypes[pch::SPECIAL_TYPE_OBJC_PROTOCOL])
+ Context->setObjCProtoType(GetType(Proto));
+ if (unsigned Class = SpecialTypes[pch::SPECIAL_TYPE_OBJC_CLASS])
+ Context->setObjCClassType(GetType(Class));
+ if (unsigned String = SpecialTypes[pch::SPECIAL_TYPE_CF_CONSTANT_STRING])
+ Context->setCFConstantStringType(GetType(String));
+ if (unsigned FastEnum
+ = SpecialTypes[pch::SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE])
+ Context->setObjCFastEnumerationStateType(GetType(FastEnum));
+ }
return Success;
}
@@ -1208,7 +1211,7 @@ PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) {
/// \returns true if the PCH file is unacceptable, false otherwise.
bool PCHReader::ParseLanguageOptions(
const llvm::SmallVectorImpl<uint64_t> &Record) {
- const LangOptions &LangOpts = Context.getLangOptions();
+ const LangOptions &LangOpts = PP.getLangOptions();
#define PARSE_LANGOPT_BENIGN(Option) ++Idx
#define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \
if (Record[Idx] != LangOpts.Option) { \
@@ -1304,52 +1307,52 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
QualType T = Base;
if (GCAttr != QualType::GCNone)
- T = Context.getObjCGCQualType(T, GCAttr);
+ T = Context->getObjCGCQualType(T, GCAttr);
if (AddressSpace)
- T = Context.getAddrSpaceQualType(T, AddressSpace);
+ T = Context->getAddrSpaceQualType(T, AddressSpace);
return T;
}
case pch::TYPE_FIXED_WIDTH_INT: {
assert(Record.size() == 2 && "Incorrect encoding of fixed-width int type");
- return Context.getFixedWidthIntType(Record[0], Record[1]);
+ return Context->getFixedWidthIntType(Record[0], Record[1]);
}
case pch::TYPE_COMPLEX: {
assert(Record.size() == 1 && "Incorrect encoding of complex type");
QualType ElemType = GetType(Record[0]);
- return Context.getComplexType(ElemType);
+ return Context->getComplexType(ElemType);
}
case pch::TYPE_POINTER: {
assert(Record.size() == 1 && "Incorrect encoding of pointer type");
QualType PointeeType = GetType(Record[0]);
- return Context.getPointerType(PointeeType);
+ return Context->getPointerType(PointeeType);
}
case pch::TYPE_BLOCK_POINTER: {
assert(Record.size() == 1 && "Incorrect encoding of block pointer type");
QualType PointeeType = GetType(Record[0]);
- return Context.getBlockPointerType(PointeeType);
+ return Context->getBlockPointerType(PointeeType);
}
case pch::TYPE_LVALUE_REFERENCE: {
assert(Record.size() == 1 && "Incorrect encoding of lvalue reference type");
QualType PointeeType = GetType(Record[0]);
- return Context.getLValueReferenceType(PointeeType);
+ return Context->getLValueReferenceType(PointeeType);
}
case pch::TYPE_RVALUE_REFERENCE: {
assert(Record.size() == 1 && "Incorrect encoding of rvalue reference type");
QualType PointeeType = GetType(Record[0]);
- return Context.getRValueReferenceType(PointeeType);
+ return Context->getRValueReferenceType(PointeeType);
}
case pch::TYPE_MEMBER_POINTER: {
assert(Record.size() == 1 && "Incorrect encoding of member pointer type");
QualType PointeeType = GetType(Record[0]);
QualType ClassType = GetType(Record[1]);
- return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr());
+ return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr());
}
case pch::TYPE_CONSTANT_ARRAY: {
@@ -1358,22 +1361,22 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
unsigned IndexTypeQuals = Record[2];
unsigned Idx = 3;
llvm::APInt Size = ReadAPInt(Record, Idx);
- return Context.getConstantArrayType(ElementType, Size, ASM, IndexTypeQuals);
+ return Context->getConstantArrayType(ElementType, Size, ASM,IndexTypeQuals);
}
case pch::TYPE_INCOMPLETE_ARRAY: {
QualType ElementType = GetType(Record[0]);
ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1];
unsigned IndexTypeQuals = Record[2];
- return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals);
+ return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals);
}
case pch::TYPE_VARIABLE_ARRAY: {
QualType ElementType = GetType(Record[0]);
ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1];
unsigned IndexTypeQuals = Record[2];
- return Context.getVariableArrayType(ElementType, ReadTypeExpr(),
- ASM, IndexTypeQuals);
+ return Context->getVariableArrayType(ElementType, ReadTypeExpr(),
+ ASM, IndexTypeQuals);
}
case pch::TYPE_VECTOR: {
@@ -1384,7 +1387,7 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
QualType ElementType = GetType(Record[0]);
unsigned NumElements = Record[1];
- return Context.getVectorType(ElementType, NumElements);
+ return Context->getVectorType(ElementType, NumElements);
}
case pch::TYPE_EXT_VECTOR: {
@@ -1395,7 +1398,7 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
QualType ElementType = GetType(Record[0]);
unsigned NumElements = Record[1];
- return Context.getExtVectorType(ElementType, NumElements);
+ return Context->getExtVectorType(ElementType, NumElements);
}
case pch::TYPE_FUNCTION_NO_PROTO: {
@@ -1404,7 +1407,7 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
return QualType();
}
QualType ResultType = GetType(Record[0]);
- return Context.getFunctionNoProtoType(ResultType);
+ return Context->getFunctionNoProtoType(ResultType);
}
case pch::TYPE_FUNCTION_PROTO: {
@@ -1416,16 +1419,16 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
ParamTypes.push_back(GetType(Record[Idx++]));
bool isVariadic = Record[Idx++];
unsigned Quals = Record[Idx++];
- return Context.getFunctionType(ResultType, &ParamTypes[0], NumParams,
- isVariadic, Quals);
+ return Context->getFunctionType(ResultType, &ParamTypes[0], NumParams,
+ isVariadic, Quals);
}
case pch::TYPE_TYPEDEF:
assert(Record.size() == 1 && "Incorrect encoding of typedef type");
- return Context.getTypeDeclType(cast<TypedefDecl>(GetDecl(Record[0])));
+ return Context->getTypeDeclType(cast<TypedefDecl>(GetDecl(Record[0])));
case pch::TYPE_TYPEOF_EXPR:
- return Context.getTypeOfExprType(ReadTypeExpr());
+ return Context->getTypeOfExprType(ReadTypeExpr());
case pch::TYPE_TYPEOF: {
if (Record.size() != 1) {
@@ -1433,20 +1436,20 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
return QualType();
}
QualType UnderlyingType = GetType(Record[0]);
- return Context.getTypeOfType(UnderlyingType);
+ return Context->getTypeOfType(UnderlyingType);
}
case pch::TYPE_RECORD:
assert(Record.size() == 1 && "Incorrect encoding of record type");
- return Context.getTypeDeclType(cast<RecordDecl>(GetDecl(Record[0])));
+ return Context->getTypeDeclType(cast<RecordDecl>(GetDecl(Record[0])));
case pch::TYPE_ENUM:
assert(Record.size() == 1 && "Incorrect encoding of enum type");
- return Context.getTypeDeclType(cast<EnumDecl>(GetDecl(Record[0])));
+ return Context->getTypeDeclType(cast<EnumDecl>(GetDecl(Record[0])));
case pch::TYPE_OBJC_INTERFACE:
assert(Record.size() == 1 && "Incorrect encoding of objc interface type");
- return Context.getObjCInterfaceType(
+ return Context->getObjCInterfaceType(
cast<ObjCInterfaceDecl>(GetDecl(Record[0])));
case pch::TYPE_OBJC_QUALIFIED_INTERFACE: {
@@ -1456,7 +1459,7 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
llvm::SmallVector<ObjCProtocolDecl*, 4> Protos;
for (unsigned I = 0; I != NumProtos; ++I)
Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++])));
- return Context.getObjCQualifiedInterfaceType(ItfD, &Protos[0], NumProtos);
+ return Context->getObjCQualifiedInterfaceType(ItfD, &Protos[0], NumProtos);
}
case pch::TYPE_OBJC_QUALIFIED_ID: {
@@ -1465,7 +1468,7 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
llvm::SmallVector<ObjCProtocolDecl*, 4> Protos;
for (unsigned I = 0; I != NumProtos; ++I)
Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++])));
- return Context.getObjCQualifiedIdType(&Protos[0], NumProtos);
+ return Context->getObjCQualifiedIdType(&Protos[0], NumProtos);
}
}
// Suppress a GCC warning
@@ -1481,31 +1484,31 @@ QualType PCHReader::GetType(pch::TypeID ID) {
QualType T;
switch ((pch::PredefinedTypeIDs)Index) {
case pch::PREDEF_TYPE_NULL_ID: return QualType();
- case pch::PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break;
- case pch::PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break;
+ case pch::PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break;
+ case pch::PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break;
case pch::PREDEF_TYPE_CHAR_U_ID:
case pch::PREDEF_TYPE_CHAR_S_ID:
// FIXME: Check that the signedness of CharTy is correct!
- T = Context.CharTy;
+ T = Context->CharTy;
break;
- case pch::PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break;
- case pch::PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break;
- case pch::PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break;
- case pch::PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break;
- case pch::PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break;
- case pch::PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break;
- case pch::PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break;
- case pch::PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break;
- case pch::PREDEF_TYPE_INT_ID: T = Context.IntTy; break;
- case pch::PREDEF_TYPE_LONG_ID: T = Context.LongTy; break;
- case pch::PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break;
- case pch::PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break;
- case pch::PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break;
- case pch::PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break;
- case pch::PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break;
- case pch::PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break;
+ case pch::PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break;
+ case pch::PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break;
+ case pch::PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break;
+ case pch::PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break;
+ case pch::PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break;
+ case pch::PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break;
+ case pch::PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break;
+ case pch::PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break;
+ case pch::PREDEF_TYPE_INT_ID: T = Context->IntTy; break;
+ case pch::PREDEF_TYPE_LONG_ID: T = Context->LongTy; break;
+ case pch::PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break;
+ case pch::PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break;
+ case pch::PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break;
+ case pch::PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break;
+ case pch::PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break;
+ case pch::PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break;
}
assert(!T.isNull() && "Unknown predefined type");
@@ -1814,7 +1817,7 @@ IdentifierInfo *PCHReader::DecodeIdentifierInfo(unsigned ID) {
const char *StrLenPtr = Str - 2;
unsigned StrLen = (((unsigned) StrLenPtr[0])
| (((unsigned) StrLenPtr[1]) << 8)) - 1;
- IdentifiersLoaded[ID - 1] = &Context.Idents.get(Str, Str + StrLen);
+ IdentifiersLoaded[ID - 1]=&PP.getIdentifierTable().get(Str, Str + StrLen);
// Turn on lookup into the on-disk hash table, if we have an
// on-disk hash table.
@@ -1883,19 +1886,19 @@ PCHReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) {
return DeclarationName(GetSelector(Record, Idx));
case DeclarationName::CXXConstructorName:
- return Context.DeclarationNames.getCXXConstructorName(
+ return Context->DeclarationNames.getCXXConstructorName(
GetType(Record[Idx++]));
case DeclarationName::CXXDestructorName:
- return Context.DeclarationNames.getCXXDestructorName(
+ return Context->DeclarationNames.getCXXDestructorName(
GetType(Record[Idx++]));
case DeclarationName::CXXConversionFunctionName:
- return Context.DeclarationNames.getCXXConversionFunctionName(
+ return Context->DeclarationNames.getCXXConversionFunctionName(
GetType(Record[Idx++]));
case DeclarationName::CXXOperatorName:
- return Context.DeclarationNames.getCXXOperatorName(
+ return Context->DeclarationNames.getCXXOperatorName(
(OverloadedOperatorKind)Record[Idx++]);
case DeclarationName::CXXUsingDirective:
@@ -1940,7 +1943,7 @@ DiagnosticBuilder PCHReader::Diag(unsigned DiagID) {
DiagnosticBuilder PCHReader::Diag(SourceLocation Loc, unsigned DiagID) {
return PP.getDiagnostics().Report(FullSourceLoc(Loc,
- Context.getSourceManager()),
+ PP.getSourceManager()),
DiagID);
}
diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp
index 2df87bfe1c..fc14a2623c 100644
--- a/lib/Frontend/PCHReaderDecl.cpp
+++ b/lib/Frontend/PCHReaderDecl.cpp
@@ -160,7 +160,7 @@ void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Params.reserve(NumParams);
for (unsigned I = 0; I != NumParams; ++I)
Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
- FD->setParams(Reader.getContext(), &Params[0], NumParams);
+ FD->setParams(*Reader.getContext(), &Params[0], NumParams);
}
void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
@@ -184,7 +184,7 @@ void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Params.reserve(NumParams);
for (unsigned I = 0; I != NumParams; ++I)
Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
- MD->setMethodParams(Reader.getContext(), &Params[0], NumParams);
+ MD->setMethodParams(*Reader.getContext(), &Params[0], NumParams);
}
void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
@@ -202,13 +202,13 @@ void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Protocols.reserve(NumProtocols);
for (unsigned I = 0; I != NumProtocols; ++I)
Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
- ID->setProtocolList(&Protocols[0], NumProtocols, Reader.getContext());
+ ID->setProtocolList(&Protocols[0], NumProtocols, *Reader.getContext());
unsigned NumIvars = Record[Idx++];
llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
IVars.reserve(NumIvars);
for (unsigned I = 0; I != NumIvars; ++I)
IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
- ID->setIVarList(&IVars[0], NumIvars, Reader.getContext());
+ ID->setIVarList(&IVars[0], NumIvars, *Reader.getContext());
ID->setCategoryList(
cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
ID->setForwardDecl(Record[Idx++]);
@@ -232,7 +232,7 @@ void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
ProtoRefs.reserve(NumProtoRefs);
for (unsigned I = 0; I != NumProtoRefs; ++I)
ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
- PD->setProtocolList(&ProtoRefs[0], NumProtoRefs, Reader.getContext());
+ PD->setProtocolList(&ProtoRefs[0], NumProtoRefs, *Reader.getContext());
}
void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
@@ -246,7 +246,7 @@ void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
ClassRefs.reserve(NumClassRefs);
for (unsigned I = 0; I != NumClassRefs; ++I)
ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
- CD->setClassList(Reader.getContext(), &ClassRefs[0], NumClassRefs);
+ CD->setClassList(*Reader.getContext(), &ClassRefs[0], NumClassRefs);
}
void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
@@ -256,7 +256,7 @@ void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
ProtoRefs.reserve(NumProtoRefs);
for (unsigned I = 0; I != NumProtoRefs; ++I)
ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
- FPD->setProtocolList(&ProtoRefs[0], NumProtoRefs, Reader.getContext());
+ FPD->setProtocolList(&ProtoRefs[0], NumProtoRefs, *Reader.getContext());
}
void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
@@ -267,7 +267,7 @@ void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
ProtoRefs.reserve(NumProtoRefs);
for (unsigned I = 0; I != NumProtoRefs; ++I)
ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
- CD->setProtocolList(&ProtoRefs[0], NumProtoRefs, Reader.getContext());
+ CD->setProtocolList(&ProtoRefs[0], NumProtoRefs, *Reader.getContext());
CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
CD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
}
@@ -372,7 +372,7 @@ void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
Params.reserve(NumParams);
for (unsigned I = 0; I != NumParams; ++I)
Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
- BD->setParams(Reader.getContext(), &Params[0], NumParams);
+ BD->setParams(*Reader.getContext(), &Params[0], NumParams);
}
std::pair<uint64_t, uint64_t>
@@ -400,17 +400,17 @@ Attr *PCHReader::ReadAttributes() {
#define SIMPLE_ATTR(Name) \
case Attr::Name: \
- New = ::new (Context) Name##Attr(); \
+ New = ::new (*Context) Name##Attr(); \
break
#define STRING_ATTR(Name) \
case Attr::Name: \
- New = ::new (Context) Name##Attr(ReadString(Record, Idx)); \
+ New = ::new (*Context) Name##Attr(ReadString(Record, Idx)); \
break
#define UNSIGNED_ATTR(Name) \
case Attr::Name: \
- New = ::new (Context) Name##Attr(Record[Idx++]); \
+ New = ::new (*Context) Name##Attr(Record[Idx++]); \
break
Attr *Attrs = 0;
@@ -428,12 +428,12 @@ Attr *PCHReader::ReadAttributes() {
STRING_ATTR(AsmLabel);
case Attr::Blocks:
- New = ::new (Context) BlocksAttr(
+ New = ::new (*Context) BlocksAttr(
(BlocksAttr::BlocksAttrTypes)Record[Idx++]);
break;
case Attr::Cleanup:
- New = ::new (Context) CleanupAttr(
+ New = ::new (*Context) CleanupAttr(
cast<FunctionDecl>(GetDecl(Record[Idx++])));
break;
@@ -449,14 +449,14 @@ Attr *PCHReader::ReadAttributes() {
std::string Type = ReadString(Record, Idx);
unsigned FormatIdx = Record[Idx++];
unsigned FirstArg = Record[Idx++];
- New = ::new (Context) FormatAttr(Type, FormatIdx, FirstArg);
+ New = ::new (*Context) FormatAttr(Type, FormatIdx, FirstArg);
break;
}
SIMPLE_ATTR(GNUInline);
case Attr::IBOutletKind:
- New = ::new (Context) IBOutletAttr();
+ New = ::new (*Context) IBOutletAttr();
break;
SIMPLE_ATTR(NoReturn);
@@ -469,7 +469,7 @@ Attr *PCHReader::ReadAttributes() {
llvm::SmallVector<unsigned, 16> ArgNums;
ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
Idx += Size;
- New = ::new (Context) NonNullAttr(&ArgNums[0], Size);
+ New = ::new (*Context) NonNullAttr(&ArgNums[0], Size);
break;
}
@@ -492,7 +492,7 @@ Attr *PCHReader::ReadAttributes() {
SIMPLE_ATTR(Used);
case Attr::Visibility:
- New = ::new (Context) VisibilityAttr(
+ New = ::new (*Context) VisibilityAttr(
(VisibilityAttr::VisibilityTypes)Record[Idx++]);
break;
@@ -574,96 +574,96 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
break;
case pch::DECL_TRANSLATION_UNIT:
assert(Index == 0 && "Translation unit must be at index 0");
- D = Context.getTranslationUnitDecl();
+ D = Context->getTranslationUnitDecl();
break;
case pch::DECL_TYPEDEF:
- D = TypedefDecl::Create(Context, 0, SourceLocation(), 0, QualType());
+ D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
break;
case pch::DECL_ENUM:
- D = EnumDecl::Create(Context, 0, SourceLocation(), 0, 0);
+ D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, 0);
break;
case pch::DECL_RECORD:
- D = RecordDecl::Create(Context, TagDecl::TK_struct, 0, SourceLocation(),
+ D = RecordDecl::Create(*Context, TagDecl::TK_struct, 0, SourceLocation(),
0, 0);
break;
case pch::DECL_ENUM_CONSTANT:
- D = EnumConstantDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
+ D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
0, llvm::APSInt());
break;
case pch::DECL_FUNCTION:
- D = FunctionDecl::Create(Context, 0, SourceLocation(), DeclarationName(),
+ D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
QualType());
break;
case pch::DECL_OBJC_METHOD:
- D = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(),
+ D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Selector(), QualType(), 0);
break;
case pch::DECL_OBJC_INTERFACE:
- D = ObjCInterfaceDecl::Create(Context, 0, SourceLocation(), 0);
+ D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
break;
case pch::DECL_OBJC_IVAR:
- D = ObjCIvarDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
+ D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
ObjCIvarDecl::None);
break;
case pch::DECL_OBJC_PROTOCOL:
- D = ObjCProtocolDecl::Create(Context, 0, SourceLocation(), 0);
+ D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
break;
case pch::DECL_OBJC_AT_DEFS_FIELD:
- D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(), 0,
+ D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
QualType(), 0);
break;
case pch::DECL_OBJC_CLASS:
- D = ObjCClassDecl::Create(Context, 0, SourceLocation());
+ D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
break;
case pch::DECL_OBJC_FORWARD_PROTOCOL:
- D = ObjCForwardProtocolDecl::Create(Context, 0, SourceLocation());
+ D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
break;
case pch::DECL_OBJC_CATEGORY:
- D = ObjCCategoryDecl::Create(Context, 0, SourceLocation(), 0);
+ D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(), 0);
break;
case pch::DECL_OBJC_CATEGORY_IMPL:
- D = ObjCCategoryImplDecl::Create(Context, 0, SourceLocation(), 0, 0);
+ D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
break;
case pch::DECL_OBJC_IMPLEMENTATION:
- D = ObjCImplementationDecl::Create(Context, 0, SourceLocation(), 0, 0);
+ D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
break;
case pch::DECL_OBJC_COMPATIBLE_ALIAS:
- D = ObjCCompatibleAliasDecl::Create(Context, 0, SourceLocation(), 0, 0);
+ D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
break;
case pch::DECL_OBJC_PROPERTY:
- D = ObjCPropertyDecl::Create(Context, 0, SourceLocation(), 0, QualType());
+ D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
break;
case pch::DECL_OBJC_PROPERTY_IMPL:
- D = ObjCPropertyImplDecl::Create(Context, 0, SourceLocation(),
+ D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
SourceLocation(), 0,
ObjCPropertyImplDecl::Dynamic, 0);
break;
case pch::DECL_FIELD:
- D = FieldDecl::Create(Context, 0, SourceLocation(), 0, QualType(), 0,
+ D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
false);
break;
case pch::DECL_VAR:
- D = VarDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
+ D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
VarDecl::None, SourceLocation());
break;
case pch::DECL_IMPLICIT_PARAM:
- D = ImplicitParamDecl::Create(Context, 0, SourceLocation(), 0, QualType());
+ D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
break;
case pch::DECL_PARM_VAR:
- D = ParmVarDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
+ D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
VarDecl::None, 0);
break;
case pch::DECL_ORIGINAL_PARM_VAR:
- D = OriginalParmVarDecl::Create(Context, 0, SourceLocation(), 0,
+ D = OriginalParmVarDecl::Create(*Context, 0, SourceLocation(), 0,
QualType(), QualType(), VarDecl::None, 0);
break;
case pch::DECL_FILE_SCOPE_ASM:
- D = FileScopeAsmDecl::Create(Context, 0, SourceLocation(), 0);
+ D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
break;
case pch::DECL_BLOCK:
- D = BlockDecl::Create(Context, 0, SourceLocation());
+ D = BlockDecl::Create(*Context, 0, SourceLocation());
break;
}
diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp
index af3e026b57..217bdf507b 100644
--- a/lib/Frontend/PCHReaderStmt.cpp
+++ b/lib/Frontend/PCHReaderStmt.cpp
@@ -134,7 +134,7 @@ unsigned PCHStmtReader::VisitNullStmt(NullStmt *S) {
unsigned PCHStmtReader::VisitCompoundStmt(CompoundStmt *S) {
VisitStmt(S);
unsigned NumStmts = Record[Idx++];
- S->setStmts(Reader.getContext(),
+ S->setStmts(*Reader.getContext(),
&StmtStack[StmtStack.size() - NumStmts], NumStmts);
S->setLBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setRBracLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
@@ -271,7 +271,7 @@ unsigned PCHStmtReader::VisitDeclStmt(DeclStmt *S) {
Decls.reserve(Record.size() - Idx);
for (unsigned N = Record.size(); Idx != N; ++Idx)
Decls.push_back(Reader.GetDecl(Record[Idx]));
- S->setDeclGroup(DeclGroupRef(DeclGroup::Create(Reader.getContext(),
+ S->setDeclGroup(DeclGroupRef(DeclGroup::Create(*Reader.getContext(),
&Decls[0], Decls.size())));
}
return 0;
@@ -367,7 +367,7 @@ unsigned PCHStmtReader::VisitStringLiteral(StringLiteral *E) {
// Read string data
llvm::SmallVector<char, 16> Str(&Record[Idx], &Record[Idx] + Len);
- E->setStrData(Reader.getContext(), &Str[0], Len);
+ E->setStrData(*Reader.getContext(), &Str[0], Len);
Idx += Len;
// Read source locations
@@ -425,7 +425,7 @@ unsigned PCHStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
unsigned PCHStmtReader::VisitCallExpr(CallExpr *E) {
VisitExpr(E);
- E->setNumArgs(Reader.getContext(), Record[Idx++]);
+ E->setNumArgs(*Reader.getContext(), Record[Idx++]);
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setCallee(cast<Expr>(StmtStack[StmtStack.size() - E->getNumArgs() - 1]));
for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
@@ -953,7 +953,7 @@ Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) {
break;
case pch::EXPR_STRING_LITERAL:
- S = StringLiteral::CreateEmpty(Context,
+ S = StringLiteral::CreateEmpty(*Context,
Record[PCHStmtReader::NumExprFields + 1]);
break;
@@ -978,7 +978,7 @@ Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) {
break;
case pch::EXPR_CALL:
- S = new (Context) CallExpr(Context, Empty);
+ S = new (Context) CallExpr(*Context, Empty);
break;
case pch::EXPR_MEMBER:
@@ -1018,7 +1018,7 @@ Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) {
break;
case pch::EXPR_DESIGNATED_INIT:
- S = DesignatedInitExpr::CreateEmpty(Context,
+ S = DesignatedInitExpr::CreateEmpty(*Context,
Record[PCHStmtReader::NumExprFields] - 1);
break;
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index f124298cbf..4f4d3a3fff 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -1657,17 +1657,8 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
ClearSourceMgr = true;
break;
}
- case RunPreprocessorOnly: { // Just lex as fast as we can, no output.
- llvm::TimeRegion Timer(ClangFrontendTimer);
- Token Tok;
- // Start parsing the specified input file.
- PP.EnterMainSourceFile();
- do {
- PP.Lex(Tok);
- } while (Tok.isNot(tok::eof));
- ClearSourceMgr = true;
+ case RunPreprocessorOnly:
break;
- }
case GeneratePTH: {
llvm::TimeRegion Timer(ClangFrontendTimer);
@@ -1683,12 +1674,8 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
break;
}
- case ParseNoop: { // -parse-noop
- llvm::TimeRegion Timer(ClangFrontendTimer);
- ParseFile(PP, new MinimalAction(PP));
- ClearSourceMgr = true;
+ case ParseNoop:
break;
- }
case ParsePrintCallbacks: {
llvm::TimeRegion Timer(ClangFrontendTimer);
@@ -1754,7 +1741,7 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
}
llvm::OwningPtr<ASTContext> ContextOwner;
- if (Consumer) {
+ if (Consumer)
ContextOwner.reset(new ASTContext(PP.getLangOptions(),
PP.getSourceManager(),
PP.getTargetInfo(),
@@ -1764,52 +1751,71 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
/* size_reserve = */0,
/* InitializeBuiltins = */ImplicitIncludePCH.empty()));
- if (!ImplicitIncludePCH.empty()) {
- // The user has asked us to include a precompiled header. Load
- // the precompiled header into the AST context.
- llvm::OwningPtr<PCHReader> Reader(new PCHReader(PP, *ContextOwner.get()));
- switch (Reader->ReadPCH(ImplicitIncludePCH)) {
- case PCHReader::Success: {
- // Attach the PCH reader to the AST context as an external AST
- // source, so that declarations will be deserialized from the
- // PCH file as needed.
- llvm::OwningPtr<ExternalASTSource> Source(Reader.take());
+ if (!ImplicitIncludePCH.empty()) {
+ // The user has asked us to include a precompiled header. Load
+ // the precompiled header into the AST context.
+ llvm::OwningPtr<PCHReader> Reader(new PCHReader(PP, ContextOwner.get()));
+ switch (Reader->ReadPCH(ImplicitIncludePCH)) {
+ case PCHReader::Success: {
+ // Attach the PCH reader to the AST context as an external AST
+ // source, so that declarations will be deserialized from the
+ // PCH file as needed.
+ llvm::OwningPtr<ExternalASTSource> Source(Reader.take());
+ if (ContextOwner)
ContextOwner->setExternalSource(Source);
- // Clear out the predefines buffer, because all of the
- // predefines are already in the PCH file.
- PP.setPredefines("");
- break;
- }
+ // Clear out the predefines buffer, because all of the
+ // predefines are already in the PCH file.
+ PP.setPredefines("");
+ break;
+ }
- case PCHReader::Failure:
- // Unrecoverable failure: don't even try to process the input
- // file.
- return;
-
- case PCHReader::IgnorePCH:
- // No suitable PCH file could be found. Just ignore the
- // -include-pch option entirely.
-
- // We delayed the initialization of builtins in the hope of
- // loading the PCH file. Since the PCH file could not be
- // loaded, initialize builtins now.
- ContextOwner->InitializeBuiltins(PP.getIdentifierTable());
- break;
- }
+ case PCHReader::Failure:
+ // Unrecoverable failure: don't even try to process the input
+ // file.
+ return;
- // Finish preprocessor initialization. We do this now (rather
- // than earlier) because this initialization creates new source
- // location entries in the source manager, which must come after
- // the source location entries for the PCH file.
- if (InitializeSourceManager(PP, InFile))
- return;
+ case PCHReader::IgnorePCH:
+ // No suitable PCH file could be found. Just ignore the
+ // -include-pch option entirely.
+
+ // We delayed the initialization of builtins in the hope of
+ // loading the PCH file. Since the PCH file could not be
+ // loaded, initialize builtins now.
+ if (ContextOwner)
+ ContextOwner->InitializeBuiltins(PP.getIdentifierTable());
+ break;
}
+ // Finish preprocessor initialization. We do this now (rather
+ // than earlier) because this initialization creates new source
+ // location entries in the source manager, which must come after
+ // the source location entries for the PCH file.
+ if (InitializeSourceManager(PP, InFile))
+ return;
+ }
+
+
+ // If we have an ASTConsumer, run the parser with it.
+ if (Consumer)
ParseAST(PP, Consumer.get(), *ContextOwner.get(), Stats,
CompleteTranslationUnit);
- }
+ if (PA == RunPreprocessorOnly) { // Just lex as fast as we can, no output.
+ llvm::TimeRegion Timer(ClangFrontendTimer);
+ Token Tok;
+ // Start parsing the specified input file.
+ PP.EnterMainSourceFile();
+ do {
+ PP.Lex(Tok);
+ } while (Tok.isNot(tok::eof));
+ ClearSourceMgr = true;
+ } else if (PA == ParseNoop) { // -parse-noop
+ llvm::TimeRegion Timer(ClangFrontendTimer);
+ ParseFile(PP, new MinimalAction(PP));
+ ClearSourceMgr = true;
+ }
+
if (FixItRewrite)
FixItRewrite->WriteFixedFile(InFile, OutputFile);