예제 #1
0
파일: parse.go 프로젝트: h12w/cwrap
func (pac *Package) getType(gt gcc.Type, ptrKind gcc.PtrKind) Type {
	if ptrKind == gcc.NotSet {
		if named, ok := gt.(gcc.Named); ok && pac.isBool(named.CName()) {
			return newBool(pac.declareEqualType(gt).CgoName())
		}
		return pac.declareEqualType(gt)
	}
	if pt, ok := gcc.ToPointer(gt); ok {
		pointedType := pt.PointedType()
		switch ptrKind {
		case gcc.PtrArray:
			return pac.newSlice(pointedType)
		case gcc.PtrArrayArray:
			pt, _ = gcc.ToPointer(pointedType)
			return pac.newSliceSlice(pt.PointedType())
		case gcc.PtrStringArray:
			return newStringSlice()
		case gcc.PtrString:
			return newString()
		case gcc.PtrTypedef:
			return pac.declareEqualType(gt)
		case gcc.PtrReturn:
			return pac.newReturnPtr(pointedType)
		}
		return pac.newPtr(pointedType)
	}
	panic("Should not goes here.")
}
예제 #2
0
파일: parse.go 프로젝트: sbinet/cwrap
func (pac *Package) newSliceSlice(t gcc.Type) SliceSlice {
	pt, _ := gcc.ToPointer(t)
	et := pac.getNamer(pt.PointedType())
	return SliceSlice{
		goName:  "[]" + et.GoName(),
		cgoName: "*" + et.CgoName(),
	}
}
예제 #3
0
파일: parse.go 프로젝트: sbinet/cwrap
func (pac *Package) getConv(gt gcc.Type, ptrKind gcc.PtrKind, callback bool) Conv {
	if ptrKind == gcc.NotSet {
		n := pac.getNamer(gt)
		if named, ok := gt.(gcc.Named); ok && pac.isBool(named.CName()) {
			return Bool{n.CgoName()}
		}
		switch n.GoName() {
		case "int32", "uint32":
			return Simple{namer{"int", n.CgoName()}}
		}
		if argType, ok := n.(Conv); ok {
			return argType
		}
	}
	if pt, ok := gcc.ToPointer(gt); ok {
		switch ptrKind {
		case gcc.PtrArray:
			return pac.newSlice(pt.PointedType())
		case gcc.PtrArrayArray:
			return pac.newSliceSlice(pt.PointedType())
		case gcc.PtrStringArray:
			return StringSlice{}
		case gcc.PtrString:
			return String{}
		case gcc.PtrTypedef:
			return pac.newPtrTypedef(gt.(*gcc.Typedef)) // Note: gt not pt.
		case gcc.PtrReference:
			if s, ok := gcc.ToComposite(pt.PointedType()); ok {
				return pac.newPtrReference(s)
			}
		case gcc.PtrReturn:
			if callback {
				return pac.newCallbackReturnPtr(pt.PointedType())
			} else {
				return pac.newReturnPtr(pt.PointedType())
			}
		}
		return pac.newPtr(pt.PointedType())
	}
	panic("Should not goes here.")
}