On Sun, Aug 9, 2015 at 11:47 AM, Andy Maloney <
asma...@gmail.com> wrote:
>
> after all the Decls are added to the Package in Record() (in main.go), call
> a function which looks at each of the exported functions and uses the Decls
> to create a map to store some information about struct parameters & results
> in cgoType(), use the map that was just created to lookup the name of the
> struct and its size (which we calculated and stored in the map) and, if we
> find it, return it
> at the end of writeExportHeader(), write out typedefs for each of the
> structs in the map
I'm not quite sure what you mean here. It seems to me that you can
treat any struct used by an exported function as though the Go code
said "C.struct_foo". That should define in Go like other cgo
structs. Perhaps this is what you are doing, or perhaps I am missing
something.
> Right now I just look at structs, but it would make sense to me that if you
> declare
> type Foo int
> and you use it as a result to a function we should see
> typedef GoInt Foo;
> in the header file. Would that make sense to add too?
I doubt it. C typedefs are not Go typedefs. Go's types are much
stricter. I expect that changing this would break currently working
code.
> Is there a way given an ast.Field.Type to get it as a string? I found a
> couple of things online, but no solution which fits since we don't have the
> text of the source file to use the Pos with. I ended up using
> fmt.Sprintf("%v", param.Type)
> which works but feels wrong...
That eems fine to me.
> I created the type map like this on Package:
> map[ast.Expr]ExpType
> (where ExpType is where I'm storing info about the struct). I don't think
> this works across packages. Is there a way to uniquely identify a type in
> the compilation unit what I can use as a key? Keeping in mind that, the way
> I've implemented it, I need access to that key in cgoType()...
The cgo interface by definition lives within a single Go package. You
can't pass C types between Go packages.
Ian