Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Commit

Permalink
checkFieldName: support anonymous bitfields
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jul 26, 2022
1 parent 94f1c06 commit 152d4a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cl/type_and_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,19 @@ func toStructType(ctx *blockCtx, t *types.Named, struc *ast.Node, pub bool) (ret
decl := struc.Inner[i]
switch decl.Kind {
case ast.FieldDecl:
name := decl.Name
if debugCompileDecl {
log.Println(" => field", decl.Name, "-", decl.Type.QualType)
log.Println(" => field", name, "-", decl.Type.QualType)
}
if name != "" {
checkFieldName(&name, pub)
}
checkFieldName(&decl.Name, pub)
typ, _ := toTypeEx(ctx, scope, nil, decl.Type, parser.FlagIsStructField)
if decl.IsBitfield {
bits := toInt64(ctx, decl.Inner[0], "non-constant bit field")
b.BitField(ctx, typ, decl.Name, int(bits))
b.BitField(ctx, typ, name, int(bits))
} else {
b.Field(ctx, ctx.goNodePos(decl), typ, decl.Name, false)
b.Field(ctx, ctx.goNodePos(decl), typ, name, false)
}
case ast.RecordDecl:
name, suKind := ctx.getSuName(decl, decl.TagUsed)
Expand Down Expand Up @@ -127,12 +130,13 @@ func toUnionType(ctx *blockCtx, t *types.Named, unio *ast.Node, pub bool) (ret t
decl := unio.Inner[i]
switch decl.Kind {
case ast.FieldDecl:
name := decl.Name
if debugCompileDecl {
log.Println(" => field", decl.Name, "-", decl.Type.QualType)
log.Println(" => field", name, "-", decl.Type.QualType)
}
checkFieldName(&decl.Name, pub)
checkFieldName(&name, pub)
typ, _ := toTypeEx(ctx, scope, nil, decl.Type, 0)
b.Field(ctx, ctx.goNodePos(decl), typ, decl.Name, false)
b.Field(ctx, ctx.goNodePos(decl), typ, name, false)
case ast.RecordDecl:
name, suKind := ctx.getSuName(decl, decl.TagUsed)
typ, del := compileStructOrUnion(ctx, name, decl, pub)
Expand Down
3 changes: 3 additions & 0 deletions testdata/libc/src/foo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ typedef struct {

struct pub {
int a;
int b :1,
:2,
c :3;
};

typedef size_t foo_t;
Expand Down

0 comments on commit 152d4a3

Please sign in to comment.