ir

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package ir (intermediate representation) transforms nodes in the go/ast format into a more workable "IR" format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuncGoIdent

func FuncGoIdent(fn *Func) string

func IdentExprIsExported

func IdentExprIsExported(expr ast.Expr) bool

func IdentIsInternal

func IdentIsInternal(modNames UniqueModuleNames, id Ident) bool

func ModulePathIsInternal

func ModulePathIsInternal(modNames UniqueModuleNames, p string) bool

func ParamsToIdents

func ParamsToIdents(modNames UniqueModuleNames, file *File, fl *ast.FieldList) (idents []NamedIdent, substImports []*File, err error)

Types

type File

type File struct {
	Name          string
	ModuleName    string
	ModulePath    string
	ImportsByName map[string]*File
	ImportsByPath map[string]*File
}

func (*File) AddImport

func (f *File) AddImport(imp *File)

type Func

type Func struct {
	Name    Ident
	Recv    *Ident // non-nil for methods
	Params  []NamedIdent
	Results []NamedIdent
	File    *File
}

func NewFunc

func NewFunc(modNames UniqueModuleNames, file *File, fd *ast.FuncDecl) (*Func, error)

func (*Func) String

func (fn *Func) String() string

type IR

type IR struct {
	Funcs      map[string]*Func
	Interfaces map[string]*Interface
	Structs    map[string]*Struct
	Typedefs   map[string]Ident
	Values     map[string]NamedIdent // consts and vars
}

func New

func New() *IR

func (*IR) AddFile

func (ir *IR) AddFile(
	modNames UniqueModuleNames,
	f *ast.File,
	fName string,
	modulePath string,
	modDefaultNames map[string]string,
	typeDeclsOnly bool,
) (

	requiredPkgs []string,
	err error,
)

func (*IR) ResolveInheritancesAndMethods

func (ir *IR) ResolveInheritancesAndMethods(modNames UniqueModuleNames) error

Resolves interface, struct, and method inheritance

type Ident

type Ident struct {
	Expr        ast.Expr
	Name        string
	IsEllipsis  bool
	File        *File
	UsedImports []*File
}

func NewIdent

func NewIdent(modNames UniqueModuleNames, file *File, expr ast.Expr) (Ident, error)

func (*Ident) GetReferencedPackage

func (id *Ident) GetReferencedPackage(modNames UniqueModuleNames, file *File) (*File, bool)

Returns *SelectorExpr referenced *File, true. If id is not *SelectorExpr, returns nil, false.

func (*Ident) RyeName

func (id *Ident) RyeName() string

type Interface

type Interface struct {
	Name             Ident
	Funcs            []*Func
	Inherits         []Ident
	HasPrivateFields bool
}

func NewInterface

func NewInterface(modNames UniqueModuleNames, file *File, name *ast.Ident, ifaceTyp *ast.InterfaceType) (*Interface, error)

type NamedIdent

type NamedIdent struct {
	Name Ident
	Type Ident
}

type Struct

type Struct struct {
	Name     Ident
	Fields   []NamedIdent
	Methods  map[string]*Func
	Inherits []Ident
}

func NewStruct

func NewStruct(modNames UniqueModuleNames, file *File, name *ast.Ident, structTyp *ast.StructType) (*Struct, error)

type UniqueModuleNames

type UniqueModuleNames map[string]string

Module path to globally unique name.

Jump to

Keyboard shortcuts

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