0

I have a problem inserting LabelDecl. My goal is to create a goto statement in the program and to do that, first I need to create LabelDecl and add it to Clang AST.

There is an API to Create Label, but I am not able to get the IdentifierInfo.

static LabelDecl *  Create (ASTContext &C, DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II) 

My Only problem is getting the IdentifierInfo *II object. Any idea on this.

Bernard Nongpoh
  • 1,028
  • 11
  • 20

1 Answers1

0

I found the solution to this problem

IdentifierInfo *Name = nullptr;
                     
string label = "your_label";  function scope. 
Name = &(*Context).Idents.get(label); // Use the context to get the identifier.
LabelDecl *labelDecl = LabelDecl::Create((*Context), Context->getTranslationUnitDecl(),stmt->getBeginLoc(), Name);
Bernard Nongpoh
  • 1,028
  • 11
  • 20