Fix to go type declarations.
This commit is contained in:
parent
500b457d32
commit
c0c17e88d1
|
@ -1,21 +0,0 @@
|
|||
package main
|
||||
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitlab.wow.st/gmp/nswrap/examples/foundation/ns"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Started")
|
||||
n1 := ns.StringWithUTF8String(ns.CharFromString("hi there"))
|
||||
c := n1.CapitalizedString()
|
||||
gstring := c.UTF8String().String()
|
||||
fmt.Println(gstring)
|
||||
n2 := ns.StringWithUTF8String(ns.CharFromString("ok bye"))
|
||||
n3 := ns.StringWithUTF8String(ns.CharFromString("one two three"))
|
||||
a := ns.ArrayWithObjects(n1)
|
||||
fmt.Println("ok")
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
package ClassOne
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -x objective-c
|
||||
#cgo LDFLAGS: -framework Foundation
|
||||
|
||||
#import "simple.h"
|
||||
|
||||
ClassOne*
|
||||
NewClassOne() {
|
||||
return [ClassOne alloc];
|
||||
}
|
||||
|
||||
int
|
||||
ClassOne_geti1(void* obj) {
|
||||
return [(id)obj geti1];
|
||||
}
|
||||
int*
|
||||
ClassOne_getp1(void* obj) {
|
||||
return [(id)obj getp1];
|
||||
}
|
||||
int
|
||||
ClassOne_hi1(void* obj, struct stru in) {
|
||||
return [(id)obj hi1:in];
|
||||
}
|
||||
int
|
||||
ClassOne_hi2(void* obj, void* in) {
|
||||
return [(id)obj hi2:in];
|
||||
}
|
||||
struct stru
|
||||
ClassOne_nstru1(void* obj) {
|
||||
return [(id)obj nstru1];
|
||||
}
|
||||
struct stru*
|
||||
ClassOne_nstru2(void* obj) {
|
||||
return [(id)obj nstru2];
|
||||
}
|
||||
ClassOne*
|
||||
ClassOne_init(void* obj) {
|
||||
return [(id)obj init];
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
//ClassOne*
|
||||
type ClassOne struct { NSObject }
|
||||
|
||||
//NSObject*
|
||||
type NSObject struct { ptr unsafe.Pointer }
|
||||
|
||||
//int
|
||||
type Int C.int
|
||||
|
||||
//struct stru
|
||||
type Stru C.struct_stru
|
||||
|
||||
func NewClassOne() *ClassOne {
|
||||
ret := &ClassOne{}
|
||||
ret.ptr = unsafe.Pointer(C.NewClassOne())
|
||||
//ret = ret.Init()
|
||||
return ret
|
||||
}
|
||||
|
||||
func (o *ClassOne) Geti1() Int {
|
||||
return (Int)(C.ClassOne_geti1(o.ptr))
|
||||
}
|
||||
|
||||
|
||||
func (o *ClassOne) Getp1() *Int {
|
||||
return (*Int)(unsafe.Pointer(C.ClassOne_getp1(o.ptr)))
|
||||
}
|
||||
|
||||
|
||||
func (o *ClassOne) Hi1(in Stru) Int {
|
||||
return (Int)(C.ClassOne_hi1(o.ptr, (C.struct_stru)(in)))
|
||||
}
|
||||
|
||||
|
||||
func (o *ClassOne) Hi2(in *Stru) Int {
|
||||
return (Int)(C.ClassOne_hi2(o.ptr, unsafe.Pointer(in)))
|
||||
}
|
||||
|
||||
|
||||
func (o *ClassOne) Nstru1() Stru {
|
||||
return (Stru)(C.ClassOne_nstru1(o.ptr))
|
||||
}
|
||||
|
||||
|
||||
func (o *ClassOne) Nstru2() *Stru {
|
||||
return (*Stru)(unsafe.Pointer(C.ClassOne_nstru2(o.ptr)))
|
||||
}
|
||||
|
||||
|
||||
func (o *ClassOne) Init() *ClassOne {
|
||||
ret := &ClassOne{}
|
||||
ret.ptr = unsafe.Pointer(C.ClassOne_init(o.ptr))
|
||||
return ret
|
||||
}
|
||||
|
|
@ -1,6 +1,85 @@
|
|||
package types
|
||||
|
||||
// Parsers for recognizing type names in C/Objective-C
|
||||
/* Parsers for recognizing type names in C/Objective-C
|
||||
|
||||
type-name:
|
||||
specifier-qualifier-list abstract-declarator<opt>
|
||||
abstract-declarator:
|
||||
pointer
|
||||
pointer<opt> direct-abstract-declarator
|
||||
direct-abstract-declarator:
|
||||
( abstract-declarator )
|
||||
direct-abstract-declarator<opt> [ type-qualifier-list<opt> assignment-expression<opt> ]
|
||||
direct-abstract-declarator<opt> [ static type-qualifier-list<opt> assignment-expression ]
|
||||
direct-abstract-declarator<opt> [ type-qualifier-list static assignment-expression ]
|
||||
direct-abstract-declarator<opt> [ * ]
|
||||
direct-abstract-declarator<opt> ( parameter-type-list<opt> )
|
||||
pointer:
|
||||
* type-qualifier-list<opt>
|
||||
* type-qualifier-list<opt> pointer
|
||||
parameter-type-list:
|
||||
parameter-list
|
||||
parameter-list , ...
|
||||
parameter-list:
|
||||
parameter-declaration
|
||||
parameter-list , parameter-declaration
|
||||
parameter-declaration:
|
||||
declaration-specifiers declarator
|
||||
declaration-specifiers abstract-declarator<opt>
|
||||
type-qualifier-list:
|
||||
type-qualifier
|
||||
type-qualifier-list type-qualifier
|
||||
specifier-qualifier-list:
|
||||
type-specifier specifier-qualifier-list<opt>
|
||||
type-qualifier specifier-qualifier-list<opt>
|
||||
type-specifier:
|
||||
void
|
||||
char
|
||||
short
|
||||
int
|
||||
long
|
||||
float
|
||||
double
|
||||
signed
|
||||
unsigned
|
||||
_Bool
|
||||
_Complex
|
||||
struct-or-union-specifier
|
||||
enum-specifier
|
||||
typedef-name
|
||||
type-qualifier:
|
||||
const
|
||||
restrict
|
||||
volatile
|
||||
struct-or-union-specifier:
|
||||
// DON'T DO struct-or-union identifier<opt> { struct-declaration-list }
|
||||
struct-or-union identifier
|
||||
struct-or-union:
|
||||
struct
|
||||
union
|
||||
struct-declaration-list:
|
||||
struct-declaration
|
||||
struct-declaration-list struct-declaration
|
||||
struct-declaration:
|
||||
specifier-qualifier-list struct-declarator-list ;
|
||||
struct-declarator-list:
|
||||
struct-declarator
|
||||
struct-declarator-list , struct-declarator
|
||||
struct-declarator:
|
||||
declarator
|
||||
declarator<opt>: constant-expression
|
||||
identifier:
|
||||
identifier-non-digit
|
||||
identifier identifier-nondigit
|
||||
identifier digit
|
||||
identifier-nondigit:
|
||||
nondigit
|
||||
universal-character-name
|
||||
nondigit:
|
||||
_ [a-zA-Z]
|
||||
digit:
|
||||
[0-9]
|
||||
*/
|
||||
|
||||
var TypeName func(s string, n *Node) (string, *Node)
|
||||
|
||||
|
|
|
@ -314,12 +314,13 @@ func (w *Wrapper) processTypes(tps []*types.Type) {
|
|||
}
|
||||
|
||||
func (w *Wrapper) processType(tp *types.Type) {
|
||||
gt := tp.GoType()
|
||||
bt := tp.BaseType()
|
||||
gt := bt.GoType()
|
||||
if gt == "" {
|
||||
return
|
||||
}
|
||||
if gt[0] == '*' {
|
||||
w.processType(tp.PointsTo())
|
||||
w.processType(bt.PointsTo())
|
||||
return
|
||||
}
|
||||
if w.Processed[gt] { return }
|
||||
|
@ -327,10 +328,10 @@ func (w *Wrapper) processType(tp *types.Type) {
|
|||
if gt == "Char" {
|
||||
w.CharHelpers()
|
||||
}
|
||||
if tp.IsFunction() {
|
||||
if bt.IsFunction() {
|
||||
return
|
||||
}
|
||||
w.goTypes.WriteString(tp.GoTypeDecl())
|
||||
w.goTypes.WriteString(bt.GoTypeDecl())
|
||||
super := types.Super(gt)
|
||||
if super != "" {
|
||||
types.Wrap(super)
|
||||
|
|
Loading…
Reference in New Issue
Block a user