forked from OSchip/llvm-project
cpp11-migrate: Replace file override container
A more flexible container for storing overrides is required for headers. Before a source goes through the transform pipeline, any headers it references will be in their original state and unaffected by transforms applied to other sources. Therefore overrides for headers need to be kept separate for each source file. This patch doesn't introduce support for storing header overrides yet. It only replaces the existing structure and makes any necessary changes to support it. llvm-svn: 183910
This commit is contained in:
parent
c0bbe36245
commit
e0a7d9ceff
|
@ -29,12 +29,13 @@ using namespace clang;
|
|||
|
||||
static llvm::cl::opt<bool> DetectMacros(
|
||||
"override-macros",
|
||||
llvm::cl::desc("Detect and use macros that expand to the 'override' keyword."));
|
||||
llvm::cl::desc(
|
||||
"Detect and use macros that expand to the 'override' keyword."));
|
||||
|
||||
int AddOverrideTransform::apply(const FileContentsByPath &InputStates,
|
||||
int AddOverrideTransform::apply(const FileOverrides &InputStates,
|
||||
const CompilationDatabase &Database,
|
||||
const std::vector<std::string> &SourcePaths,
|
||||
FileContentsByPath &ResultStates) {
|
||||
FileOverrides &ResultStates) {
|
||||
RefactoringTool AddOverrideTool(Database, SourcePaths);
|
||||
|
||||
unsigned AcceptedChanges = 0;
|
||||
|
|
|
@ -30,10 +30,10 @@ public:
|
|||
: Transform("AddOverride", Options) {}
|
||||
|
||||
/// \see Transform::run().
|
||||
virtual int apply(const FileContentsByPath &InputStates,
|
||||
virtual int apply(const FileOverrides &InputStates,
|
||||
const clang::tooling::CompilationDatabase &Database,
|
||||
const std::vector<std::string> &SourcePaths,
|
||||
FileContentsByPath &ResultStates) LLVM_OVERRIDE;
|
||||
FileOverrides &ResultStates) LLVM_OVERRIDE;
|
||||
|
||||
virtual bool handleBeginSource(clang::CompilerInstance &CI,
|
||||
llvm::StringRef Filename) LLVM_OVERRIDE;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
set(LLVM_LINK_COMPONENTS support)
|
||||
|
||||
add_clang_library(migrateCore
|
||||
FileOverrides.cpp
|
||||
SyntaxCheck.cpp
|
||||
Transforms.cpp
|
||||
Transform.cpp
|
||||
IncludeExcludeInfo.cpp
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#include "Core/FileOverrides.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
|
||||
void SourceOverrides::applyOverrides(clang::SourceManager &SM,
|
||||
clang::FileManager &FM) const {
|
||||
assert(!MainFileOverride.empty() &&
|
||||
"Main source file override should exist!");
|
||||
SM.overrideFileContents(FM.getFile(MainFileName),
|
||||
llvm::MemoryBuffer::getMemBuffer(MainFileOverride));
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
//===-- Core/FileOverrides.h ------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
///
|
||||
/// \file
|
||||
/// \brief This file provides types and functionality for dealing with source
|
||||
/// and header file content overrides.
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
#ifndef CPP11_MIGRATE_FILE_OVERRIDES_H
|
||||
#define CPP11_MIGRATE_FILE_OVERRIDES_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
// Forward Declarations
|
||||
namespace clang {
|
||||
class SourceManager;
|
||||
class FileManager;
|
||||
} // namespace clang
|
||||
|
||||
|
||||
/// \brief Container storing the file content overrides for a source file.
|
||||
struct SourceOverrides {
|
||||
SourceOverrides(const char *MainFileName)
|
||||
: MainFileName(MainFileName) {}
|
||||
|
||||
/// \brief Convenience function for applying this source's overrides to
|
||||
/// the given SourceManager.
|
||||
void applyOverrides(clang::SourceManager &SM, clang::FileManager &FM) const;
|
||||
|
||||
std::string MainFileName;
|
||||
std::string MainFileOverride;
|
||||
};
|
||||
|
||||
/// \brief Maps source file names to content override information.
|
||||
typedef std::map<std::string, SourceOverrides> FileOverrides;
|
||||
|
||||
#endif // CPP11_MIGRATE_FILE_OVERRIDES_H
|
|
@ -0,0 +1,59 @@
|
|||
#include "SyntaxCheck.h"
|
||||
#include "clang/Frontend/CompilerInstance.h"
|
||||
#include "clang/Frontend/FrontendActions.h"
|
||||
#include "clang/Tooling/Tooling.h"
|
||||
|
||||
using namespace clang;
|
||||
using namespace tooling;
|
||||
|
||||
class SyntaxCheck : public SyntaxOnlyAction {
|
||||
public:
|
||||
SyntaxCheck(const FileOverrides &Overrides) : Overrides(Overrides) {}
|
||||
|
||||
virtual bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) {
|
||||
if (!SyntaxOnlyAction::BeginSourceFileAction(CI, Filename))
|
||||
return false;
|
||||
|
||||
FileOverrides::const_iterator I = Overrides.find(Filename);
|
||||
if (I != Overrides.end())
|
||||
I->second.applyOverrides(CI.getSourceManager(), CI.getFileManager());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
const FileOverrides &Overrides;
|
||||
};
|
||||
|
||||
class SyntaxCheckFactory : public FrontendActionFactory {
|
||||
public:
|
||||
SyntaxCheckFactory(const FileOverrides &Overrides)
|
||||
: Overrides(Overrides) {}
|
||||
|
||||
virtual FrontendAction *create() { return new SyntaxCheck(Overrides); }
|
||||
|
||||
private:
|
||||
const FileOverrides &Overrides;
|
||||
};
|
||||
|
||||
class SyntaxArgumentsAdjuster : public ArgumentsAdjuster {
|
||||
CommandLineArguments Adjust(const CommandLineArguments &Args) {
|
||||
CommandLineArguments AdjustedArgs = Args;
|
||||
AdjustedArgs.push_back("-fsyntax-only");
|
||||
AdjustedArgs.push_back("-std=c++11");
|
||||
return AdjustedArgs;
|
||||
}
|
||||
};
|
||||
|
||||
bool doSyntaxCheck(const CompilationDatabase &Database,
|
||||
const std::vector<std::string> &SourcePaths,
|
||||
const FileOverrides &Overrides) {
|
||||
ClangTool SyntaxTool(Database, SourcePaths);
|
||||
|
||||
// Ensure C++11 support is enabled.
|
||||
// FIXME: This isn't necessary anymore since the Migrator requires C++11
|
||||
// to be enabled in the CompilationDatabase. Remove later.
|
||||
SyntaxTool.setArgumentsAdjuster(new SyntaxArgumentsAdjuster);
|
||||
|
||||
return SyntaxTool.run(new SyntaxCheckFactory(Overrides)) == 0;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
//===-- Core/SyntaxCheck.h --------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
///
|
||||
/// \file
|
||||
/// \brief This file exposes functionaliy for doing a syntax-only check on
|
||||
/// files with overridden contents.
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
#ifndef CPP11_MIGRATE_SYNTAX_CHECK_H
|
||||
#define CPP11_MIGRATE_SYNTAX_CHECK_H
|
||||
|
||||
#include <vector>
|
||||
#include "Core/FileOverrides.h"
|
||||
|
||||
// Forward Declarations
|
||||
namespace clang {
|
||||
namespace tooling {
|
||||
class CompilationDatabase;
|
||||
} // namespace tooling
|
||||
} // namespace clang
|
||||
|
||||
/// \brief Perform a syntax-only check over all files in \c SourcePaths using
|
||||
/// options provided by \c Database using file contents from \c Overrides if
|
||||
/// available.
|
||||
extern bool doSyntaxCheck(const clang::tooling::CompilationDatabase &Database,
|
||||
const std::vector<std::string> &SourcePaths,
|
||||
const FileOverrides &Overrides);
|
||||
|
||||
#endif // CPP11_MIGRATE_SYNTAX_CHECK_H
|
|
@ -1,7 +1,5 @@
|
|||
#include "Core/Transform.h"
|
||||
#include "clang/ASTMatchers/ASTMatchFinder.h"
|
||||
#include "clang/Basic/FileManager.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
#include "clang/Frontend/CompilerInstance.h"
|
||||
#include "clang/Rewrite/Core/Rewriter.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
@ -22,7 +20,7 @@ using namespace ast_matchers;
|
|||
/// SourceFileCallbacks.
|
||||
class ActionFactory : public clang::tooling::FrontendActionFactory {
|
||||
public:
|
||||
ActionFactory(MatchFinder &Finder, const FileContentsByPath &Overrides,
|
||||
ActionFactory(MatchFinder &Finder, const FileOverrides &Overrides,
|
||||
SourceFileCallbacks &Callbacks)
|
||||
: Finder(Finder), Overrides(Overrides), Callbacks(Callbacks) {}
|
||||
|
||||
|
@ -33,7 +31,7 @@ public:
|
|||
private:
|
||||
class FactoryAdaptor : public ASTFrontendAction {
|
||||
public:
|
||||
FactoryAdaptor(MatchFinder &Finder, const FileContentsByPath &Overrides,
|
||||
FactoryAdaptor(MatchFinder &Finder, const FileOverrides &Overrides,
|
||||
SourceFileCallbacks &Callbacks)
|
||||
: Finder(Finder), Overrides(Overrides), Callbacks(Callbacks) {}
|
||||
|
||||
|
@ -46,12 +44,10 @@ private:
|
|||
if (!ASTFrontendAction::BeginSourceFileAction(CI, Filename))
|
||||
return false;
|
||||
|
||||
FileContentsByPath::const_iterator I = Overrides.find(Filename.str());
|
||||
if (I != Overrides.end())
|
||||
// If an override exists, use it.
|
||||
CI.getSourceManager()
|
||||
.overrideFileContents(CI.getFileManager().getFile(I->first),
|
||||
llvm::MemoryBuffer::getMemBuffer(I->second));
|
||||
FileOverrides::const_iterator I = Overrides.find(Filename.str());
|
||||
if (I != Overrides.end()) {
|
||||
I->second.applyOverrides(CI.getSourceManager(), CI.getFileManager());
|
||||
}
|
||||
|
||||
return Callbacks.handleBeginSource(CI, Filename);
|
||||
}
|
||||
|
@ -63,38 +59,34 @@ private:
|
|||
|
||||
private:
|
||||
MatchFinder &Finder;
|
||||
const FileContentsByPath &Overrides;
|
||||
const FileOverrides &Overrides;
|
||||
SourceFileCallbacks &Callbacks;
|
||||
};
|
||||
|
||||
MatchFinder &Finder;
|
||||
const FileContentsByPath &Overrides;
|
||||
const FileOverrides &Overrides;
|
||||
SourceFileCallbacks &Callbacks;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
RewriterContainer::RewriterContainer(clang::FileManager &Files,
|
||||
const FileContentsByPath &InputStates)
|
||||
const FileOverrides &InputStates)
|
||||
: DiagOpts(new clang::DiagnosticOptions()),
|
||||
DiagnosticPrinter(llvm::errs(), DiagOpts.getPtr()),
|
||||
Diagnostics(llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs>(
|
||||
new clang::DiagnosticIDs()),
|
||||
DiagOpts.getPtr(), &DiagnosticPrinter, false),
|
||||
Sources(Diagnostics, Files), Rewrite(Sources, DefaultLangOptions) {
|
||||
|
||||
// Overwrite source manager's file contents with data from InputStates
|
||||
for (FileContentsByPath::const_iterator I = InputStates.begin(),
|
||||
E = InputStates.end();
|
||||
I != E; ++I) {
|
||||
Sources.overrideFileContents(Files.getFile(I->first),
|
||||
llvm::MemoryBuffer::getMemBuffer(I->second));
|
||||
}
|
||||
for (FileOverrides::const_iterator I = InputStates.begin(),
|
||||
E = InputStates.end();
|
||||
I != E; ++I)
|
||||
I->second.applyOverrides(Sources, Files);
|
||||
}
|
||||
|
||||
void collectResults(clang::Rewriter &Rewrite,
|
||||
const FileContentsByPath &InputStates,
|
||||
FileContentsByPath &Results) {
|
||||
const FileOverrides &InputStates,
|
||||
FileOverrides &Results) {
|
||||
// Copy the contents of InputStates to be modified.
|
||||
Results = InputStates;
|
||||
|
||||
|
@ -106,6 +98,12 @@ void collectResults(clang::Rewriter &Rewrite,
|
|||
assert(Entry->getName() != 0 &&
|
||||
"Unexpected NULL return from FileEntry::getName()");
|
||||
|
||||
FileOverrides::iterator OverrideI = Results.find(Entry->getName());
|
||||
if (OverrideI == Results.end()) {
|
||||
OverrideI = Results.insert(FileOverrides::value_type(
|
||||
Entry->getName(), Entry->getName())).first;
|
||||
}
|
||||
|
||||
std::string ResultBuf;
|
||||
|
||||
// Get a copy of the rewritten buffer from the Rewriter.
|
||||
|
@ -118,7 +116,7 @@ void collectResults(clang::Rewriter &Rewrite,
|
|||
// FIXME: Use move semantics to avoid copies of the buffer contents if
|
||||
// benchmarking shows the copies are expensive, especially for large source
|
||||
// files.
|
||||
Results[Entry->getName()] = ResultBuf;
|
||||
OverrideI->second.MainFileOverride = ResultBuf;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,6 +142,6 @@ void Transform::addTiming(llvm::StringRef Label, llvm::TimeRecord Duration) {
|
|||
|
||||
FrontendActionFactory *
|
||||
Transform::createActionFactory(MatchFinder &Finder,
|
||||
const FileContentsByPath &InputStates) {
|
||||
const FileOverrides &InputStates) {
|
||||
return new ActionFactory(Finder, InputStates, *this);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "IncludeExcludeInfo.h"
|
||||
#include "Core/IncludeExcludeInfo.h"
|
||||
#include "Core/FileOverrides.h"
|
||||
#include "clang/ASTMatchers/ASTMatchFinder.h"
|
||||
#include "clang/Tooling/Tooling.h"
|
||||
#include "llvm/Support/Timer.h"
|
||||
|
||||
|
@ -54,9 +56,6 @@ class MatchFinder;
|
|||
} // namespace ast_matchers
|
||||
} // namespace clang
|
||||
|
||||
/// \brief The key is the path of a file, which is mapped to a
|
||||
/// buffer with the possibly modified contents of that file.
|
||||
typedef std::map<std::string, std::string> FileContentsByPath;
|
||||
|
||||
/// \brief In \p Results place copies of the buffers resulting from applying
|
||||
/// all rewrites represented by \p Rewrite.
|
||||
|
@ -64,8 +63,8 @@ typedef std::map<std::string, std::string> FileContentsByPath;
|
|||
/// \p Results is made up of pairs {filename, buffer contents}. Pairs are
|
||||
/// simply appended to \p Results.
|
||||
void collectResults(clang::Rewriter &Rewrite,
|
||||
const FileContentsByPath &InputStates,
|
||||
FileContentsByPath &Results);
|
||||
const FileOverrides &InputStates,
|
||||
FileOverrides &Results);
|
||||
|
||||
/// \brief Class for containing a Rewriter instance and all of
|
||||
/// its lifetime dependencies.
|
||||
|
@ -80,7 +79,7 @@ void collectResults(clang::Rewriter &Rewrite,
|
|||
class RewriterContainer {
|
||||
public:
|
||||
RewriterContainer(clang::FileManager &Files,
|
||||
const FileContentsByPath &InputStates);
|
||||
const FileOverrides &InputStates);
|
||||
|
||||
clang::Rewriter &getRewriter() { return Rewrite; }
|
||||
|
||||
|
@ -140,10 +139,10 @@ public:
|
|||
/// SourcePaths and should take precedence over content of files on disk.
|
||||
/// Upon return, \p ResultStates shall contain the result of performing this
|
||||
/// transform on the files listed in \p SourcePaths.
|
||||
virtual int apply(const FileContentsByPath &InputStates,
|
||||
virtual int apply(const FileOverrides &InputStates,
|
||||
const clang::tooling::CompilationDatabase &Database,
|
||||
const std::vector<std::string> &SourcePaths,
|
||||
FileContentsByPath &ResultStates) = 0;
|
||||
FileOverrides &ResultStates) = 0;
|
||||
|
||||
/// \brief Query if changes were made during the last call to apply().
|
||||
bool getChangesMade() const { return AcceptedChanges > 0; }
|
||||
|
@ -225,7 +224,7 @@ protected:
|
|||
/// for overriding source file contents with results of previous transforms.
|
||||
clang::tooling::FrontendActionFactory *
|
||||
createActionFactory(clang::ast_matchers::MatchFinder &Finder,
|
||||
const FileContentsByPath &InputStates);
|
||||
const FileOverrides &InputStates);
|
||||
|
||||
private:
|
||||
const std::string Name;
|
||||
|
|
|
@ -25,10 +25,10 @@ using clang::ast_matchers::MatchFinder;
|
|||
using namespace clang::tooling;
|
||||
using namespace clang;
|
||||
|
||||
int LoopConvertTransform::apply(const FileContentsByPath &InputStates,
|
||||
int LoopConvertTransform::apply(const FileOverrides &InputStates,
|
||||
const CompilationDatabase &Database,
|
||||
const std::vector<std::string> &SourcePaths,
|
||||
FileContentsByPath &ResultStates) {
|
||||
FileOverrides &ResultStates) {
|
||||
RefactoringTool LoopTool(Database, SourcePaths);
|
||||
|
||||
StmtAncestorASTVisitor ParentFinder;
|
||||
|
|
|
@ -27,10 +27,10 @@ public:
|
|||
: Transform("LoopConvert", Options) {}
|
||||
|
||||
/// \see Transform::run().
|
||||
virtual int apply(const FileContentsByPath &InputStates,
|
||||
virtual int apply(const FileOverrides &InputStates,
|
||||
const clang::tooling::CompilationDatabase &Database,
|
||||
const std::vector<std::string> &SourcePaths,
|
||||
FileContentsByPath &ResultStates) LLVM_OVERRIDE;
|
||||
FileOverrides &ResultStates) LLVM_OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_LOOP_CONVERT_H
|
||||
|
|
|
@ -20,10 +20,10 @@ using clang::ast_matchers::MatchFinder;
|
|||
using namespace clang;
|
||||
using namespace clang::tooling;
|
||||
|
||||
int UseAutoTransform::apply(const FileContentsByPath &InputStates,
|
||||
int UseAutoTransform::apply(const FileOverrides &InputStates,
|
||||
const clang::tooling::CompilationDatabase &Database,
|
||||
const std::vector<std::string> &SourcePaths,
|
||||
FileContentsByPath &ResultStates) {
|
||||
FileOverrides &ResultStates) {
|
||||
RefactoringTool UseAutoTool(Database, SourcePaths);
|
||||
|
||||
unsigned AcceptedChanges = 0;
|
||||
|
|
|
@ -32,10 +32,10 @@ public:
|
|||
UseAutoTransform(const TransformOptions &Options) : Transform("UseAuto", Options) {}
|
||||
|
||||
/// \see Transform::run().
|
||||
virtual int apply(const FileContentsByPath &InputStates,
|
||||
virtual int apply(const FileOverrides &InputStates,
|
||||
const clang::tooling::CompilationDatabase &Database,
|
||||
const std::vector<std::string> &SourcePaths,
|
||||
FileContentsByPath &ResultStates) LLVM_OVERRIDE;
|
||||
FileOverrides &ResultStates) LLVM_OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_USE_AUTO_H
|
||||
|
|
|
@ -25,10 +25,10 @@ using clang::ast_matchers::MatchFinder;
|
|||
using namespace clang::tooling;
|
||||
using namespace clang;
|
||||
|
||||
int UseNullptrTransform::apply(const FileContentsByPath &InputStates,
|
||||
int UseNullptrTransform::apply(const FileOverrides &InputStates,
|
||||
const CompilationDatabase &Database,
|
||||
const std::vector<std::string> &SourcePaths,
|
||||
FileContentsByPath &ResultStates) {
|
||||
FileOverrides &ResultStates) {
|
||||
RefactoringTool UseNullptrTool(Database, SourcePaths);
|
||||
|
||||
unsigned AcceptedChanges = 0;
|
||||
|
|
|
@ -27,10 +27,10 @@ public:
|
|||
: Transform("UseNullptr", Options) {}
|
||||
|
||||
/// \see Transform::run().
|
||||
virtual int apply(const FileContentsByPath &InputStates,
|
||||
virtual int apply(const FileOverrides &InputStates,
|
||||
const clang::tooling::CompilationDatabase &Database,
|
||||
const std::vector<std::string> &SourcePaths,
|
||||
FileContentsByPath &ResultStates) LLVM_OVERRIDE;
|
||||
FileOverrides &ResultStates) LLVM_OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_USE_NULLPTR_H
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "Core/SyntaxCheck.h"
|
||||
#include "Core/Transforms.h"
|
||||
#include "Core/Transform.h"
|
||||
#include "Core/PerfSupport.h"
|
||||
|
@ -88,15 +89,6 @@ static cl::opt<bool, /*ExternalStorage=*/true> EnableHeaderModifications(
|
|||
cl::location(GlobalOptions.EnableHeaderModifications),
|
||||
cl::init(false));
|
||||
|
||||
class EndSyntaxArgumentsAdjuster : public ArgumentsAdjuster {
|
||||
CommandLineArguments Adjust(const CommandLineArguments &Args) {
|
||||
CommandLineArguments AdjustedArgs = Args;
|
||||
AdjustedArgs.push_back("-fsyntax-only");
|
||||
AdjustedArgs.push_back("-std=c++11");
|
||||
return AdjustedArgs;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, const char **argv) {
|
||||
llvm::sys::PrintStackTraceOnErrorSignal();
|
||||
Transforms TransformManager;
|
||||
|
@ -138,7 +130,7 @@ int main(int argc, const char **argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
FileContentsByPath FileStates1, FileStates2,
|
||||
FileOverrides FileStates1, FileStates2,
|
||||
*InputFileStates = &FileStates1, *OutputFileStates = &FileStates2;
|
||||
|
||||
SourcePerfData PerfData;
|
||||
|
@ -173,35 +165,20 @@ int main(int argc, const char **argv) {
|
|||
OutputFileStates->clear();
|
||||
}
|
||||
|
||||
// Final state of files is pointed at by InputFileStates.
|
||||
|
||||
if (FinalSyntaxCheck) {
|
||||
ClangTool EndSyntaxTool(OptionsParser.getCompilations(),
|
||||
OptionsParser.getSourcePathList());
|
||||
|
||||
// Add c++11 support to clang.
|
||||
EndSyntaxTool.setArgumentsAdjuster(new EndSyntaxArgumentsAdjuster);
|
||||
|
||||
for (FileContentsByPath::const_iterator I = InputFileStates->begin(),
|
||||
E = InputFileStates->end();
|
||||
I != E; ++I) {
|
||||
EndSyntaxTool.mapVirtualFile(I->first, I->second);
|
||||
}
|
||||
|
||||
if (EndSyntaxTool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>())
|
||||
!= 0) {
|
||||
if (FinalSyntaxCheck)
|
||||
// Final state of files is pointed at by InputFileStates.
|
||||
if (!doSyntaxCheck(OptionsParser.getCompilations(),
|
||||
OptionsParser.getSourcePathList(), *InputFileStates))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Write results to file.
|
||||
for (FileContentsByPath::const_iterator I = InputFileStates->begin(),
|
||||
E = InputFileStates->end();
|
||||
for (FileOverrides::const_iterator I = InputFileStates->begin(),
|
||||
E = InputFileStates->end();
|
||||
I != E; ++I) {
|
||||
std::string ErrorInfo;
|
||||
llvm::raw_fd_ostream FileStream(I->first.c_str(), ErrorInfo,
|
||||
llvm::raw_fd_ostream::F_Binary);
|
||||
FileStream << I->second;
|
||||
FileStream << I->second.MainFileOverride;
|
||||
}
|
||||
|
||||
// Report execution times.
|
||||
|
|
|
@ -9,9 +9,9 @@ public:
|
|||
TransformA(const TransformOptions &Options)
|
||||
: Transform("TransformA", Options) {}
|
||||
|
||||
virtual int apply(const FileContentsByPath &,
|
||||
virtual int apply(const FileOverrides &,
|
||||
const tooling::CompilationDatabase &,
|
||||
const std::vector<std::string> &, FileContentsByPath &) {
|
||||
const std::vector<std::string> &, FileOverrides &) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -25,9 +25,9 @@ public:
|
|||
TransformB(const TransformOptions &Options)
|
||||
: Transform("TransformB", Options) {}
|
||||
|
||||
virtual int apply(const FileContentsByPath &,
|
||||
virtual int apply(const FileOverrides &,
|
||||
const tooling::CompilationDatabase &,
|
||||
const std::vector<std::string> &, FileContentsByPath &) {
|
||||
const std::vector<std::string> &, FileOverrides &) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,10 +13,10 @@ public:
|
|||
DummyTransform(llvm::StringRef Name, const TransformOptions &Options)
|
||||
: Transform(Name, Options) {}
|
||||
|
||||
virtual int apply(const FileContentsByPath &,
|
||||
virtual int apply(const FileOverrides &,
|
||||
const tooling::CompilationDatabase &,
|
||||
const std::vector<std::string> &,
|
||||
FileContentsByPath &) { return 0; }
|
||||
FileOverrides &) { return 0; }
|
||||
|
||||
void setAcceptedChanges(unsigned Changes) {
|
||||
Transform::setAcceptedChanges(Changes);
|
||||
|
|
Loading…
Reference in New Issue