[cfe-dev] Plugin: Pragma with argument and diagnostic error messages
Marcel Schaible via cfe-dev
cfe-dev at lists.llvm.org
Wed Jul 12 04:02:31 PDT 2017
Hi,
I have solved the problem with the userdefined diagnostic message (see
below) with
<-- snippet-->
DiagnosticsEngine &m_diag;
...
unsigned warn = m_diag.getCustomDiagID(DiagnosticsEngine::Warning, "some
message");
m_diag.Report(paramDecl->getLocation(), warn);
<-- snippet-->
But with the other problem with the pragma arguments I am still struggling.
Any idea is appreciated!
Cheers
Marcel
Am 10.07.2017 um 11:13 schrieb Marcel Schaible via cfe-dev:
> Hi,
>
> I need to evaluate a user defined pragma by using the PragmaHandler class in a plugin (see the snippet below).
>
> The pragma is defined like this: #pragma TEST with mandatory arguments ARG1 and ARG2.
>
> Example:
>
> #pragma TEST ARG1
> ...
> #pragma TEST ARG2
>
>
> At the moment I am struggling with evaluating the mandatory prama arguments
> in "if (II->isStr("ARG1"))".
>
> The second problem how to define in a plugin its own diagnostic messages in "PP.Diag(PragmaLocation, diag::????????) << PragmaName;"?
>
> Any idea or pointing me into the right direction is welcome.
>
> <--- Code snippet start -->
>
> class TestPragmaHandler : public PragmaHandler {
> public:
> TESTPragmaHandler() : PragmaHandler("TEST") {}
>
> void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer ,Token &Tok)
> {
> SourceLocation PragmaLocation = Tok.getLocation();
> StringRef PragmaName = Tok.getIdentifierInfo()->getName();
>
> if (Tok.isNot(tok::string_literal)) {
> PP.Diag(PragmaLocation, diag::????????) << PragmaName;
> return;
> }
>
> const IdentifierInfo *II = Tok.getIdentifierInfo();
>
> if (II->isStr("ARG1")) {
> std::cout<< "TEST ARG1 pragma detected" << std::endl;
> PP.Lex(Tok);
> }
> else if (II->isStr("ARG2")) {
> std::cout<< "TEST ARG2 pragma detected" << std::endl;
> PP.Lex(Tok);
> }
> }
> };
>
> static PragmaHandlerRegistry::Add<TESTPragmaHandler> Y("TEST","TEST enables xxx support");
> }
>
> <--- Code snippet end -->
>
> Thanks
>
> Marcel
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list