[clang-tools-extra] r232948 - Make helpers static. clang-tools edition.

Benjamin Kramer benny.kra at googlemail.com
Mon Mar 23 05:49:15 PDT 2015


Author: d0k
Date: Mon Mar 23 07:49:15 2015
New Revision: 232948

URL: http://llvm.org/viewvc/llvm-project?rev=232948&view=rev
Log:
Make helpers static. clang-tools edition.

Also purge dead code found by it. NFC.

Modified:
    clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
    clang-tools-extra/trunk/clang-modernize/AddOverride/AddOverride.cpp
    clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopConvert.cpp
    clang-tools-extra/trunk/clang-modernize/PassByValue/PassByValue.cpp
    clang-tools-extra/trunk/clang-modernize/UseAuto/UseAuto.cpp
    clang-tools-extra/trunk/clang-modernize/UseNullptr/UseNullptr.cpp
    clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp
    clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
    clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp
    clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
    clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
    clang-tools-extra/trunk/modularize/CoverageChecker.h
    clang-tools-extra/trunk/modularize/Modularize.cpp
    clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp
    clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
    clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp
    clang-tools-extra/trunk/pp-trace/PPTrace.cpp

Modified: clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp (original)
+++ clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp Mon Mar 23 07:49:15 2015
@@ -66,6 +66,7 @@ static cl::opt<std::string>
 FormatStyleOpt("style", cl::desc(format::StyleOptionHelpDescription),
                cl::init("LLVM"), cl::cat(FormattingCategory));
 
+namespace {
 // Helper object to remove the TUReplacement files (triggered by
 // "remove-change-desc-files" command line option) when exiting current scope.
 class ScopedFileRemover {
@@ -82,8 +83,9 @@ private:
   const TUReplacementFiles &TURFiles;
   clang::DiagnosticsEngine &Diag;
 };
+} // namespace
 
-void printVersion() {
+static void printVersion() {
   outs() << "clang-apply-replacements version " CLANG_VERSION_STRING << "\n";
 }
 
@@ -134,9 +136,9 @@ getRewrittenData(const std::vector<tooli
 ///
 /// \returns \li true if all replacements applied successfully.
 ///          \li false if at least one replacement failed to apply.
-bool applyReplacements(const std::vector<tooling::Replacement> &Replacements,
-                       std::string &Result,
-                       DiagnosticsEngine &Diagnostics) {
+static bool
+applyReplacements(const std::vector<tooling::Replacement> &Replacements,
+                  std::string &Result, DiagnosticsEngine &Diagnostics) {
   FileManager Files((FileSystemOptions()));
   SourceManager SM(Diagnostics, Files);
   Rewriter Rewrites(SM, LangOptions());
@@ -161,11 +163,11 @@ bool applyReplacements(const std::vector
 /// \returns \li true if reformatting replacements were all successfully
 ///          applied.
 ///          \li false if at least one reformatting replacement failed to apply.
-bool applyFormatting(const std::vector<tooling::Replacement> &Replacements,
-                     const StringRef FileData,
-                     std::string &FormattedFileData,
-                     const format::FormatStyle &FormatStyle,
-                     DiagnosticsEngine &Diagnostics) {
+static bool
+applyFormatting(const std::vector<tooling::Replacement> &Replacements,
+                const StringRef FileData, std::string &FormattedFileData,
+                const format::FormatStyle &FormatStyle,
+                DiagnosticsEngine &Diagnostics) {
   assert(!Replacements.empty() && "Need at least one replacement");
 
   RangeVector Ranges = calculateChangedRanges(Replacements);

Modified: clang-tools-extra/trunk/clang-modernize/AddOverride/AddOverride.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/AddOverride/AddOverride.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/AddOverride/AddOverride.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/AddOverride/AddOverride.cpp Mon Mar 23 07:49:15 2015
@@ -56,6 +56,7 @@ bool AddOverrideTransform::handleBeginSo
   return Transform::handleBeginSource(CI, Filename);
 }
 
+namespace {
 struct AddOverrideFactory : TransformFactory {
   AddOverrideFactory() {
     // if detecting macros is enabled, do not impose requirements on the
@@ -73,6 +74,7 @@ struct AddOverrideFactory : TransformFac
     return new AddOverrideTransform(Opts);
   }
 };
+} // namespace
 
 // Register the factory using this statically initialized variable.
 static TransformFactoryRegistry::Add<AddOverrideFactory>

Modified: clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopConvert.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopConvert.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopConvert.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/LoopConvert/LoopConvert.cpp Mon Mar 23 07:49:15 2015
@@ -69,6 +69,7 @@ LoopConvertTransform::handleBeginSource(
   return Transform::handleBeginSource(CI, Filename);
 }
 
+namespace {
 struct LoopConvertFactory : TransformFactory {
   LoopConvertFactory() {
     Since.Clang = Version(3, 0);
@@ -81,6 +82,7 @@ struct LoopConvertFactory : TransformFac
     return new LoopConvertTransform(Opts);
   }
 };
+} // namespace
 
 // Register the factory using this statically initialized variable.
 static TransformFactoryRegistry::Add<LoopConvertFactory>

Modified: clang-tools-extra/trunk/clang-modernize/PassByValue/PassByValue.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/PassByValue/PassByValue.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/PassByValue/PassByValue.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/PassByValue/PassByValue.cpp Mon Mar 23 07:49:15 2015
@@ -53,6 +53,7 @@ bool PassByValueTransform::handleBeginSo
   return Transform::handleBeginSource(CI, Filename);
 }
 
+namespace {
 struct PassByValueFactory : TransformFactory {
   PassByValueFactory() {
     // Based on the Replace Auto-Ptr Transform that is also using std::move().
@@ -66,6 +67,7 @@ struct PassByValueFactory : TransformFac
     return new PassByValueTransform(Opts);
   }
 };
+} // namespace
 
 // Register the factory using this statically initialized variable.
 static TransformFactoryRegistry::Add<PassByValueFactory>

Modified: clang-tools-extra/trunk/clang-modernize/UseAuto/UseAuto.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/UseAuto/UseAuto.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/UseAuto/UseAuto.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/UseAuto/UseAuto.cpp Mon Mar 23 07:49:15 2015
@@ -46,6 +46,7 @@ int UseAutoTransform::apply(const clang:
   return 0;
 }
 
+namespace {
 struct UseAutoFactory : TransformFactory {
   UseAutoFactory() {
     Since.Clang = Version(2, 9);
@@ -58,6 +59,7 @@ struct UseAutoFactory : TransformFactory
     return new UseAutoTransform(Opts);
   }
 };
+} // namespace
 
 // Register the factory using this statically initialized variable.
 static TransformFactoryRegistry::Add<UseAutoFactory>

Modified: clang-tools-extra/trunk/clang-modernize/UseNullptr/UseNullptr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/UseNullptr/UseNullptr.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/UseNullptr/UseNullptr.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/UseNullptr/UseNullptr.cpp Mon Mar 23 07:49:15 2015
@@ -56,6 +56,7 @@ int UseNullptrTransform::apply(const Com
   return 0;
 }
 
+namespace {
 struct UseNullptrFactory : TransformFactory {
   UseNullptrFactory() {
     Since.Clang = Version(3, 0);
@@ -68,6 +69,7 @@ struct UseNullptrFactory : TransformFact
     return new UseNullptrTransform(Opts);
   }
 };
+} // namespace
 
 // Register the factory using this statically initialized variable.
 static TransformFactoryRegistry::Add<UseNullptrFactory>

Modified: clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp (original)
+++ clang-tools-extra/trunk/clang-modernize/tool/ClangModernize.cpp Mon Mar 23 07:49:15 2015
@@ -36,7 +36,7 @@ namespace cl = llvm::cl;
 using namespace clang;
 using namespace clang::tooling;
 
-TransformOptions GlobalOptions;
+static TransformOptions GlobalOptions;
 
 // All options must belong to locally defined categories for them to get shown
 // by -help. We explicitly hide everything else (except -help and -version).
@@ -45,7 +45,7 @@ static cl::OptionCategory FormattingCate
 static cl::OptionCategory IncludeExcludeCategory("Inclusion/Exclusion Options");
 static cl::OptionCategory SerializeCategory("Serialization Options");
 
-const cl::OptionCategory *VisibleCategories[] = {
+static const cl::OptionCategory *VisibleCategories[] = {
   &GeneralCategory,   &FormattingCategory, &IncludeExcludeCategory,
   &SerializeCategory, &TransformCategory,  &TransformsOptionsCategory,
 };
@@ -112,7 +112,7 @@ TimingDirectoryName("perf",
                     cl::ValueOptional, cl::value_desc("directory name"),
                     cl::cat(GeneralCategory));
 
-cl::opt<std::string> SupportedCompilers(
+static cl::opt<std::string> SupportedCompilers(
     "for-compilers", cl::value_desc("string"),
     cl::desc("Select transforms targeting the intersection of\n"
              "language features supported by the given compilers.\n"
@@ -189,7 +189,7 @@ SerializeLocation("serialize-dir",
 
 ////////////////////////////////////////////////////////////////////////////////
 
-void printVersion() {
+static void printVersion() {
   llvm::outs() << "clang-modernizer version " CLANG_VERSION_STRING
                << "\n";
 }
@@ -248,7 +248,7 @@ static CompilerVersions handleSupportedC
   return RequiredVersions;
 }
 
-std::unique_ptr<CompilationDatabase>
+static std::unique_ptr<CompilationDatabase>
 autoDetectCompilations(std::string &ErrorMessage) {
   // Auto-detect a compilation database from BuildPath.
   if (BuildPath.getNumOccurrences() > 0)

Modified: clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp Mon Mar 23 07:49:15 2015
@@ -33,7 +33,7 @@ AvoidCStyleCastsCheck::registerMatchers(
       this);
 }
 
-bool needsConstCast(QualType SourceType, QualType DestType) {
+static bool needsConstCast(QualType SourceType, QualType DestType) {
   SourceType = SourceType.getNonReferenceType();
   DestType = DestType.getNonReferenceType();
   while (SourceType->isPointerType() && DestType->isPointerType()) {
@@ -45,7 +45,7 @@ bool needsConstCast(QualType SourceType,
   return false;
 }
 
-bool pointedTypesAreEqual(QualType SourceType, QualType DestType) {
+static bool pointedTypesAreEqual(QualType SourceType, QualType DestType) {
   SourceType = SourceType.getNonReferenceType();
   DestType = DestType.getNonReferenceType();
   while (SourceType->isPointerType() && DestType->isPointerType()) {

Modified: clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp Mon Mar 23 07:49:15 2015
@@ -26,9 +26,9 @@ void ExplicitConstructorCheck::registerM
 
 // Looks for the token matching the predicate and returns the range of the found
 // token including trailing whitespace.
-SourceRange FindToken(const SourceManager &Sources, LangOptions LangOpts,
-                      SourceLocation StartLoc, SourceLocation EndLoc,
-                      bool (*Pred)(const Token &)) {
+static SourceRange FindToken(const SourceManager &Sources, LangOptions LangOpts,
+                             SourceLocation StartLoc, SourceLocation EndLoc,
+                             bool (*Pred)(const Token &)) {
   if (StartLoc.isMacroID() || EndLoc.isMacroID())
     return SourceRange();
   FileID File = Sources.getFileID(Sources.getSpellingLoc(StartLoc));
@@ -49,14 +49,14 @@ SourceRange FindToken(const SourceManage
   return SourceRange();
 }
 
-bool declIsStdInitializerList(const NamedDecl *D) {
+static bool declIsStdInitializerList(const NamedDecl *D) {
   // First use the fast getName() method to avoid unnecessary calls to the
   // slow getQualifiedNameAsString().
   return D->getName() == "initializer_list" &&
          D->getQualifiedNameAsString() == "std::initializer_list";
 }
 
-bool isStdInitializerList(QualType Type) {
+static bool isStdInitializerList(QualType Type) {
   Type = Type.getCanonicalType();
   if (const auto *TS = Type->getAs<TemplateSpecializationType>()) {
     if (const TemplateDecl *TD = TS->getTemplateName().getAsTemplateDecl())

Modified: clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp Mon Mar 23 07:49:15 2015
@@ -37,13 +37,14 @@ void NamespaceCommentCheck::registerMatc
   Finder->addMatcher(namespaceDecl().bind("namespace"), this);
 }
 
-bool locationsInSameFile(const SourceManager &Sources, SourceLocation Loc1,
-                         SourceLocation Loc2) {
+static bool locationsInSameFile(const SourceManager &Sources,
+                                SourceLocation Loc1, SourceLocation Loc2) {
   return Loc1.isFileID() && Loc2.isFileID() &&
          Sources.getFileID(Loc1) == Sources.getFileID(Loc2);
 }
 
-std::string getNamespaceComment(const NamespaceDecl *ND, bool InsertLineBreak) {
+static std::string getNamespaceComment(const NamespaceDecl *ND,
+                                       bool InsertLineBreak) {
   std::string Fix = "// namespace";
   if (!ND->isAnonymousNamespace())
     Fix.append(" ").append(ND->getNameAsString());

Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Mon Mar 23 07:49:15 2015
@@ -215,7 +215,7 @@ static void printProfileData(const Profi
   OS.flush();
 }
 
-std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider() {
+static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider() {
   ClangTidyGlobalOptions GlobalOptions;
   if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) {
     llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n";
@@ -261,7 +261,7 @@ std::unique_ptr<ClangTidyOptionsProvider
                                                 OverrideOptions);
 }
 
-int clangTidyMain(int argc, const char **argv) {
+static int clangTidyMain(int argc, const char **argv) {
   CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory);
 
   auto OptionsProvider = createOptionsProvider();

Modified: clang-tools-extra/trunk/modularize/CoverageChecker.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/CoverageChecker.h?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/modularize/CoverageChecker.h (original)
+++ clang-tools-extra/trunk/modularize/CoverageChecker.h Mon Mar 23 07:49:15 2015
@@ -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.

Modified: clang-tools-extra/trunk/modularize/Modularize.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/Modularize.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/modularize/Modularize.cpp (original)
+++ clang-tools-extra/trunk/modularize/Modularize.cpp Mon Mar 23 07:49:15 2015
@@ -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 CommandL
 
 // 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];

Modified: clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp (original)
+++ clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp Mon Mar 23 07:49:15 2015
@@ -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::collectUmbrell
 
 // 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);

Modified: clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp (original)
+++ clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp Mon Mar 23 07:49:15 2015
@@ -255,9 +255,6 @@
 
 namespace Modularize {
 
-// Forwards.
-class PreprocessorTrackerImpl;
-
 // Some handle types
 typedef llvm::PooledStringPtr StringHandle;
 
@@ -303,7 +300,8 @@ static void getSourceLocationLineAndColu
 }
 
 // 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::Prepr
 }
 
 // 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::Preproc
 }
 
 // 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::Preproc
 // 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(cla
 // 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
   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.

Modified: clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp (original)
+++ clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp Mon Mar 23 07:49:15 2015
@@ -78,10 +78,8 @@ static const char *PragmaMessageKindStri
                                                   "PMK_Error" };
 
 // ConditionValueKind strings.
-const char *
-ConditionValueKindStrings[] = {
-  "CVK_NotEvaluated", "CVK_False", "CVK_True"
-};
+static const char *ConditionValueKindStrings[] = {"CVK_NotEvaluated",
+                                                  "CVK_False", "CVK_True"};
 
 // Mapping strings.
 static const char *MappingStrings[] = { "0",          "MAP_IGNORE",

Modified: clang-tools-extra/trunk/pp-trace/PPTrace.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/pp-trace/PPTrace.cpp?rev=232948&r1=232947&r2=232948&view=diff
==============================================================================
--- clang-tools-extra/trunk/pp-trace/PPTrace.cpp (original)
+++ clang-tools-extra/trunk/pp-trace/PPTrace.cpp Mon Mar 23 07:49:15 2015
@@ -82,27 +82,28 @@ using namespace llvm::opt;
 // Options:
 
 // Collect the source files.
-cl::list<std::string> SourcePaths(cl::Positional,
-                                  cl::desc("<source0> [... <sourceN>]"),
-                                  cl::OneOrMore);
+static cl::list<std::string> SourcePaths(cl::Positional,
+                                         cl::desc("<source0> [... <sourceN>]"),
+                                         cl::OneOrMore);
 
 // Option to specify a list or one or more callback names to ignore.
-cl::opt<std::string> IgnoreCallbacks(
+static cl::opt<std::string> IgnoreCallbacks(
     "ignore", cl::init(""),
     cl::desc("Ignore callbacks, i.e. \"Callback1, Callback2...\"."));
 
 // Option to specify the trace output file name.
-cl::opt<std::string> OutputFileName(
+static cl::opt<std::string> OutputFileName(
     "output", cl::init(""),
     cl::desc("Output trace to the given file name or '-' for stdout."));
 
 // 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>..."));
 
 // Frontend action stuff:
 
+namespace {
 // Consumer is responsible for setting up the callbacks.
 class PPTraceConsumer : public ASTConsumer {
 public:
@@ -146,10 +147,11 @@ private:
   SmallSet<std::string, 4> &Ignore;
   std::vector<CallbackCall> &CallbackCalls;
 };
+} // namespace
 
 // Output the trace given its data structure and a stream.
-int outputPPTrace(std::vector<CallbackCall> &CallbackCalls,
-                  llvm::raw_ostream &OS) {
+static int outputPPTrace(std::vector<CallbackCall> &CallbackCalls,
+                         llvm::raw_ostream &OS) {
   // Mark start of document.
   OS << "---\n";
 





More information about the cfe-commits mailing list