Documentation ¶
Index ¶
- Constants
- func AddImportsFromFunc(file *jen.File, fe FuncInterface)
- func AllBlocksEmpty(blocks ...*FlowBlock) bool
- func CqlFormatHeaderDoc(modules []*BasicQualifier) []string
- func CqlFormatPackagePath(path string) cqljen.Code
- func CqlParamQualToCode(cqlReveiverName string, cqlMethodName string, qual *FuncQualifier) (FuncInterface, Code)
- func CreateSummary(spec *XSpec) ([]string, error)
- func FindFieldByID(st *feparser.FEStruct, id string) *feparser.FEField
- func FindFieldByName(st *feparser.FEStruct, name string) *feparser.FEField
- func FindStructByID(fe *feparser.FEPackage, id string) *feparser.FEStruct
- func FindType(path string, version string, id string) *feparser.FEType
- func FindTypeByID(fe *feparser.FEPackage, id string) *feparser.FEType
- func FormatDepstubberComment(path string, typeNames []string, funcAndVarNames []string) string
- func FormatPathVersion(path string, version string) string
- func GenCqlParamQual(idName string, dotName string, fn FuncInterface, parameterIndexes []int) (res Code)
- func GenFunctionInputOutput(idName string, fn FuncInterface, receiver bool, parameterIndexes []int, ...) []Code
- func GetCachedSource(path string, version string) *feparser.FEPackage
- func GetFuncName(raw interface{}) string
- func GroupFuncSelectors(mtd *XMethod) (b2fe BasicToFEFuncs, b2tm BasicToTypeIDToMethods, ...)
- func GuessAlias(path string) string
- func GuessContentTypeFromName(name string) string
- func HasMultiplePackages(pks []*BasicQualifier) bool
- func HasMultiversion(pks []*BasicQualifier) bool
- func HasValidEnabledFlow(qualifiers ...*FuncQualifier) bool
- func HasValidFlowBlocks(blocks ...*FlowBlock) bool
- func HasValidPos(qualifiers ...*FuncQualifier) bool
- func IsValidModelKind(kind ModelKind) bool
- func IsValidSelectorKind(kind SelectorKind) bool
- func MustPosToRelativeParamIndexes(fe FuncInterface, positions []bool) []int
- func PosToRelativeIndexes(fn FuncInterface, positions []bool) (receiver bool, parameterIndexes []int, resultIndexes []int)
- func SaveGoFile(outDir string, assetFileName string, file *jen.File) error
- func SetCachedSource(path string, version string, pkg *feparser.FEPackage)
- func ValidateFlowBlocks(blocks ...*FlowBlock) error
- func WriteCodeQLTestQuery(outDir string, name string, content string) error
- func WriteEmptyCodeQLDotExpectedFile(outDir string, name string) error
- func WriteGoModFile(outDir string, pathVersions ...string) error
- type BasicQualifier
- type BasicToFEFuncs
- type BasicToInterfaceIDToMethods
- type BasicToReceiverIDToMethods
- type BasicToStructIDToFields
- type BasicToTypeIDToMethods
- type BasicToTypes
- type FieldMeta
- type FlowBlock
- type FlowSpec
- type FuncElementMeta
- type FuncInterface
- type FuncQualifier
- type FuncQualifierElementsMeta
- type FuncQualifierSlice
- type ImportAdder
- type ModelKind
- type ModelKindHandler
- type ModelKindRouter
- func (rt *ModelKindRouter) GetHandler(kind ModelKind) ModelKindHandler
- func (rt *ModelKindRouter) HasHandler(kind ModelKind) bool
- func (rt *ModelKindRouter) ListModelKinds() []ModelKind
- func (rt *ModelKindRouter) MustGetHandler(kind ModelKind) ModelKindHandler
- func (rt *ModelKindRouter) RegisterHandler(kind ModelKind, handler ModelKindHandler) error
- type NameDB
- func (ndb *NameDB) Child(id string) *NameDB
- func (ndb *NameDB) First(pathVersion string, name string)
- func (ndb *NameDB) FromFETypes(feTypes ...*feparser.FEType)
- func (ndb *NameDB) FromType(typs ...types.Type)
- func (ndb *NameDB) PathVersions() []string
- func (ndb *NameDB) Paths() []string
- func (ndb *NameDB) ReturnByPathVersions() (map[string][]string, map[string][]string)
- func (ndb *NameDB) ReturnByPaths() (map[string][]string, map[string][]string)
- func (ndb *NameDB) Second(pathVersion string, name string)
- type PackageLoader
- type PathVersion
- type SelectorKind
- type StructQualifier
- type TypeQualifier
- type XMethod
- func (mt *XMethod) DeleteSelector(path string, version string, id string) bool
- func (mt *XMethod) DeleteTypeSelector(path string, version string, funcID string) bool
- func (mt *XMethod) GetFuncSelector(path string, version string, funcID string) *FuncQualifier
- func (mt *XMethod) GetStructSelector(path string, version string, structID string) *StructQualifier
- func (mt *XMethod) GetTypeSelector(path string, version string, funcID string) *TypeQualifier
- func (mtd *XMethod) Validate() error
- type XMethodSlice
- type XModel
- type XSelector
- func (sel *XSelector) GetBasicQualifier() *BasicQualifier
- func (sel *XSelector) GetFuncQualifier() *FuncQualifier
- func (sel *XSelector) GetStructQualifier() *StructQualifier
- func (sel *XSelector) GetTypeQualifier() *TypeQualifier
- func (sel *XSelector) UnmarshalJSON(data []byte) error
- func (sel *XSelector) Validate() error
- type XSpec
- func (spec *XSpec) AddMeta() error
- func (spec *XSpec) AppearsIn(path string, version string, id string) []string
- func (spec *XSpec) Cleanup() error
- func (spec *XSpec) HasModelName(name string) bool
- func (spec *XSpec) ListModules() []*BasicQualifier
- func (spec *XSpec) ModifyModelByName(name string, modifier func(*XModel) error) error
- func (spec *XSpec) NormalizeName() error
- func (spec *XSpec) PushModel(model *XModel) error
- func (spec *XSpec) RemoveMeta() error
- func (spec *XSpec) Sort()
- func (spec *XSpec) Validate() error
Constants ¶
const (
DefaultCodeQLTestFileName = "Test"
)
Variables ¶
This section is empty.
Functions ¶
func AddImportsFromFunc ¶
func AddImportsFromFunc(file *jen.File, fe FuncInterface)
func AllBlocksEmpty ¶
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 CqlParamQualToCode ¶
func CqlParamQualToCode(cqlReveiverName string, cqlMethodName string, qual *FuncQualifier) (FuncInterface, Code)
func CreateSummary ¶
CreateSummary creates a summary of the types for each model kind.
func FormatDepstubberComment ¶
FormatDepstubberComment returns the `depstubber` comment that will be used to stub types. The returned string is prefixed with //
func FormatPathVersion ¶
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 GetFuncName ¶
func GetFuncName(raw interface{}) string
func GroupFuncSelectors ¶
func GroupFuncSelectors(mtd *XMethod) (b2fe BasicToFEFuncs, b2tm BasicToTypeIDToMethods, b2itm BasicToInterfaceIDToMethods, err error)
func GuessAlias ¶
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 ¶
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 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 ¶
SaveGoFile encodes to a file the provided *jen.File.
func ValidateFlowBlocks ¶
ValidateFlowBlocks tells whether the blocks can be used (i.e. they have enough correct information.)
func WriteCodeQLTestQuery ¶
WriteCodeQLTestQuery will write to a file the provided codeql test query.
func WriteEmptyCodeQLDotExpectedFile ¶
WriteEmptyCodeQLDotExpectedFile will create an empty <name>.expected file in the specified directory.
func WriteGoModFile ¶
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 ¶
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 FlowSpec ¶
func (*FlowSpec) DeleteBlock ¶
type FuncElementMeta ¶
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 ¶
ImportAdder can be used to add imports to a codeql file.
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 (*NameDB) FromFETypes ¶
func (*NameDB) PathVersions ¶
func (*NameDB) ReturnByPathVersions ¶
func (*NameDB) ReturnByPaths ¶
type PackageLoader ¶
type PathVersion ¶
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 ¶
NewScavengeMethods returns an array of XMethod that are specific to the provided kind.
func ScavengeMethods ¶
func (*XMethod) DeleteSelector ¶
func (*XMethod) DeleteTypeSelector ¶
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
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 (*XModel) ListModules ¶
func (mdl *XModel) ListModules() []*BasicQualifier
ListModules lists all the modules (unique) used inside the model.
func (*XModel) ModifyMethodByName ¶
func (*XModel) NormalizeName ¶
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 ¶
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 TryLoadSpecFromFile ¶
func TryLoadSpecFromFile(path string, loader PackageLoader) (*XSpec, error)
func (*XSpec) HasModelName ¶
func (*XSpec) ListModules ¶
func (spec *XSpec) ListModules() []*BasicQualifier
ListModules lists all the modules (unique) used inside the spec.