[cfe-dev] Recombining AST Nodes

John Leidel via cfe-dev cfe-dev at lists.llvm.org
Thu Feb 4 06:59:50 PST 2021


I'm in the process of debugging (again) issues with anonymous struct
decls.  I have the following basic structures located in a C source
file that I'm attempting to transform.  I want to preserve the layout
of the structs.

struct{
  int A;
}S;

struct{
  int B;
  struct{
    int C;
  }T;
}R;

When I use my AST visitors, I can pick up the RecordDecl for the
struct definitions and the VarDecl for the variable definitions, but
the transformed code is outputted as:
struct{
  int A;
};
struct (anonymous) S;

I can view the RecordDecl as as TagDecl and save off a reference to it
if it is !isFreeStanding(), but how does one go about recombining the
declaration of "S" and the original TagDecl?

For the VarDecl ("S" in this case), I can determine whether or not its
an "ElaboratedType", but I'm not sure how to utilize the saved
reference to the RecordDecl:

if(isa<ElaboratedType>(SemaRef.Context.getBaseElementType(MyVarDecl))) {
   /// how do i recombine the VarDecl and the RecordDecl/TagDecl?
}


More information about the cfe-dev mailing list