transform

package
v0.0.0-...-c695042 Latest Latest
Warning

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

Go to latest
Published: May 12, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ACcount = 1
View Source
var CCcount = 1
View Source
var RAcount = 1

Functions

func Apply

func Apply(node ast.Node, meta *Meta, transform Transform) ast.Node

Apply applies a transformation to a node.

func ApplyAll

func ApplyAll(node ast.Node, meta *Meta, transforms []Transform) ast.Node

ApplyAll applies a list of transformations to a node.

func ApplyWith

func ApplyWith(node ast.Node, meta *Meta, transform Transform, visitor *Visitor) ast.Node

ApplyWith applies a transformation to a node with a given visitor.

func AriTreat

func AriTreat(lhs ast.Expr, tok token.Token, rhs ast.Expr) ([]ast.Stmt, bool)

func ArrayOf

func ArrayOf(typ *ast.Ident) *ast.ArrayType

ArrayOf creates an array type of the provided element type.

func InjectDecls

func InjectDecls(f *ast.File, decls []ast.Decl)

InjectDecls injects a list of declarations at the top of a file, right after the import statements.

func Int

func Int(i int) *ast.BasicLit

Int transforms an int to a basic literal.

func TokenAssignLess

func TokenAssignLess(tok token.Token) token.Token

func TokenTranslate

func TokenTranslate(tok token.Token) token.Token

Types

type AfterChannel

type AfterChannel struct {
}

func (*AfterChannel) Post

func (t *AfterChannel) Post(meta *Meta, v *Visitor) bool

func (*AfterChannel) Pre

func (t *AfterChannel) Pre(meta *Meta, v *Visitor) bool

Pre traversal

type Alive

type Alive struct {
}

func (*Alive) Post

func (t *Alive) Post(meta *Meta, v *Visitor) bool

Post traversal does nothing.

func (*Alive) Pre

func (t *Alive) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation.

type ArithmeticCall

type ArithmeticCall struct {
}

func (*ArithmeticCall) Post

func (t *ArithmeticCall) Post(meta *Meta, v *Visitor) bool

func (*ArithmeticCall) Pre

func (t *ArithmeticCall) Pre(meta *Meta, v *Visitor) bool

type Channel

type Channel struct {
	Goroutines []*cspinfo.Goroutine
	// contains filtered or unexported fields
}

func (*Channel) Post

func (t *Channel) Post(meta *Meta, v *Visitor) bool

func (*Channel) Pre

func (t *Channel) Pre(meta *Meta, v *Visitor) bool

type ConditionnalCall

type ConditionnalCall struct {
}

func (*ConditionnalCall) Post

func (t *ConditionnalCall) Post(meta *Meta, v *Visitor) bool

func (*ConditionnalCall) Pre

func (t *ConditionnalCall) Pre(meta *Meta, v *Visitor) bool

type Debug

type Debug struct {
	Output io.Writer
}

The Debug's purpose is to display the current state of transformation.

func (*Debug) Post

func (t *Debug) Post(meta *Meta, v *Visitor) bool

Post traversal applies the transformation.

func (*Debug) Pre

func (t *Debug) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation.

type DesugarArray

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

func (*DesugarArray) Post

func (t *DesugarArray) Post(meta *Meta, v *Visitor) bool

Post traversal applies the transformation.

func (*DesugarArray) Pre

func (t *DesugarArray) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation.

type DoubleBrackets

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

func (*DoubleBrackets) Post

func (t *DoubleBrackets) Post(meta *Meta, v *Visitor) bool

Post traversal applies the transformation.

func (*DoubleBrackets) Pre

func (t *DoubleBrackets) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation.

type ElseFull

type ElseFull struct {
}

func (*ElseFull) Post

func (t *ElseFull) Post(meta *Meta, v *Visitor) bool

func (*ElseFull) Pre

func (t *ElseFull) Pre(meta *Meta, v *Visitor) bool

type Format

type Format struct {
}

func (*Format) Post

func (t *Format) Post(meta *Meta, v *Visitor) bool

func (*Format) Pre

func (t *Format) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation.

type FunctionDefs

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

FunctionDefs visitor type, keeps track of the current function definition.

func (*FunctionDefs) Post

func (t *FunctionDefs) Post(meta *Meta, v *Visitor) bool

Post traversal does nothing.

func (*FunctionDefs) Pre

func (t *FunctionDefs) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation.

type FunctionRecord

type FunctionRecord struct {
	// All functions have a unique index that's used to identify them in the
	// function counter.
	Index int
	// Original identifier in the code.
	OriginalIdent *ast.Ident
	// Generated identifier.
	Ident *ast.Ident
	// List of labels that have been generated inside this function.
	Labels []*ast.Ident
	// Ordered list of the function's results.
	Results []*ast.Object
	// Ordered list of the function's parameters.
	Params []*ast.Object
	// Object that stores the caller function of this function.
	Caller *ast.Object
	// Object that stores the label in the caller function to jump to once the
	// function has finished executing.
	CallerLabel *ast.Object
	// Slice of indexes of variables belonging to this function in the global state
	Vars []int
}

FunctionRecord represents a transformed function in store.

func (*FunctionRecord) NewLabel

func (fr *FunctionRecord) NewLabel() *ast.Ident

NewLabel creates a label inside of a function and returns its ident.

type Global

type Global struct {
	GlobalVar      []string
	GlobalBlackbox map[string]bool
	ToIgnore       []string
	// contains filtered or unexported fields
}

func (*Global) Post

func (t *Global) Post(meta *Meta, v *Visitor) bool

Post traversal applies the transformation

func (*Global) Pre

func (t *Global) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation

type GlobalToState

type GlobalToState struct {
	GlobalBlackbox map[string]*ast.Object
	GlobalVar      []string
	// contains filtered or unexported fields
}

func (*GlobalToState) Post

func (t *GlobalToState) Post(meta *Meta, v *Visitor) bool

func (*GlobalToState) Pre

func (t *GlobalToState) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation

type InnerCall

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

func (*InnerCall) CallExprRec

func (t *InnerCall) CallExprRec(curNode *ast.CallExpr) ([]*ast.AssignStmt, *ast.CallExpr)

Handle recursive CallExpr

func (*InnerCall) CreateTmpVar

func (t *InnerCall) CreateTmpVar(callExpr *ast.CallExpr) *ast.Ident

func (*InnerCall) Post

func (t *InnerCall) Post(meta *Meta, v *Visitor) bool

func (*InnerCall) Pre

func (t *InnerCall) Pre(meta *Meta, v *Visitor) bool

type LocalVariableAssignments

type LocalVariableAssignments struct {
	GlobalToMain   []ast.Stmt
	GlobalBlackbox map[string]*ast.Object
	Global         bool
	// contains filtered or unexported fields
}

LocalVariableAssignments visitor type, stateless.

func (*LocalVariableAssignments) Post

func (t *LocalVariableAssignments) Post(meta *Meta, v *Visitor) bool

Post traversal sets global values and remove statements.

func (*LocalVariableAssignments) Pre

func (t *LocalVariableAssignments) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation.

type Meta

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

Meta represents all metadata kept around during the transform steps.

func NewMeta

func NewMeta(fset *token.FileSet, info *types.Info) *Meta

NewMeta returns a new Meta structure.

func (*Meta) Add

func (m *Meta) Add(obj *ast.Object, prefix string) *ast.IndexExpr

Add an object to the store. Returns an IndexExpr of the state for the given object.

func (*Meta) AddFunction

func (m *Meta) AddFunction(fd *ast.FuncDecl, prefix string) *FunctionRecord

AddFunction adds a function to the store. Returns the created function record.

func (*Meta) ChanInitialSize

func (m *Meta) ChanInitialSize(obj *ast.Object) int

func (*Meta) Create

func (m *Meta) Create(name, prefix string) *ast.Object

Create an object and add it to the store. Useful for making temporaries.

func (*Meta) FileSet

func (m *Meta) FileSet() *token.FileSet

FileSet returns the file set.

func (*Meta) FunctionCounter

func (m *Meta) FunctionCounter() *ast.Object

FunctionCounter returns an expression that points to the function counter.

func (*Meta) Get

func (m *Meta) Get(obj *ast.Object) *ast.IndexExpr

Get returns an IndexExpr of the state for the given object.

func (*Meta) GetChans

func (m *Meta) GetChans() []cspinfo.Channel

func (*Meta) GetFunction

func (m *Meta) GetFunction(fn *ast.Object) *FunctionRecord

GetFunction returns the FunctionRecord corresponding to a given function.

func (*Meta) GetFunctions

func (m *Meta) GetFunctions() []*FunctionRecord

GetFunctions returns a slice of all stored functions.

func (*Meta) GetOrAdd

func (m *Meta) GetOrAdd(obj *ast.Object, prefix string, fn *ast.Object) *ast.IndexExpr

GetOrAdd acts as Get if the object is in store, Add otherwise.

func (*Meta) GetVariables

func (m *Meta) GetVariables() []string

GetVariables returns a list of all variable names.

func (*Meta) Has

func (m *Meta) Has(obj *ast.Object) bool

Has checks whether the provided object is in store.

func (*Meta) HasFunction

func (m *Meta) HasFunction(fn *ast.Object) bool

HasFunction checks whether we have the provided function in store.

func (*Meta) Info

func (m *Meta) Info() *types.Info

Info returns package info.

func (*Meta) IsRegisterWaitGroup

func (m *Meta) IsRegisterWaitGroup(name string, obj *ast.Object) bool

func (*Meta) LabelCounter

func (m *Meta) LabelCounter() *ast.Object

LabelCounter returns an expression that points to the label counter.

func (*Meta) MainFunction

func (m *Meta) MainFunction() *FunctionRecord

MainFunction returns the FunctionRecord corresponding to the main function.

func (*Meta) RegisterArray

func (m *Meta) RegisterArray(name string, ident string, size int)

Register an array so that enough slots can be reserved when adding an object. FIXME : this should be done with object rather than simple strings

func (*Meta) RegisterChannel

func (m *Meta) RegisterChannel(obj *ast.Object, name string, ident string, size int, initial_size int)

Channels and Arrays are processed identically. Except that channels also register elsewhere for latter access.

func (*Meta) RegisterWaitGroup

func (m *Meta) RegisterWaitGroup(obj *ast.Object, name string)

Simple function used to register waitgroups

func (*Meta) Set

func (m *Meta) Set(obj *ast.Object, expr ast.Expr) *ast.AssignStmt

Set returns an AssignStmt setting the state of the given object to the given Expr.

func (*Meta) State

func (m *Meta) State() *ast.Ident

State returns the state ident.

func (*Meta) StateSize

func (m *Meta) StateSize() int

StateSize returns the size of the state.

func (*Meta) StateType

func (m *Meta) StateType() *ast.Ident

StateType returns the state type ident.

func (*Meta) StructStateType

func (m *Meta) StructStateType() *ast.Ident

type NormalizeDeclarations

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

NormalizeDeclarations visitor type

func (NormalizeDeclarations) Post

func (NormalizeDeclarations) Post(meta *Meta, v *Visitor) bool

Post traversal does nothing.

func (*NormalizeDeclarations) Pre

func (t *NormalizeDeclarations) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation.

type PostGlobal

type PostGlobal struct {
	GlobalBlackbox map[string]bool
}

func (*PostGlobal) Post

func (t *PostGlobal) Post(meta *Meta, v *Visitor) bool

Post traversal applies the transformation

func (*PostGlobal) Pre

func (t *PostGlobal) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation

type PreGlobal

type PreGlobal struct {
	GlobalVar []string
	// contains filtered or unexported fields
}

func (*PreGlobal) Post

func (t *PreGlobal) Post(meta *Meta, v *Visitor) bool

Post traversal applies the transformation

func (*PreGlobal) Pre

func (t *PreGlobal) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation

type RegularizedAffect

type RegularizedAffect struct {
}

func (*RegularizedAffect) Post

func (t *RegularizedAffect) Post(meta *Meta, v *Visitor) bool

Post traversal does nothing.

func (*RegularizedAffect) Pre

func (t *RegularizedAffect) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation.

type RoutineAssignments

type RoutineAssignments struct {
	Functions []*cspinfo.Goroutine
}

func (*RoutineAssignments) Post

func (t *RoutineAssignments) Post(meta *Meta, v *Visitor) bool

Post traversal does nothing.

func (*RoutineAssignments) Pre

func (t *RoutineAssignments) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation.

type RoutineCounter

type RoutineCounter struct {
	Functions []*cspinfo.Goroutine
	// contains filtered or unexported fields
}

func (*RoutineCounter) Post

func (t *RoutineCounter) Post(meta *Meta, v *Visitor) bool

Post traversal does nothing.

func (*RoutineCounter) Pre

func (t *RoutineCounter) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation.

type RoutinePrinter

type RoutinePrinter struct {
}

func (*RoutinePrinter) Post

func (t *RoutinePrinter) Post(meta *Meta, v *Visitor) bool

func (*RoutinePrinter) Pre

func (t *RoutinePrinter) Pre(meta *Meta, v *Visitor) bool

type Transform

type Transform interface {
	// Pre will be called on every node in pre-traversal order, and returns a
	// boolean to indicate whether or not to continue traversing downwards.
	Pre(*Meta, *Visitor) bool
	// Post will called on every node in post-traversal order, and returns a
	// boolean to indicate whether or not to continue traversing upwards.
	Post(*Meta, *Visitor) bool
}

A Transform represents a transformation.

type TypeChecker

type TypeChecker struct {
	Blackbox bool
	// contains filtered or unexported fields
}

func (TypeChecker) Post

func (TypeChecker) Post(meta *Meta, v *Visitor) bool

func (*TypeChecker) Pre

func (t *TypeChecker) Pre(meta *Meta, v *Visitor) bool

Pre traversal check if there is use of variable other than integers.

type UnrollLoop

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

FunctionDefs visitor type, keeps track of the current function definition.

func (*UnrollLoop) Post

func (t *UnrollLoop) Post(meta *Meta, v *Visitor) bool

Post traversal does nothing.

func (*UnrollLoop) Pre

func (t *UnrollLoop) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation.

type Visitor

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

A Visitor keeps track of the current node and its path, where the path is a list of all its parent identifiers (file and functions).

func (*Visitor) Cursor

func (v *Visitor) Cursor() *astutil.Cursor

Cursor returns a cursor pointed at the current node.

func (*Visitor) Name

func (v *Visitor) Name() string

Name returns the composite name of the current node.

func (*Visitor) ParentName

func (v *Visitor) ParentName() string

ParentName returns the composite name of the parent of the current node.

type WaitGroup

type WaitGroup struct {
}

FunctionDefs visitor type, keeps track of the current function definition.

func (*WaitGroup) Post

func (t *WaitGroup) Post(meta *Meta, v *Visitor) bool

Post traversal does nothing.

func (*WaitGroup) Pre

func (t *WaitGroup) Pre(meta *Meta, v *Visitor) bool

Pre traversal applies the transformation.

Directories

Path Synopsis
Package cfg constructs a simple control-flow graph (CFG) of the statements and expressions within a single function.
Package cfg constructs a simple control-flow graph (CFG) of the statements and expressions within a single function.

Jump to

Keyboard shortcuts

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