ast

package
v0.0.0-...-94861f8 Latest Latest
Warning

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

Go to latest
Published: May 3, 2017 License: BSD-3-Clause, Unlicense Imports: 6 Imported by: 0

Documentation

Overview

Package ast defines all the nodes for a SubC AST.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NotNilFilter

func NotNilFilter(_ string, v reflect.Value) bool

NotNilFilter filters out nil nodes.

func Print

func Print(x interface{}) (err error)

Print prints an AST tree given a node.

Types

type Affix

type Affix int

Affix defines what type of unary expression it is. It is used for the ++/-- operators to say if the operator is ++x or x++.

const (
	Prefix Affix = iota + 1
	Postfix
)

func (Affix) String

func (a Affix) String() string

type ArrayType

type ArrayType struct {
	Lbrack scan.Token
	Len    Expr
	Rbrack scan.Token
}

ArrayType represents an array declaration.

func (*ArrayType) Span

func (t *ArrayType) Span() scan.Span

type BadDecl

type BadDecl struct {
	From, To scanner.Position
}

BadDecl is a bad declaration.

func (*BadDecl) Span

func (d *BadDecl) Span() scan.Span

type BadExpr

type BadExpr struct {
	From, To scanner.Position
}

BadExpr represents an invalid expression.

func (*BadExpr) Span

func (e *BadExpr) Span() scan.Span

type BadStmt

type BadStmt struct {
	From, To scanner.Position
}

BadStmt represents an invalid statement.

func (*BadStmt) Span

func (s *BadStmt) Span() scan.Span

type BasicLit

type BasicLit struct {
	scan.Token
}

BasicLit represents a character, number, or a string literal.

type BasicType

type BasicType struct {
	Type scan.Token
	X    Expr
}

BasicType represents a type.

func (*BasicType) Span

func (t *BasicType) Span() scan.Span

type BinaryExpr

type BinaryExpr struct {
	X  Expr
	Op scan.Token
	Y  Expr
}

BinaryExpr represents a binary expression.

func (*BinaryExpr) Span

func (e *BinaryExpr) Span() scan.Span

type BlockStmt

type BlockStmt struct {
	Lbrace *scan.Token
	Stmt   []Stmt
	Rbrace *scan.Token
}

BlockStmt represents a block statement.

func (*BlockStmt) Span

func (s *BlockStmt) Span() scan.Span

type BranchStmt

type BranchStmt struct {
	scan.Token
}

BranchStmt represents a branch statement, such as a break, continue or goto.

type CallExpr

type CallExpr struct {
	Fun    Expr
	Lparen scan.Token
	Args   []Expr
	Rparen scan.Token
}

CallExpr represents a function call expression.

func (*CallExpr) Span

func (e *CallExpr) Span() scan.Span

type CaseClause

type CaseClause struct {
	Case  scan.Token
	Value Expr
	Colon scan.Token
	Body  []Stmt
}

CaseClause represents a case statement inside a switch statement.

func (*CaseClause) Span

func (s *CaseClause) Span() scan.Span

type CastExpr

type CastExpr struct {
	Lparen scan.Token
	Type   Expr
	Rparen scan.Token
	X      Expr
}

CastExpr represents a cast expression.

func (*CastExpr) Span

func (e *CastExpr) Span() scan.Span

type CompositeLit

type CompositeLit struct {
	Lbrace scan.Token
	Elts   []Expr
	Rbrace scan.Token
}

CompositeLit represents an initialization list for arrays.

func (*CompositeLit) Span

func (e *CompositeLit) Span() scan.Span

type CondExpr

type CondExpr struct {
	Cond Expr
	X    Expr
	Y    Expr
}

CondExpr represents ternary expressions.

func (*CondExpr) Span

func (e *CondExpr) Span() scan.Span

type ConstDecl

type ConstDecl struct {
	Name *Ident
	X    Expr
}

ConstDecl is a constant declaration.

func (*ConstDecl) Span

func (d *ConstDecl) Span() scan.Span

type Decl

type Decl interface {
	Node
}

Decl is a declaration node.

type Directive

type Directive interface {
	Node
}

Directive is a preprocessor node.

type DoStmt

type DoStmt struct {
	Do     scan.Token
	Body   Stmt
	While  scan.Token
	Lparen scan.Token
	Cond   Expr
	Rparen scan.Token
}

DoStmt represents a do-while statement.

func (*DoStmt) Span

func (s *DoStmt) Span() scan.Span

type EmptyStmt

type EmptyStmt struct {
	Semi scan.Token
}

EmptyStmt represents a ; statement.

func (*EmptyStmt) Span

func (s *EmptyStmt) Span() scan.Span

type EnumDecl

type EnumDecl struct {
	Storage *scan.Token
	Enum    scan.Token
	Name    *Ident
	Lbrace  scan.Token
	List    []*ConstDecl
	Rbrace  scan.Token
}

EnumDecl is a enum declaration.

func (*EnumDecl) Span

func (d *EnumDecl) Span() scan.Span

type Expr

type Expr interface {
	Node
}

Expr is a expression node.

type ExprStmt

type ExprStmt struct {
	X Expr
}

ExprStmt is a wrapper for expressions that can appear as a statement. Examples include call expressions and assignment expressions.

func (*ExprStmt) Span

func (s *ExprStmt) Span() scan.Span

type FieldDecl

type FieldDecl struct {
	Type Expr
	Name *Ident
}

FieldDecl is a field declaration inside a record.

func (*FieldDecl) Span

func (d *FieldDecl) Span() scan.Span

type FieldFilter

type FieldFilter func(name string, value reflect.Value) bool

FieldFilter is a function used to filter out nodes.

type ForStmt

type ForStmt struct {
	For    scan.Token
	Lparen scan.Token
	Init   Expr
	Cond   Expr
	Post   Expr
	Rparen scan.Token
	Body   Stmt
}

ForStmt represents a for statement.

func (*ForStmt) Span

func (s *ForStmt) Span() scan.Span

type FuncDecl

type FuncDecl struct {
	Storage *scan.Token
	Result  Expr
	Name    *Ident
	Lparen  scan.Token
	Params  []*FieldDecl
	Rparen  scan.Token
	Labels  []*LabeledStmt
	Decls   []Decl
	Body    *BlockStmt
}

FuncDecl is a function declaration.

func (*FuncDecl) Span

func (d *FuncDecl) Span() scan.Span

type FuncType

type FuncType struct {
	Result Expr
	Star   scan.Token
	Params []Expr
	Lparen [2]scan.Token
	Rparen [2]scan.Token
}

FuncType represents a function pointer declaration.

func (*FuncType) Span

func (t *FuncType) Span() scan.Span

type GotoStmt

type GotoStmt struct {
	Goto  scan.Token
	Label *Ident
}

GotoStmt represents a goto statement.

func (*GotoStmt) Span

func (s *GotoStmt) Span() scan.Span

type Ident

type Ident struct {
	Pos  scanner.Position
	Name string
}

Ident represents an identifier.

func (*Ident) Span

func (e *Ident) Span() scan.Span

type IfStmt

type IfStmt struct {
	If     scan.Token
	Lparen scan.Token
	Cond   Expr
	Rparen scan.Token
	Body   Stmt
	Else   Stmt
}

IfStmt represents an if statement.

func (*IfStmt) Span

func (s *IfStmt) Span() scan.Span

type IndexExpr

type IndexExpr struct {
	X      Expr
	Lbrack scan.Token
	Index  Expr
	Rbrack scan.Token
}

IndexExpr represents an array access.

func (*IndexExpr) Span

func (e *IndexExpr) Span() scan.Span

type LabeledStmt

type LabeledStmt struct {
	Label *Ident
	Colon scan.Token
	Stmt  Stmt
}

LabeledStmt represents a labeled statement.

func (*LabeledStmt) Span

func (s *LabeledStmt) Span() scan.Span

type Node

type Node interface {
	// Span returns the beginning and end position of a node
	Span() scan.Span
}

Node is a generic interface that all AST nodes must implement.

type ParenExpr

type ParenExpr struct {
	Lparen scan.Token
	X      Expr
	Rparen scan.Token
}

ParanExpr represents a parentheses expression.

func (*ParenExpr) Span

func (e *ParenExpr) Span() scan.Span

type Prog

type Prog struct {
	Decls []Decl
}

Prog represents the top level of the AST tree, it holds all the top level declarations.

type RecordDecl

type RecordDecl struct {
	Storage *scan.Token
	Record  scan.Token
	Name    *Ident
	Lbrace  scan.Token
	Fields  []*FieldDecl
	Rbrace  scan.Token
}

RecordDecl is a struct or union declaration.

func (*RecordDecl) Span

func (d *RecordDecl) Span() scan.Span

type RecordType

type RecordType struct {
	Record scan.Token
	X      Expr
	Name   *Ident
}

RecordType represents a record declaration.

func (*RecordType) Span

func (t *RecordType) Span() scan.Span

type ReturnStmt

type ReturnStmt struct {
	Return scan.Token
	X      Expr
}

ReturnStmt represents a return statement.

func (*ReturnStmt) Span

func (s *ReturnStmt) Span() scan.Span

type SelectorExpr

type SelectorExpr struct {
	X   Expr
	Op  scan.Token
	Sel *Ident
}

SelectorExpr represents a record access using the . or -> operator.

func (*SelectorExpr) Span

func (e *SelectorExpr) Span() scan.Span

type SizeofExpr

type SizeofExpr struct {
	Sizeof scan.Token
	Lparen scan.Token
	X      Expr
	Rparen scan.Token
}

SizeofExpr represents a sizeof expression.

func (*SizeofExpr) Span

func (e *SizeofExpr) Span() scan.Span

type StarExpr

type StarExpr struct {
	Star scan.Token
	X    Expr
}

StarExpr represents a dereference expression or a pointer declaration.

func (*StarExpr) Span

func (e *StarExpr) Span() scan.Span

type Stmt

type Stmt interface {
	Node
}

Stmt is a statement node.

type StringLit

type StringLit struct {
	Lits []*BasicLit
}

StringLit represents string literals that are concatenated together. Example includes char *s = "a" "b" where "a" and "b" would be inside one StringLit.

func (StringLit) Span

func (e StringLit) Span() scan.Span

type SwitchStmt

type SwitchStmt struct {
	Switch scan.Token
	Lparen scan.Token
	Tag    Expr
	Rparen scan.Token
	Body   *BlockStmt
}

SwitchStmt represents a switch statement.

func (*SwitchStmt) Span

func (s *SwitchStmt) Span() scan.Span

type UnaryExpr

type UnaryExpr struct {
	Op    scan.Token
	Affix Affix
	X     Expr
}

UnaryExpr represents a unary expression.

func (*UnaryExpr) Span

func (e *UnaryExpr) Span() scan.Span

type VarDecl

type VarDecl struct {
	Storage *scan.Token
	Type    Expr
	Name    *Ident
	Value   Expr
}

VarDecl is a node for a variable declaration.

func (*VarDecl) Span

func (d *VarDecl) Span() scan.Span

type WhileStmt

type WhileStmt struct {
	While  scan.Token
	Lparen scan.Token
	Cond   Expr
	Rparen scan.Token
	Body   Stmt
}

WhileStmt represents a while statement.

func (*WhileStmt) Span

func (s *WhileStmt) Span() scan.Span

Jump to

Keyboard shortcuts

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