Plugin: Pragma with argument and diagnostic error messages

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Plugin: Pragma with argument and diagnostic error messages

Adam Cieszkiel 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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plugin: Pragma with argument and diagnostic error messages

Adam Cieszkiel via cfe-dev
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
> [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
Loading...