diff options
author | Guy Benyei <guy.benyei@intel.com> | 2012-12-18 12:30:03 +0000 |
---|---|---|
committer | Guy Benyei <guy.benyei@intel.com> | 2012-12-18 12:30:03 +0000 |
commit | 736104a7619c53ef92553780273d7357a3cdde81 (patch) | |
tree | a9f11d9747d4f6523e19cb83ae3a8ca3124f77af /lib/Serialization | |
parent | 15cc355526cdd898f5e528c38c3e385c45746e06 (diff) |
Add OpenCL images as clang builtin types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170428 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization')
-rw-r--r-- | lib/Serialization/ASTCommon.cpp | 166 | ||||
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 13990 |
2 files changed, 7084 insertions, 7072 deletions
diff --git a/lib/Serialization/ASTCommon.cpp b/lib/Serialization/ASTCommon.cpp index aec8a81565..91eec73297 100644 --- a/lib/Serialization/ASTCommon.cpp +++ b/lib/Serialization/ASTCommon.cpp @@ -1,80 +1,86 @@ -//===--- ASTCommon.cpp - Common stuff for ASTReader/ASTWriter----*- 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 common functions that both ASTReader and ASTWriter use. -// -//===----------------------------------------------------------------------===// - -#include "ASTCommon.h" -#include "clang/Basic/IdentifierTable.h" -#include "clang/Serialization/ASTDeserializationListener.h" -#include "llvm/ADT/StringExtras.h" - -using namespace clang; - -// Give ASTDeserializationListener's VTable a home. -ASTDeserializationListener::~ASTDeserializationListener() { } - -serialization::TypeIdx -serialization::TypeIdxFromBuiltin(const BuiltinType *BT) { - unsigned ID = 0; - switch (BT->getKind()) { - case BuiltinType::Void: ID = PREDEF_TYPE_VOID_ID; break; - case BuiltinType::Bool: ID = PREDEF_TYPE_BOOL_ID; break; - case BuiltinType::Char_U: ID = PREDEF_TYPE_CHAR_U_ID; break; - case BuiltinType::UChar: ID = PREDEF_TYPE_UCHAR_ID; break; - case BuiltinType::UShort: ID = PREDEF_TYPE_USHORT_ID; break; - case BuiltinType::UInt: ID = PREDEF_TYPE_UINT_ID; break; - case BuiltinType::ULong: ID = PREDEF_TYPE_ULONG_ID; break; - case BuiltinType::ULongLong: ID = PREDEF_TYPE_ULONGLONG_ID; break; - case BuiltinType::UInt128: ID = PREDEF_TYPE_UINT128_ID; break; - case BuiltinType::Char_S: ID = PREDEF_TYPE_CHAR_S_ID; break; - case BuiltinType::SChar: ID = PREDEF_TYPE_SCHAR_ID; break; - case BuiltinType::WChar_S: - case BuiltinType::WChar_U: ID = PREDEF_TYPE_WCHAR_ID; break; - case BuiltinType::Short: ID = PREDEF_TYPE_SHORT_ID; break; - case BuiltinType::Int: ID = PREDEF_TYPE_INT_ID; break; - case BuiltinType::Long: ID = PREDEF_TYPE_LONG_ID; break; - case BuiltinType::LongLong: ID = PREDEF_TYPE_LONGLONG_ID; break; - case BuiltinType::Int128: ID = PREDEF_TYPE_INT128_ID; break; - case BuiltinType::Half: ID = PREDEF_TYPE_HALF_ID; break; - case BuiltinType::Float: ID = PREDEF_TYPE_FLOAT_ID; break; - case BuiltinType::Double: ID = PREDEF_TYPE_DOUBLE_ID; break; - case BuiltinType::LongDouble: ID = PREDEF_TYPE_LONGDOUBLE_ID; break; - case BuiltinType::NullPtr: ID = PREDEF_TYPE_NULLPTR_ID; break; - case BuiltinType::Char16: ID = PREDEF_TYPE_CHAR16_ID; break; - case BuiltinType::Char32: ID = PREDEF_TYPE_CHAR32_ID; break; - case BuiltinType::Overload: ID = PREDEF_TYPE_OVERLOAD_ID; break; - case BuiltinType::BoundMember:ID = PREDEF_TYPE_BOUND_MEMBER; break; - case BuiltinType::PseudoObject:ID = PREDEF_TYPE_PSEUDO_OBJECT;break; - case BuiltinType::Dependent: ID = PREDEF_TYPE_DEPENDENT_ID; break; - case BuiltinType::UnknownAny: ID = PREDEF_TYPE_UNKNOWN_ANY; break; - case BuiltinType::ARCUnbridgedCast: - ID = PREDEF_TYPE_ARC_UNBRIDGED_CAST; break; - case BuiltinType::ObjCId: ID = PREDEF_TYPE_OBJC_ID; break; - case BuiltinType::ObjCClass: ID = PREDEF_TYPE_OBJC_CLASS; break; - case BuiltinType::ObjCSel: ID = PREDEF_TYPE_OBJC_SEL; break; - case BuiltinType::BuiltinFn: - ID = PREDEF_TYPE_BUILTIN_FN; break; - - } - - return TypeIdx(ID); -} - -unsigned serialization::ComputeHash(Selector Sel) { - unsigned N = Sel.getNumArgs(); - if (N == 0) - ++N; - unsigned R = 5381; - for (unsigned I = 0; I != N; ++I) - if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I)) - R = llvm::HashString(II->getName(), R); - return R; -} +//===--- ASTCommon.cpp - Common stuff for ASTReader/ASTWriter----*- 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 common functions that both ASTReader and ASTWriter use.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ASTCommon.h"
+#include "clang/Basic/IdentifierTable.h"
+#include "clang/Serialization/ASTDeserializationListener.h"
+#include "llvm/ADT/StringExtras.h"
+
+using namespace clang;
+
+// Give ASTDeserializationListener's VTable a home.
+ASTDeserializationListener::~ASTDeserializationListener() { }
+
+serialization::TypeIdx
+serialization::TypeIdxFromBuiltin(const BuiltinType *BT) {
+ unsigned ID = 0;
+ switch (BT->getKind()) {
+ case BuiltinType::Void: ID = PREDEF_TYPE_VOID_ID; break;
+ case BuiltinType::Bool: ID = PREDEF_TYPE_BOOL_ID; break;
+ case BuiltinType::Char_U: ID = PREDEF_TYPE_CHAR_U_ID; break;
+ case BuiltinType::UChar: ID = PREDEF_TYPE_UCHAR_ID; break;
+ case BuiltinType::UShort: ID = PREDEF_TYPE_USHORT_ID; break;
+ case BuiltinType::UInt: ID = PREDEF_TYPE_UINT_ID; break;
+ case BuiltinType::ULong: ID = PREDEF_TYPE_ULONG_ID; break;
+ case BuiltinType::ULongLong: ID = PREDEF_TYPE_ULONGLONG_ID; break;
+ case BuiltinType::UInt128: ID = PREDEF_TYPE_UINT128_ID; break;
+ case BuiltinType::Char_S: ID = PREDEF_TYPE_CHAR_S_ID; break;
+ case BuiltinType::SChar: ID = PREDEF_TYPE_SCHAR_ID; break;
+ case BuiltinType::WChar_S:
+ case BuiltinType::WChar_U: ID = PREDEF_TYPE_WCHAR_ID; break;
+ case BuiltinType::Short: ID = PREDEF_TYPE_SHORT_ID; break;
+ case BuiltinType::Int: ID = PREDEF_TYPE_INT_ID; break;
+ case BuiltinType::Long: ID = PREDEF_TYPE_LONG_ID; break;
+ case BuiltinType::LongLong: ID = PREDEF_TYPE_LONGLONG_ID; break;
+ case BuiltinType::Int128: ID = PREDEF_TYPE_INT128_ID; break;
+ case BuiltinType::Half: ID = PREDEF_TYPE_HALF_ID; break;
+ case BuiltinType::Float: ID = PREDEF_TYPE_FLOAT_ID; break;
+ case BuiltinType::Double: ID = PREDEF_TYPE_DOUBLE_ID; break;
+ case BuiltinType::LongDouble: ID = PREDEF_TYPE_LONGDOUBLE_ID; break;
+ case BuiltinType::NullPtr: ID = PREDEF_TYPE_NULLPTR_ID; break;
+ case BuiltinType::Char16: ID = PREDEF_TYPE_CHAR16_ID; break;
+ case BuiltinType::Char32: ID = PREDEF_TYPE_CHAR32_ID; break;
+ case BuiltinType::Overload: ID = PREDEF_TYPE_OVERLOAD_ID; break;
+ case BuiltinType::BoundMember:ID = PREDEF_TYPE_BOUND_MEMBER; break;
+ case BuiltinType::PseudoObject:ID = PREDEF_TYPE_PSEUDO_OBJECT;break;
+ case BuiltinType::Dependent: ID = PREDEF_TYPE_DEPENDENT_ID; break;
+ case BuiltinType::UnknownAny: ID = PREDEF_TYPE_UNKNOWN_ANY; break;
+ case BuiltinType::ARCUnbridgedCast:
+ ID = PREDEF_TYPE_ARC_UNBRIDGED_CAST; break;
+ case BuiltinType::ObjCId: ID = PREDEF_TYPE_OBJC_ID; break;
+ case BuiltinType::ObjCClass: ID = PREDEF_TYPE_OBJC_CLASS; break;
+ case BuiltinType::ObjCSel: ID = PREDEF_TYPE_OBJC_SEL; break;
+ case BuiltinType::OCLImage1d: ID = PREDEF_TYPE_IMAGE1D_ID; break;
+ case BuiltinType::OCLImage1dArray: ID = PREDEF_TYPE_IMAGE1D_ARR_ID; break;
+ case BuiltinType::OCLImage1dBuffer: ID = PREDEF_TYPE_IMAGE1D_BUFF_ID; break;
+ case BuiltinType::OCLImage2d: ID = PREDEF_TYPE_IMAGE2D_ID; break;
+ case BuiltinType::OCLImage2dArray: ID = PREDEF_TYPE_IMAGE2D_ARR_ID; break;
+ case BuiltinType::OCLImage3d: ID = PREDEF_TYPE_IMAGE3D_ID; break;
+ case BuiltinType::BuiltinFn:
+ ID = PREDEF_TYPE_BUILTIN_FN; break;
+
+ }
+
+ return TypeIdx(ID);
+}
+
+unsigned serialization::ComputeHash(Selector Sel) {
+ unsigned N = Sel.getNumArgs();
+ if (N == 0)
+ ++N;
+ unsigned R = 5381;
+ for (unsigned I = 0; I != N; ++I)
+ if (IdentifierInfo *II = Sel.getIdentifierInfoForSlot(I))
+ R = llvm::HashString(II->getName(), R);
+ return R;
+}
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index c0976ee1e6..88b5614124 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -1,6992 +1,6998 @@ -//===--- ASTReader.cpp - AST File Reader ------------------------*- 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 ASTReader class, which reads AST files. -// -//===----------------------------------------------------------------------===// - -#include "clang/Serialization/ASTReader.h" -#include "ASTCommon.h" -#include "ASTReaderInternals.h" -#include "clang/AST/ASTConsumer.h" -#include "clang/AST/ASTContext.h" -#include "clang/AST/DeclTemplate.h" -#include "clang/AST/Expr.h" -#include "clang/AST/ExprCXX.h" -#include "clang/AST/NestedNameSpecifier.h" -#include "clang/AST/Type.h" -#include "clang/AST/TypeLocVisitor.h" -#include "clang/Basic/FileManager.h" -#include "clang/Basic/FileSystemStatCache.h" -#include "clang/Basic/OnDiskHashTable.h" -#include "clang/Basic/SourceManager.h" -#include "clang/Basic/SourceManagerInternals.h" -#include "clang/Basic/TargetInfo.h" -#include "clang/Basic/TargetOptions.h" -#include "clang/Basic/Version.h" -#include "clang/Basic/VersionTuple.h" -#include "clang/Lex/HeaderSearch.h" -#include "clang/Lex/HeaderSearchOptions.h" -#include "clang/Lex/MacroInfo.h" -#include "clang/Lex/PreprocessingRecord.h" -#include "clang/Lex/Preprocessor.h" -#include "clang/Lex/PreprocessorOptions.h" -#include "clang/Sema/Scope.h" -#include "clang/Sema/Sema.h" -#include "clang/Serialization/ASTDeserializationListener.h" -#include "clang/Serialization/ModuleManager.h" -#include "clang/Serialization/SerializationDiagnostic.h" -#include "llvm/ADT/StringExtras.h" -#include "llvm/Bitcode/BitstreamReader.h" -#include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/FileSystem.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/Path.h" -#include "llvm/Support/SaveAndRestore.h" -#include "llvm/Support/system_error.h" -#include <algorithm> -#include <cstdio> -#include <iterator> - -using namespace clang; -using namespace clang::serialization; -using namespace clang::serialization::reader; - -//===----------------------------------------------------------------------===// -// PCH validator implementation -//===----------------------------------------------------------------------===// - -ASTReaderListener::~ASTReaderListener() {} - -/// \brief Compare the given set of language options against an existing set of -/// language options. -/// -/// \param Diags If non-NULL, diagnostics will be emitted via this engine. -/// -/// \returns true if the languagae options mis-match, false otherwise. -static bool checkLanguageOptions(const LangOptions &LangOpts, - const LangOptions &ExistingLangOpts, - DiagnosticsEngine *Diags) { -#define LANGOPT(Name, Bits, Default, Description) \ - if (ExistingLangOpts.Name != LangOpts.Name) { \ - if (Diags) \ - Diags->Report(diag::err_pch_langopt_mismatch) \ - << Description << LangOpts.Name << ExistingLangOpts.Name; \ - return true; \ - } - -#define VALUE_LANGOPT(Name, Bits, Default, Description) \ - if (ExistingLangOpts.Name != LangOpts.Name) { \ - if (Diags) \ - Diags->Report(diag::err_pch_langopt_value_mismatch) \ - << Description; \ - return true; \ - } - -#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ - if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \ - if (Diags) \ - Diags->Report(diag::err_pch_langopt_value_mismatch) \ - << Description; \ - return true; \ - } - -#define BENIGN_LANGOPT(Name, Bits, Default, Description) -#define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) -#include "clang/Basic/LangOptions.def" - - if (ExistingLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) { - if (Diags) - Diags->Report(diag::err_pch_langopt_value_mismatch) - << "target Objective-C runtime"; - return true; - } - - return false; -} - -/// \brief Compare the given set of target options against an existing set of -/// target options. -/// -/// \param Diags If non-NULL, diagnostics will be emitted via this engine. -/// -/// \returns true if the target options mis-match, false otherwise. -static bool checkTargetOptions(const TargetOptions &TargetOpts, - const TargetOptions &ExistingTargetOpts, - DiagnosticsEngine *Diags) { -#define CHECK_TARGET_OPT(Field, Name) \ - if (TargetOpts.Field != ExistingTargetOpts.Field) { \ - if (Diags) \ - Diags->Report(diag::err_pch_targetopt_mismatch) \ - << Name << TargetOpts.Field << ExistingTargetOpts.Field; \ - return true; \ - } - - CHECK_TARGET_OPT(Triple, "target"); - CHECK_TARGET_OPT(CPU, "target CPU"); - CHECK_TARGET_OPT(ABI, "target ABI"); - CHECK_TARGET_OPT(CXXABI, "target C++ ABI"); - CHECK_TARGET_OPT(LinkerVersion, "target linker version"); -#undef CHECK_TARGET_OPT - - // Compare feature sets. - SmallVector<StringRef, 4> ExistingFeatures( - ExistingTargetOpts.FeaturesAsWritten.begin(), - ExistingTargetOpts.FeaturesAsWritten.end()); - SmallVector<StringRef, 4> ReadFeatures(TargetOpts.FeaturesAsWritten.begin(), - TargetOpts.FeaturesAsWritten.end()); - std::sort(ExistingFeatures.begin(), ExistingFeatures.end()); - std::sort(ReadFeatures.begin(), ReadFeatures.end()); - - unsigned ExistingIdx = 0, ExistingN = ExistingFeatures.size(); - unsigned ReadIdx = 0, ReadN = ReadFeatures.size(); - while (ExistingIdx < ExistingN && ReadIdx < ReadN) { - if (ExistingFeatures[ExistingIdx] == ReadFeatures[ReadIdx]) { - ++ExistingIdx; - ++ReadIdx; - continue; - } - - if (ReadFeatures[ReadIdx] < ExistingFeatures[ExistingIdx]) { - if (Diags) - Diags->Report(diag::err_pch_targetopt_feature_mismatch) - << false << ReadFeatures[ReadIdx]; - return true; - } - - if (Diags) - Diags->Report(diag::err_pch_targetopt_feature_mismatch) - << true << ExistingFeatures[ExistingIdx]; - return true; - } - - if (ExistingIdx < ExistingN) { - if (Diags) - Diags->Report(diag::err_pch_targetopt_feature_mismatch) - << true << ExistingFeatures[ExistingIdx]; - return true; - } - - if (ReadIdx < ReadN) { - if (Diags) - Diags->Report(diag::err_pch_targetopt_feature_mismatch) - << false << ReadFeatures[ReadIdx]; - return true; - } - - return false; -} - -bool -PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts, - bool Complain) { - const LangOptions &ExistingLangOpts = PP.getLangOpts(); - return checkLanguageOptions(LangOpts, ExistingLangOpts, - Complain? &Reader.Diags : 0); -} - -bool PCHValidator::ReadTargetOptions(const TargetOptions &TargetOpts, - bool Complain) { - const TargetOptions &ExistingTargetOpts = PP.getTargetInfo().getTargetOpts(); - return checkTargetOptions(TargetOpts, ExistingTargetOpts, - Complain? &Reader.Diags : 0); -} - -namespace { - typedef llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> > - MacroDefinitionsMap; -} - -/// \brief Collect the macro definitions provided by the given preprocessor -/// options. -static void collectMacroDefinitions(const PreprocessorOptions &PPOpts, - MacroDefinitionsMap &Macros, - SmallVectorImpl<StringRef> *MacroNames = 0){ - for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { - StringRef Macro = PPOpts.Macros[I].first; - bool IsUndef = PPOpts.Macros[I].second; - - std::pair<StringRef, StringRef> MacroPair = Macro.split('='); - StringRef MacroName = MacroPair.first; - StringRef MacroBody = MacroPair.second; - - // For an #undef'd macro, we only care about the name. - if (IsUndef) { - if (MacroNames && !Macros.count(MacroName)) - MacroNames->push_back(MacroName); - - Macros[MacroName] = std::make_pair("", true); - continue; - } - - // For a #define'd macro, figure out the actual definition. - if (MacroName.size() == Macro.size()) - MacroBody = "1"; - else { - // Note: GCC drops anything following an end-of-line character. - StringRef::size_type End = MacroBody.find_first_of("\n\r"); - MacroBody = MacroBody.substr(0, End); - } - - if (MacroNames && !Macros.count(MacroName)) - MacroNames->push_back(MacroName); - Macros[MacroName] = std::make_pair(MacroBody, false); - } -} - -/// \brief Check the preprocessor options deserialized from the control block -/// against the preprocessor options in an existing preprocessor. -/// -/// \param Diags If non-null, produce diagnostics for any mismatches incurred. -static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, - const PreprocessorOptions &ExistingPPOpts, - DiagnosticsEngine *Diags, - FileManager &FileMgr, - std::string &SuggestedPredefines) { - // Check macro definitions. - MacroDefinitionsMap ASTFileMacros; - collectMacroDefinitions(PPOpts, ASTFileMacros); - MacroDefinitionsMap ExistingMacros; - SmallVector<StringRef, 4> ExistingMacroNames; - collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames); - - for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) { - // Dig out the macro definition in the existing preprocessor options. - StringRef MacroName = ExistingMacroNames[I]; - std::pair<StringRef, bool> Existing = ExistingMacros[MacroName]; - - // Check whether we know anything about this macro name or not. - llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> >::iterator Known - = ASTFileMacros.find(MacroName); - if (Known == ASTFileMacros.end()) { - // FIXME: Check whether this identifier was referenced anywhere in the - // AST file. If so, we should reject the AST file. Unfortunately, this - // information isn't in the control block. What shall we do about it? - - if (Existing.second) { - SuggestedPredefines += "#undef "; - SuggestedPredefines += MacroName.str(); - SuggestedPredefines += '\n'; - } else { - SuggestedPredefines += "#define "; - SuggestedPredefines += MacroName.str(); - SuggestedPredefines += ' '; - SuggestedPredefines += Existing.first.str(); - SuggestedPredefines += '\n'; - } - continue; - } - - // If the macro was defined in one but undef'd in the other, we have a - // conflict. - if (Existing.second != Known->second.second) { - if (Diags) { - Diags->Report(diag::err_pch_macro_def_undef) - << MacroName << Known->second.second; - } - return true; - } - - // If the macro was #undef'd in both, or if the macro bodies are identical, - // it's fine. - if (Existing.second || Existing.first == Known->second.first) - continue; - - // The macro bodies differ; complain. - if (Diags) { - Diags->Report(diag::err_pch_macro_def_conflict) - << MacroName << Known->second.first << Existing.first; - } - return true; - } - - // Check whether we're using predefines. - if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines) { - if (Diags) { - Diags->Report(diag::err_pch_undef) << ExistingPPOpts.UsePredefines; - } - return true; - } - - // Compute the #include and #include_macros lines we need. - for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) { - StringRef File = ExistingPPOpts.Includes[I]; - if (File == ExistingPPOpts.ImplicitPCHInclude) - continue; - - if (std::find(PPOpts.Includes.begin(), PPOpts.Includes.end(), File) - != PPOpts.Includes.end()) - continue; - - SuggestedPredefines += "#include \""; - SuggestedPredefines += - HeaderSearch::NormalizeDashIncludePath(File, FileMgr); - SuggestedPredefines += "\"\n"; - } - - for (unsigned I = 0, N = ExistingPPOpts.MacroIncludes.size(); I != N; ++I) { - StringRef File = ExistingPPOpts.MacroIncludes[I]; - if (std::find(PPOpts.MacroIncludes.begin(), PPOpts.MacroIncludes.end(), - File) - != PPOpts.MacroIncludes.end()) - continue; - - SuggestedPredefines += "#__include_macros \""; - SuggestedPredefines += - HeaderSearch::NormalizeDashIncludePath(File, FileMgr); - SuggestedPredefines += "\"\n##\n"; - } - - return false; -} - -bool PCHValidator::ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, - bool Complain, - std::string &SuggestedPredefines) { - const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts(); - - return checkPreprocessorOptions(PPOpts, ExistingPPOpts, - Complain? &Reader.Diags : 0, - PP.getFileManager(), - SuggestedPredefines); -} - -void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, - unsigned ID) { - PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); - ++NumHeaderInfos; -} - -void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) { - PP.setCounterValue(Value); -} - -//===----------------------------------------------------------------------===// -// AST reader implementation -//===----------------------------------------------------------------------===// - -void -ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { - DeserializationListener = Listener; -} - - - -unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { - return serialization::ComputeHash(Sel); -} - - -std::pair<unsigned, unsigned> -ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { - using namespace clang::io; - unsigned KeyLen = ReadUnalignedLE16(d); - unsigned DataLen = ReadUnalignedLE16(d); - return std::make_pair(KeyLen, DataLen); -} - -ASTSelectorLookupTrait::internal_key_type -ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { - using namespace clang::io; - SelectorTable &SelTable = Reader.getContext().Selectors; - unsigned N = ReadUnalignedLE16(d); - IdentifierInfo *FirstII - = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); - if (N == 0) - return SelTable.getNullarySelector(FirstII); - else if (N == 1) - return SelTable.getUnarySelector(FirstII); - - SmallVector<IdentifierInfo *, 16> Args; - Args.push_back(FirstII); - for (unsigned I = 1; I != N; ++I) - Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d))); - - return SelTable.getSelector(N, Args.data()); -} - -ASTSelectorLookupTrait::data_type -ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, - unsigned DataLen) { - using namespace clang::io; - - data_type Result; - - Result.ID = Reader.getGlobalSelectorID(F, ReadUnalignedLE32(d)); - unsigned NumInstanceMethods = ReadUnalignedLE16(d); - unsigned NumFactoryMethods = ReadUnalignedLE16(d); - - // Load instance methods - for (unsigned I = 0; I != NumInstanceMethods; ++I) { - if (ObjCMethodDecl *Method - = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) - Result.Instance.push_back(Method); - } - - // Load factory methods - for (unsigned I = 0; I != NumFactoryMethods; ++I) { - if (ObjCMethodDecl *Method - = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) - Result.Factory.push_back(Method); - } - - return Result; -} - -unsigned ASTIdentifierLookupTrait::ComputeHash(const internal_key_type& a) { - return llvm::HashString(StringRef(a.first, a.second)); -} - -std::pair<unsigned, unsigned> -ASTIdentifierLookupTrait::ReadKeyDataLength(const unsigned char*& d) { - using namespace clang::io; - unsigned DataLen = ReadUnalignedLE16(d); - unsigned KeyLen = ReadUnalignedLE16(d); - return std::make_pair(KeyLen, DataLen); -} - -std::pair<const char*, unsigned> -ASTIdentifierLookupTrait::ReadKey(const unsigned char* d, unsigned n) { - assert(n >= 2 && d[n-1] == '\0'); - return std::make_pair((const char*) d, n-1); -} - -IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, - const unsigned char* d, - unsigned DataLen) { - using namespace clang::io; - unsigned RawID = ReadUnalignedLE32(d); - bool IsInteresting = RawID & 0x01; - - // Wipe out the "is interesting" bit. - RawID = RawID >> 1; - - IdentID ID = Reader.getGlobalIdentifierID(F, RawID); - if (!IsInteresting) { - // For uninteresting identifiers, just build the IdentifierInfo - // and associate it with the persistent ID. - IdentifierInfo *II = KnownII; - if (!II) { - II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); - KnownII = II; - } - Reader.SetIdentifierInfo(ID, II); - II->setIsFromAST(); - Reader.markIdentifierUpToDate(II); - return II; - } - - unsigned ObjCOrBuiltinID = ReadUnalignedLE16(d); - unsigned Bits = ReadUnalignedLE16(d); - bool CPlusPlusOperatorKeyword = Bits & 0x01; - Bits >>= 1; - bool HasRevertedTokenIDToIdentifier = Bits & 0x01; - Bits >>= 1; - bool Poisoned = Bits & 0x01; - Bits >>= 1; - bool ExtensionToken = Bits & 0x01; - Bits >>= 1; - bool hadMacroDefinition = Bits & 0x01; - Bits >>= 1; - - assert(Bits == 0 && "Extra bits in the identifier?"); - DataLen -= 8; - - // Build the IdentifierInfo itself and link the identifier ID with - // the new IdentifierInfo. - IdentifierInfo *II = KnownII; - if (!II) { - II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); - KnownII = II; - } - Reader.markIdentifierUpToDate(II); - II->setIsFromAST(); - - // Set or check the various bits in the IdentifierInfo structure. - // Token IDs are read-only. - if (HasRevertedTokenIDToIdentifier) - II->RevertTokenIDToIdentifier(); - II->setObjCOrBuiltinID(ObjCOrBuiltinID); - assert(II->isExtensionToken() == ExtensionToken && - "Incorrect extension token flag"); - (void)ExtensionToken; - if (Poisoned) - II->setIsPoisoned(true); - assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && - "Incorrect C++ operator keyword flag"); - (void)CPlusPlusOperatorKeyword; - - // If this identifier is a macro, deserialize the macro - // definition. - if (hadMacroDefinition) { - SmallVector<MacroID, 4> MacroIDs; - while (uint32_t LocalID = ReadUnalignedLE32(d)) { - MacroIDs.push_back(Reader.getGlobalMacroID(F, LocalID)); - DataLen -= 4; - } - DataLen -= 4; - Reader.setIdentifierIsMacro(II, MacroIDs); - } - - Reader.SetIdentifierInfo(ID, II); - - // Read all of the declarations visible at global scope with this - // name. - if (DataLen > 0) { - SmallVector<uint32_t, 4> DeclIDs; - for (; DataLen > 0; DataLen -= 4) - DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); - Reader.SetGloballyVisibleDecls(II, DeclIDs); - } - - return II; -} - -unsigned -ASTDeclContextNameLookupTrait::ComputeHash(const DeclNameKey &Key) const { - llvm::FoldingSetNodeID ID; - ID.AddInteger(Key.Kind); - - switch (Key.Kind) { - case DeclarationName::Identifier: - case DeclarationName::CXXLiteralOperatorName: - ID.AddString(((IdentifierInfo*)Key.Data)->getName()); - break; - case DeclarationName::ObjCZeroArgSelector: - case DeclarationName::ObjCOneArgSelector: - case DeclarationName::ObjCMultiArgSelector: - ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); - break; - case DeclarationName::CXXOperatorName: - ID.AddInteger((OverloadedOperatorKind)Key.Data); - break; - case DeclarationName::CXXConstructorName: - case DeclarationName::CXXDestructorName: - case DeclarationName::CXXConversionFunctionName: - case DeclarationName::CXXUsingDirective: - break; - } - - return ID.ComputeHash(); -} - -ASTDeclContextNameLookupTrait::internal_key_type -ASTDeclContextNameLookupTrait::GetInternalKey( - const external_key_type& Name) const { - DeclNameKey Key; - Key.Kind = Name.getNameKind(); - switch (Name.getNameKind()) { - case DeclarationName::Identifier: - Key.Data = (uint64_t)Name.getAsIdentifierInfo(); - break; - case DeclarationName::ObjCZeroArgSelector: - case DeclarationName::ObjCOneArgSelector: - case DeclarationName::ObjCMultiArgSelector: - Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); - break; - case DeclarationName::CXXOperatorName: - Key.Data = Name.getCXXOverloadedOperator(); - break; - case DeclarationName::CXXLiteralOperatorName: - Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); - break; - case DeclarationName::CXXConstructorName: - case DeclarationName::CXXDestructorName: - case DeclarationName::CXXConversionFunctionName: - case DeclarationName::CXXUsingDirective: - Key.Data = 0; - break; - } - - return Key; -} - -std::pair<unsigned, unsigned> -ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) { - using namespace clang::io; - unsigned KeyLen = ReadUnalignedLE16(d); - unsigned DataLen = ReadUnalignedLE16(d); - return std::make_pair(KeyLen, DataLen); -} - -ASTDeclContextNameLookupTrait::internal_key_type -ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) { - using namespace clang::io; - - DeclNameKey Key; - Key.Kind = (DeclarationName::NameKind)*d++; - switch (Key.Kind) { - case DeclarationName::Identifier: - Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); - break; - case DeclarationName::ObjCZeroArgSelector: - case DeclarationName::ObjCOneArgSelector: - case DeclarationName::ObjCMultiArgSelector: - Key.Data = - (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d)) - .getAsOpaquePtr(); - break; - case DeclarationName::CXXOperatorName: - Key.Data = *d++; // OverloadedOperatorKind - break; - case DeclarationName::CXXLiteralOperatorName: - Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); - break; - case DeclarationName::CXXConstructorName: - case DeclarationName::CXXDestructorName: - case DeclarationName::CXXConversionFunctionName: - case DeclarationName::CXXUsingDirective: - Key.Data = 0; - break; - } - - return Key; -} - -ASTDeclContextNameLookupTrait::data_type -ASTDeclContextNameLookupTrait::ReadData(internal_key_type, - const unsigned char* d, - unsigned DataLen) { - using namespace clang::io; - unsigned NumDecls = ReadUnalignedLE16(d); - LE32DeclID *Start = (LE32DeclID *)d; - return std::make_pair(Start, Start + NumDecls); -} - -bool ASTReader::ReadDeclContextStorage(ModuleFile &M, - llvm::BitstreamCursor &Cursor, - const std::pair<uint64_t, uint64_t> &Offsets, - DeclContextInfo &Info) { - SavedStreamPosition SavedPosition(Cursor); - // First the lexical decls. - if (Offsets.first != 0) { - Cursor.JumpToBit(Offsets.first); - - RecordData Record; - const char *Blob; - unsigned BlobLen; - unsigned Code = Cursor.ReadCode(); - unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); - if (RecCode != DECL_CONTEXT_LEXICAL) { - Error("Expected lexical block"); - return true; - } - - Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); - Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); - } - - // Now the lookup table. - if (Offsets.second != 0) { - Cursor.JumpToBit(Offsets.second); - - RecordData Record; - const char *Blob; - unsigned BlobLen; - unsigned Code = Cursor.ReadCode(); - unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); - if (RecCode != DECL_CONTEXT_VISIBLE) { - Error("Expected visible lookup table block"); - return true; - } - Info.NameLookupTableData - = ASTDeclContextNameLookupTable::Create( - (const unsigned char *)Blob + Record[0], - (const unsigned char *)Blob, - ASTDeclContextNameLookupTrait(*this, M)); - } - - return false; -} - -void ASTReader::Error(StringRef Msg) { - Error(diag::err_fe_pch_malformed, Msg); -} - -void ASTReader::Error(unsigned DiagID, - StringRef Arg1, StringRef Arg2) { - if (Diags.isDiagnosticInFlight()) - Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); - else - Diag(DiagID) << Arg1 << Arg2; -} - -//===----------------------------------------------------------------------===// -// Source Manager Deserialization -//===----------------------------------------------------------------------===// - -/// \brief Read the line table in the source manager block. -/// \returns true if there was an error. -bool ASTReader::ParseLineTable(ModuleFile &F, - SmallVectorImpl<uint64_t> &Record) { - unsigned Idx = 0; - LineTableInfo &LineTable = SourceMgr.getLineTable(); - - // Parse the file names - std::map<int, int> FileIDs; - for (int I = 0, N = Record[Idx++]; I != N; ++I) { - // Extract the file name - unsigned FilenameLen = Record[Idx++]; - std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); - Idx += FilenameLen; - MaybeAddSystemRootToFilename(F, Filename); - FileIDs[I] = LineTable.getLineTableFilenameID(Filename); - } - - // Parse the line entries - std::vector<LineEntry> Entries; - while (Idx < Record.size()) { - int FID = Record[Idx++]; - assert(FID >= 0 && "Serialized line entries for non-local file."); - // Remap FileID from 1-based old view. - FID += F.SLocEntryBaseID - 1; - - // Extract the line entries - unsigned NumEntries = Record[Idx++]; - assert(NumEntries && "Numentries is 00000"); - Entries.clear(); - Entries.reserve(NumEntries); - for (unsigned I = 0; I != NumEntries; ++I) { - unsigned FileOffset = Record[Idx++]; - unsigned LineNo = Record[Idx++]; - int FilenameID = FileIDs[Record[Idx++]]; - SrcMgr::CharacteristicKind FileKind - = (SrcMgr::CharacteristicKind)Record[Idx++]; - unsigned IncludeOffset = Record[Idx++]; - Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, - FileKind, IncludeOffset)); - } - LineTable.AddEntry(FileID::get(FID), Entries); - } |