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

Commit

Permalink
subst public types
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jul 26, 2022
1 parent 71bd9b2 commit 07b5c49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,13 @@ func compileDeclStmt(ctx *blockCtx, node *ast.Node, global bool) {
case ast.VarDecl:
compileVarDecl(ctx, decl, global)
case ast.TypedefDecl:
if typ := compileTypedef(ctx, decl, global); typ != nil && global {
name := decl.Name
if ctx.getPubName(&name) {
ctx.pkg.AliasType(name, typ, ctx.goNodePos(decl))
}
origName, pub := decl.Name, false
if global {
pub = ctx.getPubName(&decl.Name)
}
compileTypedef(ctx, decl, global, pub)
if pub {
substObj(ctx.pkg.Types, scope, origName, scope, decl.Name)
}
case ast.RecordDecl:
pub := false
Expand All @@ -327,6 +329,9 @@ func compileDeclStmt(ctx *blockCtx, node *ast.Node, global bool) {
}
typ, del := compileStructOrUnion(ctx, name, decl, pub)
if suKind != suAnonymous {
if pub {
substObj(ctx.pkg.Types, scope, decl.Name, scope, name)
}
break
}
ctx.unnameds[decl.ID] = unnamedType{typ: typ, del: del}
Expand Down
2 changes: 1 addition & 1 deletion cl/type_and_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func checkAnonymous(ctx *blockCtx, scope *types.Scope, typ types.Type, v *ast.No

// -----------------------------------------------------------------------------

func compileTypedef(ctx *blockCtx, decl *ast.Node, global bool) types.Type {
func compileTypedef(ctx *blockCtx, decl *ast.Node, global, pub bool) types.Type {
name, qualType := decl.Name, decl.Type.QualType
if debugCompileDecl {
log.Println("typedef", name, "-", qualType)
Expand Down

0 comments on commit 07b5c49

Please sign in to comment.