diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2015-03-23 12:49:15 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2015-03-23 12:49:15 +0000 |
commit | e71037123b266a4d81a3f568d773b58e7fd91285 (patch) | |
tree | 7a5342114bdb93282e059eb61cbd367f65daa7ff /clang-tools-extra/modularize | |
parent | 9e925c1d66f01026883250553fe2894fa05e918b (diff) | |
download | bcm5719-llvm-e71037123b266a4d81a3f568d773b58e7fd91285.tar.gz bcm5719-llvm-e71037123b266a4d81a3f568d773b58e7fd91285.zip |
Make helpers static. clang-tools edition.
Also purge dead code found by it. NFC.
llvm-svn: 232948
Diffstat (limited to 'clang-tools-extra/modularize')
-rw-r--r-- | clang-tools-extra/modularize/CoverageChecker.h | 7 | ||||
-rw-r--r-- | clang-tools-extra/modularize/Modularize.cpp | 25 | ||||
-rw-r--r-- | clang-tools-extra/modularize/ModularizeUtilities.cpp | 4 | ||||
-rw-r--r-- | clang-tools-extra/modularize/PreprocessorTracker.cpp | 105 |
4 files changed, 35 insertions, 106 deletions
diff --git a/clang-tools-extra/modularize/CoverageChecker.h b/clang-tools-extra/modularize/CoverageChecker.h index 321dcae756f..a0e5f6f5f7f 100644 --- a/clang-tools-extra/modularize/CoverageChecker.h +++ b/clang-tools-extra/modularize/CoverageChecker.h @@ -32,13 +32,6 @@ namespace Modularize { -/// Subclass TargetOptions so we can construct it inline with -/// the minimal option, the triple. -class ModuleMapTargetOptions : public clang::TargetOptions { -public: - ModuleMapTargetOptions() { Triple = llvm::sys::getDefaultTargetTriple(); } -}; - /// Module map checker class. /// This is the heart of the checker. /// The doChecks function does the main work. diff --git a/clang-tools-extra/modularize/Modularize.cpp b/clang-tools-extra/modularize/Modularize.cpp index f113398495c..38f1f1ac655 100644 --- a/clang-tools-extra/modularize/Modularize.cpp +++ b/clang-tools-extra/modularize/Modularize.cpp @@ -252,18 +252,18 @@ using namespace llvm::opt; using namespace Modularize; // Option to specify a file name for a list of header files to check. -cl::list<std::string>
-ListFileNames(cl::Positional, cl::value_desc("list"),
- cl::desc("<list of one or more header list files>"),
- cl::CommaSeparated);
+static cl::list<std::string> + ListFileNames(cl::Positional, cl::value_desc("list"), + cl::desc("<list of one or more header list files>"), + cl::CommaSeparated); // Collect all other arguments, which will be passed to the front end. -cl::list<std::string> -CC1Arguments(cl::ConsumeAfter, - cl::desc("<arguments to be passed to front end>...")); +static cl::list<std::string> + CC1Arguments(cl::ConsumeAfter, + cl::desc("<arguments to be passed to front end>...")); // Option to specify a prefix to be prepended to the header names. -cl::opt<std::string> HeaderPrefix( +static cl::opt<std::string> HeaderPrefix( "prefix", cl::init(""), cl::desc( "Prepend header file paths with this prefix." @@ -272,7 +272,7 @@ cl::opt<std::string> HeaderPrefix( // Option for assistant mode, telling modularize to output a module map // based on the headers list, and where to put it. -cl::opt<std::string> ModuleMapPath( +static cl::opt<std::string> ModuleMapPath( "module-map-path", cl::init(""), cl::desc("Turn on module map output and specify output path or file name." " If no path is specified and if prefix option is specified," @@ -280,7 +280,7 @@ cl::opt<std::string> ModuleMapPath( // Option for assistant mode, telling modularize to output a module map // based on the headers list, and where to put it. -cl::opt<std::string> +static cl::opt<std::string> RootModule("root-module", cl::init(""), cl::desc("Specify the name of the root module.")); @@ -314,7 +314,7 @@ const char *Argv0; std::string CommandLine; // Helper function for finding the input file in an arguments list. -std::string findInputFile(const CommandLineArguments &CLArgs) { +static std::string findInputFile(const CommandLineArguments &CLArgs) { std::unique_ptr<OptTable> Opts(createDriverOptTable()); const unsigned IncludedFlagsBitmask = options::CC1Option; unsigned MissingArgIndex, MissingArgCount; @@ -332,7 +332,8 @@ std::string findInputFile(const CommandLineArguments &CLArgs) { // This arguments adjuster inserts "-include (file)" arguments for header // dependencies. -ArgumentsAdjuster getAddDependenciesAdjuster(DependencyMap &Dependencies) { +static ArgumentsAdjuster +getAddDependenciesAdjuster(DependencyMap &Dependencies) { return [&Dependencies](const CommandLineArguments &Args) { std::string InputFile = findInputFile(Args); DependentsVector &FileDependents = Dependencies[InputFile]; diff --git a/clang-tools-extra/modularize/ModularizeUtilities.cpp b/clang-tools-extra/modularize/ModularizeUtilities.cpp index c54a6f44b72..1bbae3c84ab 100644 --- a/clang-tools-extra/modularize/ModularizeUtilities.cpp +++ b/clang-tools-extra/modularize/ModularizeUtilities.cpp @@ -29,12 +29,14 @@ using namespace clang; using namespace llvm; using namespace Modularize; +namespace { // Subclass TargetOptions so we can construct it inline with // the minimal option, the triple. class ModuleMapTargetOptions : public clang::TargetOptions { public: ModuleMapTargetOptions() { Triple = llvm::sys::getDefaultTargetTriple(); } }; +} // namespace // ModularizeUtilities class implementation. @@ -344,7 +346,7 @@ bool ModularizeUtilities::collectUmbrellaHeaders(StringRef UmbrellaDirName, // Replace .. embedded in path for purposes of having // a canonical path.
-std::string replaceDotDot(StringRef Path) {
+static std::string replaceDotDot(StringRef Path) { SmallString<128> Buffer;
llvm::sys::path::const_iterator B = llvm::sys::path::begin(Path),
E = llvm::sys::path::end(Path);
diff --git a/clang-tools-extra/modularize/PreprocessorTracker.cpp b/clang-tools-extra/modularize/PreprocessorTracker.cpp index 0b761466b3f..c48f27e0e01 100644 --- a/clang-tools-extra/modularize/PreprocessorTracker.cpp +++ b/clang-tools-extra/modularize/PreprocessorTracker.cpp @@ -255,9 +255,6 @@ namespace Modularize { -// Forwards. -class PreprocessorTrackerImpl; - // Some handle types typedef llvm::PooledStringPtr StringHandle; @@ -303,7 +300,8 @@ static void getSourceLocationLineAndColumn(clang::Preprocessor &PP, } // Retrieve source snippet from file image. -std::string getSourceString(clang::Preprocessor &PP, clang::SourceRange Range) { +static std::string getSourceString(clang::Preprocessor &PP, + clang::SourceRange Range) { clang::SourceLocation BeginLoc = Range.getBegin(); clang::SourceLocation EndLoc = Range.getEnd(); const char *BeginPtr = PP.getSourceManager().getCharacterData(BeginLoc); @@ -313,7 +311,8 @@ std::string getSourceString(clang::Preprocessor &PP, clang::SourceRange Range) { } // Retrieve source line from file image given a location. -std::string getSourceLine(clang::Preprocessor &PP, clang::SourceLocation Loc) { +static std::string getSourceLine(clang::Preprocessor &PP, + clang::SourceLocation Loc) { const llvm::MemoryBuffer *MemBuffer = PP.getSourceManager().getBuffer(PP.getSourceManager().getFileID(Loc)); const char *Buffer = MemBuffer->getBufferStart(); @@ -338,8 +337,8 @@ std::string getSourceLine(clang::Preprocessor &PP, clang::SourceLocation Loc) { } // Retrieve source line from file image given a file ID and line number. -std::string getSourceLine(clang::Preprocessor &PP, clang::FileID FileID, - int Line) { +static std::string getSourceLine(clang::Preprocessor &PP, clang::FileID FileID, + int Line) { const llvm::MemoryBuffer *MemBuffer = PP.getSourceManager().getBuffer(FileID); const char *Buffer = MemBuffer->getBufferStart(); const char *BufferEnd = MemBuffer->getBufferEnd(); @@ -375,10 +374,10 @@ std::string getSourceLine(clang::Preprocessor &PP, clang::FileID FileID, // for the macro instance, which in the case of a function-style // macro will be a ')', but for an object-style macro, it // will be the macro name itself. -std::string getMacroUnexpandedString(clang::SourceRange Range, - clang::Preprocessor &PP, - llvm::StringRef MacroName, - const clang::MacroInfo *MI) { +static std::string getMacroUnexpandedString(clang::SourceRange Range, + clang::Preprocessor &PP, + llvm::StringRef MacroName, + const clang::MacroInfo *MI) { clang::SourceLocation BeginLoc(Range.getBegin()); const char *BeginPtr = PP.getSourceManager().getCharacterData(BeginLoc); size_t Length; @@ -400,10 +399,10 @@ std::string getMacroUnexpandedString(clang::SourceRange Range, // allows modularize to effectively work with respect to macro // consistency checking, although it displays the incorrect // expansion in error messages. -std::string getMacroExpandedString(clang::Preprocessor &PP, - llvm::StringRef MacroName, - const clang::MacroInfo *MI, - const clang::MacroArgs *Args) { +static std::string getMacroExpandedString(clang::Preprocessor &PP, + llvm::StringRef MacroName, + const clang::MacroInfo *MI, + const clang::MacroArgs *Args) { std::string Expanded; // Walk over the macro Tokens. typedef clang::MacroInfo::tokens_iterator Iter; @@ -458,77 +457,7 @@ std::string getMacroExpandedString(clang::Preprocessor &PP, return Expanded; } -// Get the string representing a vector of Tokens. -std::string -getTokensSpellingString(clang::Preprocessor &PP, - llvm::SmallVectorImpl<clang::Token> &Tokens) { - std::string Expanded; - // Walk over the macro Tokens. - typedef llvm::SmallVectorImpl<clang::Token>::iterator Iter; - for (Iter I = Tokens.begin(), E = Tokens.end(); I != E; ++I) - Expanded += PP.getSpelling(*I); // Not an identifier. - return llvm::StringRef(Expanded).trim().str(); -} - -// Get the expansion for a macro instance, given the information -// provided by PPCallbacks. -std::string getExpandedString(clang::Preprocessor &PP, - llvm::StringRef MacroName, - const clang::MacroInfo *MI, - const clang::MacroArgs *Args) { - std::string Expanded; - // Walk over the macro Tokens. - typedef clang::MacroInfo::tokens_iterator Iter; - for (Iter I = MI->tokens_begin(), E = MI->tokens_end(); I != E; ++I) { - clang::IdentifierInfo *II = I->getIdentifierInfo(); - int ArgNo = (II && Args ? MI->getArgumentNum(II) : -1); - if (ArgNo == -1) { - // This isn't an argument, just add it. - if (II == nullptr) - Expanded += PP.getSpelling((*I)); // Not an identifier. - else { - // Token is for an identifier. - std::string Name = II->getName().str(); - // Check for nexted macro references. - clang::MacroInfo *MacroInfo = PP.getMacroInfo(II); - if (MacroInfo) - Expanded += getMacroExpandedString(PP, Name, MacroInfo, nullptr); - else - Expanded += Name; - } - continue; - } - // We get here if it's a function-style macro with arguments. - const clang::Token *ResultArgToks; - const clang::Token *ArgTok = Args->getUnexpArgument(ArgNo); - if (Args->ArgNeedsPreexpansion(ArgTok, PP)) - ResultArgToks = &(const_cast<clang::MacroArgs *>(Args)) - ->getPreExpArgument(ArgNo, MI, PP)[0]; - else - ResultArgToks = ArgTok; // Use non-preexpanded Tokens. - // If the arg token didn't expand into anything, ignore it. - if (ResultArgToks->is(clang::tok::eof)) - continue; - unsigned NumToks = clang::MacroArgs::getArgLength(ResultArgToks); - // Append the resulting argument expansions. - for (unsigned ArgumentIndex = 0; ArgumentIndex < NumToks; ++ArgumentIndex) { - const clang::Token &AT = ResultArgToks[ArgumentIndex]; - clang::IdentifierInfo *II = AT.getIdentifierInfo(); - if (II == nullptr) - Expanded += PP.getSpelling(AT); // Not an identifier. - else { - // It's an identifier. Check for further expansion. - std::string Name = II->getName().str(); - clang::MacroInfo *MacroInfo = PP.getMacroInfo(II); - if (MacroInfo) - Expanded += getMacroExpandedString(PP, Name, MacroInfo, nullptr); - else - Expanded += Name; - } - } - } - return Expanded; -} +namespace { // ConditionValueKind strings. const char * @@ -805,6 +734,8 @@ public: std::vector<ConditionalExpansionInstance> ConditionalExpansionInstances; }; +class PreprocessorTrackerImpl; + // Preprocessor callbacks for modularize. // // This class derives from the Clang PPCallbacks class to track preprocessor @@ -1350,6 +1281,8 @@ private: bool InNestedHeader; }; +} // namespace + // PreprocessorTracker functions. // PreprocessorTracker desctructor. |