示例#1
0
文件: struct.go 项目: NickDaison/e8vm
func newPkgStruct(s *ast.Struct) *pkgStruct {
	deps := listStructDeps(s)
	t := types.NewStruct(s.Name.Lit)

	return &pkgStruct{
		name: s.Name,
		ast:  s,
		deps: deps,
		t:    t,
		pt:   types.NewPointer(t),
	}
}
示例#2
0
文件: member.go 项目: NickDaison/e8vm
func buildMember(b *builder, m *tast.MemberExpr) *ref {
	obj := b.buildExpr(m.Expr)
	if !obj.IsSingle() {
		panic("not single")
	}

	t := obj.Type()
	if pkg, ok := t.(*types.Pkg); ok {
		return buildPkgSym(b, m, pkg)
	}

	pt := types.PointerOf(t)
	var tstruct *types.Struct
	if pt != nil {
		tstruct = pt.(*types.Struct)
	} else {
		tstruct = t.(*types.Struct)
	}

	addr := b.newPtr()
	if pt != nil {
		b.b.Assign(addr, obj.IR())
		if obj != b.this {
			nilPointerPanic(b, addr)
		}
	} else {
		b.b.Arith(addr, nil, "&", obj.IR())
	}

	sym := m.Symbol
	if sym.Type == tast.SymField {
		return buildField(b, addr, sym.Obj.(*types.Field))
	} else if sym.Type == tast.SymFunc {
		recv := newRef(types.NewPointer(tstruct), addr)
		method := sym.Obj.(*objFunc)
		ft := method.Type().(*types.Func)
		return newRecvRef(ft, recv, method.IR())
	}

	panic("bug")
}