Index: cfe/trunk/lib/Lex/Lexer.cpp =================================================================== --- cfe/trunk/lib/Lex/Lexer.cpp +++ cfe/trunk/lib/Lex/Lexer.cpp @@ -14,18 +14,27 @@ #include "clang/Lex/Lexer.h" #include "UnicodeCharSets.h" #include "clang/Basic/CharInfo.h" +#include "clang/Basic/IdentifierTable.h" #include "clang/Basic/SourceManager.h" -#include "clang/Lex/CodeCompletionHandler.h" #include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/LiteralSupport.h" #include "clang/Lex/Preprocessor.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/UnicodeCharRanges.h" +#include +#include +#include +#include #include +#include +#include +#include + using namespace clang; //===----------------------------------------------------------------------===// @@ -45,7 +54,6 @@ return specId ? specId->getObjCKeywordID() : tok::objc_not_keyword; } - //===----------------------------------------------------------------------===// // Lexer Class Implementation //===----------------------------------------------------------------------===// @@ -196,7 +204,6 @@ return L; } - /// Stringify - Convert the specified string into a C string, with surrounding /// ""'s, and with escaped \ and " characters. std::string Lexer::Stringify(StringRef Str, bool Charify) { @@ -398,7 +405,6 @@ return getSpellingSlow(Tok, TokStart, LangOpts, const_cast(Buffer)); } - /// MeasureTokenLength - Relex the token at the specified location and return /// its length in bytes in the input file. If the token needs cleaning (e.g. /// includes a trigraph or an escaped newline) then this count includes bytes @@ -526,13 +532,15 @@ } namespace { + enum PreambleDirectiveKind { PDK_Skipped, PDK_StartIf, PDK_EndIf, PDK_Unknown }; -} + +} // end anonymous namespace std::pair Lexer::ComputePreamble(StringRef Buffer, const LangOptions &LangOpts, @@ -694,7 +702,6 @@ : TheTok.isAtStartOfLine()); } - /// AdvanceToTokenCharacter - Given a location that specifies the start of a /// token, return a new location that specifies a character within the token. SourceLocation Lexer::AdvanceToTokenCharacter(SourceLocation TokStart, @@ -961,7 +968,7 @@ assert(Loc.isMacroID() && "Only reasonble to call this on macros"); // Find the location of the immediate macro expansion. - while (1) { + while (true) { FileID FID = SM.getFileID(Loc); const SrcMgr::SLocEntry *E = &SM.getSLocEntry(FID); const SrcMgr::ExpansionInfo &Expansion = E->getExpansion(); @@ -1031,7 +1038,6 @@ return isIdentifierBody(c, LangOpts.DollarIdents); } - //===----------------------------------------------------------------------===// // Diagnostics forwarding code. //===----------------------------------------------------------------------===// @@ -1157,7 +1163,7 @@ /// them), skip over them and return the first non-escaped-newline found, /// otherwise return P. const char *Lexer::SkipEscapedNewLines(const char *P) { - while (1) { + while (true) { const char *AfterEscape; if (*P == '\\') { AfterEscape = P+1; @@ -1310,7 +1316,6 @@ return *Ptr; } - /// getCharAndSizeSlowNoWarn - Handle the slow/uncommon case of the /// getCharAndSizeNoWarn method. Here we know that we can accumulate into Size, /// and that we have already incremented Ptr by Size bytes. @@ -1548,7 +1553,7 @@ // Otherwise, $,\,? in identifier found. Enter slower path. C = getCharAndSize(CurPtr, Size); - while (1) { + while (true) { if (C == '$') { // If we hit a $ and they are not supported in identifiers, we are done. if (!LangOpts.DollarIdents) goto FinishIdentifier; @@ -1837,7 +1842,7 @@ // Search for the next '"' in hopes of salvaging the lexer. Unfortunately, // it's possible the '"' was intended to be part of the raw string, but // there's not much we can do about that. - while (1) { + while (true) { char C = *CurPtr++; if (C == '"') @@ -1856,7 +1861,7 @@ const char *Prefix = CurPtr; CurPtr += PrefixLen + 1; // skip over prefix and '(' - while (1) { + while (true) { char C = *CurPtr++; if (C == ')') { @@ -1921,7 +1926,6 @@ return true; } - /// LexCharConstant - Lex the remainder of a character constant, after having /// lexed either ' or L' or u8' or u' or U'. bool Lexer::LexCharConstant(Token &Result, const char *CurPtr, @@ -2000,7 +2004,7 @@ unsigned char Char = *CurPtr; // Skip consecutive spaces efficiently. - while (1) { + while (true) { // Skip horizontal whitespace very aggressively. while (isHorizontalWhitespace(Char)) Char = *++CurPtr; @@ -2323,7 +2327,7 @@ if (C == '/') C = *CurPtr++; - while (1) { + while (true) { // Skip over all non-interesting characters until we find end of buffer or a // (probably ending) '/' character. if (CurPtr + 24 < BufferEnd && @@ -2464,7 +2468,7 @@ // CurPtr - Cache BufferPtr in an automatic variable. const char *CurPtr = BufferPtr; - while (1) { + while (true) { char Char = getAndAdvanceChar(CurPtr, Tmp); switch (Char) { default: @@ -2677,7 +2681,6 @@ return false; } - /// HandleEndOfConflictMarker - If this is a '====' or '||||' or '>>>>', or if /// it is '<<<<' and the conflict marker started with a '>>>>' marker, then it /// is the end of a conflict marker. Handle it by ignoring up until the end of @@ -3506,7 +3509,6 @@ CurPtr = ConsumeChar(CurPtr, SizeTmp, Result); Kind = tok::greatergreater; } - } else { Kind = tok::greater; } Index: cfe/trunk/lib/Lex/LiteralSupport.cpp =================================================================== --- cfe/trunk/lib/Lex/LiteralSupport.cpp +++ cfe/trunk/lib/Lex/LiteralSupport.cpp @@ -14,13 +14,25 @@ #include "clang/Lex/LiteralSupport.h" #include "clang/Basic/CharInfo.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/TargetInfo.h" #include "clang/Lex/LexDiagnostic.h" +#include "clang/Lex/Lexer.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Lex/Token.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/ErrorHandling.h" +#include +#include +#include +#include +#include +#include using namespace clang; @@ -135,7 +147,7 @@ if (Diags) Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf, diag::err_hex_escape_no_digits) << "x"; - HadError = 1; + HadError = true; break; } @@ -453,7 +465,6 @@ ResultBuf += bytesToWrite; } - /// integer-constant: [C99 6.4.4.1] /// decimal-constant integer-suffix /// octal-constant integer-suffix @@ -986,7 +997,6 @@ return Result.convertFromString(Str, APFloat::rmNearestTiesToEven); } - /// \verbatim /// user-defined-character-literal: [C++11 lex.ext] /// character-literal ud-suffix Index: cfe/trunk/lib/Lex/PPDirectives.cpp =================================================================== --- cfe/trunk/lib/Lex/PPDirectives.cpp +++ cfe/trunk/lib/Lex/PPDirectives.cpp @@ -12,24 +12,41 @@ /// //===----------------------------------------------------------------------===// +#include "clang/Basic/CharInfo.h" #include "clang/Basic/FileManager.h" +#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/Module.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" +#include "clang/Basic/TokenKinds.h" #include "clang/Lex/CodeCompletionHandler.h" #include "clang/Lex/HeaderSearch.h" -#include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/LiteralSupport.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/ModuleLoader.h" +#include "clang/Lex/ModuleMap.h" +#include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Pragma.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Lex/PTHLexer.h" +#include "clang/Lex/Token.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" -#include "llvm/ADT/iterator_range.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/AlignOf.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Path.h" -#include "llvm/Support/SaveAndRestore.h" +#include +#include +#include +#include +#include +#include using namespace clang; @@ -381,7 +398,7 @@ // disabling warnings, etc. CurPPLexer->LexingRawMode = true; Token Tok; - while (1) { + while (true) { CurLexer->Lex(Tok); if (Tok.is(tok::code_completion)) { @@ -577,7 +594,7 @@ } void Preprocessor::PTHSkipExcludedConditionalBlock() { - while (1) { + while (true) { assert(CurPTHLexer); assert(CurPTHLexer->LexingRawMode == false); @@ -1854,8 +1871,8 @@ !SuggestedModule.getModule() ->getTopLevelModule() ->HasIncompatibleModuleFile) { - clang::Module::Requirement Requirement; - clang::Module::UnresolvedHeaderDirective MissingHeader; + Module::Requirement Requirement; + Module::UnresolvedHeaderDirective MissingHeader; Module *M = SuggestedModule.getModule(); // Identify the cause. (void)M->isAvailable(getLangOpts(), getTargetInfo(), Requirement, @@ -2126,7 +2143,7 @@ bool Preprocessor::ReadMacroDefinitionArgList(MacroInfo *MI, Token &Tok) { SmallVector Arguments; - while (1) { + while (true) { LexUnexpandedToken(Tok); switch (Tok.getKind()) { case tok::r_paren: Index: cfe/trunk/lib/Lex/PPExpressions.cpp =================================================================== --- cfe/trunk/lib/Lex/PPExpressions.cpp +++ cfe/trunk/lib/Lex/PPExpressions.cpp @@ -17,14 +17,24 @@ //===----------------------------------------------------------------------===// #include "clang/Lex/Preprocessor.h" +#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" +#include "clang/Basic/TokenKinds.h" #include "clang/Lex/CodeCompletionHandler.h" #include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/LiteralSupport.h" #include "clang/Lex/MacroInfo.h" +#include "clang/Lex/PPCallbacks.h" +#include "clang/Lex/Token.h" #include "llvm/ADT/APSInt.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/SaveAndRestore.h" +#include + using namespace clang; namespace { @@ -34,6 +44,7 @@ class PPValue { SourceRange Range; IdentifierInfo *II; + public: llvm::APSInt Val; @@ -58,7 +69,7 @@ void setEnd(SourceLocation L) { Range.setEnd(L); } }; -} +} // end anonymous namespace static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec, Token &PeekTok, bool ValueLive, @@ -469,8 +480,6 @@ } } - - /// getPrecedence - Return the precedence of the specified binary operator /// token. This returns: /// ~0 - Invalid token. @@ -531,7 +540,7 @@ return true; } - while (1) { + while (true) { // If this token has a lower precedence than we are allowed to parse, return // it so that higher levels of the recursion can parse it. if (PeekPrec < MinPrec) Index: cfe/trunk/lib/Lex/PPMacroExpansion.cpp =================================================================== --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp @@ -13,6 +13,12 @@ //===----------------------------------------------------------------------===// #include "clang/Basic/Attributes.h" +#include "clang/Basic/FileManager.h" +#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/ObjCRuntime.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/TargetInfo.h" #include "clang/Lex/CodeCompletionHandler.h" #include "clang/Lex/DirectoryLookup.h" @@ -21,15 +27,34 @@ #include "clang/Lex/MacroArgs.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/Preprocessor.h" -#include "llvm/ADT/STLExtras.h" +#include "clang/Lex/PreprocessorLexer.h" +#include "clang/Lex/PTHLexer.h" +#include "clang/Lex/Token.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/FoldingSet.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Config/llvm-config.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" -#include +#include +#include +#include +#include #include +#include +#include +#include + using namespace clang; MacroDirective * @@ -285,7 +310,6 @@ return Id; } - /// RegisterBuiltinMacros - Register builtin macros, such as __LINE__ with the /// identifier table. void Preprocessor::RegisterBuiltinMacros() { @@ -366,10 +390,8 @@ // If this is a function-like macro invocation, it's safe to trivially expand // as long as the identifier is not a macro argument. return std::find(MI->arg_begin(), MI->arg_end(), II) == MI->arg_end(); - } - /// isNextPPTokenLParen - Determine whether the next preprocessor token to be /// lexed is a '('. If so, consume the token and return true, if not, this /// method should have no observable side-effect on the lexed tokens. @@ -479,7 +501,8 @@ } else { Callbacks->MacroExpands(Identifier, M, ExpansionRange, Args); if (!DelayedMacroExpandsCallbacks.empty()) { - for (unsigned i=0, e = DelayedMacroExpandsCallbacks.size(); i!=e; ++i) { + for (unsigned i = 0, e = DelayedMacroExpandsCallbacks.size(); i != e; + ++i) { MacroExpandsInfo &Info = DelayedMacroExpandsCallbacks[i]; // FIXME: We lose macro args info with delayed callback. Callbacks->MacroExpands(Info.Tok, Info.MD, Info.Range, @@ -741,7 +764,7 @@ // that we already consumed the first one. unsigned NumParens = 0; - while (1) { + while (true) { // Read arguments as unexpanded tokens. This avoids issues, e.g., where // an argument value in a macro could expand to ',' or '(' or ')'. LexUnexpandedToken(Tok); @@ -1042,7 +1065,6 @@ } } - /// HasFeature - Return true if we recognize and implement the feature /// specified by the identifier as a standard language feature. static bool HasFeature(const Preprocessor &PP, StringRef Feature) { Index: cfe/trunk/lib/Lex/Pragma.cpp =================================================================== --- cfe/trunk/lib/Lex/Pragma.cpp +++ cfe/trunk/lib/Lex/Pragma.cpp @@ -14,18 +14,35 @@ #include "clang/Lex/Pragma.h" #include "clang/Basic/FileManager.h" +#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" +#include "clang/Basic/TokenKinds.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/LexDiagnostic.h" -#include "clang/Lex/LiteralSupport.h" #include "clang/Lex/MacroInfo.h" +#include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Lex/PreprocessorLexer.h" +#include "clang/Lex/PTHLexer.h" +#include "clang/Lex/Token.h" +#include "clang/Lex/TokenLexer.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSwitch.h" -#include "llvm/ADT/StringExtras.h" #include "llvm/Support/CrashRecoveryContext.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include +#include +#include +#include +#include +#include + using namespace clang; // Out-of-line destructor to provide a home for the class. @@ -121,6 +138,7 @@ } namespace { + /// \brief Helper class for \see Preprocessor::Handle_Pragma. class LexingFor_PragmaRAII { Preprocessor &PP; @@ -155,7 +173,8 @@ Failed = true; } }; -} + +} // end anonymous namespace /// Handle_Pragma - Read a _Pragma directive, slice it up, process it, then /// return the first token after the directive. The _Pragma token has just @@ -372,13 +391,12 @@ CurPTHLexer->DiscardToEndOfLine(); } - /// HandlePragmaPoison - Handle \#pragma GCC poison. PoisonTok is the 'poison'. /// void Preprocessor::HandlePragmaPoison(Token &PoisonTok) { Token Tok; - while (1) { + while (true) { // Read the next token to poison. While doing this, pretend that we are // skipping while reading the identifier to poison. // This avoids errors on code like: @@ -610,7 +628,7 @@ // Pop PragmaPushMacroInfo stack. iter->second.pop_back(); - if (iter->second.size() == 0) + if (iter->second.empty()) PragmaPushMacroInfo.erase(iter); } else { Diag(MessageLoc, diag::warn_pragma_pop_macro_no_push) @@ -807,6 +825,7 @@ } namespace { + /// PragmaOnceHandler - "\#pragma once" marks the file as atomically included. struct PragmaOnceHandler : public PragmaHandler { PragmaOnceHandler() : PragmaHandler("once") {} @@ -821,6 +840,7 @@ /// rest of the line is not lexed. struct PragmaMarkHandler : public PragmaHandler { PragmaMarkHandler() : PragmaHandler("mark") {} + void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &MarkTok) override { PP.HandlePragmaMark(); @@ -830,6 +850,7 @@ /// PragmaPoisonHandler - "\#pragma poison x" marks x as not usable. struct PragmaPoisonHandler : public PragmaHandler { PragmaPoisonHandler() : PragmaHandler("poison") {} + void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &PoisonTok) override { PP.HandlePragmaPoison(PoisonTok); @@ -840,14 +861,17 @@ /// as a system header, which silences warnings in it. struct PragmaSystemHeaderHandler : public PragmaHandler { PragmaSystemHeaderHandler() : PragmaHandler("system_header") {} + void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &SHToken) override { PP.HandlePragmaSystemHeader(SHToken); PP.CheckEndOfDirective("pragma"); } }; + struct PragmaDependencyHandler : public PragmaHandler { PragmaDependencyHandler() : PragmaHandler("dependency") {} + void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &DepToken) override { PP.HandlePragmaDependency(DepToken); @@ -856,6 +880,7 @@ struct PragmaDebugHandler : public PragmaHandler { PragmaDebugHandler() : PragmaHandler("__debug") {} + void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &DepToken) override { Token Tok; @@ -965,9 +990,11 @@ struct PragmaDiagnosticHandler : public PragmaHandler { private: const char *Namespace; + public: explicit PragmaDiagnosticHandler(const char *NS) : PragmaHandler("diagnostic"), Namespace(NS) {} + void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &DiagToken) override { SourceLocation DiagLoc = DiagToken.getLocation(); @@ -1140,7 +1167,7 @@ while (Tok.is(tok::numeric_constant)) { uint64_t Value; if (!PP.parseSimpleIntegerLiteral(Tok, Value) || Value == 0 || - Value > INT_MAX) { + Value > std::numeric_limits::max()) { PP.Diag(Tok, diag::warn_pragma_warning_expected_number); return; } @@ -1265,17 +1292,18 @@ /// macro on the top of the stack. struct PragmaPushMacroHandler : public PragmaHandler { PragmaPushMacroHandler() : PragmaHandler("push_macro") {} + void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &PushMacroTok) override { PP.HandlePragmaPushMacro(PushMacroTok); } }; - /// PragmaPopMacroHandler - "\#pragma pop_macro" sets the value of the /// macro to the value on the top of the stack. struct PragmaPopMacroHandler : public PragmaHandler { PragmaPopMacroHandler() : PragmaHandler("pop_macro") {} + void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &PopMacroTok) override { PP.HandlePragmaPopMacro(PopMacroTok); @@ -1287,6 +1315,7 @@ /// PragmaSTDC_FENV_ACCESSHandler - "\#pragma STDC FENV_ACCESS ...". struct PragmaSTDC_FENV_ACCESSHandler : public PragmaHandler { PragmaSTDC_FENV_ACCESSHandler() : PragmaHandler("FENV_ACCESS") {} + void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &Tok) override { tok::OnOffSwitch OOS; @@ -1301,6 +1330,7 @@ struct PragmaSTDC_CX_LIMITED_RANGEHandler : public PragmaHandler { PragmaSTDC_CX_LIMITED_RANGEHandler() : PragmaHandler("CX_LIMITED_RANGE") {} + void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &Tok) override { tok::OnOffSwitch OOS; @@ -1311,6 +1341,7 @@ /// PragmaSTDC_UnknownHandler - "\#pragma STDC ...". struct PragmaSTDC_UnknownHandler : public PragmaHandler { PragmaSTDC_UnknownHandler() {} + void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &UnknownTok) override { // C99 6.10.6p2, unknown forms are not allowed. @@ -1322,6 +1353,7 @@ /// \#pragma clang arc_cf_code_audited begin/end struct PragmaARCCFCodeAuditedHandler : public PragmaHandler { PragmaARCCFCodeAuditedHandler() : PragmaHandler("arc_cf_code_audited") {} + void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &NameTok) override { SourceLocation Loc = NameTok.getLocation(); @@ -1376,6 +1408,7 @@ /// \#pragma clang assume_nonnull begin/end struct PragmaAssumeNonNullHandler : public PragmaHandler { PragmaAssumeNonNullHandler() : PragmaHandler("assume_nonnull") {} + void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, Token &NameTok) override { SourceLocation Loc = NameTok.getLocation(); @@ -1449,8 +1482,7 @@ } }; -} // end anonymous namespace - +} // end anonymous namespace /// RegisterBuiltinPragmas - Install the standard preprocessor pragmas: /// \#pragma GCC poison/system_header/dependency and \#pragma once. Index: cfe/trunk/lib/Lex/Preprocessor.cpp =================================================================== --- cfe/trunk/lib/Lex/Preprocessor.cpp +++ cfe/trunk/lib/Lex/Preprocessor.cpp @@ -43,15 +43,24 @@ #include "clang/Lex/PreprocessingRecord.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Lex/ScratchBuffer.h" -#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallString.h" -#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Capacity.h" -#include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" +#include +#include +#include +#include #include +#include + using namespace clang; LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry) @@ -74,11 +83,12 @@ IncrementalProcessing(false), TUKind(TUKind), CodeComplete(nullptr), CodeCompletionFile(nullptr), CodeCompletionOffset(0), LastTokenWasAt(false), ModuleImportExpectsIdentifier(false), - CodeCompletionReached(0), CodeCompletionII(0), MainFileDir(nullptr), - SkipMainFilePreamble(0, true), CurPPLexer(nullptr), CurDirLookup(nullptr), - CurLexerKind(CLK_Lexer), CurSubmodule(nullptr), Callbacks(nullptr), - CurSubmoduleState(&NullSubmoduleState), MacroArgCache(nullptr), - Record(nullptr), MIChainHead(nullptr), DeserialMIChainHead(nullptr) { + CodeCompletionReached(false), CodeCompletionII(nullptr), + MainFileDir(nullptr), SkipMainFilePreamble(0, true), CurPPLexer(nullptr), + CurDirLookup(nullptr), CurLexerKind(CLK_Lexer), CurSubmodule(nullptr), + Callbacks(nullptr), CurSubmoduleState(&NullSubmoduleState), + MacroArgCache(nullptr), Record(nullptr), MIChainHead(nullptr), + DeserialMIChainHead(nullptr) { OwnsHeaderSearch = OwnsHeaders; CounterValue = 0; // __COUNTER__ starts at 0. @@ -490,7 +500,6 @@ // Preprocessor Initialization Methods //===----------------------------------------------------------------------===// - /// EnterMainSourceFile - Enter the specified FileID as the main source file, /// which implicitly adds the builtin defines etc. void Preprocessor::EnterMainSourceFile() { @@ -758,7 +767,6 @@ LastTokenWasAt = Result.is(tok::at); } - /// \brief Lex a token following the 'import' contextual keyword. /// void Preprocessor::LexAfterModuleImport(Token &Result) { Index: cfe/trunk/lib/Serialization/ASTReader.cpp =================================================================== --- cfe/trunk/lib/Serialization/ASTReader.cpp +++ cfe/trunk/lib/Serialization/ASTReader.cpp @@ -1,4 +1,4 @@ -//===-- ASTReader.cpp - AST File Reader ----------------------------------===// +//===-- ASTReader.cpp - AST File Reader -----------------------------------===// // // The LLVM Compiler Infrastructure // @@ -16,39 +16,62 @@ #include "ASTReaderInternals.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/ASTMutationListener.h" +#include "clang/AST/ASTUnresolvedSet.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclGroup.h" +#include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" -#include "clang/Frontend/PCHContainerOperations.h" -#include "clang/AST/ASTMutationListener.h" #include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/RawCommentList.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLocVisitor.h" +#include "clang/AST/UnresolvedSet.h" +#include "clang/Basic/CommentOptions.h" #include "clang/Basic/DiagnosticOptions.h" +#include "clang/Basic/ExceptionSpecificationType.h" #include "clang/Basic/FileManager.h" +#include "clang/Basic/FileSystemOptions.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/ObjCRuntime.h" +#include "clang/Basic/OperatorKinds.h" +#include "clang/Basic/Sanitizers.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/SourceManagerInternals.h" +#include "clang/Basic/Specifiers.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" +#include "clang/Basic/TokenKinds.h" #include "clang/Basic/Version.h" #include "clang/Basic/VersionTuple.h" -#include "clang/Frontend/Utils.h" +#include "clang/Frontend/PCHContainerOperations.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/MacroInfo.h" +#include "clang/Lex/ModuleMap.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/Sema/Weak.h" #include "clang/Serialization/ASTDeserializationListener.h" #include "clang/Serialization/GlobalModuleIndex.h" #include "clang/Serialization/ModuleManager.h" #include "clang/Serialization/SerializationDiagnostic.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/APSInt.h" #include "llvm/ADT/Hashing.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/Triple.h" #include "llvm/Bitcode/BitstreamReader.h" #include "llvm/Support/Compression.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" @@ -56,16 +79,27 @@ #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/raw_ostream.h" #include +#include +#include #include +#include +#include #include +#include +#include +#include +#include +#include #include +#include +#include +#include using namespace clang; using namespace clang::serialization; using namespace clang::serialization::reader; using llvm::BitstreamCursor; - //===----------------------------------------------------------------------===// // ChainedASTReaderListener implementation //===----------------------------------------------------------------------===// @@ -75,14 +109,17 @@ return First->ReadFullVersionInformation(FullVersion) || Second->ReadFullVersionInformation(FullVersion); } + void ChainedASTReaderListener::ReadModuleName(StringRef ModuleName) { First->ReadModuleName(ModuleName); Second->ReadModuleName(ModuleName); } + void ChainedASTReaderListener::ReadModuleMapFile(StringRef ModuleMapPath) { First->ReadModuleMapFile(ModuleMapPath); Second->ReadModuleMapFile(ModuleMapPath); } + bool ChainedASTReaderListener::ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, @@ -92,6 +129,7 @@ Second->ReadLanguageOptions(LangOpts, Complain, AllowCompatibleDifferences); } + bool ChainedASTReaderListener::ReadTargetOptions( const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences) { @@ -100,11 +138,13 @@ Second->ReadTargetOptions(TargetOpts, Complain, AllowCompatibleDifferences); } + bool ChainedASTReaderListener::ReadDiagnosticOptions( IntrusiveRefCntPtr DiagOpts, bool Complain) { return First->ReadDiagnosticOptions(DiagOpts, Complain) || Second->ReadDiagnosticOptions(DiagOpts, Complain); } + bool ChainedASTReaderListener::ReadFileSystemOptions(const FileSystemOptions &FSOpts, bool Complain) { @@ -120,6 +160,7 @@ Second->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, Complain); } + bool ChainedASTReaderListener::ReadPreprocessorOptions( const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines) { @@ -145,6 +186,7 @@ First->visitModuleFile(Filename, Kind); Second->visitModuleFile(Filename, Kind); } + bool ChainedASTReaderListener::visitInputFile(StringRef Filename, bool isSystem, bool isOverridden, @@ -336,11 +378,13 @@ } namespace { + typedef llvm::StringMap > MacroDefinitionsMap; typedef llvm::DenseMap > DeclsMap; -} + +} // end anonymous namespace static bool checkDiagnosticGroupMappings(DiagnosticsEngine &StoredDiags, DiagnosticsEngine &Diags, @@ -679,13 +723,10 @@ OwnsDeserializationListener = TakeOwnership; } - - unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { return serialization::ComputeHash(Sel); } - std::pair ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { using namespace llvm::support; @@ -1715,6 +1756,7 @@ } namespace { + /// \brief Visitor class used to look up identifirs in an AST file. class IdentifierLookupVisitor { StringRef Name; @@ -1766,7 +1808,8 @@ // files. IdentifierInfo *getIdentifierInfo() const { return Found; } }; -} + +} // end anonymous namespace void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { // Note that we are loading an identifier. @@ -1990,7 +2033,7 @@ ErrorStr += "' referenced by AST file '"; ErrorStr += F.FileName; ErrorStr += "'"; - Error(ErrorStr.c_str()); + Error(ErrorStr); } // Record that we didn't find the file. F.InputFilesLoaded[ID-1] = InputFile::getNotFound(); @@ -2107,7 +2150,7 @@ // Read all of the records in the options block. RecordData Record; ASTReadResult Result = Success; - while (1) { + while (true) { llvm::BitstreamEntry Entry = Stream.advance(); switch (Entry.Kind) { @@ -2195,7 +2238,7 @@ RecordData Record; unsigned NumInputs = 0; unsigned NumUserInputs = 0; - while (1) { + while (true) { llvm::BitstreamEntry Entry = Stream.advance(); switch (Entry.Kind) { @@ -2480,7 +2523,7 @@ // Read all of the records and blocks for the AST file. RecordData Record; - while (1) { + while (true) { llvm::BitstreamEntry Entry = Stream.advance(); switch (Entry.Kind) { @@ -3467,7 +3510,7 @@ /// cursor into the start of the given block ID, returning false on success and /// true on failure. static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) { - while (1) { + while (true) { llvm::BitstreamEntry Entry = Cursor.advance(); switch (Entry.Kind) { case llvm::BitstreamEntry::Error: @@ -3815,7 +3858,7 @@ // This is used for compatibility with older PCH formats. bool HaveReadControlBlock = false; - while (1) { + while (true) { llvm::BitstreamEntry Entry = Stream.advance(); switch (Entry.Kind) { @@ -4105,7 +4148,7 @@ // Scan for SIGNATURE inside the control block. ASTReader::RecordData Record; - while (1) { + while (true) { llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); if (Entry.Kind == llvm::BitstreamEntry::EndBlock || Entry.Kind != llvm::BitstreamEntry::Record) @@ -4151,7 +4194,7 @@ // Scan for ORIGINAL_FILE inside the control block. RecordData Record; - while (1) { + while (true) { llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); if (Entry.Kind == llvm::BitstreamEntry::EndBlock) return std::string(); @@ -4169,6 +4212,7 @@ } namespace { + class SimplePCHValidator : public ASTReaderListener { const LangOptions &ExistingLangOpts; const TargetOptions &ExistingTargetOpts; @@ -4195,11 +4239,13 @@ return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr, AllowCompatibleDifferences); } + bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, bool AllowCompatibleDifferences) override { return checkTargetOptions(ExistingTargetOpts, TargetOpts, nullptr, AllowCompatibleDifferences); } + bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool Complain) override { @@ -4207,6 +4253,7 @@ ExistingModuleCachePath, nullptr, ExistingLangOpts); } + bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain, std::string &SuggestedPredefines) override { @@ -4214,7 +4261,8 @@ SuggestedPredefines, ExistingLangOpts); } }; -} + +} // end anonymous namespace bool ASTReader::readASTFileControlBlock( StringRef Filename, FileManager &FileMgr, @@ -5040,7 +5088,7 @@ } }; -} +} // end anonymous namespace PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const { @@ -5130,6 +5178,7 @@ } namespace { + /// \brief Visitor used to search for information about a header file. class HeaderFileInfoVisitor { const FileEntry *FE; @@ -5157,7 +5206,8 @@ Optional getHeaderFileInfo() const { return HFI; } }; -} + +} // end anonymous namespace HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { HeaderFileInfoVisitor Visitor(FE); @@ -5195,7 +5245,7 @@ Diag.DiagStatePoints.push_back( DiagnosticsEngine::DiagStatePoint(NewState, FullSourceLoc(Loc, SourceMgr))); - while (1) { + while (true) { assert(Idx < F.PragmaDiagMappings.size() && "Invalid data, didn't find '-1' marking end of diag/map pairs"); if (Idx >= F.PragmaDiagMappings.size()) { @@ -5771,6 +5821,7 @@ void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { // nothing to do } + void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); if (TL.needsExtraLocalData()) { @@ -5780,31 +5831,40 @@ TL.setModeAttr(Record[Idx++]); } } + void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { TL.setStarLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitDecayedTypeLoc(DecayedTypeLoc TL) { // nothing to do } + void TypeLocReader::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { // nothing to do } + void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { TL.setCaretLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { TL.setAmpLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { TL.setStarLoc(ReadSourceLocation(Record, Idx)); TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); } + void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); @@ -5813,29 +5873,37 @@ else TL.setSizeExpr(nullptr); } + void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocReader::VisitDependentSizedArrayTypeLoc( DependentSizedArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( DependentSizedExtVectorTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); TL.setLParenLoc(ReadSourceLocation(Record, Idx)); @@ -5845,9 +5913,11 @@ TL.setParam(i, ReadDeclAs(Record, Idx)); } } + void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { VisitFunctionTypeLoc(TL); } + void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { VisitFunctionTypeLoc(TL); } @@ -5871,21 +5941,26 @@ void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { TL.setKWLoc(ReadSourceLocation(Record, Idx)); TL.setLParenLoc(ReadSourceLocation(Record, Idx)); TL.setRParenLoc(ReadSourceLocation(Record, Idx)); TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); } + void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); if (TL.hasAttrOperand()) { @@ -5902,9 +5977,11 @@ } else if (TL.hasAttrEnumOperand()) TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( SubstTemplateTypeParmTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); @@ -5929,18 +6006,22 @@ TL.setLParenLoc(ReadSourceLocation(Record, Idx)); TL.setRParenLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); } + void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( DependentTemplateSpecializationTypeLoc TL) { TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); @@ -5955,12 +6036,15 @@ TL.getTypePtr()->getArg(I).getKind(), Record, Idx)); } + void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { TL.setNameLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { TL.setHasBaseTypeAsWritten(Record[Idx++]); TL.setTypeArgsLAngleLoc(ReadSourceLocation(Record, Idx)); @@ -5972,14 +6056,17 @@ for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { TL.setStarLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { TL.setKWLoc(ReadSourceLocation(Record, Idx)); TL.setLParenLoc(ReadSourceLocation(Record, Idx)); TL.setRParenLoc(ReadSourceLocation(Record, Idx)); } + void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) { TL.setKWLoc(ReadSourceLocation(Record, Idx)); } @@ -6625,7 +6712,7 @@ } }; -} +} // end anonymous namespace void ASTReader::FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length, @@ -7033,6 +7120,7 @@ } namespace clang { + /// \brief An identifier-lookup iterator that enumerates all of the /// identifiers stored within a set of AST files. class ASTIdentifierIterator : public IdentifierIterator { @@ -7060,7 +7148,8 @@ StringRef Next() override; }; -} + +} // end namespace clang ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader, bool SkipModules) @@ -7092,6 +7181,7 @@ } namespace { + /// A utility for appending two IdentifierIterators. class ChainedIdentifierIterator : public IdentifierIterator { std::unique_ptr Current; @@ -7116,6 +7206,7 @@ return Next(); } }; + } // end anonymous namespace. IdentifierIterator *ASTReader::getIdentifiers() { @@ -7131,7 +7222,9 @@ return new ASTIdentifierIterator(*this); } -namespace clang { namespace serialization { +namespace clang { +namespace serialization { + class ReadMethodPoolVisitor { ASTReader &Reader; Selector Sel; @@ -7201,7 +7294,9 @@ } bool factoryHasMoreThanOneDecl() const { return FactoryHasMoreThanOneDecl; } }; -} } // end namespace clang::serialization + +} // end namespace serialization +} // end namespace clang /// \brief Add the given set of methods to the method list. static void addMethodsToPool(Sema &S, ArrayRef Methods, @@ -7796,7 +7891,7 @@ Info.NumTemplParamLists = NumTPLists; if (NumTPLists) { Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; - for (unsigned i=0; i != NumTPLists; ++i) + for (unsigned i = 0; i != NumTPLists; ++i) Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); } } @@ -8016,7 +8111,7 @@ } else { SourceOrderOrNumArrayIndices = Record[Idx++]; Indices.reserve(SourceOrderOrNumArrayIndices); - for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) + for (unsigned i = 0; i != SourceOrderOrNumArrayIndices; ++i) Indices.push_back(ReadDeclAs(F, Record, Idx)); } Index: cfe/trunk/lib/Serialization/ASTWriter.cpp =================================================================== --- cfe/trunk/lib/Serialization/ASTWriter.cpp +++ cfe/trunk/lib/Serialization/ASTWriter.cpp @@ -16,18 +16,27 @@ #include "ASTReaderInternals.h" #include "MultiOnDiskHashTable.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/ASTUnresolvedSet.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclContextInternals.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclFriend.h" -#include "clang/AST/DeclLookups.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" +#include "clang/AST/LambdaCapture.h" +#include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/RawCommentList.h" +#include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLocVisitor.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/FileManager.h" -#include "clang/Basic/FileSystemStatCache.h" +#include "clang/Basic/FileSystemOptions.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/Module.h" +#include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/SourceManagerInternals.h" #include "clang/Basic/TargetInfo.h" @@ -37,28 +46,48 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/MacroInfo.h" +#include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessingRecord.h" #include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorOptions.h" +#include "clang/Lex/Token.h" #include "clang/Sema/IdentifierResolver.h" +#include "clang/Sema/ObjCMethodList.h" #include "clang/Sema/Sema.h" +#include "clang/Sema/Weak.h" #include "clang/Serialization/ASTReader.h" +#include "clang/Serialization/Module.h" #include "clang/Serialization/ModuleFileExtension.h" #include "clang/Serialization/SerializationDiagnostic.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/Hashing.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Bitcode/BitCodes.h" #include "llvm/Bitcode/BitstreamWriter.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Compression.h" #include "llvm/Support/EndianStream.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/OnDiskHashTable.h" #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" +#include "llvm/Support/raw_ostream.h" #include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include using namespace clang; @@ -82,6 +111,7 @@ //===----------------------------------------------------------------------===// namespace clang { + class ASTTypeWriter { ASTWriter &Writer; ASTRecordWriter Record; @@ -126,6 +156,7 @@ #define ABSTRACT_TYPE(Class, Base) #include "clang/AST/TypeNodes.def" }; + } // end namespace clang void ASTTypeWriter::VisitBuiltinType(const BuiltinType *T) { @@ -503,6 +534,7 @@ void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { // nothing to do } + void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { Record.AddSourceLocation(TL.getBuiltinLoc()); if (TL.needsExtraLocalData()) { @@ -512,31 +544,40 @@ Record.push_back(TL.hasModeAttr()); } } + void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { Record.AddSourceLocation(TL.getStarLoc()); } + void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) { // nothing to do } + void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { // nothing to do } + void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { Record.AddSourceLocation(TL.getCaretLoc()); } + void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { Record.AddSourceLocation(TL.getAmpLoc()); } + void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { Record.AddSourceLocation(TL.getAmpAmpLoc()); } + void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { Record.AddSourceLocation(TL.getStarLoc()); Record.AddTypeSourceInfo(TL.getClassTInfo()); } + void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { Record.AddSourceLocation(TL.getLBracketLoc()); Record.AddSourceLocation(TL.getRBracketLoc()); @@ -544,29 +585,37 @@ if (TL.getSizeExpr()) Record.AddStmt(TL.getSizeExpr()); } + void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocWriter::VisitDependentSizedArrayTypeLoc( DependentSizedArrayTypeLoc TL) { VisitArrayTypeLoc(TL); } + void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( DependentSizedExtVectorTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { Record.AddSourceLocation(TL.getLocalRangeBegin()); Record.AddSourceLocation(TL.getLParenLoc()); @@ -592,30 +641,37 @@ Record.AddSourceLocation(TL.getLParenLoc()); Record.AddSourceLocation(TL.getRParenLoc()); } + void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { Record.AddSourceLocation(TL.getTypeofLoc()); Record.AddSourceLocation(TL.getLParenLoc()); Record.AddSourceLocation(TL.getRParenLoc()); Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); } + void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { Record.AddSourceLocation(TL.getKWLoc()); Record.AddSourceLocation(TL.getLParenLoc()); Record.AddSourceLocation(TL.getRParenLoc()); Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); } + void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { Record.AddSourceLocation(TL.getAttrNameLoc()); if (TL.hasAttrOperand()) { @@ -631,17 +687,21 @@ Record.AddSourceLocation(TL.getAttrEnumOperandLoc()); } } + void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( SubstTemplateTypeParmTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( SubstTemplateTypeParmPackTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitTemplateSpecializationTypeLoc( TemplateSpecializationTypeLoc TL) { Record.AddSourceLocation(TL.getTemplateKeywordLoc()); @@ -652,22 +712,27 @@ Record.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), TL.getArgLoc(i).getLocInfo()); } + void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { Record.AddSourceLocation(TL.getLParenLoc()); Record.AddSourceLocation(TL.getRParenLoc()); } + void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); } + void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( DependentTemplateSpecializationTypeLoc TL) { Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); @@ -680,12 +745,15 @@ Record.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), TL.getArgLoc(I).getLocInfo()); } + void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { Record.AddSourceLocation(TL.getEllipsisLoc()); } + void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } + void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { Record.push_back(TL.hasBaseTypeAsWritten()); Record.AddSourceLocation(TL.getTypeArgsLAngleLoc()); @@ -697,14 +765,17 @@ for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) Record.AddSourceLocation(TL.getProtocolLoc(i)); } + void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { Record.AddSourceLocation(TL.getStarLoc()); } + void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { Record.AddSourceLocation(TL.getKWLoc()); Record.AddSourceLocation(TL.getLParenLoc()); Record.AddSourceLocation(TL.getRParenLoc()); } + void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) { Record.AddSourceLocation(TL.getKWLoc()); } @@ -1212,7 +1283,7 @@ } static ASTFileSignature getSignature() { - while (1) { + while (true) { if (ASTFileSignature S = llvm::sys::Process::GetRandomNumber()) return S; // Rely on GetRandomNumber to eventually return non-zero... @@ -1534,6 +1605,7 @@ } namespace { + /// \brief An input file. struct InputFileEntry { const FileEntry *File; @@ -1541,6 +1613,7 @@ bool IsTransient; bool BufferOverridden; }; + } // end anonymous namespace void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, @@ -1701,6 +1774,7 @@ } namespace { + // Trait used for the on-disk hash table of header search information. class HeaderFileInfoTrait { ASTWriter &Writer; @@ -1809,6 +1883,7 @@ const char *strings_begin() const { return FrameworkStringData.begin(); } const char *strings_end() const { return FrameworkStringData.end(); } }; + } // end anonymous namespace /// \brief Write the header search block for the list of files that @@ -2869,6 +2944,7 @@ //===----------------------------------------------------------------------===// namespace { + // Trait used for the on-disk hash table used in the method pool. class ASTMethodPoolTrait { ASTWriter &Writer; @@ -2973,6 +3049,7 @@ assert(Out.tell() - Start == DataLen && "Data length is wrong"); } }; + } // end anonymous namespace /// \brief Write ObjC data: selectors and the method pool. @@ -3144,6 +3221,7 @@ } namespace { + class ASTIdentifierTableTrait { ASTWriter &Writer; Preprocessor &PP; @@ -3194,6 +3272,7 @@ auto MacroOffset = Writer.getMacroDirectivesOffset(II); return isInterestingIdentifier(II, MacroOffset); } + bool isInterestingNonMacroIdentifier(const IdentifierInfo *II) { return isInterestingIdentifier(II, 0); } @@ -3287,6 +3366,7 @@ } } }; + } // end anonymous namespace /// \brief Write the identifier table into the AST file. @@ -3393,6 +3473,7 @@ //===----------------------------------------------------------------------===// namespace { + // Trait used for the on-disk hash table used in the method pool. class ASTDeclContextNameLookupTrait { ASTWriter &Writer; @@ -3518,6 +3599,7 @@ assert(Out.tell() - Start == DataLen && "Data length is wrong"); } }; + } // end anonymous namespace bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result, @@ -5184,7 +5266,7 @@ void ASTRecordWriter::AddQualifierInfo(const QualifierInfo &Info) { AddNestedNameSpecifierLoc(Info.QualifierLoc); Record->push_back(Info.NumTemplParamLists); - for (unsigned i=0, e=Info.NumTemplParamLists; i != e; ++i) + for (unsigned i = 0, e = Info.NumTemplParamLists; i != e; ++i) AddTemplateParameterList(Info.TemplParamLists[i]); } @@ -5397,7 +5479,7 @@ const TemplateArgumentList *TemplateArgs) { assert(TemplateArgs && "No TemplateArgs!"); Record->push_back(TemplateArgs->size()); - for (int i=0, e = TemplateArgs->size(); i != e; ++i) + for (int i = 0, e = TemplateArgs->size(); i != e; ++i) AddTemplateArgument(TemplateArgs->get(i)); } @@ -5408,7 +5490,7 @@ AddSourceLocation(ASTTemplArgList->RAngleLoc); Record->push_back(ASTTemplArgList->NumTemplateArgs); const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); - for (int i=0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) + for (int i = 0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) AddTemplateArgumentLoc(TemplArgs[i]); }