[cfe-dev] Clang AST: Modifying anonymous structs

John Leidel via cfe-dev cfe-dev at lists.llvm.org
Fri Dec 18 12:31:59 PST 2020


I'm working on an external Clang tool that translates one c-based
language construct to another.  I have a series of recursive AST
functions that walk and modify elements as necessary.  I have an issue
with anonymous structures that reside within structs or unions.

Specifically, I have:
typedef struct test_case_t {
  struct {int value;} first[1];
  int second;
  int third[1];
} test_case_t;

That gets translated to:
struct test_case_t {
    struct {   // should be struct first
        int value;
    };
    struct first first[1];
    int second;
    int third[1];
};
typedef struct test_case_t test_case_t;

Note that the nested struct should be "struct first{ ... }".

My question is, using the FieldDecl for "first[1]", how do I derive
the defining struct type and modify the definition to be "struct
first{ ... }"?  I'm able to construct a QualType that is "struct
test_case_t::first", but I'm not sure how to modify the existing
struct definition.

Any thoughts?


More information about the cfe-dev mailing list