From: Peter Collingbourne Date: Mon, 21 Mar 2011 01:45:18 +0000 (+0000) Subject: Code modification hints have been known as fix-it hints for almost X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=38448d3ae8dbea95ba7d6852169dd00874bf7be9;p=clang Code modification hints have been known as fix-it hints for almost a year now. Update the internals manual. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127983 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/InternalsManual.html b/docs/InternalsManual.html index 6956a118b1..961198938f 100644 --- a/docs/InternalsManual.html +++ b/docs/InternalsManual.html @@ -412,7 +412,7 @@ it is rendered.

-

Code Modification Hints

+

Fix-It Hints

In some cases, the front end emits diagnostics when it is clear @@ -422,14 +422,14 @@ deprecated syntax that is easily rewritten into a more modern form. Clang tries very hard to emit the diagnostic and recover gracefully in these and other cases.

-

However, for these cases where the fix is obvious, the diagnostic -can be annotated with a code -modification "hint" that describes how to change the code referenced -by the diagnostic to fix the problem. For example, it might add the -missing semicolon at the end of the statement or rewrite the use of a -deprecated construct into something more palatable. Here is one such -example C++ front end, where we warn about the right-shift operator -changing meaning from C++98 to C++0x:

+

However, for these cases where the fix is obvious, the diagnostic +can be annotated with a hint (referred to as a "fix-it hint") that +describes how to change the code referenced by the diagnostic to fix +the problem. For example, it might add the missing semicolon at the +end of the statement or rewrite the use of a deprecated construct +into something more palatable. Here is one such example from the C++ +front end, where we warn about the right-shift operator changing +meaning from C++98 to C++0x:

 test.cpp:3:7: warning: use of right-shift operator ('>>') in template argument will require parentheses in C++0x
@@ -438,33 +438,31 @@ A<100 >> 2> *a;
   (       )
 
-

Here, the code modification hint is suggesting that parentheses be -added, and showing exactly where those parentheses would be inserted -into the source code. The code modification hints themselves describe -what changes to make to the source code in an abstract manner, which -the text diagnostic printer renders as a line of "insertions" below -the caret line. Other diagnostic -clients might choose to render the code differently (e.g., as -markup inline) or even give the user the ability to automatically fix -the problem.

- -

All code modification hints are described by the -CodeModificationHint class, instances of which should be -attached to the diagnostic using the << operator in the same way -that highlighted source ranges and arguments are passed to the -diagnostic. Code modification hints can be created with one of three -constructors:

+

Here, the fix-it hint is suggesting that parentheses be added, +and showing exactly where those parentheses would be inserted into the +source code. The fix-it hints themselves describe what changes to make +to the source code in an abstract manner, which the text diagnostic +printer renders as a line of "insertions" below the caret line. Other diagnostic clients might choose +to render the code differently (e.g., as markup inline) or even give +the user the ability to automatically fix the problem.

+ +

All fix-it hints are described by the FixItHint class, +instances of which should be attached to the diagnostic using the +<< operator in the same way that highlighted source ranges and +arguments are passed to the diagnostic. Fix-it hints can be created +with one of three constructors:

-
CodeModificationHint::CreateInsertion(Loc, Code)
+
FixItHint::CreateInsertion(Loc, Code)
Specifies that the given Code (a string) should be inserted before the source location Loc.
-
CodeModificationHint::CreateRemoval(Range)
+
FixItHint::CreateRemoval(Range)
Specifies that the code in the given source Range should be removed.
-
CodeModificationHint::CreateReplacement(Range, Code)
+
FixItHint::CreateReplacement(Range, Code)
Specifies that the code in the given source Range should be removed, and replaced with the given Code string.