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

Commit

Permalink
c2go: support local type
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jul 22, 2022
1 parent f391e89 commit 82f817c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
4 changes: 4 additions & 0 deletions cl/multifiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ func (p *blockCtx) checkExists(name string) (exist bool) {
return
}

func (p *blockCtx) inSrcFile() bool {
return p.hasMulti && !p.inHeader
}

func canonical(baseDir string, uri string) string {
if filepath.IsAbs(uri) {
return uri
Expand Down
19 changes: 15 additions & 4 deletions cl/type_and_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,21 @@ func compileStructOrUnion(ctx *blockCtx, name string, decl *ast.Node) (*types.Na
if debugCompileDecl {
log.Println(decl.TagUsed, name, "-", decl.Loc.PresumedLine)
}
t, decled := ctx.typdecls[name]
if !decled {
t = ctx.cb.NewType(name, ctx.goNodePos(decl))
ctx.typdecls[name] = t
var t *gox.TypeDecl
pos := ctx.goNodePos(decl)
realName := name
if ctx.inSrcFile() && decl.Name != "" {
realName = ctx.autoStaticName(name)
var scope = ctx.cb.Scope()
t = ctx.cb.NewType(realName, pos)
substObj(ctx.pkg.Types, scope, name, scope, realName)
} else {
var decled bool
t, decled = ctx.typdecls[name]
if !decled {
t = ctx.cb.NewType(realName, pos)
ctx.typdecls[name] = t
}
}
if decl.CompleteDefinition {
var inner types.Type
Expand Down
7 changes: 6 additions & 1 deletion testdata/libc/src/foo.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "foo.h"

struct cookie {
int a;
};

foo_t foo() {
return 100;
struct cookie v = {100};
return v.a;
}
8 changes: 7 additions & 1 deletion testdata/libc/src/foo2.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include "foo.h"

struct cookie {
double a;
int b;
};

static foo_t foo2() {
return 10;
struct cookie v = {0, 10};
return v.b;
}

0 comments on commit 82f817c

Please sign in to comment.