Plugin: Pragma with argument and diagnostic error messages


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.


#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 {
    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;

    const IdentifierInfo *II = Tok.getIdentifierInfo();

      if (II->isStr("ARG1")) {
    std::cout<< "TEST ARG1 pragma detected" << std::endl;
      else if (II->isStr("ARG2")) {
    std::cout<< "TEST ARG2 pragma detected" << std::endl;
  static PragmaHandlerRegistry::Add<TESTPragmaHandler> Y("TEST","TEST enables xxx support");

<--- Code snippet end -->




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!