ast

package
v0.0.0-...-620ce17 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2015 License: BSD-3-Clause Imports: 0 Imported by: 2

Documentation

Overview

Package ast represents a language agnostic Abstract Syntax Tree (AST).

The aim of this package is to provide a generic syntactic representation.

Serialization Constraints

Every expression must have a field called "expression_name" that represents the type of the expression as defined by the package token. The same rules applies to statements, which must have a field "statement_name".

IMPORTANT: That field MUST be the first one of the structure. This is imperative to make the JSON decoding work. This constraint is not really convenient but necessary in order to make performance optimizations in the JSON decoding process.

For more information about how serialization work, refer to the documentation of the src package:

http://godoc.org/github.com/DevMine/srcanlzr/src

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayExpr

type ArrayExpr struct {
	ExprName string     `json:"expression_name"`
	Type     *ArrayType `json:"type"`
}

type ArrayLit

type ArrayLit struct {
	ExprName string     `json:"expression_name"`
	Type     *ArrayType `json:"type"`
	Elts     []Expr     `json:"elements"`
}

type ArrayType

type ArrayType struct {
	// Dimensions
	Dims []int64 `json:"dimensions"`

	Elt Expr `json:"element_type,omitempty"` // element type
}

type AssignStmt

type AssignStmt struct {
	StmtName string `json:"statement_name"`
	LHS      []Expr `json:"left_hand_side"`
	RHS      []Expr `json:"right_hand_side"`
	Line     int64  `json:"line"`
}

type Attr

type Attr struct {
	Var
	Constant bool `json:"constant"`
	Static   bool `json:"static"`
}

type AttrRef

type AttrRef struct {
	ExprName string `json:"expression_name"`
	Name     *Ident `json:"name"`
}

type BasicLit

type BasicLit struct {
	ExprName string `json:"expression_name"`
	Kind     string `json:"kind"`
	Value    string `json:"value"`
}

type BinaryExpr

type BinaryExpr struct {
	ExprName  string `json:"expression_name"`
	LeftExpr  Expr   `json:"left_expression,omitempty"`  // left operand
	Op        string `json:"operator"`                   // operator
	RightExpr Expr   `json:"right_expression,omitempty"` // right operand
}

type CallExpr

type CallExpr struct {
	ExprName string   `json:"expression_name"`
	Fun      *FuncRef `json:"function"`  // Reference to the function
	Args     []Expr   `json:"arguments"` // function arguments
	Line     int64    `json:"line"`      // line number
}

type CaseClause

type CaseClause struct {
	Conds []Expr `json:"conditions,omitempty"`
	Body  []Stmt `json:"body,omitempty"`
}

type CatchClause

type CatchClause struct {
	Params []*Field `json:"parameters,omitempty"`
	Body   []Stmt   `json:"body,omitempty"`
}

type ClassDecl

type ClassDecl struct {
	Doc                   []string           `json:"doc,omitempty"`
	Name                  string             `json:"name"`
	Visibility            string             `json:"visibility"`
	ExtendedClasses       []*ClassRef        `json:"extended_classes,omitempty"`
	ImplementedInterfaces []*InterfaceRef    `json:"implemented_interfaces,omitempty"`
	Attrs                 []*Attr            `json:"attributes,omitempty"`
	Constructors          []*ConstructorDecl `json:"constructors,omitempty"`
	Destructors           []*DestructorDecl  `json:"destructors,omitempty"`
	Methods               []*MethodDecl      `json:"methods,omitempty"`
	NestedClasses         []*ClassDecl       `json:"nested_classes,omitempty"`
	Mixins                []*TraitRef        `json:"mixins,omitempty"`
}

type ClassLit

type ClassLit struct {
	ExprName              string             `json:"expression_name"`
	ExtendedClasses       []*ClassRef        `json:"extended_classes,omitempty"`
	ImplementedInterfaces []*InterfaceRef    `json:"implemented_interfaces,omitempty"`
	Attrs                 []*Attr            `json:"attributes,omitempty"`
	Constructors          []*ConstructorDecl `json:"constructors,omitempty"`
	Destructors           []*DestructorDecl  `json:"destructors,omitempty"`
	Methods               []*MethodDecl      `json:"methods,omitempty"`
}

type ClassRef

type ClassRef struct {
	Namespace string `json:"namespace"`
	ClassName string `json:"class_name"`
}

type Constant

type Constant struct {
	Doc        []string `json:"doc"`
	Name       string   `json:"name"`
	Type       string   `json:"type"`  // TODO rename into TypeName or use a type Type
	Value      string   `json:"value"` // TODO use an Expr instead of string value
	IsPointer  bool     `json:"is_pointer"`
	Visibility string   `json:"visibility,omitempty"`
}

type ConstructorCallExpr

type ConstructorCallExpr struct {
	CallExpr
}

type ConstructorDecl

type ConstructorDecl struct {
	Doc        []string `json:"doc,omitempty"`
	Name       string   `json:"name"`
	Params     []*Field `json:"parameters,omitempty"`
	Body       []Stmt   `json:"body,omitempty"`
	Visibility string   `json:"visibility"`
	LoC        int64    `json:"loc"`
}

type DeclStmt

type DeclStmt struct {
	AssignStmt
	Kind string `json:"kind"`
}

type DestructorDecl

type DestructorDecl struct {
	ConstructorDecl
}

type EnumDecl

type EnumDecl struct {
	Doc                   []string           `json:"doc,omitempty"`
	Name                  string             `json:"name"`
	Visibility            string             `json:"visibility"`
	ImplementedInterfaces []*InterfaceRef    `json:"implemented_interfaces,omitempty"`
	EnumConstants         []*Ident           `json:"enum_constants,omitempty"`
	Attrs                 []*Attr            `json:"attributes,omitempty"`
	Constructors          []*ConstructorDecl `json:"constructors,omitempty"`
	Destructors           []*DestructorDecl  `json:"destructors,omitempty"`
	Methods               []*MethodDecl      `json:"methods,omitempty"`
}

type Expr

type Expr interface{}

type ExprStmt

type ExprStmt struct {
	StmtName string `json:"statement_name"`
	X        Expr   `json:"expression"` // expression
}

type Field

type Field struct {
	Doc  []string `json:"doc,omitempty"`  // associated documentation; or nil
	Name string   `json:"name,omitempty"` // name of the field; or nil
	Type string   `json:"type,omitempty"` // type of the field; or nil
}

Field represents a pair name/type.

type FuncDecl

type FuncDecl struct {
	Doc        []string  `json:"doc,omitempty"`
	Name       string    `json:"name"`
	Type       *FuncType `json:"type"`
	Body       []Stmt    `json:"body,omitempty"`
	Visibility string    `json:"visibility"`
	LoC        int64     `json:"loc"` // Lines of Code
}

type FuncLit

type FuncLit struct {
	ExprName string    `json:"expression_name"`
	Type     *FuncType `json:"type"`
	Body     []Stmt    `json:"body,omitempty"`
	LoC      int64     `json:"loc"` // Lines of Code
}

type FuncRef

type FuncRef struct {
	Namespace string `json:"namespace"`
	FuncName  string `json:"function_name"`
}

type FuncType

type FuncType struct {
	Params  []*Field `json:"parameters,omitempty"`
	Results []*Field `json:"results,omitempty"`
}

type GlobalDecl

type GlobalDecl struct {
	Doc        []string `json:"doc,omitempty"`   // associated documentation; or nil
	Name       *Ident   `json:"name"`            // name of the var, const, or type
	Value      Expr     `json:"value,omitempty"` // default value; or nil
	Type       *Ident   `json:"type,omitempty"`  // type identifier; or nil
	Visibility string   `json:"visibility"`      // visibility (see the constants for the list of supported visibilities)
}

GlobalDecl represents any declaration (var, const, type) declared outside of a function, class, trait, etc.

type Ident

type Ident struct {
	ExprName string `json:"expression_name"`
	Name     string `json:"name"`
}

type IfStmt

type IfStmt struct {
	StmtName string `json:"statement_name"`
	Init     Stmt   `json:"initialization,omitempty"`
	Cond     Expr   `json:"condition"`
	Body     []Stmt `json:"body"`
	Else     []Stmt `json:"else,omitempty"`
	Line     int64  `json:"line"` // Line number of the statement relatively to the function.
}

type IncDecExpr

type IncDecExpr struct {
	ExprName string `json:"expression_name"`
	X        Expr   `json:"operand"`
	Op       string `json:"operator"` // INC or DEC
	IsPre    bool   `json:"is_pre"`   // pre = ++i, not pre = i++
}

type IndexExpr

type IndexExpr struct {
	ExprName string `json:"expression_name"`
	X        Expr   `json:"expression,omitempty"` // expression
	Index    Expr   `json:"index,omitempty"`      // index expression
}

type Interface

type Interface struct {
	Doc                   []string        `json:"doc,omitempty"`
	Name                  string          `json:"name"`
	ImplementedInterfaces []*InterfaceRef `json:"implemented_interfaces,omitempty"`
	Protos                []*ProtoDecl    `json:"prototypes"`
	Visibility            string          `json:"visibility"`
}

type InterfaceRef

type InterfaceRef struct {
	Namespace     string `json:"namespace"`
	InterfaceName string `json:"interface_name"`
}

type KeyValuePair

type KeyValuePair struct {
	Key   Expr `json:"key"`
	Value Expr `json:"value"`
}

type ListLit

type ListLit struct {
	Type *ListType `json:"type"`
	Elts []Expr    `json:"elements"`
}

type ListType

type ListType struct {
	Len int64 `json:"length,omitempty"`
	Max int64 `json:"capacity,omitempty"` // maximum capacity
	Elt Expr  `json:"element_type"`
}

type LoopStmt

type LoopStmt struct {
	StmtName   string `json:"statement_name"`
	Init       []Stmt `json:"initialization,omitempty"`
	Cond       Expr   `json:"condition,omitempty"`
	Post       []Stmt `json:"post_iteration_statement,omitempty"`
	Body       []Stmt `json:"body"`
	Else       []Stmt `json:"else,omitempty"`
	IsPostEval bool   `json:"is_post_evaluated"`
	Line       int64  `json:"line"` // Line number of the statement relatively to the function.
}

type MapLit

type MapLit struct {
	Type *MapType        `json:"type"`
	Elts []*KeyValuePair `json:"elements"`
}

type MapType

type MapType struct {
	KeyType   Expr `json:"key_type"`
	ValueType Expr `json:"value_type"`
}

type MethodDecl

type MethodDecl struct {
	FuncDecl
	Override bool `json:"override"`
}

type OtherStmt

type OtherStmt struct {
	StmtName string `json:"statement_name"`
	Body     []Stmt `json:"body,omitempty"`
	Line     int64  `json:"line"` // Line number of the statement relatively to the function.
}

type ProtoDecl

type ProtoDecl struct {
	Doc        []string  `json:"doc"`
	Name       *Ident    `json:"name"`
	Type       *FuncType `json:"type"`
	Visibility string    `json:"visibility"`
}

Method/Function prototype declaration

type RangeLoopStmt

type RangeLoopStmt struct {
	StmtName string `json:"statement_name"`
	Vars     []Expr `json:"variables,omitempty"`
	Iterable Expr   `json:"iterable,omitempty"`
	Body     []Stmt `json:"body"`
	Line     int64  `json:"line"` // Line number of the statement relatively to the function.
}

type ReturnStmt

type ReturnStmt struct {
	StmtName string `json:"statement_name"`
	Results  []Expr `json:"results,omitempty"` // result expressions; or nil
	Line     int64  `json:"line"`
}

A ReturnStmt represents a return statement.

type Stmt

type Stmt interface{}

type StructType

type StructType struct {
	// This field is only used by the unmarshaller to "guess" the type while it
	// is unmarshalling a generic type. Since the StructType is considered as
	// an expression (which is represented by an interface{}), this is the only
	// way for the unmarshaller to know what type is it.
	//
	// The value of the ExprName for a StructType must always be "STRUCT", as
	// defined by the constant src.StructTypeName.
	ExprName string `json:"expression_name"`

	Doc    []string `json:"doc"`              // associated documentation; or nil
	Name   *Ident   `json:"name,omitempty"`   // name of the struct; or nil
	Fields []*Field `json:"fields,omitempty"` // the fields of the struct; or nil
}

StructType represents a structured type. Most of the Object Oriented languages use a Class or a Trait instead.

In Go, a StructType would be something of the form:

struct {
   Bar string
}

type SwitchStmt

type SwitchStmt struct {
	StmtName    string        `json:"statement_name"`
	Init        Stmt          `json:"initialization,omitempty"`
	Cond        Expr          `json:"condition,omitempty"` // TODO rename with a more appropriate name
	CaseClauses []*CaseClause `json:"case_clauses,omitempty"`
	Default     []Stmt        `json:"default,omitempty"`
}

type TernaryExpr

type TernaryExpr struct {
	ExprName string `json:"expression_name"`
	Cond     Expr   `json:"condition"`
	Then     Expr   `json:"then"`
	Else     Expr   `json:"else"`
}

type ThrowStmt

type ThrowStmt struct {
	StmtName string `json:"statement_name"`
	X        Expr   `json:"expression"`
}

type Trait

type Trait struct {
	Name    string        `json:"name"`
	Attrs   []*Attr       `json:"attributes"`
	Methods []*MethodDecl `json:"methods"`
	Classes []*ClassDecl  `json:"classes"`
	Traits  []*Trait      `json:"traits"`
}

type TraitRef

type TraitRef struct {
	Namespace string `json:"namespace"`
	TraitName string `json:"trait_name"`
}

type TryStmt

type TryStmt struct {
	StmtName     string         `json:"statement_name"`
	Body         []Stmt         `json:"body"`
	CatchClauses []*CatchClause `json:"catch_clauses,omitempty"`
	Finally      []Stmt         `json:"finally,omitempty"`
}

type TypeSpec

type TypeSpec struct {
	Doc  []string `json:"doc,omitempty"`  // associated documentation; or nil
	Name *Ident   `json:"name"`           // type name (in the exemple, the name is "Foo")
	Type Expr     `json:"type,omitempty"` // *Ident or any of the *XxxType; or nil
}

TypeSpec represents a type declaration. Most of the object oriented languages does not have such a node, they use classes and traits instead.

In Go, a TypeSpec would be something of the form:

type Foo struct {
   Bar string
}

type UnaryExpr

type UnaryExpr struct {
	ExprName string `json:"expression_name"`
	Op       string `json:"operator"`          // operator
	X        Expr   `json:"operand,omitempty"` // operand (XXX investigate the omitempty)
}

type ValueSpec

type ValueSpec struct {
	ExprName string `json:"expression_name"`
	Name     *Ident `json:"name"`
	Type     *Ident `json:"type"`
}

type Var

type Var struct {
	Doc        []string `json:"doc,omitempty"`
	Name       string   `json:"name"`
	Type       string   `json:"type,omitempty"`
	Value      string   `json:"value,omitempty"`
	IsPointer  bool     `json:"is_pointer"`
	Visibility string   `json:"visibility,omitempty"`
}

Jump to

Keyboard shortcuts

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