ast2

package
v3.41.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LiteralInt is a kind for integer literals in C: 42, 0x42, etc.
	LiteralInt = LiteralKind(iota)
	// LiteralFloat is a kind for float/double literals: 1.0, 1e5, etc.
	LiteralFloat
	// LiteralChar is a kind for char literals: 'a', '\n', etc.
	LiteralChar
	// LiteralWChar is a kind for long/wide char literals: L'a'.
	LiteralWChar
	// LiteralString is a kind for string literals: "abc".
	LiteralString
	// LiteralString is a kind for long/wide string literals: L"abc".
	LiteralWString
)
View Source
const (
	// UnaryPlus is a plus operator in C: +x.
	UnaryPlus = UnaryOp(iota)
	// UnaryMinus is a minus operator in C: -x.
	UnaryMinus
	// UnaryInvert is a bit inversion operator in C: ~x.
	UnaryInvert
	// UnaryNot is a not operator in C: !x.
	UnaryNot
	// UnaryAddr is a take address operator in C: &x.
	UnaryAddr
	// UnaryDeref is a pointer dereference operator in C: *x.
	UnaryDeref
)
View Source
const (
	// BinaryNone is an fake C binary operator used in assign expressions: x = y.
	BinaryNone = BinaryOp(iota)
	// BinaryAdd is an addition operator in C: x + y.
	BinaryAdd
	// BinarySub is a subtraction operator in C: x - y.
	BinarySub
	// BinaryMul is a multiplication operator in C: x * y.
	BinaryMul
	// BinaryDiv is a division operator in C: x / y.
	BinaryDiv
	// BinaryMod is a modulo operator in C: x % y.
	BinaryMod
	// BinaryLsh is a binary left shift operator in C: x << y.
	BinaryLsh
	// BinaryRsh is a binary right shift operator in C: x >> y.
	BinaryRsh
	// BinaryEqual is an equality operator in C: x == y.
	BinaryEqual
	// BinaryNotEqual is an inequality operator in C: x != y.
	BinaryNotEqual
	// BinaryLess is a less than operator in C: x < y.
	BinaryLess
	// BinaryGreater is a greater than operator in C: x > y.
	BinaryGreater
	// BinaryLessEqual is a less than or equal operator in C: x <= y.
	BinaryLessEqual
	// BinaryGreaterEqual is a greater than or equal operator in C: x >= y.
	BinaryGreaterEqual
	// BinaryAnd is a logical and operator in C: x && y.
	BinaryAnd
	// BinaryOr is a logical or operator in C: x || y.
	BinaryOr
	// BinaryBitAnd is a bit and operator in C: x & y.
	BinaryBitAnd
	// BinaryBitOr is a bit or operator in C: x | y.
	BinaryBitOr
	// BinaryBitXOr is a exclusive bit or operator in C: x ^ y.
	BinaryBitXOr
)
View Source
const (
	// IncPost is a postfix increment operator in C: x++.
	IncPost = IncDecOp(iota)
	// DecPost is a postfix decrement operator in C: x--.
	DecPost
	// IncPre is a prefix increment operator in C: ++x.
	IncPre
	// DecPre is a prefix decrement operator in C: --x.
	DecPre
)

Variables

This section is empty.

Functions

func PrintExpr

func PrintExpr(w io.Writer, e Expr) error

PrintExpr prints an expression as C code. It doesn't guarantee any specific formatting.

Types

type AssignExpr

type AssignExpr struct {
	Left  Expr
	Op    BinaryOp
	Right Expr
}

AssignExpr is an assignment expression in C: x = y, x += y, etc. It returns a value that was assigned, allowing chaining assignments: x = y = z.

func (*AssignExpr) Type

func (e *AssignExpr) Type() Type

Type implements Expr.

type BinaryExpr

type BinaryExpr struct {
	X  Expr
	Op BinaryOp
	Y  Expr
	// contains filtered or unexported fields
}

BinaryExpr is a binary expression in C: x + y, x == y, etc.

func (*BinaryExpr) Type

func (e *BinaryExpr) Type() Type

Type implements Expr.

type BinaryOp

type BinaryOp int

BinaryOp is an enum for binary operators in C.

type CallExpr

type CallExpr struct {
	Func Expr
	Args []Expr
}

CallExpr is a function call expression in C: x(a1, a2, a3).

func (*CallExpr) Type

func (e *CallExpr) Type() Type

Type implements Expr.

type CommaExpr

type CommaExpr []Expr

CommaExpr is a comma expression in C: x1, x2, ..., xN. It evaluates all expressions in order and returns the result of the last one only. Other results are discarded.

func (CommaExpr) Type

func (e CommaExpr) Type() Type

Type implements Expr.

type CondExpr

type CondExpr struct {
	Cond Expr
	Then Expr
	Else Expr
	// contains filtered or unexported fields
}

CondExpr is a conditional expression in C: x ? y : z. If condition evaluates to true, "then" expression is returned. Otherwise, the "else" expression is returned.

func (*CondExpr) Type

func (e *CondExpr) Type() Type

Type implements Expr.

type Expr

type Expr interface {

	// Type returns a type of an expression.
	Type() Type
	// contains filtered or unexported methods
}

Expr is an interface type for C expressions.

func NewExprFrom

func NewExprFrom(n cc.Node) Expr

NewExprFrom creates an Expr node from a CC AST node (*cc.Expression, *cc.PrimaryExpression, etc).

type Ident

type Ident struct {
	Name string
	// contains filtered or unexported fields
}

Ident is an identifier in C.

func NewIdent

func NewIdent(name string, typ Type) *Ident

NewIdent creates a new identifier with a given type.

func (*Ident) Type

func (e *Ident) Type() Type

Type implements Expr.

type IdentExpr

type IdentExpr struct {
	*Ident
}

IdentExpr is an identifier expression in C.

type IncDecExpr

type IncDecExpr struct {
	X  Expr
	Op IncDecOp
}

IncDecExpr is an increment/decrement expression in C: x++, ++x, x--, etc. Prefix operators first increment the value and return a modified one, while postfix variant return an old value and then increment the value.

func (*IncDecExpr) Type

func (e *IncDecExpr) Type() Type

Type implements Expr.

type IncDecOp

type IncDecOp int

IncDecOp is an enum for increment/decrement operators in C.

type IndexExpr

type IndexExpr struct {
	X   Expr
	Ind Expr
}

IndexExpr is an index expression in C: x[y]. The left operand should be either an array or a pointer.

func (*IndexExpr) Type

func (e *IndexExpr) Type() Type

Type implements Expr.

type Literal

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

Literal is a constant literal expression in C. See LiteralKind for details on specific kinds.

func (*Literal) Kind

func (e *Literal) Kind() LiteralKind

Kind returns a kind of a literal.

func (*Literal) Type

func (e *Literal) Type() Type

Type implements Expr.

func (*Literal) Value

func (e *Literal) Value() string

Kind returns a literal value.

type LiteralKind

type LiteralKind int

LiteralKind is an enum for literal kinds in C.

type ParenExpr

type ParenExpr struct {
	X Expr
}

ParenExpr is a parentheses expression in C: (x). It returns the expression value without changes. Used primarily to control evaluation order in binary expressions.

func (*ParenExpr) Type

func (e *ParenExpr) Type() Type

Type implements Expr.

type SelectExpr

type SelectExpr struct {
	X   Expr
	Sel *Ident
	Ptr bool
}

SelectExpr is field select expression in C: x.y, x->y.

func (*SelectExpr) Type

func (e *SelectExpr) Type() Type

Type implements Expr.

type Type

type Type = cc.Type

type UnaryExpr

type UnaryExpr struct {
	Op UnaryOp
	X  Expr
	// contains filtered or unexported fields
}

UnaryExpr is an unary expression in C: !x, *x, etc.

func (*UnaryExpr) Type

func (e *UnaryExpr) Type() Type

Type implements Expr.

type UnaryOp

type UnaryOp int

UnaryOp is an enum for unary operators in C.

Jump to

Keyboard shortcuts

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