Skip to content

Commit

Permalink
dsl/types: add Struct type
Browse files Browse the repository at this point in the history
  • Loading branch information
quasilyte committed May 18, 2022
1 parent 6f71591 commit 631ca07
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dsl/types/ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ func AsSlice(x Type) *Slice { return nil }
// Returns nil if type is not a pointer.
func AsPointer(x Type) *Pointer { return nil }

// AsStruct is a type-assert like operation, x.(*Struct), but never panics.
// Returns nil if type is not a struct.
func AsStruct(x Type) *Struct { return nil }

// AsInterface is a type-assert like operation, x.(*Interface), but never panics.
// Returns nil if type is not an interface.
func AsInterface(x Type) *Interface { return nil }
13 changes: 13 additions & 0 deletions dsl/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type (

// An Interface represents an interface type.
Interface struct{}

// A struct represents a struct type.
Struct struct{}
)

// NewArray returns a new array type for the given element type and length.
Expand All @@ -53,3 +56,13 @@ func NewPointer(elem Type) *Pointer { return nil }

// Elem returns the element type for the given pointer.
func (*Pointer) Elem() Type { return nil }

func (*Struct) NumFields() int { return 0 }

func (*Struct) Field(i int) *Var { return nil }

type Var struct{}

func (*Var) Embedded() bool { return false }

func (*Var) Type() Type { return nil }

0 comments on commit 631ca07

Please sign in to comment.