visitorgen

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package visitorgen is responsible for taking the ast.go of Vitess and and producing visitor infrastructure for it.

This is accomplished in a few steps. Step 1: Walk the AST and collect the interesting information into a format that is

  	easy to consume for the next step. The output format is a *SourceFile, that
 	contains the needed information in a format that is pretty close to the golang ast,
		but simplified

Step 2: A SourceFile is packaged into a SourceInformation. SourceInformation is still

concerned with the input ast - it's just an even more distilled and easy to
consume format for the last step. This step is performed by the code in transformer.go.

Step 3: Using the SourceInformation, the struct_producer.go code produces the final data structure

used, a VisitorPlan. This is focused on the output - it contains a list of all fields or
arrays that need to be handled by the visitor produced.

Step 4: The VisitorPlan is lastly turned into a string that is written as the output of

this whole process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmitReplacementMethods

func EmitReplacementMethods(vd *VisitorPlan) string

EmitReplacementMethods is an anti-parser (a.k.a prettifier) - it takes a struct that is much like an AST, and produces a string from it. This method will produce the replacement methods that make it possible to replace objects in fields or in slices.

func EmitTypeSwitches

func EmitTypeSwitches(vd *VisitorPlan) string

EmitTypeSwitches is an anti-parser (a.k.a prettifier) - it takes a struct that is much like an AST, and produces a string from it. This method will produce the switch cases needed to cover the Vitess AST.

Types

type Array

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

Array is an array of things, such as `[]string`

type ArrayFieldItem

type ArrayFieldItem struct {
	StructType, ItemType Type
	FieldName            string
}

ArrayFieldItem is an array field in a struct

type ArrayItem

type ArrayItem struct {
	StructType, ItemType Type
}

ArrayItem is an array that implements SQLNode

type Field

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

Field is a field in a struct - a name with a type tuple

func (*Field) String

func (f *Field) String() string

String returns a string representation of a field

type FuncDeclaration

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

FuncDeclaration represents a function declaration. These are tracked to know which types implement interfaces.

type InterfaceDeclaration

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

InterfaceDeclaration represents a declaration of an interface. This is used to keep track of which types need to be handled by the visitor framework

type Ref

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

Ref is a reference to something, such as `*string`

type Sast

type Sast interface {
	// contains filtered or unexported methods
}

Sast or simplified AST, is a representation of the ast.go lines we are interested in

type SingleFieldItem

type SingleFieldItem struct {
	StructType, FieldType Type
	FieldName             string
}

SingleFieldItem is a single field in a struct

type SourceFile

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

SourceFile contains all important lines from an ast.go file

func Walk

func Walk(node ast.Node) *SourceFile

Walk walks the given AST and translates it to the simplified AST used by the next steps

func (*SourceFile) String

func (t *SourceFile) String() string

String returns a textual representation of the SourceFile. This is for testing purposed

type SourceInformation

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

SourceInformation contains the information from the ast.go file, but in a format that is easier to consume

func Transform

func Transform(input *SourceFile) *SourceInformation

Transform takes an input file and collects the information into an easier to consume format

func (*SourceInformation) String

func (v *SourceInformation) String() string

type StructDeclaration

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

StructDeclaration represents a struct. It contains the fields and their types

type SwitchCase

type SwitchCase struct {
	Type   Type
	Fields []VisitorItem
}

SwitchCase is what we need to know to produce all the type switch cases in the visitor.

func (*SwitchCase) Len

func (s *SwitchCase) Len() int

func (*SwitchCase) Less

func (s *SwitchCase) Less(i, j int) bool

func (*SwitchCase) Swap

func (s *SwitchCase) Swap(i, j int)

type Type

type Type interface {
	// contains filtered or unexported methods
}

Type represents a type in the golang type system. Used to keep track of type we need to handle, and the types of fields.

type TypeAlias

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

TypeAlias is used whenever we see a `type XXX YYY` - XXX is the new name for YYY. Note that YYY could be an array or a reference

type TypeString

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

TypeString is a raw type name, such as `string`

type VisitorItem

type VisitorItem interface {
	// contains filtered or unexported methods
}

VisitorItem represents something that needs to be added to the rewriter infrastructure

type VisitorPlan

type VisitorPlan struct {
	Switches []*SwitchCase // The cases for the big switch statement used to implement the visitor
}

VisitorPlan represents all the output needed for the rewriter

func ToVisitorPlan

func ToVisitorPlan(input *SourceInformation) *VisitorPlan

ToVisitorPlan transforms the source information into a plan for the visitor code that needs to be produced

func (*VisitorPlan) Len

func (v *VisitorPlan) Len() int

func (*VisitorPlan) Less

func (v *VisitorPlan) Less(i, j int) bool

func (*VisitorPlan) String

func (v *VisitorPlan) String() string

String returns a string, used for testing

func (*VisitorPlan) Swap

func (v *VisitorPlan) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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