[cfe-commits] PATCH: teach clang -fixit to fix what it can
Douglas Gregor
dgregor at apple.com
Fri Aug 13 08:39:57 PDT 2010
On Aug 12, 2010, at 9:04 PM, Nick Lewycky wrote:
> The attached patch adds a new feature to clang -fixit, labelled "-fix-what-you-can". By default, fix-it will refuse to make any fixes in a file that contains unfixable errors. This is undesirable behaviour much of the time, so the new -fix-what-you-can flag applies all fixits in each file.
>
> It's implemented by extending the existing FixItPathRewriter to include a bool FixWhatYouCan, and then renaming it to FixItOptions since it's no longer just for rewriting paths.
>
> Please review!
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp (revision 110945)
+++ lib/Frontend/CompilerInvocation.cpp (working copy)
@@ -1050,6 +1050,7 @@
Opts.ViewClassInheritance = Args.getLastArgValue(OPT_cxx_inheritance_view);
Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge);
Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
+ Opts.FixWhatYouCan = Args.hasArg(OPT_fix_what_you_can);
InputKind DashX = IK_None;
if (const Arg *A = Args.getLastArg(OPT_x)) {
Shouldn't you also update FrontendOptsToArgs?
Index: lib/Rewrite/FixItRewriter.cpp
===================================================================
--- lib/Rewrite/FixItRewriter.cpp (revision 110945)
+++ lib/Rewrite/FixItRewriter.cpp (working copy)
@@ -27,10 +27,10 @@
FixItRewriter::FixItRewriter(Diagnostic &Diags, SourceManager &SourceMgr,
const LangOptions &LangOpts,
- FixItPathRewriter *PathRewriter)
+ FixItOptions *FixItOpts)
: Diags(Diags),
Rewrite(SourceMgr, LangOpts),
- PathRewriter(PathRewriter),
+ FixItOpts(FixItOpts),
NumFailures(0) {
Client = Diags.getClient();
Diags.setClient(this);
@@ -49,7 +49,7 @@
}
bool FixItRewriter::WriteFixedFiles() {
- if (NumFailures > 0) {
+ if (NumFailures > 0 && !FixItOpts->FixWhatYouCan) {
Diag(FullSourceLoc(), diag::warn_fixit_no_changes);
return true;
}
In general, this is pretty dangerous, since a wrong Fix-It (e.g., typo-correcting to the wrong thing) can mean that you're mangling the user's source code. But, I guess that's what you want... so the patch is fine.
- Doug
>
> Nick
>
> <fix-what-you-can.patch>_______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list