Move FixItAtLocations into FrontendOptions

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@87046 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2009-11-12 23:52:56 +00:00
Родитель 1417c74b82
Коммит c86804bc9c
4 изменённых файлов: 23 добавлений и 19 удалений

Просмотреть файл

@ -1,3 +1,4 @@
//===--- CommandLineSourceLoc.h - Parsing for source locations-*- C++ -*---===//
//
// The LLVM Compiler Infrastructure
@ -37,7 +38,7 @@ namespace llvm {
class parser<clang::ParsedSourceLocation>
: public basic_parser<clang::ParsedSourceLocation> {
public:
bool parse(Option &O, StringRef ArgName, StringRef ArgValue,
inline bool parse(Option &O, StringRef ArgName, StringRef ArgValue,
clang::ParsedSourceLocation &Val);
};

Просмотреть файл

@ -10,6 +10,7 @@
#ifndef LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
#define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
#include "clang/Frontend/CommandLineSourceLoc.h"
#include <string>
#include <vector>
@ -36,6 +37,9 @@ public:
/// If given, the name for a C++ class to view the inheritance of.
std::string ViewClassInheritance;
/// A list of locations to apply fix-its at.
std::vector<ParsedSourceLocation> FixItLocations;
public:
FrontendOptions() {
DisableFree = 0;

Просмотреть файл

@ -313,6 +313,10 @@ InheritanceViewCls("cxx-inheritance-view",
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"));
static llvm::cl::opt<std::string>
OutputFile("o",
llvm::cl::value_desc("path"),
@ -757,6 +761,7 @@ void clang::InitializeFrontendOptions(FrontendOptions &Opts) {
Opts.DisableFree = DisableFree;
Opts.EmptyInputOnly = EmptyInputOnly;
Opts.FixItAll = FixItAll;
Opts.FixItLocations = FixItAtLocations;
Opts.RelocatablePCH = RelocatablePCH;
Opts.ShowStats = Stats;
Opts.ShowTimers = TimeReport;

Просмотреть файл

@ -210,14 +210,6 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
"Rewrite Blocks to C"),
clEnumValEnd));
//===----------------------------------------------------------------------===//
// Frontend Options
//===----------------------------------------------------------------------===//
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"));
//===----------------------------------------------------------------------===//
// Language Options
//===----------------------------------------------------------------------===//
@ -445,20 +437,21 @@ static llvm::raw_ostream *ComputeOutFile(const CompilerInvocation &CompOpts,
/// 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) {
FileManager &FileMgr,
const std::vector<ParsedSourceLocation> &Locs) {
bool AddedFixItLocation = false;
for (unsigned i = 0, e = FixItAtLocations.size(); i != e; ++i) {
if (const FileEntry *File = FileMgr.getFile(FixItAtLocations[i].FileName)) {
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 = FixItAtLocations[i].Line;
Requested.Column = FixItAtLocations[i].Column;
Requested.Line = Locs[i].Line;
Requested.Column = Locs[i].Column;
FixItRewrite->addFixItLocation(Requested);
AddedFixItLocation = true;
} else {
llvm::errs() << "FIX-IT could not find file \""
<< FixItAtLocations[i].FileName << "\"\n";
<< Locs[i].FileName << "\"\n";
}
}
@ -517,7 +510,7 @@ static ASTConsumer *CreateConsumerAction(const CompilerInvocation &CompOpts,
}
// Fix-its can change semantics, disallow with any IRgen action.
if (FEOpts.FixItAll || !FixItAtLocations.empty()) {
if (FEOpts.FixItAll || !FEOpts.FixItLocations.empty()) {
PP.getDiagnostics().Report(diag::err_fe_no_fixit_and_codegen);
return 0;
}
@ -655,12 +648,13 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts,
}
// Check if we want a fix-it rewriter.
if (FEOpts.FixItAll || !FixItAtLocations.empty()) {
if (FEOpts.FixItAll || !FEOpts.FixItLocations.empty()) {
FixItRewrite = new FixItRewriter(PP.getDiagnostics(),
PP.getSourceManager(),
PP.getLangOptions());
if (!FixItAtLocations.empty() &&
!AddFixItLocations(FixItRewrite, PP.getFileManager())) {
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;