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.

4

1 回答 1

0

我找到了解决这个问题的方法

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);
于 2021-08-20T08:34:11.997 回答