How to assign a Custom Diagnostic IDs in Clang Tool

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

How to assign a Custom Diagnostic IDs in Clang Tool

Jon Chesterfield via cfe-dev
Hello,
I want to create a fixed sets of IDs for error messages in Clang tool. So I can put them into tool documentation.

Is it possible to somehow assign a fixed ID for diagnostic? DiagnosticEngine::getCustomDiagID() generates ID automatically, so I have no control on IDs.

Should I probably instantiate my own DiagnosticEngine instead of using one from AstContext ?

Thanks,
Roman

_______________________________________________
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: How to assign a Custom Diagnostic IDs in Clang Tool

Jon Chesterfield via cfe-dev
Looks like DiagnosticEngine does not allow to be instantiated with User-supplied IDs.
The problem is that DiagnosticIDs is not an interface to IDs database, but rather a final class not designed for inheritance.

So I don't find a way how Clang diagnostic library can be reused by 3rd party tool.

2018-02-01 12:10 GMT-08:00 Roman Popov <[hidden email]>:
Hello,
I want to create a fixed sets of IDs for error messages in Clang tool. So I can put them into tool documentation.

Is it possible to somehow assign a fixed ID for diagnostic? DiagnosticEngine::getCustomDiagID() generates ID automatically, so I have no control on IDs.

Should I probably instantiate my own DiagnosticEngine instead of using one from AstContext ?

Thanks,
Roman


_______________________________________________
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: How to assign a Custom Diagnostic IDs in Clang Tool

Jon Chesterfield via cfe-dev
Probably I'm just thinking in wrong direction. Why do I need to have fixed IDs, instead I should probably have fixed error/warning names?

On Feb 1, 2018 1:12 PM, "Roman Popov" <[hidden email]> wrote:
Looks like DiagnosticEngine does not allow to be instantiated with User-supplied IDs.
The problem is that DiagnosticIDs is not an interface to IDs database, but rather a final class not designed for inheritance.

So I don't find a way how Clang diagnostic library can be reused by 3rd party tool.

2018-02-01 12:10 GMT-08:00 Roman Popov <[hidden email]>:
Hello,
I want to create a fixed sets of IDs for error messages in Clang tool. So I can put them into tool documentation.

Is it possible to somehow assign a fixed ID for diagnostic? DiagnosticEngine::getCustomDiagID() generates ID automatically, so I have no control on IDs.

Should I probably instantiate my own DiagnosticEngine instead of using one from AstContext ?

Thanks,
Roman


_______________________________________________
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: How to assign a Custom Diagnostic IDs in Clang Tool

Jon Chesterfield via cfe-dev
In reply to this post by Jon Chesterfield via cfe-dev
Are you trying to put the actual numerical value in the documentation?  That won't work since it's based on the enum value that gets computed at compile time -- actually via tablegen -- and changes over time as diagnostics are added/removed.

Tooling may already do this, but if not, just create your own enum that starts at the first available value, clang::diag::DIAG_UPPER_LIMIT, and go from there.  Then you can publish and use those enum values, e.g., MyTool::Some_Diag.  Take a look at how new id numbers are generated and use the same technique, e.g.:


If you need a string you can pass on the command line, you can create your own mapping.

hth...
don


On Thu, Feb 1, 2018 at 1:12 PM, Roman Popov via cfe-dev <[hidden email]> wrote:
Looks like DiagnosticEngine does not allow to be instantiated with User-supplied IDs.
The problem is that DiagnosticIDs is not an interface to IDs database, but rather a final class not designed for inheritance.

So I don't find a way how Clang diagnostic library can be reused by 3rd party tool.

2018-02-01 12:10 GMT-08:00 Roman Popov <[hidden email]>:
Hello,
I want to create a fixed sets of IDs for error messages in Clang tool. So I can put them into tool documentation.

Is it possible to somehow assign a fixed ID for diagnostic? DiagnosticEngine::getCustomDiagID() generates ID automatically, so I have no control on IDs.

Should I probably instantiate my own DiagnosticEngine instead of using one from AstContext ?

Thanks,
Roman


_______________________________________________
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: How to assign a Custom Diagnostic IDs in Clang Tool

Jon Chesterfield via cfe-dev
Btw, you still need to call DiagnosticEngine::getCustomDiagID(), but you can use your new enum to access the new id.


On Thu, Feb 1, 2018 at 1:52 PM, Don Hinton <[hidden email]> wrote:
Are you trying to put the actual numerical value in the documentation?  That won't work since it's based on the enum value that gets computed at compile time -- actually via tablegen -- and changes over time as diagnostics are added/removed.

Tooling may already do this, but if not, just create your own enum that starts at the first available value, clang::diag::DIAG_UPPER_LIMIT, and go from there.  Then you can publish and use those enum values, e.g., MyTool::Some_Diag.  Take a look at how new id numbers are generated and use the same technique, e.g.:


If you need a string you can pass on the command line, you can create your own mapping.

hth...
don


On Thu, Feb 1, 2018 at 1:12 PM, Roman Popov via cfe-dev <[hidden email]> wrote:
Looks like DiagnosticEngine does not allow to be instantiated with User-supplied IDs.
The problem is that DiagnosticIDs is not an interface to IDs database, but rather a final class not designed for inheritance.

So I don't find a way how Clang diagnostic library can be reused by 3rd party tool.

2018-02-01 12:10 GMT-08:00 Roman Popov <[hidden email]>:
Hello,
I want to create a fixed sets of IDs for error messages in Clang tool. So I can put them into tool documentation.

Is it possible to somehow assign a fixed ID for diagnostic? DiagnosticEngine::getCustomDiagID() generates ID automatically, so I have no control on IDs.

Should I probably instantiate my own DiagnosticEngine instead of using one from AstContext ?

Thanks,
Roman


_______________________________________________
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: How to assign a Custom Diagnostic IDs in Clang Tool

Jon Chesterfield via cfe-dev
Thanks, this works for me!

On Feb 1, 2018 1:58 PM, "Don Hinton" <[hidden email]> wrote:
Btw, you still need to call DiagnosticEngine::getCustomDiagID(), but you can use your new enum to access the new id.


On Thu, Feb 1, 2018 at 1:52 PM, Don Hinton <[hidden email]> wrote:
Are you trying to put the actual numerical value in the documentation?  That won't work since it's based on the enum value that gets computed at compile time -- actually via tablegen -- and changes over time as diagnostics are added/removed.

Tooling may already do this, but if not, just create your own enum that starts at the first available value, clang::diag::DIAG_UPPER_LIMIT, and go from there.  Then you can publish and use those enum values, e.g., MyTool::Some_Diag.  Take a look at how new id numbers are generated and use the same technique, e.g.:


If you need a string you can pass on the command line, you can create your own mapping.

hth...
don


On Thu, Feb 1, 2018 at 1:12 PM, Roman Popov via cfe-dev <[hidden email]> wrote:
Looks like DiagnosticEngine does not allow to be instantiated with User-supplied IDs.
The problem is that DiagnosticIDs is not an interface to IDs database, but rather a final class not designed for inheritance.

So I don't find a way how Clang diagnostic library can be reused by 3rd party tool.

2018-02-01 12:10 GMT-08:00 Roman Popov <[hidden email]>:
Hello,
I want to create a fixed sets of IDs for error messages in Clang tool. So I can put them into tool documentation.

Is it possible to somehow assign a fixed ID for diagnostic? DiagnosticEngine::getCustomDiagID() generates ID automatically, so I have no control on IDs.

Should I probably instantiate my own DiagnosticEngine instead of using one from AstContext ?

Thanks,
Roman


_______________________________________________
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: How to assign a Custom Diagnostic IDs in Clang Tool

Jon Chesterfield via cfe-dev
I failed to ask what sort of tool you were writing and assumed it was standalone and didn't include any other components that may also call DiagnosticEngine::getCustomDiagID().  If that's not the case, e.g., plugins or clang-tidy checkers, then you shouldn't rely on your set of id's starting at clang::diag::DIAG_UPPER_LIMIT+1.

However, if you map them to a string anyway, there's no need to create your own contiguous enum.

On Thu, Feb 1, 2018 at 2:00 PM, Roman Popov <[hidden email]> wrote:
Thanks, this works for me!

On Feb 1, 2018 1:58 PM, "Don Hinton" <[hidden email]> wrote:
Btw, you still need to call DiagnosticEngine::getCustomDiagID(), but you can use your new enum to access the new id.


On Thu, Feb 1, 2018 at 1:52 PM, Don Hinton <[hidden email]> wrote:
Are you trying to put the actual numerical value in the documentation?  That won't work since it's based on the enum value that gets computed at compile time -- actually via tablegen -- and changes over time as diagnostics are added/removed.

Tooling may already do this, but if not, just create your own enum that starts at the first available value, clang::diag::DIAG_UPPER_LIMIT, and go from there.  Then you can publish and use those enum values, e.g., MyTool::Some_Diag.  Take a look at how new id numbers are generated and use the same technique, e.g.:


If you need a string you can pass on the command line, you can create your own mapping.

hth...
don


On Thu, Feb 1, 2018 at 1:12 PM, Roman Popov via cfe-dev <[hidden email]> wrote:
Looks like DiagnosticEngine does not allow to be instantiated with User-supplied IDs.
The problem is that DiagnosticIDs is not an interface to IDs database, but rather a final class not designed for inheritance.

So I don't find a way how Clang diagnostic library can be reused by 3rd party tool.

2018-02-01 12:10 GMT-08:00 Roman Popov <[hidden email]>:
Hello,
I want to create a fixed sets of IDs for error messages in Clang tool. So I can put them into tool documentation.

Is it possible to somehow assign a fixed ID for diagnostic? DiagnosticEngine::getCustomDiagID() generates ID automatically, so I have no control on IDs.

Should I probably instantiate my own DiagnosticEngine instead of using one from AstContext ?

Thanks,
Roman


_______________________________________________
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: How to assign a Custom Diagnostic IDs in Clang Tool

Jon Chesterfield via cfe-dev
Tool is standalone.  But yes, map is what I ended up with. 

Approach with DIAG_UPPER_LIMIT turned out to be not nice in other way: there is no way to specify ID and FormatString in same place. So code with enum is not very readable.

So the only approach that works well is to map your own IDs to getCustomDiagID IDs.

-Roman

2018-02-01 16:09 GMT-08:00 Don Hinton <[hidden email]>:
I failed to ask what sort of tool you were writing and assumed it was standalone and didn't include any other components that may also call DiagnosticEngine::getCustomDiagID().  If that's not the case, e.g., plugins or clang-tidy checkers, then you shouldn't rely on your set of id's starting at clang::diag::DIAG_UPPER_LIMIT+1.

However, if you map them to a string anyway, there's no need to create your own contiguous enum.

On Thu, Feb 1, 2018 at 2:00 PM, Roman Popov <[hidden email]> wrote:
Thanks, this works for me!

On Feb 1, 2018 1:58 PM, "Don Hinton" <[hidden email]> wrote:
Btw, you still need to call DiagnosticEngine::getCustomDiagID(), but you can use your new enum to access the new id.


On Thu, Feb 1, 2018 at 1:52 PM, Don Hinton <[hidden email]> wrote:
Are you trying to put the actual numerical value in the documentation?  That won't work since it's based on the enum value that gets computed at compile time -- actually via tablegen -- and changes over time as diagnostics are added/removed.

Tooling may already do this, but if not, just create your own enum that starts at the first available value, clang::diag::DIAG_UPPER_LIMIT, and go from there.  Then you can publish and use those enum values, e.g., MyTool::Some_Diag.  Take a look at how new id numbers are generated and use the same technique, e.g.:


If you need a string you can pass on the command line, you can create your own mapping.

hth...
don


On Thu, Feb 1, 2018 at 1:12 PM, Roman Popov via cfe-dev <[hidden email]> wrote:
Looks like DiagnosticEngine does not allow to be instantiated with User-supplied IDs.
The problem is that DiagnosticIDs is not an interface to IDs database, but rather a final class not designed for inheritance.

So I don't find a way how Clang diagnostic library can be reused by 3rd party tool.

2018-02-01 12:10 GMT-08:00 Roman Popov <[hidden email]>:
Hello,
I want to create a fixed sets of IDs for error messages in Clang tool. So I can put them into tool documentation.

Is it possible to somehow assign a fixed ID for diagnostic? DiagnosticEngine::getCustomDiagID() generates ID automatically, so I have no control on IDs.

Should I probably instantiate my own DiagnosticEngine instead of using one from AstContext ?

Thanks,
Roman


_______________________________________________
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: How to assign a Custom Diagnostic IDs in Clang Tool

Jon Chesterfield via cfe-dev
Ouch. 
What I've found out is that getCustomDiagID takes reference to C-Style array as a parameter. Not a StringRef. So it's really inconvenient to use:
I can't declare FormatStrings in one place, and generate IDs in another place.

2018-02-01 16:21 GMT-08:00 Roman Popov <[hidden email]>:
Tool is standalone.  But yes, map is what I ended up with. 

Approach with DIAG_UPPER_LIMIT turned out to be not nice in other way: there is no way to specify ID and FormatString in same place. So code with enum is not very readable.

So the only approach that works well is to map your own IDs to getCustomDiagID IDs.

-Roman

2018-02-01 16:09 GMT-08:00 Don Hinton <[hidden email]>:
I failed to ask what sort of tool you were writing and assumed it was standalone and didn't include any other components that may also call DiagnosticEngine::getCustomDiagID().  If that's not the case, e.g., plugins or clang-tidy checkers, then you shouldn't rely on your set of id's starting at clang::diag::DIAG_UPPER_LIMIT+1.

However, if you map them to a string anyway, there's no need to create your own contiguous enum.

On Thu, Feb 1, 2018 at 2:00 PM, Roman Popov <[hidden email]> wrote:
Thanks, this works for me!

On Feb 1, 2018 1:58 PM, "Don Hinton" <[hidden email]> wrote:
Btw, you still need to call DiagnosticEngine::getCustomDiagID(), but you can use your new enum to access the new id.


On Thu, Feb 1, 2018 at 1:52 PM, Don Hinton <[hidden email]> wrote:
Are you trying to put the actual numerical value in the documentation?  That won't work since it's based on the enum value that gets computed at compile time -- actually via tablegen -- and changes over time as diagnostics are added/removed.

Tooling may already do this, but if not, just create your own enum that starts at the first available value, clang::diag::DIAG_UPPER_LIMIT, and go from there.  Then you can publish and use those enum values, e.g., MyTool::Some_Diag.  Take a look at how new id numbers are generated and use the same technique, e.g.:


If you need a string you can pass on the command line, you can create your own mapping.

hth...
don


On Thu, Feb 1, 2018 at 1:12 PM, Roman Popov via cfe-dev <[hidden email]> wrote:
Looks like DiagnosticEngine does not allow to be instantiated with User-supplied IDs.
The problem is that DiagnosticIDs is not an interface to IDs database, but rather a final class not designed for inheritance.

So I don't find a way how Clang diagnostic library can be reused by 3rd party tool.

2018-02-01 12:10 GMT-08:00 Roman Popov <[hidden email]>:
Hello,
I want to create a fixed sets of IDs for error messages in Clang tool. So I can put them into tool documentation.

Is it possible to somehow assign a fixed ID for diagnostic? DiagnosticEngine::getCustomDiagID() generates ID automatically, so I have no control on IDs.

Should I probably instantiate my own DiagnosticEngine instead of using one from AstContext ?

Thanks,
Roman


_______________________________________________
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: How to assign a Custom Diagnostic IDs in Clang Tool

Jon Chesterfield via cfe-dev
It mostly seems to be used on the fly.  Take a look at how it's used in clang-tidy and see if that'll work for you.

On Thu, Feb 1, 2018 at 4:35 PM, Roman Popov <[hidden email]> wrote:
Ouch. 
What I've found out is that getCustomDiagID takes reference to C-Style array as a parameter. Not a StringRef. So it's really inconvenient to use:
I can't declare FormatStrings in one place, and generate IDs in another place.

2018-02-01 16:21 GMT-08:00 Roman Popov <[hidden email]>:
Tool is standalone.  But yes, map is what I ended up with. 

Approach with DIAG_UPPER_LIMIT turned out to be not nice in other way: there is no way to specify ID and FormatString in same place. So code with enum is not very readable.

So the only approach that works well is to map your own IDs to getCustomDiagID IDs.

-Roman

2018-02-01 16:09 GMT-08:00 Don Hinton <[hidden email]>:
I failed to ask what sort of tool you were writing and assumed it was standalone and didn't include any other components that may also call DiagnosticEngine::getCustomDiagID().  If that's not the case, e.g., plugins or clang-tidy checkers, then you shouldn't rely on your set of id's starting at clang::diag::DIAG_UPPER_LIMIT+1.

However, if you map them to a string anyway, there's no need to create your own contiguous enum.

On Thu, Feb 1, 2018 at 2:00 PM, Roman Popov <[hidden email]> wrote:
Thanks, this works for me!

On Feb 1, 2018 1:58 PM, "Don Hinton" <[hidden email]> wrote:
Btw, you still need to call DiagnosticEngine::getCustomDiagID(), but you can use your new enum to access the new id.


On Thu, Feb 1, 2018 at 1:52 PM, Don Hinton <[hidden email]> wrote:
Are you trying to put the actual numerical value in the documentation?  That won't work since it's based on the enum value that gets computed at compile time -- actually via tablegen -- and changes over time as diagnostics are added/removed.

Tooling may already do this, but if not, just create your own enum that starts at the first available value, clang::diag::DIAG_UPPER_LIMIT, and go from there.  Then you can publish and use those enum values, e.g., MyTool::Some_Diag.  Take a look at how new id numbers are generated and use the same technique, e.g.:


If you need a string you can pass on the command line, you can create your own mapping.

hth...
don


On Thu, Feb 1, 2018 at 1:12 PM, Roman Popov via cfe-dev <[hidden email]> wrote:
Looks like DiagnosticEngine does not allow to be instantiated with User-supplied IDs.
The problem is that DiagnosticIDs is not an interface to IDs database, but rather a final class not designed for inheritance.

So I don't find a way how Clang diagnostic library can be reused by 3rd party tool.

2018-02-01 12:10 GMT-08:00 Roman Popov <[hidden email]>:
Hello,
I want to create a fixed sets of IDs for error messages in Clang tool. So I can put them into tool documentation.

Is it possible to somehow assign a fixed ID for diagnostic? DiagnosticEngine::getCustomDiagID() generates ID automatically, so I have no control on IDs.

Should I probably instantiate my own DiagnosticEngine instead of using one from AstContext ?

Thanks,
Roman


_______________________________________________
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: How to assign a Custom Diagnostic IDs in Clang Tool

Jon Chesterfield via cfe-dev
In reply to this post by Jon Chesterfield via cfe-dev
While I don't quite follow your question - you might be interested in this change I'm working on (well, taken a bit of a break, but will be coming back to): https://reviews.llvm.org/D41357 

On Thu, Feb 1, 2018 at 12:10 PM Roman Popov via cfe-dev <[hidden email]> wrote:
Hello,
I want to create a fixed sets of IDs for error messages in Clang tool. So I can put them into tool documentation.

Is it possible to somehow assign a fixed ID for diagnostic? DiagnosticEngine::getCustomDiagID() generates ID automatically, so I have no control on IDs.

Should I probably instantiate my own DiagnosticEngine instead of using one from AstContext ?

Thanks,
Roman
_______________________________________________
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