parser

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallGraph added in v0.0.10

type CallGraph struct {
	Root      *CallNode
	Functions map[string]*CallNode // Function key -> node
}

CallGraph represents the complete function call graph

type CallNode added in v0.0.10

type CallNode struct {
	Function *FunctionInfo
	Calls    []*CallNode
	CalledBy []*CallNode
}

CallNode represents a node in the call graph

type Config

type Config struct {
	IgnoreDirs             []string
	IgnoreFiles            []string
	IncludeTests           bool
	IncludeVendor          bool
	BuildTags              []string
	LoadMode               packages.LoadMode
	EnableSSA              bool
	EnableCallGraph        bool
	EnablePerformanceStats bool // Enable detailed performance monitoring for SSA builds
	EnableMemoryMonitoring bool // Enable memory monitoring during SSA builds (can impact performance)
}

Config represents parser configuration

type ConstantInfo

type ConstantInfo struct {
	Name       string
	Type       types.Type
	Value      string // String representation of the value
	IsExported bool
	LineStart  int
	LineEnd    int
}

ConstantInfo represents a constant declaration

type DirectoryResult added in v0.0.10

type DirectoryResult struct {
	DirectoryPath string         // Path to the parsed directory
	Packages      []*PackageInfo // All packages found in the directory
	ParseTime     int64          // Time taken to parse in milliseconds
}

DirectoryResult contains results for directory parsing (backward compatibility)

type FieldInfo

type FieldInfo struct {
	Name       string
	Type       types.Type
	Tag        string
	IsExported bool
	Anonymous  bool // For embedded fields
}

FieldInfo represents a struct field with full type information

type FileInfo

type FileInfo struct {
	Path         string
	Package      string
	Imports      []*ImportInfo
	Functions    []*FunctionInfo
	Types        []*TypeInfo
	Constants    []*ConstantInfo
	Variables    []*VariableInfo
	Dependencies []string
}

FileInfo represents analyzed file information

type FileResult added in v0.0.10

type FileResult struct {
	FilePath  string       // Path to the parsed file
	Package   *PackageInfo // Package information containing the file
	FileInfo  *FileInfo    // Specific file information
	ParseTime int64        // Time taken to parse in milliseconds
}

FileResult contains results for single file parsing (backward compatibility)

type FunctionCall

type FunctionCall struct {
	Function *FunctionInfo
	Position string
	Line     int
}

FunctionCall represents a resolved function call

type FunctionInfo

type FunctionInfo struct {
	Name       string
	Receiver   *TypeInfo // For methods
	Signature  *types.Signature
	SSAFunc    *ssa.Function // SSA representation
	Calls      []*FunctionCall
	CalledBy   []*FunctionInfo
	LineStart  int
	LineEnd    int
	IsExported bool
}

FunctionInfo represents a function or method with type information

type Implementation added in v0.0.10

type Implementation struct {
	Type           *TypeInfo
	Interface      *InterfaceInfo
	IsComplete     bool
	MethodMatches  map[string]*FunctionInfo // Interface method -> implementation
	MissingMethods []string
}

Implementation represents a type implementing an interface

type ImportInfo

type ImportInfo struct {
	Name    string            // Local name (alias or package name)
	Path    string            // Import path
	Package *packages.Package // Resolved package
}

ImportInfo represents an import with resolved information

type InterfaceInfo

type InterfaceInfo struct {
	Name            string
	Package         string // Package path where interface is declared
	Type            *types.Interface
	Methods         []*MethodInfo
	Embeds          []*InterfaceInfo
	Implementations []*Implementation
	LineStart       int
	LineEnd         int
	IsExported      bool
}

InterfaceInfo represents an interface with implementation tracking

type MethodInfo

type MethodInfo struct {
	Name      string
	Signature *types.Signature
}

MethodInfo represents an interface method

type PackageInfo added in v0.0.10

type PackageInfo struct {
	*packages.Package                  // Embedded package info
	Path              string           // Import path
	Name              string           // Package name
	Files             []*FileInfo      // Analyzed files
	Functions         []*FunctionInfo  // All functions and methods
	Types             []*TypeInfo      // All type declarations
	Interfaces        []*InterfaceInfo // Interface declarations
	Constants         []*ConstantInfo  // Constant declarations
	Variables         []*VariableInfo  // Variable declarations
	SSAPackage        *ssa.Package     // SSA representation
}

PackageInfo represents analyzed package information

type ParseResult

type ParseResult struct {
	ProjectPath      string                 // Root path of the project
	Packages         []*PackageInfo         // All analyzed packages
	SSAProgram       *ssa.Program           // SSA form of the program
	CallGraph        *CallGraph             // Complete call graph
	Interfaces       []*InterfaceInfo       // All interfaces with implementations
	ParseTime        int64                  // Time taken to parse in milliseconds
	PerformanceStats *SSAPerformanceMetrics // SSA build performance metrics (optional)
}

ParseResult contains comprehensive analysis results

type Parser

type Parser interface {
	ParseProject(ctx context.Context, projectPath string, config *Config) (*ParseResult, error)
	// Backward compatibility methods
	ParseFile(ctx context.Context, filePath string, config *Config) (*FileResult, error)
	ParseDirectory(ctx context.Context, dirPath string, config *Config) (*DirectoryResult, error)
}

Parser defines the interface for advanced Go source code analysis

func NewService

func NewService(config *Config) Parser

NewService creates a new parser service

type SSAMemoryProfile added in v0.0.10

type SSAMemoryProfile struct {
	InitialMemoryMB     int64 // Memory usage before SSA build
	PreparationMemoryMB int64 // Memory after package preparation
	BuildMemoryMB       int64 // Memory after SSA construction
	PeakMemoryMB        int64 // Peak memory usage during build
	FinalMemoryMB       int64 // Memory usage after build completion
}

SSAMemoryProfile tracks memory usage during different SSA build phases

type SSAPerformanceMetrics added in v0.0.10

type SSAPerformanceMetrics struct {
	BuildDuration     time.Duration            // Total SSA build time
	PreparationTime   time.Duration            // Time to prepare SSA packages
	ConstructionTime  time.Duration            // Time for actual SSA construction
	PackagesProcessed int                      // Number of packages processed
	FunctionsAnalyzed int                      // Total functions in SSA program
	CallGraphNodes    int                      // Number of call graph nodes (if enabled)
	MemoryUsageMB     int64                    // Peak memory usage during SSA build in MB
	PhaseBreakdown    map[string]time.Duration // Detailed timing per SSA phase
	MemoryProfile     *SSAMemoryProfile        // Memory usage profile during build
}

SSAPerformanceMetrics contains detailed performance metrics for SSA build operations

type Service

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

Service implements the Parser interface using modern Go analysis tools

func (*Service) ParseDirectory

func (s *Service) ParseDirectory(ctx context.Context, dirPath string, config *Config) (*DirectoryResult, error)

ParseDirectory parses all Go files in a directory (backward compatibility method)

func (*Service) ParseFile

func (s *Service) ParseFile(ctx context.Context, filePath string, config *Config) (*FileResult, error)

ParseFile parses a single Go file (backward compatibility method)

func (*Service) ParseProject

func (s *Service) ParseProject(ctx context.Context, projectPath string, config *Config) (*ParseResult, error)

ParseProject parses an entire Go project with full type information

type TypeInfo added in v0.0.10

type TypeInfo struct {
	Name       string
	Type       types.Type
	Underlying types.Type
	Methods    []*FunctionInfo
	Fields     []*FieldInfo     // For structs
	Embeds     []*TypeInfo      // Embedded types
	Implements []*InterfaceInfo // Interfaces implemented
	LineStart  int
	LineEnd    int
	IsExported bool
}

TypeInfo represents any Go type (struct, interface, alias, etc.)

type VariableInfo

type VariableInfo struct {
	Name       string
	Type       types.Type
	Value      string // String representation of the initial value (if any)
	IsExported bool
	LineStart  int
	LineEnd    int
}

VariableInfo represents a variable declaration

Jump to

Keyboard shortcuts

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