x

package
v0.0.0-...-ff5eb55 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCodeQLTestFileName = "Test"
)

Variables

This section is empty.

Functions

func AddImportsFromFunc

func AddImportsFromFunc(file *jen.File, fe FuncInterface)

func AllBlocksEmpty

func AllBlocksEmpty(blocks ...*FlowBlock) bool

AllBlocksEmpty returns true if all blocks have all false values for both Inp and Out. NOTE: returns false even if only Inp or Out have at least 1 true value.

func CqlFormatHeaderDoc

func CqlFormatHeaderDoc(modules []*BasicQualifier) []string

func CqlFormatPackagePath

func CqlFormatPackagePath(path string) cqljen.Code

func CqlParamQualToCode

func CqlParamQualToCode(cqlReveiverName string, cqlMethodName string, qual *FuncQualifier) (FuncInterface, Code)

func CreateSummary

func CreateSummary(spec *XSpec) ([]string, error)

CreateSummary creates a summary of the types for each model kind.

func FindFieldByID

func FindFieldByID(st *feparser.FEStruct, id string) *feparser.FEField

func FindFieldByName

func FindFieldByName(st *feparser.FEStruct, name string) *feparser.FEField

func FindStructByID

func FindStructByID(fe *feparser.FEPackage, id string) *feparser.FEStruct

func FindType

func FindType(path string, version string, id string) *feparser.FEType

func FindTypeByID

func FindTypeByID(fe *feparser.FEPackage, id string) *feparser.FEType

func FormatDepstubberComment

func FormatDepstubberComment(path string, typeNames []string, funcAndVarNames []string) string

FormatDepstubberComment returns the `depstubber` comment that will be used to stub types. The returned string is prefixed with //

func FormatPathVersion

func FormatPathVersion(path string, version string) string

func GenCqlParamQual

func GenCqlParamQual(idName string, dotName string, fn FuncInterface, parameterIndexes []int) (res Code)

func GenFunctionInputOutput

func GenFunctionInputOutput(idName string, fn FuncInterface, receiver bool, parameterIndexes []int, resultIndexes []int) []Code

func GetCachedSource

func GetCachedSource(path string, version string) *feparser.FEPackage

func GetFuncName

func GetFuncName(raw interface{}) string

func GroupFuncSelectors

func GroupFuncSelectors(mtd *XMethod) (b2fe BasicToFEFuncs, b2tm BasicToTypeIDToMethods, b2itm BasicToInterfaceIDToMethods, err error)

func GuessAlias

func GuessAlias(path string) string

func GuessContentTypeFromName

func GuessContentTypeFromName(name string) string

func HasMultiplePackages

func HasMultiplePackages(pks []*BasicQualifier) bool

HasMultiplePackages returns true if the provided array of BasicQualifiers contains more than one different paths (regardless of versions).

func HasMultiversion

func HasMultiversion(pks []*BasicQualifier) bool

HasMultiversion returns true if the provided array of BasicQualifiers contains multiple qualifiers with the same path.

func HasValidEnabledFlow

func HasValidEnabledFlow(qualifiers ...*FuncQualifier) bool

HasValidEnabledFlow returns true if there is at least one Enabled flow which has at least one valid block.

func HasValidFlowBlocks

func HasValidFlowBlocks(blocks ...*FlowBlock) bool

HasValidFlowBlocks returns true if any of the provided blocks is a valid block, i.e. it has at least one `Inp` and one `Out` set to true.

func HasValidPos

func HasValidPos(qualifiers ...*FuncQualifier) bool

HasValidPos returns true if there is at least one Qualifier that contains at least one true values in its Pos bool array.

func IsValidModelKind

func IsValidModelKind(kind ModelKind) bool

func IsValidSelectorKind

func IsValidSelectorKind(kind SelectorKind) bool

func MustPosToRelativeParamIndexes

func MustPosToRelativeParamIndexes(fe FuncInterface, positions []bool) []int

MustPosToRelativeParamIndexes returns the relative parameter indexes given the absolute positions. Panics if a position is not referred to a parameter.

func PosToRelativeIndexes

func PosToRelativeIndexes(fn FuncInterface, positions []bool) (receiver bool, parameterIndexes []int, resultIndexes []int)

func SaveGoFile

func SaveGoFile(outDir string, assetFileName string, file *jen.File) error

SaveGoFile encodes to a file the provided *jen.File.

func SetCachedSource

func SetCachedSource(path string, version string, pkg *feparser.FEPackage)

func ValidateFlowBlocks

func ValidateFlowBlocks(blocks ...*FlowBlock) error

ValidateFlowBlocks tells whether the blocks can be used (i.e. they have enough correct information.)

func WriteCodeQLTestQuery

func WriteCodeQLTestQuery(outDir string, name string, content string) error

WriteCodeQLTestQuery will write to a file the provided codeql test query.

func WriteEmptyCodeQLDotExpectedFile

func WriteEmptyCodeQLDotExpectedFile(outDir string, name string) error

WriteEmptyCodeQLDotExpectedFile will create an empty <name>.expected file in the specified directory.

func WriteGoModFile

func WriteGoModFile(outDir string, pathVersions ...string) error

WriteGoModFile will generate a go.mod file requiring the provided pathVersions, i.e. an array of example.com/hello/world@v.1.1

Types

type BasicQualifier

type BasicQualifier struct {
	Path    string
	Version string
	ID      string
}

func (*BasicQualifier) Is

func (qual *BasicQualifier) Is(path string, version string, id string) bool

func (*BasicQualifier) IsEqual

func (qual *BasicQualifier) IsEqual(q *BasicQualifier) bool

func (*BasicQualifier) PathVersion

func (bq *BasicQualifier) PathVersion() string

func (*BasicQualifier) PathVersionClean

func (bq *BasicQualifier) PathVersionClean() string

PathVersionClean returns Path if it belongs to standard library; otherwise, it returns PathVersion.

func (*BasicQualifier) Validate

func (qual *BasicQualifier) Validate() error

Validate validates a BasicQualifier.

type BasicToFEFuncs

type BasicToFEFuncs map[string]FuncQualifierSlice

For each PathVersionClean, there is an array of FEFunc.

type BasicToInterfaceIDToMethods

type BasicToInterfaceIDToMethods BasicToReceiverIDToMethods

For each PathVersionClean, there is a map of InterfaceIDs (TypeID); for each TypeID, there is an array of methods.

func (BasicToInterfaceIDToMethods) IterValid

func (b2itm BasicToInterfaceIDToMethods) IterValid(
	pathVersion string,
	iterator func(receiverTypeID string, methodQualifiers FuncQualifierSlice),
)

type BasicToReceiverIDToMethods

type BasicToReceiverIDToMethods map[string]map[string]FuncQualifierSlice

For each PathVersionClean, there is a map of ReceiverIDs (a type or interface); for each ReceiverIDs, there is an array of methods.

func (BasicToReceiverIDToMethods) IterValid

func (b2tm BasicToReceiverIDToMethods) IterValid(
	pathVersion string,
	iterator func(receiverTypeID string, methodQualifiers FuncQualifierSlice),
)

type BasicToStructIDToFields

type BasicToStructIDToFields map[string][]*StructQualifier

For each PathVersionClean, there is a map of StructIDs (TypeID); for each TypeID, there is an array of fields.

func GroupStructSelectors

func GroupStructSelectors(mtd *XMethod) (b2st BasicToStructIDToFields, err error)

type BasicToTypeIDToMethods

type BasicToTypeIDToMethods BasicToReceiverIDToMethods

For each PathVersionClean, there is a map of TypeIDs; for each TypeID, there is an array of methods.

func (BasicToTypeIDToMethods) IterValid

func (b2tm BasicToTypeIDToMethods) IterValid(
	pathVersion string,
	iterator func(receiverTypeID string, methodQualifiers FuncQualifierSlice),
)

type BasicToTypes

type BasicToTypes map[string][]*TypeQualifier

For each PathVersionClean, there is an array of types.

func GroupTypeSelectors

func GroupTypeSelectors(mtd *XMethod) (b2typ BasicToTypes, err error)

type FieldMeta

type FieldMeta struct {
	Name       string `json:",omitempty"`
	TypeString string `json:",omitempty"`
	KindString string `json:",omitempty"`
}

type FlowBlock

type FlowBlock struct {
	Inp []bool
	Out []bool
}

type FlowSpec

type FlowSpec struct {
	Blocks  []*FlowBlock
	Enabled bool
}

func (*FlowSpec) DeleteBlock

func (fls *FlowSpec) DeleteBlock(index int) bool

func (*FlowSpec) Validate

func (fls *FlowSpec) Validate() error

type FuncElementMeta

type FuncElementMeta struct {
	AI         int    // Absolute index
	RI         int    // Relative index
	Name       string // The VarName
	TypeString string
	KindString string
}

type FuncInterface

type FuncInterface interface {
	// Len returns the total length of the function
	// (summing receiver if present, parameters, and results).
	Len() int
	// Lengths returns the lengths of the function, i.e.
	// receiver (1 or 0), parameters, and results.
	Lengths() (int, int, int)
	GetRelativeElement(index int) (feparser.Element, interface{}, int, error)

	GetFunc() *feparser.FEFunc
	GetReceiver() *feparser.FEReceiver
}

func FindFuncByID

func FindFuncByID(fe *feparser.FEPackage, id string) FuncInterface

func GetFuncByQualifier

func GetFuncByQualifier(qual *FuncQualifier) FuncInterface

type FuncQualifier

type FuncQualifier struct {
	BasicQualifier

	Pos   []bool    // Pos is used depending on the ModelKind.
	Flows *FlowSpec // The FuncQualifier can either be in Pos mode, or Flow mode; it depends on the ModelKind that will handle it.

	Name     string                     // Name of the func.
	Elements *FuncQualifierElementsMeta `json:",omitempty"`
}

func (*FuncQualifier) Validate

func (qual *FuncQualifier) Validate() error

Validate validates a FuncQualifier.

type FuncQualifierElementsMeta

type FuncQualifierElementsMeta struct {
	Receiver   *FuncElementMeta
	Parameters []*FuncElementMeta
	Results    []*FuncElementMeta
}

func CompileFuncQualifierElementsMeta

func CompileFuncQualifierElementsMeta(raw interface{}) *FuncQualifierElementsMeta

type FuncQualifierSlice

type FuncQualifierSlice []*FuncQualifier

func (FuncQualifierSlice) ByBasicQualifier

func (qualifiers FuncQualifierSlice) ByBasicQualifier(qual BasicQualifier) *FuncQualifier

type ImportAdder

type ImportAdder interface {
	Import(path string)
	ImportAs(path string, as string)
}

ImportAdder can be used to add imports to a codeql file.

type ModelKind

type ModelKind string

type ModelKindHandler

type ModelKindHandler interface {
	// GenerateCodeQL generates codeql code based on the
	// provided model; the generated code is then saved in the
	// destination dir.
	GenerateCodeQL(impAdder ImportAdder, mdl *XModel, moduleGroup *cqljen.Group) error

	// GenerateGo generates go code based on the
	// provided model; the generated code is then saved in the
	// destination dir.
	GenerateGo(dir string, mdl *XModel) error

	// ScavengeMethods returns an array of initialized
	// methods unique to the ModelKind.
	ScavengeMethods() []*XMethod

	// Validate validates the provided XModel.
	Validate(mdl *XModel) error
}

type ModelKindRouter

type ModelKindRouter struct {
	// contains filtered or unexported fields
}

ModelKindRouter is a router that handles the generation of code for each registered ModelKind.

func NewModelKindRouter

func NewModelKindRouter() (*ModelKindRouter, error)

func Router

func Router() *ModelKindRouter

Router returns the initialized global ModelKind router. Panics if the router hasn't been created yet.

func (*ModelKindRouter) GetHandler

func (rt *ModelKindRouter) GetHandler(kind ModelKind) ModelKindHandler

func (*ModelKindRouter) HasHandler

func (rt *ModelKindRouter) HasHandler(kind ModelKind) bool

func (*ModelKindRouter) ListModelKinds

func (rt *ModelKindRouter) ListModelKinds() []ModelKind

func (*ModelKindRouter) MustGetHandler

func (rt *ModelKindRouter) MustGetHandler(kind ModelKind) ModelKindHandler

func (*ModelKindRouter) RegisterHandler

func (rt *ModelKindRouter) RegisterHandler(kind ModelKind, handler ModelKindHandler) error

type NameDB

type NameDB struct {
	// contains filtered or unexported fields
}

func NewNameDB

func NewNameDB() *NameDB

func (*NameDB) Child

func (ndb *NameDB) Child(id string) *NameDB

func (*NameDB) First

func (ndb *NameDB) First(pathVersion string, name string)

func (*NameDB) FromFETypes

func (ndb *NameDB) FromFETypes(feTypes ...*feparser.FEType)

func (*NameDB) FromType

func (ndb *NameDB) FromType(typs ...types.Type)

func (*NameDB) PathVersions

func (ndb *NameDB) PathVersions() []string

func (*NameDB) Paths

func (ndb *NameDB) Paths() []string

func (*NameDB) ReturnByPathVersions

func (ndb *NameDB) ReturnByPathVersions() (map[string][]string, map[string][]string)

func (*NameDB) ReturnByPaths

func (ndb *NameDB) ReturnByPaths() (map[string][]string, map[string][]string)

func (*NameDB) Second

func (ndb *NameDB) Second(pathVersion string, name string)

type PackageLoader

type PackageLoader func(path string, version string) (*feparser.FEPackage, error)

type PathVersion

type PathVersion struct {
	Path    string
	Version string
}

func GetListCachedSources

func GetListCachedSources() []PathVersion

type SelectorKind

type SelectorKind string
const (
	SelectorKindStruct SelectorKind = "Struct" // Qualifier for structs.
	SelectorKindFunc   SelectorKind = "Func"   // Qualifier for funcs, type methods, interface methods.
	SelectorKindType   SelectorKind = "Type"   // Qualifier for types.
)

type StructQualifier

type StructQualifier struct {
	BasicQualifier
	TypeName string
	Fields   map[string]*FieldMeta
	Total    int `json:",omitempty"`
	Left     int `json:",omitempty"`
}

func (*StructQualifier) Validate

func (qual *StructQualifier) Validate() error

Validate validates a StructQualifier.

type TypeQualifier

type TypeQualifier struct {
	BasicQualifier
	TypeName   string // Name of the type.
	KindString string `json:",omitempty"`
	Value      bool
}

type XMethod

type XMethod struct {
	Name        string // Name is immutable, system-defined.
	Description string `json:",omitempty"` // Description is immutable, system-defined.
	Selectors   []*XSelector
}

func NewScavengeMethods

func NewScavengeMethods(kind ModelKind) []*XMethod

NewScavengeMethods returns an array of XMethod that are specific to the provided kind.

func ScavengeMethods

func ScavengeMethods(methodNames ...string) []*XMethod

func ScavengeMethodsWithNameDescription

func ScavengeMethodsWithNameDescription(nameDescs ...string) []*XMethod

func (*XMethod) DeleteSelector

func (mt *XMethod) DeleteSelector(
	path string,
	version string,
	id string,
) bool

func (*XMethod) DeleteTypeSelector

func (mt *XMethod) DeleteTypeSelector(
	path string,
	version string,
	funcID string,
) bool

func (*XMethod) GetFuncSelector

func (mt *XMethod) GetFuncSelector(
	path string,
	version string,
	funcID string,
) *FuncQualifier

func (*XMethod) GetStructSelector

func (mt *XMethod) GetStructSelector(
	path string,
	version string,
	structID string,
) *StructQualifier

func (*XMethod) GetTypeSelector

func (mt *XMethod) GetTypeSelector(
	path string,
	version string,
	funcID string,
) *TypeQualifier

func (*XMethod) Validate

func (mtd *XMethod) Validate() error

Validate validates a method.

type XMethodSlice

type XMethodSlice []*XMethod

func (XMethodSlice) ByName

func (methods XMethodSlice) ByName(name string) *XMethod

type XModel

type XModel struct {
	Name    string // Name is user-defined.
	Kind    ModelKind
	Methods XMethodSlice
}

func (*XModel) ListAllPathVersions

func (mdl *XModel) ListAllPathVersions() []string

func (*XModel) ListModules

func (mdl *XModel) ListModules() []*BasicQualifier

ListModules lists all the modules (unique) used inside the model.

func (*XModel) ModifyMethodByName

func (mdl *XModel) ModifyMethodByName(
	name string,
	modifier func(*XMethod) error,
) error

func (*XModel) NormalizeName

func (mdl *XModel) NormalizeName() error

func (*XModel) Validate

func (mdl *XModel) Validate() error

Validate validates a model.

type XSelector

type XSelector struct {
	Kind      SelectorKind
	Qualifier interface{}
}

func (*XSelector) GetBasicQualifier

func (sel *XSelector) GetBasicQualifier() *BasicQualifier

func (*XSelector) GetFuncQualifier

func (sel *XSelector) GetFuncQualifier() *FuncQualifier

func (*XSelector) GetStructQualifier

func (sel *XSelector) GetStructQualifier() *StructQualifier

func (*XSelector) GetTypeQualifier

func (sel *XSelector) GetTypeQualifier() *TypeQualifier

func (*XSelector) UnmarshalJSON

func (sel *XSelector) UnmarshalJSON(data []byte) error

func (*XSelector) Validate

func (sel *XSelector) Validate() error

Validate validates a selector.

type XSpec

type XSpec struct {
	Name    string   // Name of the module, user-defined.
	Preload []string // Preload any packages listed here;
	Models  []*XModel
	*sync.RWMutex
}

func NewXSpecWithName

func NewXSpecWithName(name string) *XSpec

func TryLoadSpecFromFile

func TryLoadSpecFromFile(path string, loader PackageLoader) (*XSpec, error)

func (*XSpec) AddMeta

func (spec *XSpec) AddMeta() error

AddMeta populates a spec with meta.

func (*XSpec) AppearsIn

func (spec *XSpec) AppearsIn(path string, version string, id string) []string

func (*XSpec) Cleanup

func (spec *XSpec) Cleanup() error

Cleanup cleans up a spec..

func (*XSpec) HasModelName

func (spec *XSpec) HasModelName(name string) bool

func (*XSpec) ListModules

func (spec *XSpec) ListModules() []*BasicQualifier

ListModules lists all the modules (unique) used inside the spec.

func (*XSpec) ModifyModelByName

func (spec *XSpec) ModifyModelByName(
	name string,
	modifier func(*XModel) error,
) error

func (*XSpec) NormalizeName

func (spec *XSpec) NormalizeName() error

func (*XSpec) PushModel

func (spec *XSpec) PushModel(model *XModel) error

func (*XSpec) RemoveMeta

func (spec *XSpec) RemoveMeta() error

func (*XSpec) Sort

func (spec *XSpec) Sort()

Sort sorts things inside the spec.

func (*XSpec) Validate

func (spec *XSpec) Validate() error

Validate validates a spec.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL