semantic

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSecurityCategory added in v0.0.16

func GetSecurityCategory(qualifiedName string) string

GetSecurityCategory returns the security check category for a stdlib function (e.g., "sql", "html", "fetch", "files", "redirect", "shell"), or "" if none.

func GetSliceGenericClass added in v0.0.16

func GetSliceGenericClass(qualifiedName string) string

GetSliceGenericClass returns the generic classification for a stdlib/slice function: "T" (uses any), "K" (uses any2), "TK" (uses both), or "" (not generic).

func GetStdlibEntry added in v0.0.15

func GetStdlibEntry(name string) (goStdlibEntry, bool)

GetStdlibEntry returns the Kukicha stdlib registry entry for the given qualified name (e.g., "string.PadRight"). Returns the entry and true if found.

func IsKnownInterface added in v0.0.16

func IsKnownInterface(qualifiedName string) bool

IsKnownInterface returns true if the qualified type name is a known interface from either the Go stdlib or the Kukicha stdlib registries.

Types

type Analyzer

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

Analyzer performs semantic analysis on the AST

func New

func New(program *ast.Program) *Analyzer

New creates a new semantic analyzer

func NewWithFile added in v0.0.5

func NewWithFile(program *ast.Program, sourceFile string) *Analyzer

NewWithFile creates a new semantic analyzer with the source file path. The file path is used to allow Kukicha stdlib packages to use Go stdlib names.

func (*Analyzer) Analyze

func (a *Analyzer) Analyze() []error

Analyze performs semantic analysis on the program

func (*Analyzer) ExprTypes added in v0.0.13

func (a *Analyzer) ExprTypes() map[ast.Expression]*TypeInfo

ExprTypes returns the inferred types for expressions. Call after Analyze() to pass these to codegen via SetExprTypes.

func (*Analyzer) ReturnCounts added in v0.0.2

func (a *Analyzer) ReturnCounts() map[ast.Expression]int

ReturnCounts returns the inferred return counts for expressions. Call after Analyze() to pass these to codegen.

func (*Analyzer) Warnings added in v0.0.9

func (a *Analyzer) Warnings() []error

Warnings returns non-fatal diagnostics collected during analysis. Call after Analyze(). The caller decides whether to display or promote them to errors.

type Scope

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

Scope represents a lexical scope

func NewScope

func NewScope(parent *Scope) *Scope

NewScope creates a new scope

func (*Scope) Define

func (s *Scope) Define(symbol *Symbol) error

Define adds a symbol to the current scope

func (*Scope) Resolve

func (s *Scope) Resolve(name string) *Symbol

Resolve looks up a symbol in the current scope and parent scopes

type Symbol

type Symbol struct {
	Name     string
	Kind     SymbolKind
	Type     *TypeInfo
	Defined  ast.Position
	Mutable  bool
	Exported bool
}

Symbol represents a symbol in the symbol table

type SymbolKind

type SymbolKind int

SymbolKind represents the kind of symbol

const (
	SymbolVariable SymbolKind = iota
	SymbolParameter
	SymbolFunction
	SymbolType
	SymbolInterface
	SymbolConst
)

func (SymbolKind) String

func (sk SymbolKind) String() string

type SymbolTable

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

SymbolTable manages scopes and symbols

func NewSymbolTable

func NewSymbolTable() *SymbolTable

NewSymbolTable creates a new symbol table

func (*SymbolTable) CurrentScope

func (st *SymbolTable) CurrentScope() *Scope

CurrentScope returns the current scope

func (*SymbolTable) Define

func (st *SymbolTable) Define(symbol *Symbol) error

Define adds a symbol to the current scope

func (*SymbolTable) EnterScope

func (st *SymbolTable) EnterScope()

EnterScope creates a new scope

func (*SymbolTable) ExitScope

func (st *SymbolTable) ExitScope()

ExitScope removes the current scope

func (*SymbolTable) Resolve

func (st *SymbolTable) Resolve(name string) *Symbol

Resolve looks up a symbol

type TypeInfo

type TypeInfo struct {
	Kind         TypeKind
	Name         string               // For named types and placeholders
	ElementType  *TypeInfo            // For lists, channels, references
	KeyType      *TypeInfo            // For maps
	ValueType    *TypeInfo            // For maps
	Params       []*TypeInfo          // For functions
	Returns      []*TypeInfo          // For functions
	Constraint   string               // For placeholders: "any", "comparable", "cmp.Ordered"
	Variadic     bool                 // For functions: true if last param is variadic
	ParamNames   []string             // For functions: parameter names (for named argument validation)
	DefaultCount int                  // For functions: number of parameters with default values
	Fields       map[string]*TypeInfo // For structs: field name → field type
	Methods      map[string]*TypeInfo // For structs: method name → function TypeInfo
}

TypeInfo represents type information

func (*TypeInfo) String

func (ti *TypeInfo) String() string

type TypeKind

type TypeKind int

TypeKind represents the kind of type

const (
	TypeKindUnknown TypeKind = iota
	TypeKindInt
	TypeKindFloat
	TypeKindString
	TypeKindBool
	TypeKindList
	TypeKindMap
	TypeKindChannel
	TypeKindReference
	TypeKindFunction
	TypeKindStruct
	TypeKindInterface
	TypeKindNamed
	TypeKindPlaceholder // For generic type placeholders (element, item, etc.)
	TypeKindNil         // For the 'empty' keyword (nil)
)

func (TypeKind) String

func (tk TypeKind) String() string

Jump to

Keyboard shortcuts

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