Help writing fixits in clang

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Help writing fixits in clang

Zachary Turner via cfe-dev
Hi,

I'd like to add a fixit (or two) to suggest parentheses in the following expressions:

  struct S { float value; };
  S operator"" _f(long double t);

  void test() {
    int i = 0x2e+'a';          // fixit: (0x2e)+'a'
    float j = 100.0_e-10.0;    // fixit: (100.0_e)-10.0
    float k = 100.0_f.value;   // fixit: (100.0_f).value
    int l = 0x2e+i;            // fixit: (0x2e)+i
  }

However, I am not sure of the correct way to do this.

Would someone, please, give me a quick tutorial or, if easier, point out an similar example in the clang code.

Many thanks,
Andy

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Help writing fixits in clang

Zachary Turner via cfe-dev
Hi!

A bit of an off-topic note beforehand: Why not add a space inside of parens?

Fixits are actually pretty straightforward to implement. It's like this:

Diag(ErrorLoc, diag::err_missing_foo) << VarName // some diagnostic, unchanged
<< FixItHint::CreateInsertion(ErrorLoc, " foo");

This creates a diagnostic with a fixit at ErrorLoc and inserts foo there. There are other fixit hints that you can use like replacement.

Hope that helps!

On Wed, Dec 12, 2018, 11:03 AM Andy Gibbs via cfe-dev <[hidden email] wrote:
Hi,

I'd like to add a fixit (or two) to suggest parentheses in the following expressions:

  struct S { float value; };
  S operator"" _f(long double t);

  void test() {
    int i = 0x2e+'a';          // fixit: (0x2e)+'a'
    float j = 100.0_e-10.0;    // fixit: (100.0_e)-10.0
    float k = 100.0_f.value;   // fixit: (100.0_f).value
    int l = 0x2e+i;            // fixit: (0x2e)+i
  }

However, I am not sure of the correct way to do this.

Would someone, please, give me a quick tutorial or, if easier, point out an similar example in the clang code.

Many thanks,
Andy
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Help writing fixits in clang

Zachary Turner via cfe-dev
In reply to this post by Zachary Turner via cfe-dev

Hi Andy,


this sounds like a great clang-tidy check in the readability-module. You can check out the documentation (https://clang.llvm.org/extra/clang-tidy/) which has a section on writing the check and emitting diagnostics with fixits.


If you want to produce a standalone tool that does the job, this information will still be relevant, is it will use the same functionality of clang.


Best, Jonas


Am 12.12.18 um 11:03 schrieb Andy Gibbs via cfe-dev:
Hi,

I'd like to add a fixit (or two) to suggest parentheses in the following expressions:

  struct S { float value; };
  S operator"" _f(long double t);

  void test() {
    int i = 0x2e+'a';          // fixit: (0x2e)+'a'
    float j = 100.0_e-10.0;    // fixit: (100.0_e)-10.0
    float k = 100.0_f.value;   // fixit: (100.0_f).value
    int l = 0x2e+i;            // fixit: (0x2e)+i
  }

However, I am not sure of the correct way to do this.

Would someone, please, give me a quick tutorial or, if easier, point out an similar example in the clang code.

Many thanks,
Andy

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev