Index: lib/Analysis/PrintfFormatString.cpp =================================================================== --- lib/Analysis/PrintfFormatString.cpp +++ lib/Analysis/PrintfFormatString.cpp @@ -13,8 +13,18 @@ //===----------------------------------------------------------------------===// #include "clang/Analysis/Analyses/FormatString.h" -#include "FormatStringParsing.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" +#include "clang/AST/Type.h" +#include "clang/Basic/LLVM.h" #include "clang/Basic/TargetInfo.h" +#include "FormatStringParsing.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Triple.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" +#include using clang::analyze_format_string::ArgType; using clang::analyze_format_string::FormatStringHandler; @@ -75,7 +85,6 @@ const TargetInfo &Target, bool Warn, bool isFreeBSDKPrintf) { - using namespace clang::analyze_format_string; using namespace clang::analyze_printf; @@ -329,7 +338,6 @@ const LangOptions &LO, const TargetInfo &Target, bool isFreeBSDKPrintf) { - unsigned argIndex = 0; // Keep looking for a format specifier until we have exhausted the string. @@ -358,7 +366,6 @@ const char *E, const LangOptions &LO, const TargetInfo &Target) { - unsigned argIndex = 0; // Keep looking for a %s format specifier until we have exhausted the string. @@ -585,8 +592,8 @@ CS.setKind(ConversionSpecifier::sArg); // Disable irrelevant flags - HasAlternativeForm = 0; - HasLeadingZeroes = 0; + HasAlternativeForm = false; + HasLeadingZeroes = false; // Set the long length modifier for wide characters if (QT->getPointeeType()->isWideCharType()) @@ -701,9 +708,9 @@ CS.setKind(ConversionSpecifier::cArg); LM.setKind(LengthModifier::None); Precision.setHowSpecified(OptionalAmount::NotSpecified); - HasAlternativeForm = 0; - HasLeadingZeroes = 0; - HasPlusPrefix = 0; + HasAlternativeForm = false; + HasLeadingZeroes = false; + HasPlusPrefix = false; } // Test for Floating type first as LongDouble can pass isUnsignedIntegerType else if (QT->isRealFloatingType()) { @@ -711,12 +718,12 @@ } else if (QT->isSignedIntegerType()) { CS.setKind(ConversionSpecifier::dArg); - HasAlternativeForm = 0; + HasAlternativeForm = false; } else if (QT->isUnsignedIntegerType()) { CS.setKind(ConversionSpecifier::uArg); - HasAlternativeForm = 0; - HasPlusPrefix = 0; + HasAlternativeForm = false; + HasPlusPrefix = false; } else { llvm_unreachable("Unexpected type"); } @@ -928,6 +935,7 @@ return false; } } + bool PrintfSpecifier::hasValidFieldWidth() const { if (FieldWidth.getHowSpecified() == OptionalAmount::NotSpecified) return true; Index: lib/Basic/Diagnostic.cpp =================================================================== --- lib/Basic/Diagnostic.cpp +++ lib/Basic/Diagnostic.cpp @@ -16,11 +16,24 @@ #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/PartialDiagnostic.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/Specifiers.h" +#include "clang/Basic/TokenKinds.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Support/Locale.h" #include "llvm/Support/raw_ostream.h" +#include +#include +#include +#include +#include +#include +#include using namespace clang; @@ -395,7 +408,6 @@ return Emitted; } - DiagnosticConsumer::~DiagnosticConsumer() {} void DiagnosticConsumer::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, @@ -493,7 +505,6 @@ Out << ValNo << llvm::getOrdinalSuffix(ValNo); } - /// PluralNumber - Parse an unsigned integer and advance Start. static unsigned PluralNumber(const char *&Start, const char *End) { // Programming 101: Parse a decimal number :-) @@ -529,7 +540,7 @@ if (*Start == ':') return true; - while (1) { + while (true) { char C = *Start; if (C == '%') { // Modulo expression @@ -594,7 +605,7 @@ const char *Argument, unsigned ArgumentLen, SmallVectorImpl &OutStr) { const char *ArgumentEnd = Argument + ArgumentLen; - while (1) { + while (true) { assert(Argument < ArgumentEnd && "Plural expression didn't match."); const char *ExprEnd = Argument; while (*ExprEnd != ':') { Index: lib/Basic/SourceManager.cpp =================================================================== --- lib/Basic/SourceManager.cpp +++ lib/Basic/SourceManager.cpp @@ -14,17 +14,29 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" +#include "clang/Basic/LLVM.h" #include "clang/Basic/SourceManagerInternals.h" +#include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include +#include +#include #include +#include +#include +#include using namespace clang; using namespace SrcMgr; @@ -193,7 +205,7 @@ assert((Entries.empty() || Entries.back().FileOffset < Offset) && "Adding line entries out of order!"); - SrcMgr::CharacteristicKind Kind = SrcMgr::C_User; + CharacteristicKind Kind = C_User; unsigned IncludeOffset = 0; if (!Entries.empty()) { @@ -294,10 +306,10 @@ if (!Entry.isFile() || Invalid) return; - const SrcMgr::FileInfo &FileInfo = Entry.getFile(); + const FileInfo &FI = Entry.getFile(); // Remember that this file has #line directives now if it doesn't already. - const_cast(FileInfo).setHasLineDirectives(); + const_cast(FI).setHasLineDirectives(); getLineTable().AddLineNote(LocInfo.first, LocInfo.second, LineNo, FilenameID); } @@ -322,20 +334,20 @@ if (!Entry.isFile() || Invalid) return; - const SrcMgr::FileInfo &FileInfo = Entry.getFile(); + const FileInfo &FI = Entry.getFile(); // Remember that this file has #line directives now if it doesn't already. - const_cast(FileInfo).setHasLineDirectives(); + const_cast(FI).setHasLineDirectives(); (void) getLineTable(); - SrcMgr::CharacteristicKind FileKind; + CharacteristicKind FileKind; if (IsExternCHeader) - FileKind = SrcMgr::C_ExternCSystem; + FileKind = C_ExternCSystem; else if (IsSystemHeader) - FileKind = SrcMgr::C_System; + FileKind = C_System; else - FileKind = SrcMgr::C_User; + FileKind = C_User; unsigned EntryExit = 0; if (IsFileEntry) @@ -379,11 +391,10 @@ ContentCacheAlloc.Deallocate(MemBufferInfos[i]); } } - for (llvm::DenseMap::iterator - I = FileInfos.begin(), E = FileInfos.end(); I != E; ++I) { - if (I->second) { - I->second->~ContentCache(); - ContentCacheAlloc.Deallocate(I->second); + for (const auto &I : FileInfos) { + if (I.second) { + I.second->~ContentCache(); + ContentCacheAlloc.Deallocate(I.second); } } @@ -443,7 +454,6 @@ return Entry; } - /// createMemBufferContentCache - Create a new ContentCache for the specified /// memory buffer. This does no caching. const ContentCache *SourceManager::createMemBufferContentCache( @@ -468,7 +478,7 @@ LoadedSLocEntryTable[Index] = SLocEntry::get(0, FileInfo::get(SourceLocation(), getFakeContentCacheForRecovery(), - SrcMgr::C_User)); + C_User)); } } @@ -504,7 +514,7 @@ const SrcMgr::ContentCache * SourceManager::getFakeContentCacheForRecovery() const { if (!FakeContentCacheForRecovery) { - FakeContentCacheForRecovery = llvm::make_unique(); + FakeContentCacheForRecovery = llvm::make_unique(); FakeContentCacheForRecovery->replaceBuffer(getFakeBufferForRecovery(), /*DoNotFree=*/true); } @@ -632,7 +642,7 @@ llvm::MemoryBuffer *SourceManager::getMemoryBufferForFile(const FileEntry *File, bool *Invalid) { - const SrcMgr::ContentCache *IR = getOrCreateContentCache(File); + const ContentCache *IR = getOrCreateContentCache(File); assert(IR && "getOrCreateContentCache() cannot return NULL"); return IR->getBuffer(Diag, *this, SourceLocation(), Invalid); } @@ -640,11 +650,11 @@ void SourceManager::overrideFileContents(const FileEntry *SourceFile, llvm::MemoryBuffer *Buffer, bool DoNotFree) { - const SrcMgr::ContentCache *IR = getOrCreateContentCache(SourceFile); + const ContentCache *IR = getOrCreateContentCache(SourceFile); assert(IR && "getOrCreateContentCache() cannot return NULL"); - const_cast(IR)->replaceBuffer(Buffer, DoNotFree); - const_cast(IR)->BufferOverridden = true; + const_cast(IR)->replaceBuffer(Buffer, DoNotFree); + const_cast(IR)->BufferOverridden = true; getOverriddenFilesInfo().OverriddenFilesWithBuffer.insert(SourceFile); } @@ -664,9 +674,9 @@ if (!isFileOverridden(File)) return; - const SrcMgr::ContentCache *IR = getOrCreateContentCache(File); - const_cast(IR)->replaceBuffer(nullptr); - const_cast(IR)->ContentsEntry = IR->OrigEntry; + const ContentCache *IR = getOrCreateContentCache(File); + const_cast(IR)->replaceBuffer(nullptr); + const_cast(IR)->ContentsEntry = IR->OrigEntry; assert(OverriddenFilesInfo); OverriddenFilesInfo->OverriddenFiles.erase(File); @@ -674,8 +684,8 @@ } void SourceManager::setFileIsTransient(const FileEntry *File) { - const SrcMgr::ContentCache *CC = getOrCreateContentCache(File); - const_cast(CC)->IsTransient = true; + const ContentCache *CC = getOrCreateContentCache(File); + const_cast(CC)->IsTransient = true; } StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const { @@ -736,7 +746,7 @@ // See if this is near the file point - worst case we start scanning from the // most newly created FileID. - const SrcMgr::SLocEntry *I; + const SLocEntry *I; if (LastFileIDLookup.ID < 0 || LocalSLocEntryTable[LastFileIDLookup.ID].getOffset() < SLocOffset) { @@ -750,7 +760,7 @@ // Find the FileID that contains this. "I" is an iterator that points to a // FileID whose offset is known to be larger than SLocOffset. unsigned NumProbes = 0; - while (1) { + while (true) { --I; if (I->getOffset() <= SLocOffset) { FileID Res = FileID::get(int(I - LocalSLocEntryTable.begin())); @@ -774,7 +784,7 @@ // SLocOffset. unsigned LessIndex = 0; NumProbes = 0; - while (1) { + while (true) { bool Invalid = false; unsigned MiddleIndex = (GreaterIndex-LessIndex)/2+LessIndex; unsigned MidOffset = getLocalSLocEntry(MiddleIndex, &Invalid).getOffset(); @@ -834,7 +844,7 @@ unsigned NumProbes; for (NumProbes = 0; NumProbes < 8; ++NumProbes, ++I) { // Make sure the entry is loaded! - const SrcMgr::SLocEntry &E = getLoadedSLocEntry(I); + const SLocEntry &E = getLoadedSLocEntry(I); if (E.getOffset() <= SLocOffset) { FileID Res = FileID::get(-int(I) - 2); @@ -851,10 +861,10 @@ unsigned GreaterIndex = I; unsigned LessIndex = LoadedSLocEntryTable.size(); NumProbes = 0; - while (1) { + while (true) { ++NumProbes; unsigned MiddleIndex = (LessIndex - GreaterIndex) / 2 + GreaterIndex; - const SrcMgr::SLocEntry &E = getLoadedSLocEntry(MiddleIndex); + const SLocEntry &E = getLoadedSLocEntry(MiddleIndex); if (E.getOffset() == 0) return FileID(); // invalid entry. @@ -921,7 +931,6 @@ return Loc; } - std::pair SourceManager::getDecomposedExpansionLocSlowCase( const SrcMgr::SLocEntry *E) const { @@ -969,7 +978,6 @@ return Loc.getLocWithOffset(LocInfo.second); } - /// getImmediateExpansionRange - Loc is required to be an expansion location. /// Return the start/end of the expansion information. std::pair @@ -1002,7 +1010,7 @@ if (!Loc.isMacroID()) return false; FileID FID = getFileID(Loc); - const SrcMgr::ExpansionInfo &Expansion = getSLocEntry(FID).getExpansion(); + const ExpansionInfo &Expansion = getSLocEntry(FID).getExpansion(); if (!Expansion.isMacroArgExpansion()) return false; if (StartLoc) @@ -1014,7 +1022,7 @@ if (!Loc.isMacroID()) return false; FileID FID = getFileID(Loc); - const SrcMgr::ExpansionInfo &Expansion = getSLocEntry(FID).getExpansion(); + const ExpansionInfo &Expansion = getSLocEntry(FID).getExpansion(); return Expansion.isMacroBodyExpansion(); } @@ -1027,19 +1035,19 @@ return false; // Does not point at the start of expansion range. bool Invalid = false; - const SrcMgr::ExpansionInfo &ExpInfo = + const ExpansionInfo &Expansion = getSLocEntry(DecompLoc.first, &Invalid).getExpansion(); if (Invalid) return false; - SourceLocation ExpLoc = ExpInfo.getExpansionLocStart(); + SourceLocation ExpLoc = Expansion.getExpansionLocStart(); - if (ExpInfo.isMacroArgExpansion()) { + if (Expansion.isMacroArgExpansion()) { // For macro argument expansions, check if the previous FileID is part of // the same argument expansion, in which case this Loc is not at the // beginning of the expansion. FileID PrevFID = getPreviousFileID(DecompLoc.first); if (!PrevFID.isInvalid()) { - const SrcMgr::SLocEntry &PrevEntry = getSLocEntry(PrevFID, &Invalid); + const SLocEntry &PrevEntry = getSLocEntry(PrevFID, &Invalid); if (Invalid) return false; if (PrevEntry.isExpansion() && @@ -1063,33 +1071,31 @@ return false; // Does not point at the end of expansion range. bool Invalid = false; - const SrcMgr::ExpansionInfo &ExpInfo = - getSLocEntry(FID, &Invalid).getExpansion(); + const ExpansionInfo &Expansion = getSLocEntry(FID, &Invalid).getExpansion(); if (Invalid) return false; - if (ExpInfo.isMacroArgExpansion()) { + if (Expansion.isMacroArgExpansion()) { // For macro argument expansions, check if the next FileID is part of the // same argument expansion, in which case this Loc is not at the end of the // expansion. FileID NextFID = getNextFileID(FID); if (!NextFID.isInvalid()) { - const SrcMgr::SLocEntry &NextEntry = getSLocEntry(NextFID, &Invalid); + const SLocEntry &NextEntry = getSLocEntry(NextFID, &Invalid); if (Invalid) return false; if (NextEntry.isExpansion() && NextEntry.getExpansion().getExpansionLocStart() == - ExpInfo.getExpansionLocStart()) + Expansion.getExpansionLocStart()) return false; } } if (MacroEnd) - *MacroEnd = ExpInfo.getExpansionLocEnd(); + *MacroEnd = Expansion.getExpansionLocEnd(); return true; } - //===----------------------------------------------------------------------===// // Queries about the code at a SourceLocation. //===----------------------------------------------------------------------===// @@ -1118,7 +1124,6 @@ return Buffer->getBufferStart() + (CharDataInvalid? 0 : LocInfo.second); } - /// getColumnNumber - Return the column # for the specified file position. /// this is significantly cheaper to compute than the line number. unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos, @@ -1195,10 +1200,7 @@ static LLVM_ATTRIBUTE_NOINLINE void ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI, llvm::BumpPtrAllocator &Alloc, - const SourceManager &SM, bool &Invalid); -static void ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI, - llvm::BumpPtrAllocator &Alloc, - const SourceManager &SM, bool &Invalid) { + const SourceManager &SM, bool &Invalid) { // Note that calling 'getBuffer()' may lazily page in the file. MemoryBuffer *Buffer = FI->getBuffer(Diag, SM, SourceLocation(), &Invalid); if (Invalid) @@ -1214,7 +1216,7 @@ const unsigned char *Buf = (const unsigned char *)Buffer->getBufferStart(); const unsigned char *End = (const unsigned char *)Buffer->getBufferEnd(); unsigned Offs = 0; - while (1) { + while (true) { // Skip over the contents of the line. const unsigned char *NextBuf = (const unsigned char *)Buf; @@ -1415,7 +1417,7 @@ if (Invalid || !SEntry.isFile()) return C_User; - const SrcMgr::FileInfo &FI = SEntry.getFile(); + const FileInfo &FI = SEntry.getFile(); // If there are no #line directives in this file, just return the whole-file // state. @@ -1444,7 +1446,6 @@ return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier(); } - /// getPresumedLoc - This method returns the "presumed" location of a /// SourceLocation specifies. A "presumed location" can be modified by \#line /// or GNU line marker directives. This provides a view on the data that a @@ -1464,8 +1465,8 @@ if (Invalid || !Entry.isFile()) return PresumedLoc(); - const SrcMgr::FileInfo &FI = Entry.getFile(); - const SrcMgr::ContentCache *C = FI.getContentCache(); + const FileInfo &FI = Entry.getFile(); + const ContentCache *C = FI.getContentCache(); // To get the source name, first consult the FileEntry (if one exists) // before the MemBuffer as this will avoid unnecessarily paging in the @@ -1534,7 +1535,7 @@ if (Invalid || !Entry.isFile()) return false; - const SrcMgr::FileInfo &FI = Entry.getFile(); + const FileInfo &FI = Entry.getFile(); // Check if there is a line directive for this location. if (FI.hasLineDirectives()) @@ -1549,7 +1550,7 @@ /// \brief The size of the SLocEntry that \p FID represents. unsigned SourceManager::getFileIDSize(FileID FID) const { bool Invalid = false; - const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); + const SLocEntry &Entry = getSLocEntry(FID, &Invalid); if (Invalid) return 0; @@ -1795,7 +1796,7 @@ MacroArgsCache.insert(std::make_pair(0, SourceLocation())); int ID = FID.ID; - while (1) { + while (true) { ++ID; // Stop if there are no more FileIDs to check. if (ID > 0) { @@ -1806,7 +1807,7 @@ } bool Invalid = false; - const SrcMgr::SLocEntry &Entry = getSLocEntryByID(ID, &Invalid); + const SLocEntry &Entry = getSLocEntryByID(ID, &Invalid); if (Invalid) return; if (Entry.isFile()) { @@ -1823,18 +1824,18 @@ continue; } - const ExpansionInfo &ExpInfo = Entry.getExpansion(); + const ExpansionInfo &Expansion = Entry.getExpansion(); - if (ExpInfo.getExpansionLocStart().isFileID()) { - if (!isInFileID(ExpInfo.getExpansionLocStart(), FID)) + if (Expansion.getExpansionLocStart().isFileID()) { + if (!isInFileID(Expansion.getExpansionLocStart(), FID)) return; // No more files/macros that may be "contained" in this file. } - if (!ExpInfo.isMacroArgExpansion()) + if (!Expansion.isMacroArgExpansion()) continue; associateFileChunkWithMacroArgExp(MacroArgsCache, FID, - ExpInfo.getSpellingLoc(), + Expansion.getSpellingLoc(), SourceLocation::getMacroLoc(Entry.getOffset()), getFileIDSize(FileID::get(ID))); } @@ -1858,7 +1859,7 @@ FileID SpellFID; // Current FileID in the spelling range. unsigned SpellRelativeOffs; std::tie(SpellFID, SpellRelativeOffs) = getDecomposedLoc(SpellLoc); - while (1) { + while (true) { const SLocEntry &Entry = getSLocEntry(SpellFID); unsigned SpellFIDBeginOffs = Entry.getOffset(); unsigned SpellFIDSize = getFileIDSize(SpellFID); @@ -1885,7 +1886,6 @@ ++SpellFID.ID; SpellRelativeOffs = 0; } - } assert(SpellLoc.isFileID()); @@ -1973,7 +1973,7 @@ SourceLocation UpperLoc; bool Invalid = false; - const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid); + const SLocEntry &Entry = getSLocEntry(FID, &Invalid); if (!Invalid) { if (Entry.isExpansion()) UpperLoc = Entry.getExpansion().getExpansionLocStart(); @@ -2158,7 +2158,7 @@ LLVM_DUMP_METHOD void SourceManager::dump() const { llvm::raw_ostream &out = llvm::errs(); - auto DumpSLocEntry = [&](int ID, const SrcMgr::SLocEntry &Entry, + auto DumpSLocEntry = [&](int ID, const SLocEntry &Entry, llvm::Optional NextStart) { out << "SLocEntry " << (Entry.isFile() ? "file" : "expansion") << " using namespace clang; using namespace index; @@ -18,7 +23,7 @@ do { \ if (!CALL_EXPR) \ return false; \ - } while (0) + } while (false) namespace { @@ -409,7 +414,7 @@ } }; -} // anonymous namespace +} // end anonymous namespace bool IndexingContext::indexDecl(const Decl *D) { if (D->isImplicit() && shouldIgnoreIfImplicit(D)) Index: lib/Index/IndexTypeSourceInfo.cpp =================================================================== --- lib/Index/IndexTypeSourceInfo.cpp +++ lib/Index/IndexTypeSourceInfo.cpp @@ -9,6 +9,12 @@ #include "IndexingContext.h" #include "clang/AST/RecursiveASTVisitor.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Index/IndexSymbol.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Casting.h" +#include using namespace clang; using namespace index; @@ -46,7 +52,7 @@ do { \ if (!CALL_EXPR) \ return false; \ - } while (0) + } while (false) bool traverseParamVarHelper(ParmVarDecl *D) { TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc())); @@ -125,7 +131,7 @@ } }; -} // anonymous namespace +} // end anonymous namespace void IndexingContext::indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, Index: lib/Lex/PTHLexer.cpp =================================================================== --- lib/Lex/PTHLexer.cpp +++ lib/Lex/PTHLexer.cpp @@ -15,16 +15,30 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/FileSystemStatCache.h" #include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/SourceManager.h" #include "clang/Basic/TokenKinds.h" #include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/PTHManager.h" #include "clang/Lex/Preprocessor.h" #include "clang/Lex/Token.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/Support/EndianStream.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Endian.h" +#include "llvm/Support/ErrorOr.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/OnDiskHashTable.h" +#include +#include +#include +#include +#include +#include #include -#include +#include +#include + using namespace clang; static const unsigned StoredTokenSize = 1 + 1 + 2 + 4 + 4; @@ -167,7 +181,7 @@ // We don't need to actually reconstruct full tokens from the token buffer. // This saves some copies and it also reduces IdentifierInfo* lookup. const unsigned char* p = CurPtr; - while (1) { + while (true) { // Read the token kind. Are we at the end of the file? tok::TokenKind x = (tok::TokenKind) (uint8_t) *p; if (x == tok::eof) break; @@ -303,9 +317,11 @@ /// to map from FileEntry objects managed by FileManager to offsets within /// the PTH file. namespace { + class PTHFileData { const uint32_t TokenOff; const uint32_t PPCondOff; + public: PTHFileData(uint32_t tokenOff, uint32_t ppCondOff) : TokenOff(tokenOff), PPCondOff(ppCondOff) {} @@ -314,7 +330,6 @@ uint32_t getPPCondOffset() const { return PPCondOff; } }; - class PTHFileLookupCommonTrait { public: typedef std::pair internal_key_type; @@ -626,6 +641,7 @@ //===----------------------------------------------------------------------===// namespace { + class PTHStatData { public: uint64_t Size; @@ -660,7 +676,6 @@ static data_type ReadData(const internal_key_type& k, const unsigned char* d, unsigned) { - if (k.first /* File or Directory */) { bool IsDirectory = true; if (k.first == 0x1 /* File */) { @@ -682,9 +697,11 @@ return data_type(); } }; + } // end anonymous namespace namespace clang { + class PTHStatCache : public FileSystemStatCache { typedef llvm::OnDiskChainedHashTable CacheTy; CacheTy Cache; @@ -720,7 +737,8 @@ return CacheExists; } }; -} + +} // end namespace clang std::unique_ptr PTHManager::createStatCache() { return llvm::make_unique(*FileLookup); Index: lib/Parse/ParseCXXInlineMethods.cpp =================================================================== --- lib/Parse/ParseCXXInlineMethods.cpp +++ lib/Parse/ParseCXXInlineMethods.cpp @@ -13,10 +13,27 @@ #include "clang/Parse/Parser.h" #include "RAIIObjectsForParser.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclTemplate.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/TokenKinds.h" +#include "clang/Lex/Token.h" #include "clang/Parse/ParseDiagnostic.h" #include "clang/Sema/DeclSpec.h" +#include "clang/Sema/Ownership.h" #include "clang/Sema/Scope.h" +#include "clang/Sema/Sema.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorHandling.h" +#include +#include +#include + using namespace clang; /// ParseCXXInlineMethodDef - We parsed and verified that the specified @@ -672,7 +689,7 @@ // We always want this function to consume at least one token if the first // token isn't T and if not at EOF. bool isFirstTokenConsumed = true; - while (1) { + while (true) { // If we found one of the tokens, stop and return true. if (Tok.is(T1) || Tok.is(T2)) { if (ConsumeFinalToken) { @@ -1012,7 +1029,7 @@ unsigned AngleCount = 0; unsigned KnownTemplateCount = 0; - while (1) { + while (true) { switch (Tok.getKind()) { case tok::comma: // If we might be in a template, perform a tentative parse to check. Index: lib/Parse/ParseDecl.cpp =================================================================== --- lib/Parse/ParseDecl.cpp +++ lib/Parse/ParseDecl.cpp @@ -15,20 +15,42 @@ #include "RAIIObjectsForParser.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclTemplate.h" -#include "clang/Basic/AddressSpaces.h" #include "clang/Basic/Attributes.h" #include "clang/Basic/CharInfo.h" -#include "clang/Basic/TargetInfo.h" +#include "clang/Basic/ExceptionSpecificationType.h" +#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/Specifiers.h" +#include "clang/Basic/TokenKinds.h" +#include "clang/Basic/VersionTuple.h" +#include "clang/Lex/Token.h" #include "clang/Parse/ParseDiagnostic.h" +#include "clang/Sema/AttributeList.h" +#include "clang/Sema/DeclSpec.h" #include "clang/Sema/Lookup.h" +#include "clang/Sema/Ownership.h" #include "clang/Sema/ParsedTemplate.h" #include "clang/Sema/PrettyDeclStackTrace.h" #include "clang/Sema/Scope.h" +#include "clang/Sema/Sema.h" #include "clang/Sema/SemaDiagnostic.h" +#include "llvm/ADT/None.h" #include "llvm/ADT/SmallSet.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/Support/Casting.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ScopedPrinter.h" +#include +#include +#include +#include using namespace clang; @@ -2696,7 +2718,7 @@ ParsedAttributesWithRange attrs(AttrFactory); // We use Sema's policy to get bool macros right. PrintingPolicy Policy = Actions.getPrintingPolicy(); - while (1) { + while (true) { bool isInvalid = false; bool isStorageClass = false; const char *PrevSpec = nullptr; @@ -2710,7 +2732,7 @@ // the class is used. If we are currently parsing such a declaration, treat // the token as an identifier. if (getLangOpts().MSVCCompat && Tok.is(tok::kw__Atomic) && - DS.getStorageClassSpec() == clang::DeclSpec::SCS_typedef && + DS.getStorageClassSpec() == DeclSpec::SCS_typedef && !DS.hasTypeSpecifier() && GetLookAheadToken(1).is(tok::less)) Tok.setKind(tok::identifier); @@ -3618,7 +3640,7 @@ // Read struct-declarators until we find the semicolon. bool FirstDeclarator = true; SourceLocation CommaLoc; - while (1) { + while (true) { ParsingFieldDeclarator DeclaratorInfo(*this, DS); DeclaratorInfo.D.setCommaLoc(CommaLoc); @@ -4802,7 +4824,7 @@ SourceLocation EndLoc; - while (1) { + while (true) { bool isInvalid = false; const char *PrevSpec = nullptr; unsigned DiagID = 0; @@ -5418,7 +5440,7 @@ if (D.hasName() && !D.getNumTypeObjects()) MaybeParseCXX11Attributes(D); - while (1) { + while (true) { if (Tok.is(tok::l_paren)) { // Enter function-declaration scope, limiting any declarators to the // function prototype scope, including parameter declarators. Index: lib/Parse/ParseExpr.cpp =================================================================== --- lib/Parse/ParseExpr.cpp +++ lib/Parse/ParseExpr.cpp @@ -23,13 +23,39 @@ #include "RAIIObjectsForParser.h" #include "clang/AST/ASTContext.h" +#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/OperatorPrecedence.h" #include "clang/Basic/PrettyStackTrace.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Basic/TokenKinds.h" +#include "clang/Basic/TypeTraits.h" +#include "clang/Basic/VersionTuple.h" +#include "clang/Lex/Token.h" #include "clang/Parse/Parser.h" +#include "clang/Sema/AttributeList.h" #include "clang/Sema/DeclSpec.h" #include "clang/Sema/ParsedTemplate.h" +#include "clang/Sema/Ownership.h" #include "clang/Sema/Scope.h" +#include "clang/Sema/Sema.h" #include "clang/Sema/TypoCorrection.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorHandling.h" +#include +#include +#include + using namespace clang; /// \brief Simple precedence-based parser for binary/ternary operators. @@ -251,7 +277,7 @@ getLangOpts().CPlusPlus11); SourceLocation ColonLoc; - while (1) { + while (true) { // If this token has a lower precedence than we are allowed to parse (e.g. // because we are called recursively, or because the token is not a binop), // then we are done! @@ -485,8 +511,9 @@ } namespace { + class CastExpressionIdValidator : public CorrectionCandidateCallback { - public: +public: CastExpressionIdValidator(Token Next, bool AllowTypes, bool AllowNonTypes) : NextToken(Next), AllowNonTypes(AllowNonTypes) { WantTypeSpecifiers = WantFunctionLikeCasts = AllowTypes; @@ -514,11 +541,12 @@ return false; } - private: +private: Token NextToken; bool AllowNonTypes; }; -} + +} // end anonymous namespace /// \brief Parse a cast-expression, or, if \pisUnaryExpression is true, parse /// a unary-expression. @@ -1407,7 +1435,7 @@ // Now that the primary-expression piece of the postfix-expression has been // parsed, see if there are any postfix-expression pieces here. SourceLocation Loc; - while (1) { + while (true) { switch (Tok.getKind()) { case tok::code_completion: if (InMessageExpression) @@ -1810,7 +1838,6 @@ return Operand; } - /// \brief Parse a sizeof or alignof expression. /// /// \verbatim @@ -2004,7 +2031,7 @@ Comps.back().LocStart = Comps.back().LocEnd = ConsumeToken(); // FIXME: This loop leaks the index expressions on error. - while (1) { + while (true) { if (Tok.is(tok::period)) { // offsetof-member-designator: offsetof-member-designator '.' identifier Comps.push_back(Sema::OffsetOfComponent()); @@ -2658,7 +2685,7 @@ SmallVectorImpl &CommaLocs, std::function Completer) { bool SawError = false; - while (1) { + while (true) { if (Tok.is(tok::code_completion)) { if (Completer) Completer(); @@ -2711,7 +2738,7 @@ bool Parser::ParseSimpleExpressionList(SmallVectorImpl &Exprs, SmallVectorImpl &CommaLocs) { - while (1) { + while (true) { ExprResult Expr = ParseAssignmentExpression(); if (Expr.isInvalid()) return true; Index: lib/Rewrite/DeltaTree.cpp =================================================================== --- lib/Rewrite/DeltaTree.cpp +++ lib/Rewrite/DeltaTree.cpp @@ -13,8 +13,10 @@ #include "clang/Rewrite/Core/DeltaTree.h" #include "clang/Basic/LLVM.h" -#include +#include "llvm/Support/Casting.h" +#include #include + using namespace clang; /// The DeltaTree class is a multiway search tree (BTree) structure with some @@ -33,6 +35,7 @@ /// full delta implied by a whole subtree in constant time. namespace { + /// SourceDelta - As code in the original input buffer is added and deleted, /// SourceDelta records are used to keep track of how the input SourceLocation /// object is mapped into the output buffer. @@ -81,6 +84,7 @@ /// FullDelta - This is the full delta of all the values in this node and /// all children nodes. int FullDelta; + public: DeltaTreeNode(bool isLeaf = true) : NumValuesUsed(0), IsLeaf(isLeaf), FullDelta(0) {} @@ -90,6 +94,7 @@ bool isFull() const { return NumValuesUsed == 2*WidthFactor-1; } unsigned getNumValuesUsed() const { return NumValuesUsed; } + const SourceDelta &getValue(unsigned i) const { assert(i < NumValuesUsed && "Invalid value #"); return Values[i]; @@ -114,18 +119,19 @@ void Destroy(); }; -} // end anonymous namespace -namespace { /// DeltaTreeInteriorNode - When isLeaf = false, a node has child pointers. /// This class tracks them. class DeltaTreeInteriorNode : public DeltaTreeNode { DeltaTreeNode *Children[2*WidthFactor]; + ~DeltaTreeInteriorNode() { for (unsigned i = 0, e = NumValuesUsed+1; i != e; ++i) Children[i]->Destroy(); } + friend class DeltaTreeNode; + public: DeltaTreeInteriorNode() : DeltaTreeNode(false /*nonleaf*/) {} @@ -149,8 +155,8 @@ static inline bool classof(const DeltaTreeNode *N) { return !N->isLeaf(); } }; -} +} // end anonymous namespace /// Destroy - A 'virtual' destructor. void DeltaTreeNode::Destroy() { @@ -328,8 +334,6 @@ InsertRes.Split = Values[WidthFactor-1]; } - - //===----------------------------------------------------------------------===// // DeltaTree Implementation //===----------------------------------------------------------------------===// @@ -407,7 +411,7 @@ int Result = 0; // Walk down the tree. - while (1) { + while (true) { // For all nodes, include any local deltas before the specified file // index by summing them up directly. Keep track of how many were // included. @@ -461,4 +465,3 @@ VerifyTree(MyRoot); #endif } - Index: lib/Rewrite/HTMLRewrite.cpp =================================================================== --- lib/Rewrite/HTMLRewrite.cpp +++ lib/Rewrite/HTMLRewrite.cpp @@ -13,17 +13,25 @@ //===----------------------------------------------------------------------===// #include "clang/Rewrite/Core/HTMLRewrite.h" +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceManager.h" +#include "clang/Lex/Lexer.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Lex/Token.h" #include "clang/Lex/TokenConcatenation.h" +#include "clang/Rewrite/Core/RewriteBuffer.h" #include "clang/Rewrite/Core/Rewriter.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" -#include -using namespace clang; +#include +#include +#include +#include +using namespace clang; /// HighlightRange - Highlight a range in the source code with the specified /// start/end tags. B/E must be in the same file. This ensures that @@ -269,7 +277,6 @@ void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, FileID FID, const char *title) { - const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FID); const char* FileStart = Buf->getBufferStart(); const char* FileEnd = Buf->getBufferEnd(); @@ -453,7 +460,7 @@ // Lex all the tokens in raw mode, to avoid entering #includes or expanding // macros. - while (1) { + while (true) { Token Tok; L.LexFromRawLexer(Tok); @@ -567,7 +574,6 @@ TmpPP.Lex(Tok); } - // Insert the expansion as the end tag, so that multi-line macros all get // highlighted. Expansion = "" + Expansion + "";