Documentation
¶
Overview ¶
Package closed extracts closed types from a package.
A closed type is a type whose valid values is a subset of the domain of its underlying type.
It is impossible to extract all closed types, but this package attempts to extract all that can be heuristically identified by matching common coding conventions. However, false positives and negatives are still possible.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bitset ¶
type Bitset struct { //Flags are the single bit labels in this Bitset. Flags [][]*types.Const //OrFlags are any multibit convienence labels. OrFlags [][]*types.Const // contains filtered or unexported fields }
A Bitset.
type EmptySum ¶
type EmptySum struct { //Nil is true if the nil value is legal. Nil bool //Members are valid types for this sum. Members []types.Type // contains filtered or unexported fields }
EmptySum is a defined empty interface externally specified to contain only a finite number of types.
type Enum ¶
type Enum struct { //NonZero is true if there is an explicit comment directive forbidding //zero from being a valid value. //It is meaningless if there is a label for the zero value. NonZero bool //Labels are the valid members of the enumeration. //If len(Labels[i]) > 1, then Labels[i][1:] are synonyms. //For example, given // type Enum int // const ( // A Enum = iota // B // C = B // ) //there would be two Labels. //The first would just be A and the second would be B and C. Labels [][]*types.Const // contains filtered or unexported fields }
Enum is a set of const labels with a defined type that is not a bitset.
type Interface ¶
type Interface struct { //NonNil is true if there is a comment directive marked this //type as not being able to contain nil. NonNil bool //Members are the types in the sum. Members []*TypeNamesAndType //FalseMembers are unexported zero-sized types with the appropriate tag //that are used to embed in the exported members. FalseMembers []*TypeNamesAndType //TagMethods is a list of the tag methods used by this sum. TagMethods []string // contains filtered or unexported fields }
An Interface is an interface with at least one exported method. If it follows the conventional means of marking a sum type by an empty, nullary, unexported method tag, that will be recorded in TagMethods. If not it may not be a sum type or a closed type, but likely is.
type OptionalStruct ¶
type OptionalStruct struct { Discriminant *types.Var Field *types.Var // contains filtered or unexported fields }
An OptionalStruct is a struct of the form
struct { set bool val T }
where the field val is only valid if set is true.
func (*OptionalStruct) Types ¶
func (o *OptionalStruct) Types() []*types.TypeName
type Type ¶
type Type interface { //Types returns the TypeNames for this Type. //Types()[0] is always the name of the defined type, //and Types()[1:] are aliases to that type definied in the same package. Types() []*types.TypeName // contains filtered or unexported methods }
A Type is one of the closed types recognized by this package.
type TypeNamesAndType ¶
TypeNamesAndType records the TypeName of a defined type (always TypeName[0]) and any aliases in the same package (TypeName[1:]).
The Type field is either identical to TypeName.Type() or types.NewPointer(TypeName.Type()), whichever satisfies the interface that this value is associated with.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
cmds
|
|
closed-explorer
Command closed-explorer analyzes a package and prints its closed types to stdout.
|
Command closed-explorer analyzes a package and prints its closed types to stdout. |
clvalid
Command clvalid generates a method or func to validate that the value of a closed type is legal.
|
Command clvalid generates a method or func to validate that the value of a closed type is legal. |
fillswitch
Command fillswitch(1) populates missing cases in Go switches when the expression switched is a *closed.Enum, *closed.Interface, or *closed.EmptySum.
|
Command fillswitch(1) populates missing cases in Go switches when the expression switched is a *closed.Enum, *closed.Interface, or *closed.EmptySum. |
fillswitch/internal/guess
Package guess was copied out of the source for golang.org/x/tools/cmd/guru
|
Package guess was copied out of the source for golang.org/x/tools/cmd/guru |