Turn -fixit it back into a mode, but make -fixit-at imply that mode this time

(instead of running it with arbitrary consumers).
 - Also, turn any -fixit-at lookup failure into an error.

llvm-svn: 88757
This commit is contained in:
Daniel Dunbar
2009-11-14 04:39:29 +00:00
parent b774685c08
commit 10563ea92e
4 changed files with 35 additions and 44 deletions

View File

@@ -26,6 +26,8 @@ def err_fe_incompatible_options : Error<
"'%0' cannot be used with '%1'">, DefaultFatal;
def err_fe_no_fixit_and_codegen : Error<
"FIX-ITs cannot be applied when generating code">;
def err_fe_unable_to_find_fixit_file : Error<
"FIX-IT could not find file '%0'">;
def err_verify_bogus_characters : Error<
"bogus characters before '{{' in expected string">;

View File

@@ -41,8 +41,6 @@ public:
unsigned EmptyInputOnly : 1; ///< Force input files to be treated
/// as if they were empty, for timing
/// the frontend startup.
unsigned FixItAll : 1; ///< Apply FIX-IT advice to the input
/// source files.
unsigned RelocatablePCH : 1; ///< When generating PCH files,
/// instruct the PCH writer to create
/// relocatable PCH files.
@@ -80,7 +78,6 @@ public:
DebugCodeCompletionPrinter = 0;
DisableFree = 0;
EmptyInputOnly = 0;
FixItAll = 0;
RelocatablePCH = 0;
ShowMacrosInCodeCompletion = 0;
ShowStats = 0;

View File

@@ -372,9 +372,6 @@ InheritanceViewCls("cxx-inheritance-view",
llvm::cl::value_desc("class name"),
llvm::cl::desc("View C++ inheritance for a specified class"));
static llvm::cl::opt<bool>
FixItAll("fixit", llvm::cl::desc("Apply fix-it advice to the input source"));
static llvm::cl::list<ParsedSourceLocation>
FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"),
llvm::cl::desc("Perform Fix-It modifications at the given source location"));
@@ -832,7 +829,6 @@ void clang::InitializeFrontendOptions(FrontendOptions &Opts) {
Opts.DebugCodeCompletionPrinter = CodeCompletionDebugPrinter;
Opts.DisableFree = DisableFree;
Opts.EmptyInputOnly = EmptyInputOnly;
Opts.FixItAll = FixItAll;
Opts.FixItLocations = FixItAtLocations;
Opts.OutputFile = OutputFile;
Opts.RelocatablePCH = RelocatablePCH;
@@ -856,7 +852,6 @@ void clang::InitializeFrontendOptions(FrontendOptions &Opts) {
if (IK == FrontendOptions::IK_None)
IK = FrontendOptions::getInputKindForExtension(Ext);
Opts.Inputs.push_back(std::make_pair(IK, InputFilenames[i]));
}
}
}

View File

@@ -90,6 +90,7 @@ enum ProgActions {
DumpRecordLayouts, // Dump record layout information.
ParsePrintCallbacks, // Parse and print each callback.
ParseSyntaxOnly, // Parse and perform semantic analysis.
FixIt, // Parse and apply any fixits to the source.
ParseNoop, // Parse with noop callbacks.
RunPreprocessorOnly, // Just lex, no output.
PrintPreprocessedInput, // -E mode.
@@ -119,6 +120,8 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
"Run parser with noop callbacks (for timings)"),
clEnumValN(ParseSyntaxOnly, "fsyntax-only",
"Run parser and perform semantic analysis"),
clEnumValN(FixIt, "fixit",
"Apply fix-it advice to the input source"),
clEnumValN(ParsePrintCallbacks, "parse-print-callbacks",
"Run parser and print each callback invoked"),
clEnumValN(EmitHTML, "emit-html",
@@ -234,27 +237,27 @@ static void ParseFile(Preprocessor &PP, MinimalAction *PA) {
llvm::Timer *ClangFrontendTimer = 0;
/// AddFixItLocations - Add any individual user specified "fix-it" locations,
/// and return true on success (if any were added).
static bool AddFixItLocations(FixItRewriter *FixItRewrite,
FileManager &FileMgr,
const std::vector<ParsedSourceLocation> &Locs) {
bool AddedFixItLocation = false;
/// and return true on success.
static bool AddFixItLocations(CompilerInstance &CI,
FixItRewriter &FixItRewrite) {
const std::vector<ParsedSourceLocation> &Locs =
CI.getFrontendOpts().FixItLocations;
for (unsigned i = 0, e = Locs.size(); i != e; ++i) {
if (const FileEntry *File = FileMgr.getFile(Locs[i].FileName)) {
RequestedSourceLocation Requested;
Requested.File = File;
Requested.Line = Locs[i].Line;
Requested.Column = Locs[i].Column;
FixItRewrite->addFixItLocation(Requested);
AddedFixItLocation = true;
} else {
llvm::errs() << "FIX-IT could not find file \""
<< Locs[i].FileName << "\"\n";
const FileEntry *File = CI.getFileManager().getFile(Locs[i].FileName);
if (!File) {
CI.getDiagnostics().Report(diag::err_fe_unable_to_find_fixit_file)
<< Locs[i].FileName;
return false;
}
RequestedSourceLocation Requested;
Requested.File = File;
Requested.Line = Locs[i].Line;
Requested.Column = Locs[i].Column;
FixItRewrite.addFixItLocation(Requested);
}
return AddedFixItLocation;
return true;
}
static ASTConsumer *CreateConsumerAction(CompilerInstance &CI,
@@ -305,12 +308,6 @@ static ASTConsumer *CreateConsumerAction(CompilerInstance &CI,
OS.reset(CI.createDefaultOutputFile(true, InFile, "bc"));
}
// Fix-its can change semantics, disallow with any IRgen action.
if (FEOpts.FixItAll || !FEOpts.FixItLocations.empty()) {
PP.getDiagnostics().Report(diag::err_fe_no_fixit_and_codegen);
return 0;
}
return CreateBackendConsumer(Act, PP.getDiagnostics(), PP.getLangOptions(),
CI.getCodeGenOpts(), InFile, OS.take(),
CI.getLLVMContext());
@@ -326,6 +323,9 @@ static ASTConsumer *CreateConsumerAction(CompilerInstance &CI,
return CreateBlockRewriter(InFile, PP.getDiagnostics(),
PP.getLangOptions());
case FixIt:
return new ASTConsumer();
case ParseSyntaxOnly:
return new ASTConsumer();
@@ -340,7 +340,7 @@ static void ProcessInputFile(CompilerInstance &CI, const std::string &InFile,
Preprocessor &PP = CI.getPreprocessor();
const FrontendOptions &FEOpts = CI.getFrontendOpts();
llvm::OwningPtr<ASTConsumer> Consumer;
FixItRewriter *FixItRewrite = 0;
llvm::OwningPtr<FixItRewriter> FixItRewrite;
bool CompleteTranslationUnit = true;
switch (PA) {
@@ -393,17 +393,12 @@ static void ProcessInputFile(CompilerInstance &CI, const std::string &InFile,
}
// Check if we want a fix-it rewriter.
if (FEOpts.FixItAll || !FEOpts.FixItLocations.empty()) {
FixItRewrite = new FixItRewriter(PP.getDiagnostics(),
PP.getSourceManager(),
PP.getLangOptions());
if (!FEOpts.FixItLocations.empty() &&
!AddFixItLocations(FixItRewrite, PP.getFileManager(),
FEOpts.FixItLocations)) {
// All of the fix-it locations were bad. Don't fix anything.
delete FixItRewrite;
FixItRewrite = 0;
}
if (PA == FixIt) {
FixItRewrite.reset(new FixItRewriter(PP.getDiagnostics(),
PP.getSourceManager(),
PP.getLangOptions()));
if (!AddFixItLocations(CI, *FixItRewrite))
return;
}
if (Consumer) {
@@ -731,9 +726,11 @@ int main(int argc, char **argv) {
if (Clang.getFrontendOpts().ShowTimers)
ClangFrontendTimer = new llvm::Timer("Clang front-end time");
// C++ visualization?
// Enforce certain implications.
if (!Clang.getFrontendOpts().ViewClassInheritance.empty())
ProgAction = InheritanceView;
if (!Clang.getFrontendOpts().FixItLocations.empty())
ProgAction = FixIt;
// Create the source manager.
Clang.createSourceManager();