vet/pkg/code/lang.go
abhisek e6f6288701
feat: Code analysis framework infra
feat: Building code graph

Refactor to support import processing

Handle relative import name fixup

Add docs for code analysis framework

Update docs to include additional examples

feat: Function call graph

Update code graph to link function decl and calls

Include call node in function calls

feat: Flatten vulnerabilities in CSV reporter

refactor: Maintain separation of concerns for code analysis framework

refactor: Separate storage entities in its own package

feat: Add callback support in code graph builder

docs: Fix code analysis framework docs
Signed-off-by: abhisek <abhisek.datta@gmail.com>
2024-07-11 15:09:11 +05:30

39 lines
1.3 KiB
Go

package code
import (
"github.com/safedep/vet/pkg/code/nodes"
)
// Declarative metadata for the source language
type SourceLanguageMeta struct {
SourceFileGlobs []string
}
// Any source language implementation must support these
// primitives for integration with the code analysis system
type SourceLanguage interface {
// Get metadata for the source language
GetMeta() SourceLanguageMeta
// Parse a source file and return the CST (tree-sitter concrete syntax tree)
ParseSource(file SourceFile) (*nodes.CST, error)
// Get import nodes from the CST
GetImportNodes(cst *nodes.CST) ([]nodes.CSTImportNode, error)
// Get function declaration nodes from the CST
GetFunctionDeclarationNodes(cst *nodes.CST) ([]nodes.CSTFunctionNode, error)
// Get function call nodes from the CST
GetFunctionCallNodes(cst *nodes.CST) ([]nodes.CSTFunctionCallNode, error)
// Resolve the import module / package name from relative path
ResolveImportNameFromPath(relPath string) (string, error)
// Resolve import name to possible relative file names
// Multiple paths are possible because an import such
// as a.b can resolve to a/b.py or a/b/__init__.py depending
// on language and file system
ResolveImportPathsFromName(currentFile SourceFile, importName string, includeImports bool) ([]string, error)
}