cc

package module
v5.0.0-...-c840d7a Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Overview

Package cc is a C99 compiler front end.

Online documentation

See https://godoc.org/modernc.org/cc/v4.

Index

Examples

Constants

View Source
const (
	BinaryOperationAdd = BinaryOperation(iota + 1)
	BinaryOperationSub
	BinaryOperationMul
	BinaryOperationDiv
	BinaryOperationMod
	BinaryOperationOr
	BinaryOperationAnd
	BinaryOperationXor
	BinaryOperationLsh
	BinaryOperationRsh
	BinaryOperationEq
	BinaryOperationNeq
	BinaryOperationLt
	BinaryOperationGt
	BinaryOperationLeq
	BinaryOperationGeq
	BinaryOperationLOr
	BinaryOperationLAnd
)
View Source
const (
	AssignmentOperationAssign = AssignmentOperation(iota)
	AssignmentOperationMul
	AssignmentOperationDiv
	AssignmentOperationMod
	AssignmentOperationAdd
	AssignmentOperationSub
	AssignmentOperationLsh
	AssignmentOperationRsh
	AssignmentOperationAnd
	AssignmentOperationXor
	AssignmentOperationOr
)
View Source
const (
	DmesgsFile = "/tmp/cc.log"

	// Builtin definitions used by package tests. Possibly usable also by consumers
	// of this package.
	Builtin = `` /* 8310-byte string literal not displayed */

)
View Source
const (
	ADDASSIGN         tokCh // '+='
	ALIGNAS                 // '_Alignas'
	ALIGNOF                 // '_Alignof'
	ANDAND                  // '&&'
	ANDASSIGN               // '&='
	ARROW                   // '->'
	ASM                     // '__asm__'
	ATOMIC                  // '_Atomic'
	ATTRIBUTE               // '__attribute__'
	AUTO                    // 'auto'
	AUTOTYPE                // '__auto_type'
	BOOL                    // '_Bool'
	BREAK                   // 'break'
	CASE                    // 'case'
	CHAR                    // 'char'
	CHARCONST               // character constant
	COMPLEX                 // '_Complex'
	CONST                   // 'const'
	CONTINUE                // 'continue'
	DDD                     // '...'
	DEC                     // '--'
	DECIMAL128              // '_Decimal128'
	DECIMAL32               // '_Decimal32'
	DECIMAL64               // '_Decimal64'
	DECLSPEC                // '__declspec'
	DEFAULT                 // 'default'
	DIVASSIGN               // '/='
	DO                      // 'do'
	DOUBLE                  // 'double'
	ELSE                    // 'else'
	ENUM                    // 'enum'
	EQ                      // '=='
	EXTERN                  // 'extern'
	FLOAT                   // 'float'
	FLOAT128                // '_Float128'
	FLOAT128X               // '_Float128x'
	FLOAT16                 // '_Float16'
	FLOAT32                 // '_Float32'
	FLOAT32X                // '_Float32x'
	FLOAT64                 // '_Float64'
	FLOAT64X                // '_Float64x'
	FLOATCONST              // floating point constant
	FOR                     // 'for'
	GENERIC                 // '_Generic'
	GEQ                     // '>='
	GOTO                    // 'goto'
	HEADER_NAME             // <header-name>
	IDENTIFIER              // identifier
	IF                      // 'if'
	IMAG                    // '__imag__'
	IMAGINARY               // '_Imaginary'
	INC                     // '++'
	INLINE                  // 'inline'
	INT                     // 'int'
	INT8                    // '__int8'
	INT16                   // '__int16'
	INT32                   // '__int32'
	INT64                   // '__int64'
	INT128                  // '__int128'
	INTCONST                // integer constant
	LABEL                   // '__label__'
	LEQ                     // '<='
	LONG                    // 'long'
	LONGCHARCONST           // long character constant
	LONGSTRINGLITERAL       // long string literal
	LSH                     // '<<'
	LSHASSIGN               // '<<='
	MODASSIGN               // '%='
	MULASSIGN               // '*='
	NEQ                     // '!='
	NONNULL                 // '_Nonnull'
	NORETURN                // '_Noreturn'
	ORASSIGN                // '|='
	OROR                    // '||'
	PPNUMBER                // preprocessing number
	PPPASTE                 // '##'
	REAL                    // '__real__'
	REGISTER                // 'register'
	RESTRICT                // 'restrict'
	RETURN                  // 'return'
	RSH                     // '>>'
	RSHASSIGN               // '>>='
	SHORT                   // 'short'
	SIGNED                  // 'signed'
	SIZEOF                  // 'sizeof'
	STATIC                  // 'static'
	STATICASSERT            // _Static_assert
	STRINGLITERAL           // string literal
	STRUCT                  // 'struct'
	SUBASSIGN               // '-='
	SWITCH                  // 'switch'
	THREADLOCAL             // '_Thread_local'
	TYPEDEF                 // 'typedef'
	TYPENAME                // type name
	TYPEOF                  // 'typeof'
	UINT8                   // '__uint8_t'
	UINT16                  // '__uint16_t'
	UINT32                  // '__uint32_t'
	UINT64                  // '__uint64_t'
	UINT128                 // '__uint128_t'
	UNION                   // 'union'
	UNSIGNED                // 'unsigned'
	VOID                    // 'void'
	VOLATILE                // 'volatile'
	WHILE                   // 'while'
	XORASSIGN               // '^='
)

Values of Token.Rune representing non-character categories.

View Source
const Dmesgs = false

Variables

This section is empty.

Functions

func Dmesg

func Dmesg(s string, args ...interface{})

Dmesg does nothing. To enable use -tags=cc.dmesg. Cannot be enabled on Windows.

func IsArithmeticType

func IsArithmeticType(t Type) bool

IsArithmeticType reports whether t is an arithmetic type.

func IsComplexType

func IsComplexType(t Type) bool

IsComplexType reports whether t is a complex type.

func IsFloatingPointType

func IsFloatingPointType(t Type) bool

IsFloatingPointType reports whether t is a floating point type.

func IsIntegerType

func IsIntegerType(t Type) bool

IsIntegerType reports whether t is an integer type.

func IsRealType

func IsRealType(t Type) bool

IsRealType reports whether t is a real type.

func IsScalarType

func IsScalarType(t Type) bool

IsScalarType reports whether t is a scalar type.

func IsSignedInteger

func IsSignedInteger(t Type) bool

IsSignedInteger reports whether t is a signed integer type.

func LongDouble64Flag

func LongDouble64Flag(os, arch string) string

LongDouble64Flag returns the C compiler flag that switches long double to 64 bits, if any.

func NodeSource

func NodeSource(s ...Node) string

NodeSource returns the source form of s. Non-empty separators between tokens are replaced by a single ' '.

func Preprocess

func Preprocess(cfg *Config, sources []Source, w io.Writer) (err error)

Preprocess preprocesses a translation unit, consisting of inputs in sources, and writes the result to w.

func PrettyString

func PrettyString(v interface{}) string

PrettyString returns a formatted representation of Tokens and AST nodes.

Types

type ABI

type ABI struct {
	ByteOrder binary.ByteOrder

	Types map[Kind]AbiType

	SignedChar bool
	// contains filtered or unexported fields
}

ABI describes selected parts of the Application Binary Interface.

func NewABI

func NewABI(os, arch string) (*ABI, error)

NewABI creates an ABI based on the os+arch pair.

type AST

type AST struct {
	ABI          *ABI
	Char         Type // Valid only after Translate
	Double       Type // Valid only after Translate
	EOF          Token
	Float        Type // Valid only after Translate
	Int          Type // Valid only after Translate
	Long         Type // Valid only after Translate
	LongDouble   Type // Valid only after Translate
	LongLong     Type // Valid only after Translate
	Macros       map[string]*Macro
	PVoid        Type   // Valid only after Translate
	SChar        Type   // Valid only after Translate
	Scope        *Scope // File scope.
	SizeT        Type   // Valid only after Translate
	Declarations []ExternalDeclaration
	UChar        Type // Valid only after Translate
	UInt         Type // Valid only after Translate
	ULong        Type // Valid only after Translate
	ULongLong    Type // Valid only after Translate
	Void         Type // Valid only after Translate
	// contains filtered or unexported fields
}

func Parse

func Parse(cfg *Config, sources []Source) (*AST, error)

Parse preprocesses and parses a translation unit, consisting of inputs in sources.

func Translate

func Translate(cfg *Config, sources []Source) (*AST, error)

Translate preprocesses, parses and type checks a translation unit, consisting of inputs in sources.

func (*AST) Position

func (n *AST) Position() (r token.Position)

Position reports the position of the first component of n, if available.

type AbiType

type AbiType struct {
	Size       int64
	Align      int
	FieldAlign int
}

type AbstractDeclarator

type AbstractDeclarator struct {
	Case                     AbstractDeclaratorCase `PrettyPrint:"stringer,zero"`
	DirectAbstractDeclarator *DirectAbstractDeclarator
	Pointer                  *Pointer
	// contains filtered or unexported fields
}

AbstractDeclarator represents data reduced by productions:

AbstractDeclarator:
        Pointer                           // Case AbstractDeclaratorPtr
|       Pointer DirectAbstractDeclarator  // Case AbstractDeclaratorDecl
Example (Decl)
fmt.Println(exampleAST(196, "void f(int());"))
Output:

&cc.AbstractDeclarator{
· Case: AbstractDeclaratorDecl,
· DirectAbstractDeclarator: &cc.DirectAbstractDeclarator{
· · Case: DirectAbstractDeclaratorFunc,
· · Token: example.c:1:11: '(' "(",
· · Token2: example.c:1:12: ')' ")",
· },
}
Example (Ptr)
fmt.Println(exampleAST(195, "void f(int*);"))
Output:

&cc.AbstractDeclarator{
· Case: AbstractDeclaratorPtr,
· Pointer: &cc.Pointer{
· · Case: PointerTypeQual,
· · Token: example.c:1:11: '*' "*",
· },
}

func (*AbstractDeclarator) Position

func (n *AbstractDeclarator) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AbstractDeclarator) String

func (n *AbstractDeclarator) String() string

String implements fmt.Stringer.

func (AbstractDeclarator) Type

func (t AbstractDeclarator) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

type AbstractDeclaratorCase

type AbstractDeclaratorCase int

AbstractDeclaratorCase represents case numbers of production AbstractDeclarator

const (
	AbstractDeclaratorPtr AbstractDeclaratorCase = iota
	AbstractDeclaratorDecl
)

Values of type AbstractDeclaratorCase

func (AbstractDeclaratorCase) String

func (n AbstractDeclaratorCase) String() string

String implements fmt.Stringer

type AlignOfExpr

type AlignOfExpr struct {
	Token Token
	Expr  Expression
	// contains filtered or unexported fields
}
Example (AlignofExpr)
fmt.Println(exampleAST(38, "int i = _Alignof(x);"))
Output:

&cc.AlignOfExpr{
· Token: example.c:1:9: '_Alignof' "_Alignof",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionExpr,
· · ExpressionList: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:18: identifier "x",
· · },
· · Token: example.c:1:17: '(' "(",
· · Token2: example.c:1:19: ')' ")",
· },
}

func (*AlignOfExpr) Position

func (n *AlignOfExpr) Position() (r token.Position)

func (*AlignOfExpr) String

func (n *AlignOfExpr) String() string

String implements fmt.Stringer.

func (AlignOfExpr) Type

func (t AlignOfExpr) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (AlignOfExpr) Value

func (v AlignOfExpr) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type AlignOfTypeExpr

type AlignOfTypeExpr struct {
	Token      Token
	LeftParen  Token
	TypeName   *TypeName
	RightParen Token
	// contains filtered or unexported fields
}
Example (AlignofType)
fmt.Println(exampleAST(39, "int i = _Alignof(int);"))
Output:

&cc.AlignOfTypeExpr{
· Token: example.c:1:9: '_Alignof' "_Alignof",
· LeftParen: example.c:1:17: '(' "(",
· TypeName: &cc.TypeName{
· · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · 0: &cc.TypeSpecName{
· · · · Case: TypeSpecifierInt,
· · · · Name: example.c:1:18: 'int' "int",
· · · },
· · },
· },
· RightParen: example.c:1:21: ')' ")",
}

func (*AlignOfTypeExpr) Position

func (n *AlignOfTypeExpr) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AlignOfTypeExpr) String

func (n *AlignOfTypeExpr) String() string

String implements fmt.Stringer.

func (AlignOfTypeExpr) Type

func (t AlignOfTypeExpr) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (AlignOfTypeExpr) Value

func (v AlignOfTypeExpr) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type AlignmentSpecifier

type AlignmentSpecifier struct {
	Case       AlignmentSpecifierCase `PrettyPrint:"stringer,zero"`
	Expression Expression
	Token      Token
	Token2     Token
	Token3     Token
	TypeName   *TypeName
}

AlignmentSpecifier represents data reduced by productions:

AlignmentSpecifier:
        "_Alignas" '(' TypeName ')'            // Case AlignmentSpecifierType
|       "_Alignas" '(' ConstantExpression ')'  // Case AlignmentSpecifierExpr
Example (AlignSpec)
fmt.Println(exampleAST(150, "struct {_Alignas(double) int i;};"))
Output:

&cc.AlignmentSpecifier{
· Case: AlignmentSpecifierType,
· Token: example.c:1:9: '_Alignas' "_Alignas",
· Token2: example.c:1:17: '(' "(",
· Token3: example.c:1:24: ')' ")",
· TypeName: &cc.TypeName{
· · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · 0: &cc.TypeSpecName{
· · · · Case: TypeSpecifierDouble,
· · · · Name: example.c:1:18: 'double' "double",
· · · },
· · },
· },
}
Example (Expr)
fmt.Println(exampleAST(172, "_Alignas(0ll) char c;"))
Output:

&cc.AlignmentSpecifier{
· Case: AlignmentSpecifierExpr,
· Expression: &cc.ConstantExpression{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:10: integer constant "0ll",
· · },
· },
· Token: example.c:1:1: '_Alignas' "_Alignas",
· Token2: example.c:1:9: '(' "(",
· Token3: example.c:1:13: ')' ")",
}
Example (Type)
fmt.Println(exampleAST(171, "_Alignas(double) char c;"))
Output:

&cc.AlignmentSpecifier{
· Case: AlignmentSpecifierType,
· Token: example.c:1:1: '_Alignas' "_Alignas",
· Token2: example.c:1:9: '(' "(",
· Token3: example.c:1:16: ')' ")",
· TypeName: &cc.TypeName{
· · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · 0: &cc.TypeSpecName{
· · · · Case: TypeSpecifierDouble,
· · · · Name: example.c:1:10: 'double' "double",
· · · },
· · },
· },
}

func (*AlignmentSpecifier) Position

func (n *AlignmentSpecifier) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AlignmentSpecifier) String

func (n *AlignmentSpecifier) String() string

String implements fmt.Stringer.

type AlignmentSpecifierCase

type AlignmentSpecifierCase int

AlignmentSpecifierCase represents case numbers of production AlignmentSpecifier

const (
	AlignmentSpecifierType AlignmentSpecifierCase = iota
	AlignmentSpecifierExpr
)

Values of type AlignmentSpecifierCase

func (AlignmentSpecifierCase) String

func (n AlignmentSpecifierCase) String() string

String implements fmt.Stringer

type ArgumentExpressionList

type ArgumentExpressionList struct {
	ArgumentExpressionList *ArgumentExpressionList
	Expression             Expression
	Token                  Token
}

ArgumentExpressionList represents data reduced by productions:

ArgumentExpressionList:
        AssignmentExpression
|       ArgumentExpressionList ',' AssignmentExpression
Example (Case0)
fmt.Println(exampleAST(24, "int i = f(x);"))
Output:

&cc.ArgumentExpressionList{
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
}
Example (Case1)
fmt.Println(exampleAST(25, "int i = f(x, y);"))
Output:

&cc.ArgumentExpressionList{
· ArgumentExpressionList: &cc.ArgumentExpressionList{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:14: identifier "y",
· · },
· · Token: example.c:1:12: ',' ",",
· },
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
}

func (*ArgumentExpressionList) Position

func (n *ArgumentExpressionList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*ArgumentExpressionList) String

func (n *ArgumentExpressionList) String() string

String implements fmt.Stringer.

type ArrayType

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

func (*ArrayType) Align

func (n *ArrayType) Align() int

Align implements Type.

func (ArrayType) Attributes

func (n ArrayType) Attributes() *Attributes

Attributes implemets Type.

func (*ArrayType) Decay

func (n *ArrayType) Decay() Type

Decay implements Type.

func (*ArrayType) Elem

func (n *ArrayType) Elem() Type

Elem reports the element type of n.

func (*ArrayType) FieldAlign

func (n *ArrayType) FieldAlign() int

FieldAlign implements Type.

func (*ArrayType) IsCompatible

func (n *ArrayType) IsCompatible(t Type) bool

func (*ArrayType) IsIncomplete

func (n *ArrayType) IsIncomplete() bool

IsIncomplete implements Type.

func (*ArrayType) IsVLA

func (n *ArrayType) IsVLA() bool

func (*ArrayType) Kind

func (n *ArrayType) Kind() Kind

Kind implements Type.

func (*ArrayType) Len

func (n *ArrayType) Len() int64

Len reports the number of elements in n or a negative value if n is incomplete.

func (*ArrayType) Pointer

func (n *ArrayType) Pointer() Type

Pointer implements Type.

func (*ArrayType) Size

func (n *ArrayType) Size() int64

Size implements Type.

func (*ArrayType) String

func (n *ArrayType) String() string

String implements Type.

func (ArrayType) Typedef

func (n ArrayType) Typedef() *Declarator

Typedef implements Type

func (*ArrayType) Undecay

func (n *ArrayType) Undecay() Type

Undecay implements Type.

func (ArrayType) VectorSize

func (ArrayType) VectorSize() int64

VectorSize implements Type.

type Asm

type Asm struct {
	AsmArgList       *AsmArgList
	AsmQualifierList *AsmQualifierList
	Token            Token
	Token2           Token
	Token3           Token
	Token4           Token
}

Asm represents data reduced by production:

Asm:
        "__asm__" AsmQualifierList '(' STRINGLITERAL AsmArgList ')'
Example (Case0)
fmt.Println(exampleAST(260, "__asm__(\"nop\");"))
Output:

&cc.Asm{
· Token: example.c:1:1: '__asm__' "__asm__",
· Token2: example.c:1:8: '(' "(",
· Token3: example.c:1:9: string literal "\"nop\"",
· Token4: example.c:1:14: ')' ")",
}

func (*Asm) Position

func (n *Asm) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*Asm) String

func (n *Asm) String() string

String implements fmt.Stringer.

type AsmArgList

type AsmArgList struct {
	AsmArgList        *AsmArgList
	AsmExpressionList *AsmExpressionList
	Token             Token
}

AsmArgList represents data reduced by productions:

AsmArgList:
        ':' AsmExpressionList
|       AsmArgList ':' AsmExpressionList
Example (Case0)
fmt.Println(exampleAST(258, "__asm__(\"nop\": a);"))
Output:

&cc.AsmArgList{
· AsmExpressionList: &cc.AsmExpressionList{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:16: identifier "a",
· · },
· },
· Token: example.c:1:14: ':' ":",
}
Example (Case1)
fmt.Println(exampleAST(259, "__asm__(\"nop\": a : b);"))
Output:

&cc.AsmArgList{
· AsmArgList: &cc.AsmArgList{
· · AsmExpressionList: &cc.AsmExpressionList{
· · · Expression: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:20: identifier "b",
· · · },
· · },
· · Token: example.c:1:18: ':' ":",
· },
· AsmExpressionList: &cc.AsmExpressionList{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:16: identifier "a",
· · },
· },
· Token: example.c:1:14: ':' ":",
}

func (*AsmArgList) Position

func (n *AsmArgList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AsmArgList) String

func (n *AsmArgList) String() string

String implements fmt.Stringer.

type AsmExpressionList

type AsmExpressionList struct {
	AsmExpressionList *AsmExpressionList
	AsmIndex          *AsmIndex
	Expression        Expression
	Token             Token
}

AsmExpressionList represents data reduced by productions:

AsmExpressionList:
        AsmIndex AssignmentExpression
|       AsmExpressionList ',' AsmIndex AssignmentExpression
Example (Case0)
fmt.Println(exampleAST(256, "__asm__(\"nop\": a);"))
Output:

&cc.AsmExpressionList{
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:16: identifier "a",
· },
}
Example (Case1)
fmt.Println(exampleAST(257, "__asm__(\"nop\": a, b);"))
Output:

&cc.AsmExpressionList{
· AsmExpressionList: &cc.AsmExpressionList{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:19: identifier "b",
· · },
· · Token: example.c:1:17: ',' ",",
· },
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:16: identifier "a",
· },
}

func (*AsmExpressionList) Position

func (n *AsmExpressionList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AsmExpressionList) String

func (n *AsmExpressionList) String() string

String implements fmt.Stringer.

type AsmIndex

type AsmIndex struct {
	ExpressionList Expression
	Token          Token
	Token2         Token
}

AsmIndex represents data reduced by production:

AsmIndex:
        '[' ExpressionList ']'
Example (Case0)
fmt.Println(exampleAST(255, "__asm__(\"nop\": [a] b);"))
Output:

&cc.AsmIndex{
· ExpressionList: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:17: identifier "a",
· },
· Token: example.c:1:16: '[' "[",
· Token2: example.c:1:18: ']' "]",
}

func (*AsmIndex) Position

func (n *AsmIndex) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AsmIndex) String

func (n *AsmIndex) String() string

String implements fmt.Stringer.

type AsmQualifier

type AsmQualifier struct {
	Case  AsmQualifierCase `PrettyPrint:"stringer,zero"`
	Token Token
}

AsmQualifier represents data reduced by productions:

AsmQualifier:
        "volatile"  // Case AsmQualifierVolatile
|       "inline"    // Case AsmQualifierInline
|       "goto"      // Case AsmQualifierGoto
Example (Goto)
fmt.Println(exampleAST(264, "__asm__ goto (\"nop\");"))
Output:

&cc.AsmQualifier{
· Case: AsmQualifierGoto,
· Token: example.c:1:9: 'goto' "goto",
}
Example (Inline)
fmt.Println(exampleAST(263, "__asm__ inline (\"nop\");"))
Output:

&cc.AsmQualifier{
· Case: AsmQualifierInline,
· Token: example.c:1:9: 'inline' "inline",
}
Example (Volatile)
fmt.Println(exampleAST(262, "__asm__ volatile (\"nop\");"))
Output:

&cc.AsmQualifier{
· Case: AsmQualifierVolatile,
· Token: example.c:1:9: 'volatile' "volatile",
}

func (*AsmQualifier) Position

func (n *AsmQualifier) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AsmQualifier) String

func (n *AsmQualifier) String() string

String implements fmt.Stringer.

type AsmQualifierCase

type AsmQualifierCase int

AsmQualifierCase represents case numbers of production AsmQualifier

const (
	AsmQualifierVolatile AsmQualifierCase = iota
	AsmQualifierInline
	AsmQualifierGoto
)

Values of type AsmQualifierCase

func (AsmQualifierCase) String

func (n AsmQualifierCase) String() string

String implements fmt.Stringer

type AsmQualifierList

type AsmQualifierList struct {
	AsmQualifier     *AsmQualifier
	AsmQualifierList *AsmQualifierList
}

AsmQualifierList represents data reduced by productions:

AsmQualifierList:
        AsmQualifier
|       AsmQualifierList AsmQualifier
Example (Case0)
fmt.Println(exampleAST(265, "__asm__ inline (\"nop\");"))
Output:

&cc.AsmQualifierList{
· AsmQualifier: &cc.AsmQualifier{
· · Case: AsmQualifierInline,
· · Token: example.c:1:9: 'inline' "inline",
· },
}
Example (Case1)
fmt.Println(exampleAST(266, "__asm__ inline volatile (\"nop\");"))
Output:

&cc.AsmQualifierList{
· AsmQualifier: &cc.AsmQualifier{
· · Case: AsmQualifierInline,
· · Token: example.c:1:9: 'inline' "inline",
· },
· AsmQualifierList: &cc.AsmQualifierList{
· · AsmQualifier: &cc.AsmQualifier{
· · · Case: AsmQualifierVolatile,
· · · Token: example.c:1:16: 'volatile' "volatile",
· · },
· },
}

func (*AsmQualifierList) Position

func (n *AsmQualifierList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AsmQualifierList) String

func (n *AsmQualifierList) String() string

String implements fmt.Stringer.

type AsmStatement

type AsmStatement struct {
	Asm   *Asm
	Token Token
}

AsmStatement represents data reduced by production:

AsmStatement:
        Asm ';'
Example (Case0)
fmt.Println(exampleAST(261, "void f() { __asm__(\"nop\"); }"))
Output:

&cc.AsmStatement{
· Asm: &cc.Asm{
· · Token: example.c:1:12: '__asm__' "__asm__",
· · Token2: example.c:1:19: '(' "(",
· · Token3: example.c:1:20: string literal "\"nop\"",
· · Token4: example.c:1:25: ')' ")",
· },
· Token: example.c:1:26: ';' ";",
}

func (*AsmStatement) Position

func (n *AsmStatement) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AsmStatement) String

func (n *AsmStatement) String() string

String implements fmt.Stringer.

type AssignmentExpression

type AssignmentExpression struct {
	Lhs   Expression
	Op    AssignmentOperation `PrettyPrint:"stringer,zero"`
	Token Token
	Rhs   Expression
	// contains filtered or unexported fields
}

AssignmentExpression represents data reduced by productions:

AssignmentExpression:
        ConditionalExpression                       // Case AssignmentExpressionCond
|       UnaryExpression '=' AssignmentExpression    // Case AssignmentExpressionAssign
|       UnaryExpression "*=" AssignmentExpression   // Case AssignmentExpressionMul
|       UnaryExpression "/=" AssignmentExpression   // Case AssignmentExpressionDiv
|       UnaryExpression "%=" AssignmentExpression   // Case AssignmentExpressionMod
|       UnaryExpression "+=" AssignmentExpression   // Case AssignmentExpressionAdd
|       UnaryExpression "-=" AssignmentExpression   // Case AssignmentExpressionSub
|       UnaryExpression "<<=" AssignmentExpression  // Case AssignmentExpressionLsh
|       UnaryExpression ">>=" AssignmentExpression  // Case AssignmentExpressionRsh
|       UnaryExpression "&=" AssignmentExpression   // Case AssignmentExpressionAnd
|       UnaryExpression "^=" AssignmentExpression   // Case AssignmentExpressionXor
|       UnaryExpression "|=" AssignmentExpression   // Case AssignmentExpressionOr
Example (Add)
fmt.Println(exampleAST(79, "int f() { x += y; }"))
Output:

&cc.AssignmentExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
· Op: AssignmentOperationAdd,
· Token: example.c:1:13: '+=' "+=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:16: identifier "y",
· },
}
Example (And)
fmt.Println(exampleAST(83, "int f() { x &= y; }"))
Output:

&cc.AssignmentExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
· Op: AssignmentOperationAnd,
· Token: example.c:1:13: '&=' "&=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:16: identifier "y",
· },
}
Example (Assign)
fmt.Println(exampleAST(75, "int f() { x = y; }"))
Output:

&cc.AssignmentExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
· Op: AssignmentOperationAssign,
· Token: example.c:1:13: '=' "=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:15: identifier "y",
· },
}
Example (Div)
fmt.Println(exampleAST(77, "int f() { x /= y; }"))
Output:

&cc.AssignmentExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
· Op: AssignmentOperationDiv,
· Token: example.c:1:13: '/=' "/=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:16: identifier "y",
· },
}
Example (Lsh)
fmt.Println(exampleAST(81, "int f() { x <<= y; }"))
Output:

&cc.AssignmentExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
· Op: AssignmentOperationLsh,
· Token: example.c:1:13: '<<=' "<<=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:17: identifier "y",
· },
}
Example (Mod)
fmt.Println(exampleAST(78, "int f() { x %= y; }"))
Output:

&cc.AssignmentExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
· Op: AssignmentOperationMod,
· Token: example.c:1:13: '%=' "%=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:16: identifier "y",
· },
}
Example (Mul)
fmt.Println(exampleAST(76, "int f() { x *= y; }"))
Output:

&cc.AssignmentExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
· Op: AssignmentOperationMul,
· Token: example.c:1:13: '*=' "*=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:16: identifier "y",
· },
}
Example (Or)
fmt.Println(exampleAST(85, "int f() { x |= y; }"))
Output:

&cc.AssignmentExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
· Op: AssignmentOperationOr,
· Token: example.c:1:13: '|=' "|=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:16: identifier "y",
· },
}
Example (Rsh)
fmt.Println(exampleAST(82, "int f() { x >>= y; }"))
Output:

&cc.AssignmentExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
· Op: AssignmentOperationRsh,
· Token: example.c:1:13: '>>=' ">>=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:17: identifier "y",
· },
}
Example (Sub)
fmt.Println(exampleAST(80, "int f() { x -= y; }"))
Output:

&cc.AssignmentExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
· Op: AssignmentOperationSub,
· Token: example.c:1:13: '-=' "-=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:16: identifier "y",
· },
}
Example (Xor)
fmt.Println(exampleAST(84, "int f() { x ^= y; }"))
Output:

&cc.AssignmentExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
· Op: AssignmentOperationXor,
· Token: example.c:1:13: '^=' "^=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:16: identifier "y",
· },
}

func (*AssignmentExpression) Position

func (n *AssignmentExpression) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AssignmentExpression) String

func (n *AssignmentExpression) String() string

String implements fmt.Stringer.

func (AssignmentExpression) Type

func (t AssignmentExpression) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (AssignmentExpression) Value

func (v AssignmentExpression) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type AssignmentOperation

type AssignmentOperation int

func (AssignmentOperation) String

func (i AssignmentOperation) String() string

type AtomicTypeSpecifier

type AtomicTypeSpecifier struct {
	Token    Token
	Token2   Token
	Token3   Token
	TypeName *TypeName
}

AtomicTypeSpecifier represents data reduced by production:

AtomicTypeSpecifier:
        "_Atomic" '(' TypeName ')'
Example (Case0)
fmt.Println(exampleAST(161, "_Atomic(int) i;"))
Output:

&cc.AtomicTypeSpecifier{
· Token: example.c:1:1: '_Atomic' "_Atomic",
· Token2: example.c:1:8: '(' "(",
· Token3: example.c:1:12: ')' ")",
· TypeName: &cc.TypeName{
· · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · 0: &cc.TypeSpecName{
· · · · Case: TypeSpecifierInt,
· · · · Name: example.c:1:9: 'int' "int",
· · · },
· · },
· },
}

func (*AtomicTypeSpecifier) Position

func (n *AtomicTypeSpecifier) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AtomicTypeSpecifier) String

func (n *AtomicTypeSpecifier) String() string

String implements fmt.Stringer.

type AttributeSpecifier

type AttributeSpecifier struct {
	AttributeValueList *AttributeValueList
	Token              Token
	Token2             Token
	Token3             Token
	Token4             Token
	Token5             Token
}

AttributeSpecifier represents data reduced by production:

AttributeSpecifier:
        "__attribute__" '(' '(' AttributeValueList ')' ')'
Example (Case0)
fmt.Println(exampleAST(271, "int i __attribute__((a));"))
Output:

&cc.AttributeSpecifier{
· AttributeValueList: &cc.AttributeValueList{
· · AttributeValue: &cc.AttributeValue{
· · · Case: AttributeValueIdent,
· · · Token: example.c:1:22: identifier "a",
· · },
· },
· Token: example.c:1:7: '__attribute__' "__attribute__",
· Token2: example.c:1:20: '(' "(",
· Token3: example.c:1:21: '(' "(",
· Token4: example.c:1:23: ')' ")",
· Token5: example.c:1:24: ')' ")",
}
Example (Case1)
fmt.Println(exampleAST(272, "int i __attribute__((a));"))
Output:

&cc.AttributeSpecifier{
· AttributeValueList: &cc.AttributeValueList{
· · AttributeValue: &cc.AttributeValue{
· · · Case: AttributeValueIdent,
· · · Token: example.c:1:22: identifier "a",
· · },
· },
· Token: example.c:1:7: '__attribute__' "__attribute__",
· Token2: example.c:1:20: '(' "(",
· Token3: example.c:1:21: '(' "(",
· Token4: example.c:1:23: ')' ")",
· Token5: example.c:1:24: ')' ")",
}
Example (Case2)
fmt.Println(exampleAST(273, "int i __attribute__((a)) __attribute__((b));"))
Output:

&cc.AttributeSpecifier{
· AttributeValueList: &cc.AttributeValueList{
· · AttributeValue: &cc.AttributeValue{
· · · Case: AttributeValueIdent,
· · · Token: example.c:1:22: identifier "a",
· · },
· },
· Token: example.c:1:7: '__attribute__' "__attribute__",
· Token2: example.c:1:20: '(' "(",
· Token3: example.c:1:21: '(' "(",
· Token4: example.c:1:23: ')' ")",
· Token5: example.c:1:24: ')' ")",
}
&cc.AttributeSpecifier{
· AttributeValueList: &cc.AttributeValueList{
· · AttributeValue: &cc.AttributeValue{
· · · Case: AttributeValueIdent,
· · · Token: example.c:1:41: identifier "b",
· · },
· },
· Token: example.c:1:26: '__attribute__' "__attribute__",
· Token2: example.c:1:39: '(' "(",
· Token3: example.c:1:40: '(' "(",
· Token4: example.c:1:42: ')' ")",
· Token5: example.c:1:43: ')' ")",
}

func (*AttributeSpecifier) Position

func (n *AttributeSpecifier) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AttributeSpecifier) String

func (n *AttributeSpecifier) String() string

String implements fmt.Stringer.

type AttributeValue

type AttributeValue struct {
	ArgumentExpressionList *ArgumentExpressionList
	Case                   AttributeValueCase `PrettyPrint:"stringer,zero"`
	Token                  Token
	Token2                 Token
	Token3                 Token
}

AttributeValue represents data reduced by productions:

AttributeValue:
        IDENTIFIER                                 // Case AttributeValueIdent
|       IDENTIFIER '(' ArgumentExpressionList ')'  // Case AttributeValueExpr
Example (Expr)
fmt.Println(exampleAST(268, "int i __attribute__((a(b)));"))
Output:

&cc.AttributeValue{
· ArgumentExpressionList: &cc.ArgumentExpressionList{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:24: identifier "b",
· · },
· },
· Case: AttributeValueExpr,
· Token: example.c:1:22: identifier "a",
· Token2: example.c:1:23: '(' "(",
· Token3: example.c:1:25: ')' ")",
}
Example (Ident)
fmt.Println(exampleAST(267, "int i __attribute__((a));"))
Output:

&cc.AttributeValue{
· Case: AttributeValueIdent,
· Token: example.c:1:22: identifier "a",
}

func (*AttributeValue) Position

func (n *AttributeValue) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AttributeValue) String

func (n *AttributeValue) String() string

String implements fmt.Stringer.

type AttributeValueCase

type AttributeValueCase int

AttributeValueCase represents case numbers of production AttributeValue

const (
	AttributeValueIdent AttributeValueCase = iota
	AttributeValueExpr
)

Values of type AttributeValueCase

func (AttributeValueCase) String

func (n AttributeValueCase) String() string

String implements fmt.Stringer

type AttributeValueList

type AttributeValueList struct {
	AttributeValue     *AttributeValue
	AttributeValueList *AttributeValueList
	Token              Token
}

AttributeValueList represents data reduced by productions:

AttributeValueList:
        AttributeValue
|       AttributeValueList ',' AttributeValue
Example (Case0)
fmt.Println(exampleAST(269, "int i __attribute__((a));"))
Output:

&cc.AttributeValueList{
· AttributeValue: &cc.AttributeValue{
· · Case: AttributeValueIdent,
· · Token: example.c:1:22: identifier "a",
· },
}
Example (Case1)
fmt.Println(exampleAST(270, "int i __attribute__((a, b));"))
Output:

&cc.AttributeValueList{
· AttributeValue: &cc.AttributeValue{
· · Case: AttributeValueIdent,
· · Token: example.c:1:22: identifier "a",
· },
· AttributeValueList: &cc.AttributeValueList{
· · AttributeValue: &cc.AttributeValue{
· · · Case: AttributeValueIdent,
· · · Token: example.c:1:25: identifier "b",
· · },
· · Token: example.c:1:23: ',' ",",
· },
}

func (*AttributeValueList) Position

func (n *AttributeValueList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AttributeValueList) String

func (n *AttributeValueList) String() string

String implements fmt.Stringer.

type Attributes

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

Attributes represent selected values from __attribute__ constructs.

See also https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html

func (*Attributes) Alias

func (n *Attributes) Alias() string

Alias returns S from __attribute__((alias("S"))) or "" if not present

func (*Attributes) Aligned

func (n *Attributes) Aligned() int64

Aligned returns N from __attribute__((aligned(N)) or -1 if not present/valid.

func (*Attributes) VectorSize

func (n *Attributes) VectorSize() int64

VectorSize returns N from __attribute__((vector_size(N)) or -1 if not present/valid.

The vector_size attribute is only applicable to integral and floating scalars, otherwise it's ignored.

type AutoDeclaration

type AutoDeclaration struct {
	Token       Token
	Declarator  *Declarator
	Token2      Token
	Initializer *Initializer
	Token3      Token
}

func (*AutoDeclaration) Position

func (n *AutoDeclaration) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*AutoDeclaration) String

func (n *AutoDeclaration) String() string

String implements fmt.Stringer.

type BinaryExpression

type BinaryExpression struct {
	Lhs   Expression
	Op    BinaryOperation `PrettyPrint:"stringer,zero"`
	Token Token
	Rhs   Expression
	// contains filtered or unexported fields
}
Example (Add)
fmt.Println(exampleAST(49, "int i = x+y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationAdd,
· Token: example.c:1:10: '+' "+",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "y",
· },
}
Example (And)
fmt.Println(exampleAST(63, "int i = x & y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationAnd,
· Token: example.c:1:11: '&' "&",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:13: identifier "y",
· },
}
Example (Div)
fmt.Println(exampleAST(46, "int i = x / y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationDiv,
· Token: example.c:1:11: '/' "/",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:13: identifier "y",
· },
}
Example (Eq)
fmt.Println(exampleAST(60, "int i = x == y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationEq,
· Token: example.c:1:11: '==' "==",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:14: identifier "y",
· },
}
Example (Geq)
fmt.Println(exampleAST(58, "int i = x >= y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationGeq,
· Token: example.c:1:11: '>=' ">=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:14: identifier "y",
· },
}
Example (Gt)
fmt.Println(exampleAST(56, "int i = x > y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationGt,
· Token: example.c:1:11: '>' ">",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:13: identifier "y",
· },
}
Example (LAnd)
fmt.Println(exampleAST(69, "int i = x && y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationLAnd,
· Token: example.c:1:11: '&&' "&&",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:14: identifier "y",
· },
}
Example (LOr)
fmt.Println(exampleAST(71, "int i = x || y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationLOr,
· Token: example.c:1:11: '||' "||",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:14: identifier "y",
· },
}
Example (Leq)
fmt.Println(exampleAST(57, "int i = x <= y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationLeq,
· Token: example.c:1:11: '<=' "<=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:14: identifier "y",
· },
}
Example (Lsh)
fmt.Println(exampleAST(52, "int i = x << y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationLsh,
· Token: example.c:1:11: '<<' "<<",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:14: identifier "y",
· },
}
Example (Lt)
fmt.Println(exampleAST(55, "int i = x < y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationLt,
· Token: example.c:1:11: '<' "<",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:13: identifier "y",
· },
}
Example (Mod)
fmt.Println(exampleAST(47, "int i = x % y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationMod,
· Token: example.c:1:11: '%' "%",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:13: identifier "y",
· },
}
Example (Mul)
fmt.Println(exampleAST(45, "int i = x * y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationMul,
· Token: example.c:1:11: '*' "*",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:13: identifier "y",
· },
}
Example (Neq)
fmt.Println(exampleAST(61, "int i = x != y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationNeq,
· Token: example.c:1:11: '!=' "!=",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:14: identifier "y",
· },
}
Example (Or)
fmt.Println(exampleAST(67, "int i = x|y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationOr,
· Token: example.c:1:10: '|' "|",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "y",
· },
}
Example (Rsh)
fmt.Println(exampleAST(53, "int i = x >> y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationRsh,
· Token: example.c:1:11: '>>' ">>",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:14: identifier "y",
· },
}
Example (Sub)
fmt.Println(exampleAST(50, "int i = x-y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationSub,
· Token: example.c:1:10: '-' "-",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "y",
· },
}
Example (Xor)
fmt.Println(exampleAST(65, "int i = x^y;"))
Output:

&cc.BinaryExpression{
· Lhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Op: BinaryOperationXor,
· Token: example.c:1:10: '^' "^",
· Rhs: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "y",
· },
}

func (*BinaryExpression) Position

func (n *BinaryExpression) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*BinaryExpression) String

func (n *BinaryExpression) String() string

String implements fmt.Stringer.

func (BinaryExpression) Type

func (t BinaryExpression) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (BinaryExpression) Value

func (v BinaryExpression) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type BinaryOperation

type BinaryOperation int

func (BinaryOperation) String

func (i BinaryOperation) String() string

type BlockItem

type BlockItem interface {
	Node
	fmt.Stringer
	// contains filtered or unexported methods
}

BlockItem represents data reduced by productions:

BlockItem:
        Declaration                                         // Case BlockItemDecl
|       LabelDeclaration                                    // Case BlockItemLabel
|       Statement                                           // Case BlockItemStmt
|       DeclarationSpecifiers Declarator CompoundStatement  // Case BlockItemFuncDef
Example (Case0)
fmt.Println(exampleAST(227, "int f() { int i; }"))
Output:

&cc.FunctionDefinition{
· Specifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:1: 'int' "int",
· · },
· },
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorFuncParam,
· · · DirectDeclarator: &cc.DirectDeclarator{
· · · · Case: DirectDeclaratorIdent,
· · · · Token: example.c:1:5: identifier "f",
· · · },
· · · Token: example.c:1:6: '(' "(",
· · · Token2: example.c:1:7: ')' ")",
· · },
· },
· Body: &cc.CompoundStatement{
· · Lbrace: example.c:1:9: '{' "{",
· · List: []*cc.CommonDeclaration{ // len 2
· · · 0: &cc.CommonDeclaration{
· · · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · · 0: &cc.StorageClassSpecifier{
· · · · · · Case: StorageClassSpecifierStatic,
· · · · · · Token: example.c:1:9: 'static' "static",
· · · · · },
· · · · · 1: &cc.TypeQualifier{
· · · · · · Case: TypeQualifierConst,
· · · · · · Token: example.c:1:9: 'const' "const",
· · · · · },
· · · · · 2: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierChar,
· · · · · · Name: example.c:1:9: 'char' "char",
· · · · · },
· · · · },
· · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · 0: &cc.InitDeclarator{
· · · · · · Declarator: &cc.Declarator{
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorArr,
· · · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · · },
· · · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · · },
· · · · · · },
· · · · · · Initializer: &cc.Initializer{
· · · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · · Case: PrimaryExpressionString,
· · · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · · },
· · · · · · · Case: InitializerExpr,
· · · · · · },
· · · · · · Token: example.c:1:9: '=' "=",
· · · · · },
· · · · },
· · · · Token: example.c:1:9: ';' ";",
· · · },
· · · 1: &cc.CommonDeclaration{
· · · · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · · · 0: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierInt,
· · · · · · Name: example.c:1:11: 'int' "int",
· · · · · },
· · · · },
· · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · 0: &cc.InitDeclarator{
· · · · · · Declarator: &cc.Declarator{
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · Token: example.c:1:15: identifier "i",
· · · · · · · },
· · · · · · },
· · · · · },
· · · · },
· · · · Token: example.c:1:16: ';' ";",
· · · },
· · },
· · Rbrace: example.c:1:18: '}' "}",
· },
}
Example (Case1)
fmt.Println(exampleAST(228, "int f() { int i; double j; }"))
Output:

&cc.FunctionDefinition{
· Specifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:1: 'int' "int",
· · },
· },
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorFuncParam,
· · · DirectDeclarator: &cc.DirectDeclarator{
· · · · Case: DirectDeclaratorIdent,
· · · · Token: example.c:1:5: identifier "f",
· · · },
· · · Token: example.c:1:6: '(' "(",
· · · Token2: example.c:1:7: ')' ")",
· · },
· },
· Body: &cc.CompoundStatement{
· · Lbrace: example.c:1:9: '{' "{",
· · List: []*cc.CommonDeclaration{ // len 3
· · · 0: &cc.CommonDeclaration{
· · · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · · 0: &cc.StorageClassSpecifier{
· · · · · · Case: StorageClassSpecifierStatic,
· · · · · · Token: example.c:1:9: 'static' "static",
· · · · · },
· · · · · 1: &cc.TypeQualifier{
· · · · · · Case: TypeQualifierConst,
· · · · · · Token: example.c:1:9: 'const' "const",
· · · · · },
· · · · · 2: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierChar,
· · · · · · Name: example.c:1:9: 'char' "char",
· · · · · },
· · · · },
· · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · 0: &cc.InitDeclarator{
· · · · · · Declarator: &cc.Declarator{
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorArr,
· · · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · · },
· · · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · · },
· · · · · · },
· · · · · · Initializer: &cc.Initializer{
· · · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · · Case: PrimaryExpressionString,
· · · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · · },
· · · · · · · Case: InitializerExpr,
· · · · · · },
· · · · · · Token: example.c:1:9: '=' "=",
· · · · · },
· · · · },
· · · · Token: example.c:1:9: ';' ";",
· · · },
· · · 1: &cc.CommonDeclaration{
· · · · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · · · 0: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierInt,
· · · · · · Name: example.c:1:11: 'int' "int",
· · · · · },
· · · · },
· · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · 0: &cc.InitDeclarator{
· · · · · · Declarator: &cc.Declarator{
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · Token: example.c:1:15: identifier "i",
· · · · · · · },
· · · · · · },
· · · · · },
· · · · },
· · · · Token: example.c:1:16: ';' ";",
· · · },
· · · 2: &cc.CommonDeclaration{
· · · · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · · · 0: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierDouble,
· · · · · · Name: example.c:1:18: 'double' "double",
· · · · · },
· · · · },
· · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · 0: &cc.InitDeclarator{
· · · · · · Declarator: &cc.Declarator{
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · Token: example.c:1:25: identifier "j",
· · · · · · · },
· · · · · · },
· · · · · },
· · · · },
· · · · Token: example.c:1:26: ';' ";",
· · · },
· · },
· · Rbrace: example.c:1:28: '}' "}",
· },
}
Example (Decl)
fmt.Println(exampleAST(229, "int f() { int i; }"))
Output:

&cc.FunctionDefinition{
· Specifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:1: 'int' "int",
· · },
· },
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorFuncParam,
· · · DirectDeclarator: &cc.DirectDeclarator{
· · · · Case: DirectDeclaratorIdent,
· · · · Token: example.c:1:5: identifier "f",
· · · },
· · · Token: example.c:1:6: '(' "(",
· · · Token2: example.c:1:7: ')' ")",
· · },
· },
· Body: &cc.CompoundStatement{
· · Lbrace: example.c:1:9: '{' "{",
· · List: []*cc.CommonDeclaration{ // len 2
· · · 0: &cc.CommonDeclaration{
· · · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · · 0: &cc.StorageClassSpecifier{
· · · · · · Case: StorageClassSpecifierStatic,
· · · · · · Token: example.c:1:9: 'static' "static",
· · · · · },
· · · · · 1: &cc.TypeQualifier{
· · · · · · Case: TypeQualifierConst,
· · · · · · Token: example.c:1:9: 'const' "const",
· · · · · },
· · · · · 2: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierChar,
· · · · · · Name: example.c:1:9: 'char' "char",
· · · · · },
· · · · },
· · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · 0: &cc.InitDeclarator{
· · · · · · Declarator: &cc.Declarator{
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorArr,
· · · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · · },
· · · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · · },
· · · · · · },
· · · · · · Initializer: &cc.Initializer{
· · · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · · Case: PrimaryExpressionString,
· · · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · · },
· · · · · · · Case: InitializerExpr,
· · · · · · },
· · · · · · Token: example.c:1:9: '=' "=",
· · · · · },
· · · · },
· · · · Token: example.c:1:9: ';' ";",
· · · },
· · · 1: &cc.CommonDeclaration{
· · · · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · · · 0: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierInt,
· · · · · · Name: example.c:1:11: 'int' "int",
· · · · · },
· · · · },
· · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · 0: &cc.InitDeclarator{
· · · · · · Declarator: &cc.Declarator{
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · Token: example.c:1:15: identifier "i",
· · · · · · · },
· · · · · · },
· · · · · },
· · · · },
· · · · Token: example.c:1:16: ';' ";",
· · · },
· · },
· · Rbrace: example.c:1:18: '}' "}",
· },
}
Example (FuncDef)
fmt.Println(exampleAST(232, "int f() { int g() {} }"))
Output:

&cc.FunctionDefinition{
· Specifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:1: 'int' "int",
· · },
· },
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorFuncParam,
· · · DirectDeclarator: &cc.DirectDeclarator{
· · · · Case: DirectDeclaratorIdent,
· · · · Token: example.c:1:5: identifier "f",
· · · },
· · · Token: example.c:1:6: '(' "(",
· · · Token2: example.c:1:7: ')' ")",
· · },
· },
· Body: &cc.CompoundStatement{
· · Lbrace: example.c:1:9: '{' "{",
· · List: []*cc.CommonDeclaration{ // len 2
· · · 0: &cc.CommonDeclaration{
· · · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · · 0: &cc.StorageClassSpecifier{
· · · · · · Case: StorageClassSpecifierStatic,
· · · · · · Token: example.c:1:9: 'static' "static",
· · · · · },
· · · · · 1: &cc.TypeQualifier{
· · · · · · Case: TypeQualifierConst,
· · · · · · Token: example.c:1:9: 'const' "const",
· · · · · },
· · · · · 2: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierChar,
· · · · · · Name: example.c:1:9: 'char' "char",
· · · · · },
· · · · },
· · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · 0: &cc.InitDeclarator{
· · · · · · Declarator: &cc.Declarator{
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorArr,
· · · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · · },
· · · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · · },
· · · · · · },
· · · · · · Initializer: &cc.Initializer{
· · · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · · Case: PrimaryExpressionString,
· · · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · · },
· · · · · · · Case: InitializerExpr,
· · · · · · },
· · · · · · Token: example.c:1:9: '=' "=",
· · · · · },
· · · · },
· · · · Token: example.c:1:9: ';' ";",
· · · },
· · · 1: &cc.FunctionDefinition{
· · · · Specifiers: []*cc.TypeSpecName{ // len 1
· · · · · 0: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierInt,
· · · · · · Name: example.c:1:11: 'int' "int",
· · · · · },
· · · · },
· · · · Declarator: &cc.Declarator{
· · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · Case: DirectDeclaratorFuncParam,
· · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · Token: example.c:1:15: identifier "g",
· · · · · · },
· · · · · · Token: example.c:1:16: '(' "(",
· · · · · · Token2: example.c:1:17: ')' ")",
· · · · · },
· · · · },
· · · · Body: &cc.CompoundStatement{
· · · · · Lbrace: example.c:1:19: '{' "{",
· · · · · List: []*cc.CommonDeclaration{ // len 1
· · · · · · 0: &cc.CommonDeclaration{
· · · · · · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · · · · · 0: &cc.StorageClassSpecifier{
· · · · · · · · · Case: StorageClassSpecifierStatic,
· · · · · · · · · Token: example.c:1:19: 'static' "static",
· · · · · · · · },
· · · · · · · · 1: &cc.TypeQualifier{
· · · · · · · · · Case: TypeQualifierConst,
· · · · · · · · · Token: example.c:1:19: 'const' "const",
· · · · · · · · },
· · · · · · · · 2: &cc.TypeSpecName{
· · · · · · · · · Case: TypeSpecifierChar,
· · · · · · · · · Name: example.c:1:19: 'char' "char",
· · · · · · · · },
· · · · · · · },
· · · · · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · · · · 0: &cc.InitDeclarator{
· · · · · · · · · Declarator: &cc.Declarator{
· · · · · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · · · · Case: DirectDeclaratorArr,
· · · · · · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · · · · · Token: example.c:1:19: identifier "__func__",
· · · · · · · · · · · },
· · · · · · · · · · · Token: example.c:1:19: '[' "[",
· · · · · · · · · · · Token2: example.c:1:19: ']' "]",
· · · · · · · · · · },
· · · · · · · · · },
· · · · · · · · · Initializer: &cc.Initializer{
· · · · · · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · · · · · Case: PrimaryExpressionString,
· · · · · · · · · · · Token: example.c:1:19: string literal "\"g\"",
· · · · · · · · · · },
· · · · · · · · · · Case: InitializerExpr,
· · · · · · · · · },
· · · · · · · · · Token: example.c:1:19: '=' "=",
· · · · · · · · },
· · · · · · · },
· · · · · · · Token: example.c:1:19: ';' ";",
· · · · · · },
· · · · · },
· · · · · Rbrace: example.c:1:20: '}' "}",
· · · · },
· · · },
· · },
· · Rbrace: example.c:1:22: '}' "}",
· },
}
Example (Label)
fmt.Println(exampleAST(230, "int f() { __label__ L; int i; }"))
Output:

&cc.FunctionDefinition{
· Specifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:1: 'int' "int",
· · },
· },
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorFuncParam,
· · · DirectDeclarator: &cc.DirectDeclarator{
· · · · Case: DirectDeclaratorIdent,
· · · · Token: example.c:1:5: identifier "f",
· · · },
· · · Token: example.c:1:6: '(' "(",
· · · Token2: example.c:1:7: ')' ")",
· · },
· },
· Body: &cc.CompoundStatement{
· · Lbrace: example.c:1:9: '{' "{",
· · List: []*cc.CommonDeclaration{ // len 3
· · · 0: &cc.CommonDeclaration{
· · · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · · 0: &cc.StorageClassSpecifier{
· · · · · · Case: StorageClassSpecifierStatic,
· · · · · · Token: example.c:1:9: 'static' "static",
· · · · · },
· · · · · 1: &cc.TypeQualifier{
· · · · · · Case: TypeQualifierConst,
· · · · · · Token: example.c:1:9: 'const' "const",
· · · · · },
· · · · · 2: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierChar,
· · · · · · Name: example.c:1:9: 'char' "char",
· · · · · },
· · · · },
· · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · 0: &cc.InitDeclarator{
· · · · · · Declarator: &cc.Declarator{
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorArr,
· · · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · · },
· · · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · · },
· · · · · · },
· · · · · · Initializer: &cc.Initializer{
· · · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · · Case: PrimaryExpressionString,
· · · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · · },
· · · · · · · Case: InitializerExpr,
· · · · · · },
· · · · · · Token: example.c:1:9: '=' "=",
· · · · · },
· · · · },
· · · · Token: example.c:1:9: ';' ";",
· · · },
· · · 1: &cc.LabelDeclaration{
· · · · IdentifierList: &cc.IdentifierList{
· · · · · Token2: example.c:1:21: identifier "L",
· · · · },
· · · · Token: example.c:1:11: '__label__' "__label__",
· · · · Token2: example.c:1:22: ';' ";",
· · · },
· · · 2: &cc.CommonDeclaration{
· · · · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · · · 0: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierInt,
· · · · · · Name: example.c:1:24: 'int' "int",
· · · · · },
· · · · },
· · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · 0: &cc.InitDeclarator{
· · · · · · Declarator: &cc.Declarator{
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · Token: example.c:1:28: identifier "i",
· · · · · · · },
· · · · · · },
· · · · · },
· · · · },
· · · · Token: example.c:1:29: ';' ";",
· · · },
· · },
· · Rbrace: example.c:1:31: '}' "}",
· },
}
Example (Stmt)
fmt.Println(exampleAST(231, "int f() { g(); }"))
Output:

&cc.FunctionDefinition{
· Specifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:1: 'int' "int",
· · },
· },
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorFuncParam,
· · · DirectDeclarator: &cc.DirectDeclarator{
· · · · Case: DirectDeclaratorIdent,
· · · · Token: example.c:1:5: identifier "f",
· · · },
· · · Token: example.c:1:6: '(' "(",
· · · Token2: example.c:1:7: ')' ")",
· · },
· },
· Body: &cc.CompoundStatement{
· · Lbrace: example.c:1:9: '{' "{",
· · List: []*cc.CommonDeclaration{ // len 2
· · · 0: &cc.CommonDeclaration{
· · · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · · 0: &cc.StorageClassSpecifier{
· · · · · · Case: StorageClassSpecifierStatic,
· · · · · · Token: example.c:1:9: 'static' "static",
· · · · · },
· · · · · 1: &cc.TypeQualifier{
· · · · · · Case: TypeQualifierConst,
· · · · · · Token: example.c:1:9: 'const' "const",
· · · · · },
· · · · · 2: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierChar,
· · · · · · Name: example.c:1:9: 'char' "char",
· · · · · },
· · · · },
· · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · 0: &cc.InitDeclarator{
· · · · · · Declarator: &cc.Declarator{
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorArr,
· · · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · · },
· · · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · · },
· · · · · · },
· · · · · · Initializer: &cc.Initializer{
· · · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · · Case: PrimaryExpressionString,
· · · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · · },
· · · · · · · Case: InitializerExpr,
· · · · · · },
· · · · · · Token: example.c:1:9: '=' "=",
· · · · · },
· · · · },
· · · · Token: example.c:1:9: ';' ";",
· · · },
· · · 1: &cc.ExpressionStatement{
· · · · ExpressionList: &cc.CallExpr{
· · · · · Func: &cc.PrimaryExpression{
· · · · · · Case: PrimaryExpressionIdent,
· · · · · · Token: example.c:1:11: identifier "g",
· · · · · },
· · · · · LeftParen: example.c:1:12: '(' "(",
· · · · · RightParen: example.c:1:13: ')' ")",
· · · · },
· · · · Token: example.c:1:14: ';' ";",
· · · },
· · },
· · Rbrace: example.c:1:16: '}' "}",
· },
}

type CallExpr

type CallExpr struct {
	Func       Expression
	LeftParen  Token
	Arguments  *ArgumentExpressionList
	RightParen Token
	// contains filtered or unexported fields
}
Example (Call)
fmt.Println(exampleAST(18, "int i = x(y);"))
Output:

&cc.CallExpr{
· Func: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· LeftParen: example.c:1:10: '(' "(",
· Arguments: &cc.ArgumentExpressionList{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:11: identifier "y",
· · },
· },
· RightParen: example.c:1:12: ')' ")",
}

func (*CallExpr) Position

func (n *CallExpr) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*CallExpr) String

func (n *CallExpr) String() string

String implements fmt.Stringer.

func (CallExpr) Type

func (t CallExpr) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (CallExpr) Value

func (v CallExpr) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type CastExpr

type CastExpr struct {
	Lparen   Token
	TypeName *TypeName
	Rparen   Token
	Expr     Expression
	// contains filtered or unexported fields
}

CastExpr represents data reduced by productions:

CastExpression:
        UnaryExpression                  // Case CastExpressionUnary
|       '(' TypeName ')' CastExpression  // Case CastExpressionCast
Example (Cast)
fmt.Println(exampleAST(43, "int i = (__attribute__((a)) int)3.14;"))
Output:

&cc.CastExpr{
· Lparen: example.c:1:9: '(' "(",
· TypeName: &cc.TypeName{
· · SpecifierQualifiers: []*cc.TypeQualifier{ // len 2
· · · 0: &cc.TypeQualifier{
· · · · AttributeSpecifiers: []*cc.AttributeSpecifier{ // len 1
· · · · · 0: &cc.AttributeSpecifier{
· · · · · · AttributeValueList: &cc.AttributeValueList{
· · · · · · · AttributeValue: &cc.AttributeValue{
· · · · · · · · Case: AttributeValueIdent,
· · · · · · · · Token: example.c:1:25: identifier "a",
· · · · · · · },
· · · · · · },
· · · · · · Token: example.c:1:10: '__attribute__' "__attribute__",
· · · · · · Token2: example.c:1:23: '(' "(",
· · · · · · Token3: example.c:1:24: '(' "(",
· · · · · · Token4: example.c:1:26: ')' ")",
· · · · · · Token5: example.c:1:27: ')' ")",
· · · · · },
· · · · },
· · · · Case: TypeQualifierAttr,
· · · },
· · · 1: &cc.TypeSpecName{
· · · · Case: TypeSpecifierInt,
· · · · Name: example.c:1:29: 'int' "int",
· · · },
· · },
· },
· Rparen: example.c:1:32: ')' ")",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionFloat,
· · Token: example.c:1:33: floating point constant "3.14",
· },
}

func (*CastExpr) Position

func (n *CastExpr) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*CastExpr) String

func (n *CastExpr) String() string

String implements fmt.Stringer.

func (CastExpr) Type

func (t CastExpr) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (CastExpr) Value

func (v CastExpr) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type CommonDeclaration

type CommonDeclaration struct {
	DeclarationSpecifiers DeclarationSpecifiers
	InitDeclarators       []*InitDeclarator
	AttributeSpecifiers   []*AttributeSpecifier
	Token                 Token
}

func (*CommonDeclaration) Position

func (n *CommonDeclaration) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*CommonDeclaration) String

func (n *CommonDeclaration) String() string

String implements fmt.Stringer.

type Complex128Value

type Complex128Value complex128

func (Complex128Value) Convert

func (n Complex128Value) Convert(to Type) Value

type Complex64Value

type Complex64Value complex64

func (Complex64Value) Convert

func (n Complex64Value) Convert(to Type) Value

type ComplexLongDoubleValue

type ComplexLongDoubleValue struct {
	Re *LongDoubleValue
	Im *LongDoubleValue
}

func (*ComplexLongDoubleValue) Convert

func (n *ComplexLongDoubleValue) Convert(to Type) Value

type CompositeLitExpr

type CompositeLitExpr struct {
	LeftParen       Token
	TypeName        *TypeName
	RightParen      Token
	LeftBrace       Token
	InitializerList *InitializerList
	Comma           Token
	RightBrace      Token
	// contains filtered or unexported fields
}
Example (Complit)
fmt.Println(exampleAST(23, "int i = (int[]){y};"))
Output:

&cc.CompositeLitExpr{
· LeftParen: example.c:1:9: '(' "(",
· TypeName: &cc.TypeName{
· · AbstractDeclarator: &cc.AbstractDeclarator{
· · · Case: AbstractDeclaratorDecl,
· · · DirectAbstractDeclarator: &cc.DirectAbstractDeclarator{
· · · · Case: DirectAbstractDeclaratorArr,
· · · · Token: example.c:1:13: '[' "[",
· · · · Token2: example.c:1:14: ']' "]",
· · · },
· · },
· · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · 0: &cc.TypeSpecName{
· · · · Case: TypeSpecifierInt,
· · · · Name: example.c:1:10: 'int' "int",
· · · },
· · },
· },
· RightParen: example.c:1:15: ')' ")",
· LeftBrace: example.c:1:16: '{' "{",
· InitializerList: &cc.InitializerList{
· · Initializer: &cc.Initializer{
· · · Expression: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:17: identifier "y",
· · · },
· · · Case: InitializerExpr,
· · },
· },
· RightBrace: example.c:1:18: '}' "}",
}

func (*CompositeLitExpr) Position

func (n *CompositeLitExpr) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*CompositeLitExpr) String

func (n *CompositeLitExpr) String() string

String implements fmt.Stringer.

func (CompositeLitExpr) Type

func (t CompositeLitExpr) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (CompositeLitExpr) Value

func (v CompositeLitExpr) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type CompoundStatement

type CompoundStatement struct {
	Lbrace Token
	List   []BlockItem
	Rbrace Token
	// contains filtered or unexported fields
}

CompoundStatement represents data reduced by production:

CompoundStatement:
        '{' BlockItemList '}'
Example (Case0)
fmt.Println(exampleAST(225, "int f() { __label__ L; int i; }"))
Output:

&cc.CompoundStatement{
· Lbrace: example.c:1:9: '{' "{",
· List: []*cc.CommonDeclaration{ // len 3
· · 0: &cc.CommonDeclaration{
· · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · 0: &cc.StorageClassSpecifier{
· · · · · Case: StorageClassSpecifierStatic,
· · · · · Token: example.c:1:9: 'static' "static",
· · · · },
· · · · 1: &cc.TypeQualifier{
· · · · · Case: TypeQualifierConst,
· · · · · Token: example.c:1:9: 'const' "const",
· · · · },
· · · · 2: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierChar,
· · · · · Name: example.c:1:9: 'char' "char",
· · · · },
· · · },
· · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · 0: &cc.InitDeclarator{
· · · · · Declarator: &cc.Declarator{
· · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · Case: DirectDeclaratorArr,
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · },
· · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · },
· · · · · },
· · · · · Initializer: &cc.Initializer{
· · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · Case: PrimaryExpressionString,
· · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · },
· · · · · · Case: InitializerExpr,
· · · · · },
· · · · · Token: example.c:1:9: '=' "=",
· · · · },
· · · },
· · · Token: example.c:1:9: ';' ";",
· · },
· · 1: &cc.LabelDeclaration{
· · · IdentifierList: &cc.IdentifierList{
· · · · Token2: example.c:1:21: identifier "L",
· · · },
· · · Token: example.c:1:11: '__label__' "__label__",
· · · Token2: example.c:1:22: ';' ";",
· · },
· · 2: &cc.CommonDeclaration{
· · · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · · 0: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierInt,
· · · · · Name: example.c:1:24: 'int' "int",
· · · · },
· · · },
· · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · 0: &cc.InitDeclarator{
· · · · · Declarator: &cc.Declarator{
· · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · Token: example.c:1:28: identifier "i",
· · · · · · },
· · · · · },
· · · · },
· · · },
· · · Token: example.c:1:29: ';' ";",
· · },
· },
· Rbrace: example.c:1:31: '}' "}",
}

func (*CompoundStatement) Gotos

func (n *CompoundStatement) Gotos() []*JumpStatement

Gotos returns a slice of all goto statements in n if n is a function block.

func (CompoundStatement) LexicalScope

func (n CompoundStatement) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*CompoundStatement) Position

func (n *CompoundStatement) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*CompoundStatement) String

func (n *CompoundStatement) String() string

String implements fmt.Stringer.

type ConditionalExpression

type ConditionalExpression struct {
	Condition Expression
	Token     Token
	Then      Expression
	Token2    Token
	Else      Expression
	// contains filtered or unexported fields
}

ConditionalExpression represents data reduced by productions:

ConditionalExpression:
        LogicalOrExpression                                               // Case ConditionalExpressionLOr
|       LogicalOrExpression '?' ExpressionList ':' ConditionalExpression  // Case ConditionalExpressionCond
Example (Cond)
fmt.Println(exampleAST(73, "int i = x ? y : z;"))
Output:

&cc.ConditionalExpression{
· Condition: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Token: example.c:1:11: '?' "?",
· Then: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:13: identifier "y",
· },
· Token2: example.c:1:15: ':' ":",
· Else: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:17: identifier "z",
· },
}

func (*ConditionalExpression) Position

func (n *ConditionalExpression) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*ConditionalExpression) String

func (n *ConditionalExpression) String() string

String implements fmt.Stringer.

func (ConditionalExpression) Type

func (t ConditionalExpression) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (ConditionalExpression) Value

func (v ConditionalExpression) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type Config

type Config struct {
	ABI                 *ABI
	CC                  string // The configured C compiler, filled by NewConfig.
	FS                  fs.FS
	HostIncludePaths    []string
	HostSysIncludePaths []string
	IncludePaths        []string
	PragmaHandler       func([]Token) error
	Predefined          string // The predefined macros from CC, filled by NewConfig.
	SysIncludePaths     []string
	// contains filtered or unexported fields
}

Config configures the preprocessor, parser and type checker.

Search paths listed in IncludePaths and SysIncludePaths are used to resolve #include "foo.h" and #include <foo.h> preprocessing directives respectively. A special search path "@" is interpreted as 'the same directory as where the file with the #include directive is'.

If FS is nil, os.Open is used to open named files.

func NewConfig

func NewConfig(goos, goarch string, opts ...string) (r *Config, err error)

NewConfig returns the system C compiler configuration, or an error, if any. The function will look for the compiler first in the environment variable CC, then it'll try other options. Usually that means looking for the "cc" and "gcc" binary, in that order.

Additional arguments (flags) in opts are passed to the system C compiler unchanged. For example, the _REENTRANT preprocessor macro is defined when the -pthread flag is present. The set of recognized keywords is adjusted to emulate gcc, see:

https://gcc.gnu.org/onlinedocs/gcc/Alternate-Keywords.html#Alternate-Keywords

Execution of NewConfig is expensive, caching the results is recommended wherever possible.

type ConstantExpression

type ConstantExpression struct {
	Expression Expression
	// contains filtered or unexported fields
}

ConstantExpression represents data reduced by production:

ConstantExpression:
        ConditionalExpression
Example (Case0)
fmt.Println(exampleAST(88, "struct { int i:3; };"))
Output:

&cc.ConstantExpression{
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionInt,
· · Token: example.c:1:16: integer constant "3",
· },
}

func (*ConstantExpression) Position

func (n *ConstantExpression) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*ConstantExpression) String

func (n *ConstantExpression) String() string

String implements fmt.Stringer.

func (ConstantExpression) Type

func (t ConstantExpression) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (ConstantExpression) Value

func (v ConstantExpression) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type Declaration

type Declaration interface {
	Node
	fmt.Stringer
	BlockItem
	ExternalDeclaration
	// contains filtered or unexported methods
}

Declaration represents data reduced by productions:

Declaration:
        DeclarationSpecifiers InitDeclaratorList AttributeSpecifierList ';'  // Case DeclarationDecl
|       StaticAssertDeclaration                                              // Case DeclarationAssert
|       "__auto_type" Declarator '=' Initializer ';'                         // Case DeclarationAuto
Example (Assert)
fmt.Println(exampleAST(90, "_Static_assert(x > y, \"abc\")"))
Output:

&cc.StaticAssertDeclaration{
· Expression: &cc.ConstantExpression{
· · Expression: &cc.BinaryExpression{
· · · Lhs: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:16: identifier "x",
· · · },
· · · Op: BinaryOperationGt,
· · · Token: example.c:1:18: '>' ">",
· · · Rhs: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:20: identifier "y",
· · · },
· · },
· },
· Token: example.c:1:1: _Static_assert "_Static_assert",
· Token2: example.c:1:15: '(' "(",
· Token3: example.c:1:21: ',' ",",
· Token4: example.c:1:23: string literal "\"abc\"",
· Token5: example.c:1:28: ')' ")",
}
Example (Auto)
fmt.Println(exampleAST(91, "__auto_type x = y;"))
Output:

&cc.AutoDeclaration{
· Token: example.c:1:1: '__auto_type' "__auto_type",
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorIdent,
· · · Token: example.c:1:13: identifier "x",
· · },
· },
· Token2: example.c:1:15: '=' "=",
· Initializer: &cc.Initializer{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:17: identifier "y",
· · },
· · Case: InitializerExpr,
· },
· Token3: example.c:1:18: ';' ";",
}
Example (Case0)
fmt.Println(exampleAST(253, "int f(i) int i; {}"))
Output:

&cc.CommonDeclaration{
· DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:10: 'int' "int",
· · },
· },
· InitDeclarators: []*cc.InitDeclarator{ // len 1
· · 0: &cc.InitDeclarator{
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:14: identifier "i",
· · · · },
· · · },
· · },
· },
· Token: example.c:1:15: ';' ";",
}
&cc.CommonDeclaration{
· DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · 0: &cc.StorageClassSpecifier{
· · · Case: StorageClassSpecifierStatic,
· · · Token: example.c:1:17: 'static' "static",
· · },
· · 1: &cc.TypeQualifier{
· · · Case: TypeQualifierConst,
· · · Token: example.c:1:17: 'const' "const",
· · },
· · 2: &cc.TypeSpecName{
· · · Case: TypeSpecifierChar,
· · · Name: example.c:1:17: 'char' "char",
· · },
· },
· InitDeclarators: []*cc.InitDeclarator{ // len 1
· · 0: &cc.InitDeclarator{
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorArr,
· · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · Case: DirectDeclaratorIdent,
· · · · · · Token: example.c:1:17: identifier "__func__",
· · · · · },
· · · · · Token: example.c:1:17: '[' "[",
· · · · · Token2: example.c:1:17: ']' "]",
· · · · },
· · · },
· · · Initializer: &cc.Initializer{
· · · · Expression: &cc.PrimaryExpression{
· · · · · Case: PrimaryExpressionString,
· · · · · Token: example.c:1:17: string literal "\"f\"",
· · · · },
· · · · Case: InitializerExpr,
· · · },
· · · Token: example.c:1:17: '=' "=",
· · },
· },
· Token: example.c:1:17: ';' ";",
}
Example (Case1)
fmt.Println(exampleAST(254, "int f(i, j) int i; int j; {}"))
Output:

&cc.CommonDeclaration{
· DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:13: 'int' "int",
· · },
· },
· InitDeclarators: []*cc.InitDeclarator{ // len 1
· · 0: &cc.InitDeclarator{
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:17: identifier "i",
· · · · },
· · · },
· · },
· },
· Token: example.c:1:18: ';' ";",
}
&cc.CommonDeclaration{
· DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:20: 'int' "int",
· · },
· },
· InitDeclarators: []*cc.InitDeclarator{ // len 1
· · 0: &cc.InitDeclarator{
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:24: identifier "j",
· · · · },
· · · },
· · },
· },
· Token: example.c:1:25: ';' ";",
}
&cc.CommonDeclaration{
· DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · 0: &cc.StorageClassSpecifier{
· · · Case: StorageClassSpecifierStatic,
· · · Token: example.c:1:27: 'static' "static",
· · },
· · 1: &cc.TypeQualifier{
· · · Case: TypeQualifierConst,
· · · Token: example.c:1:27: 'const' "const",
· · },
· · 2: &cc.TypeSpecName{
· · · Case: TypeSpecifierChar,
· · · Name: example.c:1:27: 'char' "char",
· · },
· },
· InitDeclarators: []*cc.InitDeclarator{ // len 1
· · 0: &cc.InitDeclarator{
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorArr,
· · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · Case: DirectDeclaratorIdent,
· · · · · · Token: example.c:1:27: identifier "__func__",
· · · · · },
· · · · · Token: example.c:1:27: '[' "[",
· · · · · Token2: example.c:1:27: ']' "]",
· · · · },
· · · },
· · · Initializer: &cc.Initializer{
· · · · Expression: &cc.PrimaryExpression{
· · · · · Case: PrimaryExpressionString,
· · · · · Token: example.c:1:27: string literal "\"f\"",
· · · · },
· · · · Case: InitializerExpr,
· · · },
· · · Token: example.c:1:27: '=' "=",
· · },
· },
· Token: example.c:1:27: ';' ";",
}
Example (Decl)
fmt.Println(exampleAST(89, "int i, j __attribute__((a));"))
Output:

&cc.CommonDeclaration{
· DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:1: 'int' "int",
· · },
· },
· InitDeclarators: []*cc.InitDeclarator{ // len 2
· · 0: &cc.InitDeclarator{
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:5: identifier "i",
· · · · },
· · · },
· · · Token2: example.c:1:6: ',' ",",
· · },
· · 1: &cc.InitDeclarator{
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:8: identifier "j",
· · · · },
· · · },
· · },
· },
· Token: example.c:1:28: ';' ";",
}

type DeclarationSpecifier

type DeclarationSpecifier interface {
	Node
	fmt.Stringer
	// contains filtered or unexported methods
}

DeclarationSpecifier represents data reduced by productions:

DeclarationSpecifiers:
        StorageClassSpecifier DeclarationSpecifiers  // Case DeclarationSpecifiersStorage
|       TypeSpecifier DeclarationSpecifiers          // Case DeclarationSpecifiersTypeSpec
|       TypeQualifier DeclarationSpecifiers          // Case DeclarationSpecifiersTypeQual
|       FunctionSpecifier DeclarationSpecifiers      // Case DeclarationSpecifiersFunc
|       AlignmentSpecifier DeclarationSpecifiers     // Case DeclarationSpecifiersAlignSpec
|       "__attribute__"                              // Case DeclarationSpecifiersAttr
Example (AlignSpec)
fmt.Println(exampleAST(97, "_Alignas(double) int i;"))
Output:

&cc.AlignmentSpecifier{
· Case: AlignmentSpecifierType,
· Token: example.c:1:1: '_Alignas' "_Alignas",
· Token2: example.c:1:9: '(' "(",
· Token3: example.c:1:16: ')' ")",
· TypeName: &cc.TypeName{
· · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · 0: &cc.TypeSpecName{
· · · · Case: TypeSpecifierDouble,
· · · · Name: example.c:1:10: 'double' "double",
· · · },
· · },
· },
}
&cc.TypeSpecName{
· Case: TypeSpecifierInt,
· Name: example.c:1:18: 'int' "int",
}
Example (Attr)
fmt.Println(exampleAST(98, "__attribute__((a)) int i;"))
Output:

&cc.AttributeSpecifier{
· AttributeValueList: &cc.AttributeValueList{
· · AttributeValue: &cc.AttributeValue{
· · · Case: AttributeValueIdent,
· · · Token: example.c:1:16: identifier "a",
· · },
· },
· Token: example.c:1:1: '__attribute__' "__attribute__",
· Token2: example.c:1:14: '(' "(",
· Token3: example.c:1:15: '(' "(",
· Token4: example.c:1:17: ')' ")",
· Token5: example.c:1:18: ')' ")",
}
&cc.TypeSpecName{
· Case: TypeSpecifierInt,
· Name: example.c:1:20: 'int' "int",
}
Example (Func)
fmt.Println(exampleAST(96, "inline int f() {}"))
Output:

&cc.FunctionSpecifier{
· Case: FunctionSpecifierInline,
· Token: example.c:1:1: 'inline' "inline",
}
&cc.TypeSpecName{
· Case: TypeSpecifierInt,
· Name: example.c:1:8: 'int' "int",
}
&cc.StorageClassSpecifier{
· Case: StorageClassSpecifierStatic,
· Token: example.c:1:16: 'static' "static",
}
&cc.TypeQualifier{
· Case: TypeQualifierConst,
· Token: example.c:1:16: 'const' "const",
}
&cc.TypeSpecName{
· Case: TypeSpecifierChar,
· Name: example.c:1:16: 'char' "char",
}
Example (Storage)
fmt.Println(exampleAST(93, "__attribute__((a)) static int i;"))
Output:

&cc.AttributeSpecifier{
· AttributeValueList: &cc.AttributeValueList{
· · AttributeValue: &cc.AttributeValue{
· · · Case: AttributeValueIdent,
· · · Token: example.c:1:16: identifier "a",
· · },
· },
· Token: example.c:1:1: '__attribute__' "__attribute__",
· Token2: example.c:1:14: '(' "(",
· Token3: example.c:1:15: '(' "(",
· Token4: example.c:1:17: ')' ")",
· Token5: example.c:1:18: ')' ")",
}
&cc.StorageClassSpecifier{
· Case: StorageClassSpecifierStatic,
· Token: example.c:1:20: 'static' "static",
}
&cc.TypeSpecName{
· Case: TypeSpecifierInt,
· Name: example.c:1:27: 'int' "int",
}
Example (TypeQual)
fmt.Println(exampleAST(95, "volatile int i;"))
Output:

&cc.TypeQualifier{
· Case: TypeQualifierVolatile,
· Token: example.c:1:1: 'volatile' "volatile",
}
&cc.TypeSpecName{
· Case: TypeSpecifierInt,
· Name: example.c:1:10: 'int' "int",
}
Example (TypeSpec)
fmt.Println(exampleAST(94, "int i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierInt,
· Name: example.c:1:1: 'int' "int",
}

type DeclarationSpecifiers

type DeclarationSpecifiers []DeclarationSpecifier

func (DeclarationSpecifiers) IsTypedef

func (list DeclarationSpecifiers) IsTypedef() bool

type Declarator

type Declarator struct {
	DirectDeclarator *DirectDeclarator
	Pointer          *Pointer
	// contains filtered or unexported fields
}

Declarator represents data reduced by production:

Declarator:
        Pointer DirectDeclarator
Example (Case0)
fmt.Println(exampleAST(170, "int *p;"))
Output:

&cc.Declarator{
· DirectDeclarator: &cc.DirectDeclarator{
· · Case: DirectDeclaratorIdent,
· · Token: example.c:1:6: identifier "p",
· },
· Pointer: &cc.Pointer{
· · Case: PointerTypeQual,
· · Token: example.c:1:5: '*' "*",
· },
}

func (*Declarator) AddressTaken

func (n *Declarator) AddressTaken() bool

AddressTaken reports whether address of n is taken. The result is valid after Translate.

func (*Declarator) Alignas

func (n *Declarator) Alignas() int

Alignas reports whether the _Alignas specifier was present in the declaration specifiers of n, if non-zero.

func (*Declarator) HasInitializer

func (n *Declarator) HasInitializer() bool

HasInitializer reports whether n has an initializer.

func (*Declarator) IsAtomic

func (n *Declarator) IsAtomic() bool

IsAtomic reports whether the type specifier '_Atomic' was present in the declaration of n.

func (*Declarator) IsConst

func (n *Declarator) IsConst() bool

IsConst reports whether the type qualifier 'const' was present in the declaration of n.

func (*Declarator) IsExtern

func (n *Declarator) IsExtern() bool

IsExtern reports whether the storage class specifier 'extern' was present in the declaration of n.

func (*Declarator) IsFuncDef

func (n *Declarator) IsFuncDef() bool

IsFuncDef reports whether n declares the name of a function definition.

func (*Declarator) IsInline

func (n *Declarator) IsInline() bool

IsInline reports whether the function specifier 'inline' was present in the declaration of n.

func (*Declarator) IsParam

func (n *Declarator) IsParam() bool

IsParam reports whether n is a function paramater.

func (*Declarator) IsRegister

func (n *Declarator) IsRegister() bool

IsRegister reports whether the storage class specifier 'register' was present in the declaration of n.

func (*Declarator) IsStatic

func (n *Declarator) IsStatic() bool

IsStatic reports whether the storage class specifier 'static' was present in the declaration of n.

func (*Declarator) IsSynthetic

func (n *Declarator) IsSynthetic() bool

IsSynthetic reports whether n is synthesized.

func (*Declarator) IsThreadLocal

func (n *Declarator) IsThreadLocal() bool

IsThreadLocal reports whether the storage class specifier '_Thread_local' was present in the declaration of n.

func (*Declarator) IsTypename

func (n *Declarator) IsTypename() bool

IsTypename reports whether n is a typedef.

func (*Declarator) IsVolatile

func (n *Declarator) IsVolatile() bool

IsVolatile reports whether the type qualifier 'volatile' was present in the declaration of n.

func (Declarator) LexicalScope

func (n Declarator) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*Declarator) Linkage

func (n *Declarator) Linkage() Linkage

Linkage reports n's linkage.

func (*Declarator) Name

func (n *Declarator) Name() string

Name returns the name of n.

func (*Declarator) NameTok

func (n *Declarator) NameTok() (r Token)

NameTok returns the name token of n.

func (*Declarator) Position

func (n *Declarator) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*Declarator) ReadCount

func (n *Declarator) ReadCount() int

ReadCount reports the number of times n is read. The result is valid after Translate.

func (Declarator) ResolvedIn

func (n Declarator) ResolvedIn() *Scope

ResolvedIn returns the scope an identifier was resolved in, if any.

func (*Declarator) SizeofCount

func (n *Declarator) SizeofCount() int

SizeofCount reports the number of times n appears in sizeof(expr). The result is valid after Translate.

func (*Declarator) StorageDuration

func (n *Declarator) StorageDuration() StorageDuration

func (*Declarator) String

func (n *Declarator) String() string

String implements fmt.Stringer.

func (Declarator) Type

func (t Declarator) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (Declarator) Visible

func (v Declarator) Visible() int

Visible reports the token sequence number where the visibility of a name starts.

func (*Declarator) WriteCount

func (n *Declarator) WriteCount() int

WriteCount reports the number of times n is written. The result is valid after Translate.

type Designation

type Designation struct {
	Designators []*Designator
	Token       Token
}

Designation represents data reduced by production:

Designation:
        DesignatorList '='
Example (Case0)
fmt.Println(exampleAST(207, "int a[] = { [42] = 314 };"))
Output:

&cc.Designation{
· Designators: []*cc.Designator{ // len 1
· · 0: &cc.Designator{
· · · Case: DesignatorIndex,
· · · ConstantExpression: &cc.ConstantExpression{
· · · · Expression: &cc.PrimaryExpression{
· · · · · Case: PrimaryExpressionInt,
· · · · · Token: example.c:1:14: integer constant "42",
· · · · },
· · · },
· · · Token: example.c:1:13: '[' "[",
· · · Token2: example.c:1:16: ']' "]",
· · },
· },
· Token: example.c:1:18: '=' "=",
}

func (*Designation) Position

func (n *Designation) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*Designation) String

func (n *Designation) String() string

String implements fmt.Stringer.

type Designator

type Designator struct {
	Case                DesignatorCase `PrettyPrint:"stringer,zero"`
	ConstantExpression  Expression
	ConstantExpression2 Expression
	Token               Token
	Token2              Token
	Token3              Token
	// contains filtered or unexported fields
}

Designator represents data reduced by productions:

Designator:
        '[' ConstantExpression ']'                           // Case DesignatorIndex
|       '[' ConstantExpression "..." ConstantExpression ']'  // Case DesignatorIndex2
|       '.' IDENTIFIER                                       // Case DesignatorField
|       IDENTIFIER ':'                                       // Case DesignatorField2
Example (Case0)
fmt.Println(exampleAST(208, "int a[] = { [42] = 314 };"))
Output:

&cc.Designator{
· Case: DesignatorIndex,
· ConstantExpression: &cc.ConstantExpression{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:14: integer constant "42",
· · },
· },
· Token: example.c:1:13: '[' "[",
· Token2: example.c:1:16: ']' "]",
}
Example (Case1)
fmt.Println(exampleAST(209, "int a[100][] = { [42][12] = 314 };"))
Output:

&cc.Designator{
· Case: DesignatorIndex,
· ConstantExpression: &cc.ConstantExpression{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:19: integer constant "42",
· · },
· },
· Token: example.c:1:18: '[' "[",
· Token2: example.c:1:21: ']' "]",
}
&cc.Designator{
· Case: DesignatorIndex,
· ConstantExpression: &cc.ConstantExpression{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:23: integer constant "12",
· · },
· },
· Token: example.c:1:22: '[' "[",
· Token2: example.c:1:25: ']' "]",
}
Example (Field)
fmt.Println(exampleAST(212, "struct t s = { .fld = 314 };"))
Output:

&cc.Designator{
· Case: DesignatorField,
· Token: example.c:1:16: '.' ".",
· Token2: example.c:1:17: identifier "fld",
}
Example (Field2)
fmt.Println(exampleAST(213, "struct t s = { fld: 314 };"))
Output:

&cc.Designator{
· Case: DesignatorField2,
· Token: example.c:1:16: identifier "fld",
· Token2: example.c:1:19: ':' ":",
}
Example (Index)
fmt.Println(exampleAST(210, "int a[] = { [42] = 314 };"))
Output:

&cc.Designator{
· Case: DesignatorIndex,
· ConstantExpression: &cc.ConstantExpression{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:14: integer constant "42",
· · },
· },
· Token: example.c:1:13: '[' "[",
· Token2: example.c:1:16: ']' "]",
}
Example (Index2)
fmt.Println(exampleAST(211, "int a[] = { [42 ... 278] = 314 };"))
Output:

&cc.Designator{
· Case: DesignatorIndex2,
· ConstantExpression: &cc.ConstantExpression{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:14: integer constant "42",
· · },
· },
· ConstantExpression2: &cc.ConstantExpression{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:21: integer constant "278",
· · },
· },
· Token: example.c:1:13: '[' "[",
· Token2: example.c:1:17: '...' "...",
· Token3: example.c:1:24: ']' "]",
}

func (*Designator) Position

func (n *Designator) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*Designator) String

func (n *Designator) String() string

String implements fmt.Stringer.

func (Designator) Type

func (t Designator) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

type DesignatorCase

type DesignatorCase int

DesignatorCase represents case numbers of production Designator

const (
	DesignatorIndex DesignatorCase = iota
	DesignatorIndex2
	DesignatorField
	DesignatorField2
)

Values of type DesignatorCase

func (DesignatorCase) String

func (n DesignatorCase) String() string

String implements fmt.Stringer

type DirectAbstractDeclarator

type DirectAbstractDeclarator struct {
	AbstractDeclarator       *AbstractDeclarator
	Expression               Expression
	Case                     DirectAbstractDeclaratorCase `PrettyPrint:"stringer,zero"`
	DirectAbstractDeclarator *DirectAbstractDeclarator
	ParameterTypeList        *ParameterTypeList
	Token                    Token
	Token2                   Token
	Token3                   Token
	TypeQualifiers           []*TypeQualifier
	// contains filtered or unexported fields
}

DirectAbstractDeclarator represents data reduced by productions:

DirectAbstractDeclarator:
        '(' AbstractDeclarator ')'                                                     // Case DirectAbstractDeclaratorDecl
|       DirectAbstractDeclarator '[' TypeQualifiers AssignmentExpression ']'           // Case DirectAbstractDeclaratorArr
|       DirectAbstractDeclarator '[' "static" TypeQualifiers AssignmentExpression ']'  // Case DirectAbstractDeclaratorStaticArr
|       DirectAbstractDeclarator '[' TypeQualifiers "static" AssignmentExpression ']'  // Case DirectAbstractDeclaratorArrStatic
|       DirectAbstractDeclarator '[' '*' ']'                                           // Case DirectAbstractDeclaratorArrStar
|       DirectAbstractDeclarator '(' ParameterTypeList ')'                             // Case DirectAbstractDeclaratorFunc
Example (Arr)
fmt.Println(exampleAST(198, "void f(int[const 42]);"))
Output:

&cc.DirectAbstractDeclarator{
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionInt,
· · Token: example.c:1:18: integer constant "42",
· },
· Case: DirectAbstractDeclaratorArr,
· Token: example.c:1:11: '[' "[",
· Token2: example.c:1:20: ']' "]",
· TypeQualifiers: []*cc.TypeQualifier{ // len 1
· · 0: &cc.TypeQualifier{
· · · Case: TypeQualifierConst,
· · · Token: example.c:1:12: 'const' "const",
· · },
· },
}
Example (ArrStar)
fmt.Println(exampleAST(201, "void f(int[*]);"))
Output:

&cc.DirectAbstractDeclarator{
· Case: DirectAbstractDeclaratorArrStar,
· Token: example.c:1:11: '[' "[",
· Token2: example.c:1:12: '*' "*",
· Token3: example.c:1:13: ']' "]",
}
Example (ArrStatic)
fmt.Println(exampleAST(200, "void f(int[const static 42]);"))
Output:

&cc.DirectAbstractDeclarator{
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionInt,
· · Token: example.c:1:25: integer constant "42",
· },
· Case: DirectAbstractDeclaratorArr,
· Token: example.c:1:11: '[' "[",
· Token2: example.c:1:18: 'static' "static",
· Token3: example.c:1:27: ']' "]",
· TypeQualifiers: []*cc.TypeQualifier{ // len 1
· · 0: &cc.TypeQualifier{
· · · Case: TypeQualifierConst,
· · · Token: example.c:1:12: 'const' "const",
· · },
· },
}
Example (Decl)
fmt.Println(exampleAST(197, "void f(int(*));"))
Output:

&cc.DirectAbstractDeclarator{
· AbstractDeclarator: &cc.AbstractDeclarator{
· · Case: AbstractDeclaratorPtr,
· · Pointer: &cc.Pointer{
· · · Case: PointerTypeQual,
· · · Token: example.c:1:12: '*' "*",
· · },
· },
· Case: DirectAbstractDeclaratorDecl,
· Token: example.c:1:11: '(' "(",
· Token2: example.c:1:13: ')' ")",
}
Example (Func)
fmt.Println(exampleAST(202, "void f(int(char));"))
Output:

&cc.DirectAbstractDeclarator{
· Case: DirectAbstractDeclaratorFunc,
· ParameterTypeList: &cc.ParameterTypeList{
· · Case: ParameterTypeListList,
· · ParameterList: &cc.ParameterList{
· · · ParameterDeclaration: &cc.ParameterDeclaration{
· · · · Case: ParameterDeclarationAbstract,
· · · · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · · · 0: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierChar,
· · · · · · Name: example.c:1:12: 'char' "char",
· · · · · },
· · · · },
· · · },
· · },
· },
· Token: example.c:1:11: '(' "(",
· Token2: example.c:1:16: ')' ")",
}
Example (StaticArr)
fmt.Println(exampleAST(199, "void f(int[static const 42]);"))
Output:

&cc.DirectAbstractDeclarator{
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionInt,
· · Token: example.c:1:25: integer constant "42",
· },
· Case: DirectAbstractDeclaratorStaticArr,
· Token: example.c:1:11: '[' "[",
· Token2: example.c:1:12: 'static' "static",
· Token3: example.c:1:27: ']' "]",
· TypeQualifiers: []*cc.TypeQualifier{ // len 1
· · 0: &cc.TypeQualifier{
· · · Case: TypeQualifierConst,
· · · Token: example.c:1:19: 'const' "const",
· · },
· },
}

func (*DirectAbstractDeclarator) Position

func (n *DirectAbstractDeclarator) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*DirectAbstractDeclarator) String

func (n *DirectAbstractDeclarator) String() string

String implements fmt.Stringer.

type DirectAbstractDeclaratorCase

type DirectAbstractDeclaratorCase int

DirectAbstractDeclaratorCase represents case numbers of production DirectAbstractDeclarator

const (
	DirectAbstractDeclaratorDecl DirectAbstractDeclaratorCase = iota
	DirectAbstractDeclaratorArr
	DirectAbstractDeclaratorStaticArr
	DirectAbstractDeclaratorArrStatic
	DirectAbstractDeclaratorArrStar
	DirectAbstractDeclaratorFunc
)

Values of type DirectAbstractDeclaratorCase

func (DirectAbstractDeclaratorCase) String

String implements fmt.Stringer

type DirectDeclarator

type DirectDeclarator struct {
	Expression        Expression
	Case              DirectDeclaratorCase `PrettyPrint:"stringer,zero"`
	Declarator        *Declarator
	DirectDeclarator  *DirectDeclarator
	IdentifierList    *IdentifierList
	ParameterTypeList *ParameterTypeList
	Token             Token
	Token2            Token
	Token3            Token
	TypeQualifiers    []*TypeQualifier
	// contains filtered or unexported fields
}

DirectDeclarator represents data reduced by productions:

DirectDeclarator:
        IDENTIFIER                                                             // Case DirectDeclaratorIdent
|       '(' Declarator ')'                                                     // Case DirectDeclaratorDecl
|       DirectDeclarator '[' TypeQualifiers AssignmentExpression ']'           // Case DirectDeclaratorArr
|       DirectDeclarator '[' "static" TypeQualifiers AssignmentExpression ']'  // Case DirectDeclaratorStaticArr
|       DirectDeclarator '[' TypeQualifiers "static" AssignmentExpression ']'  // Case DirectDeclaratorArrStatic
|       DirectDeclarator '[' TypeQualifiers '*' ']'                            // Case DirectDeclaratorStar
|       DirectDeclarator '(' ParameterTypeList ')'                             // Case DirectDeclaratorFuncParam
|       DirectDeclarator '(' IdentifierList ')'                                // Case DirectDeclaratorFuncIdent
Example (Arr)
fmt.Println(exampleAST(175, "int i[const 42];"))
Output:

&cc.DirectDeclarator{
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionInt,
· · Token: example.c:1:13: integer constant "42",
· },
· Case: DirectDeclaratorArr,
· DirectDeclarator: &cc.DirectDeclarator{
· · Case: DirectDeclaratorIdent,
· · Token: example.c:1:5: identifier "i",
· },
· Token: example.c:1:6: '[' "[",
· Token3: example.c:1:15: ']' "]",
· TypeQualifiers: []*cc.TypeQualifier{ // len 1
· · 0: &cc.TypeQualifier{
· · · Case: TypeQualifierConst,
· · · Token: example.c:1:7: 'const' "const",
· · },
· },
}
Example (ArrStatic)
fmt.Println(exampleAST(177, "int i[const static 42];"))
Output:

&cc.DirectDeclarator{
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionInt,
· · Token: example.c:1:20: integer constant "42",
· },
· Case: DirectDeclaratorArrStatic,
· DirectDeclarator: &cc.DirectDeclarator{
· · Case: DirectDeclaratorIdent,
· · Token: example.c:1:5: identifier "i",
· },
· Token: example.c:1:6: '[' "[",
· Token2: example.c:1:13: 'static' "static",
· Token3: example.c:1:22: ']' "]",
· TypeQualifiers: []*cc.TypeQualifier{ // len 1
· · 0: &cc.TypeQualifier{
· · · Case: TypeQualifierConst,
· · · Token: example.c:1:7: 'const' "const",
· · },
· },
}
Example (Decl)
fmt.Println(exampleAST(174, "int (f);"))
Output:

&cc.DirectDeclarator{
· Case: DirectDeclaratorDecl,
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorIdent,
· · · Token: example.c:1:6: identifier "f",
· · },
· },
· Token: example.c:1:5: '(' "(",
· Token2: example.c:1:7: ')' ")",
}
Example (FuncIdent)
fmt.Println(exampleAST(180, "int f(a);"))
Output:

&cc.DirectDeclarator{
· Case: DirectDeclaratorFuncIdent,
· DirectDeclarator: &cc.DirectDeclarator{
· · Case: DirectDeclaratorIdent,
· · Token: example.c:1:5: identifier "f",
· },
· IdentifierList: &cc.IdentifierList{
· · Token2: example.c:1:7: identifier "a",
· },
· Token: example.c:1:6: '(' "(",
· Token2: example.c:1:8: ')' ")",
}
Example (FuncParam)
fmt.Println(exampleAST(179, "int f(int i);"))
Output:

&cc.DirectDeclarator{
· Case: DirectDeclaratorFuncParam,
· DirectDeclarator: &cc.DirectDeclarator{
· · Case: DirectDeclaratorIdent,
· · Token: example.c:1:5: identifier "f",
· },
· ParameterTypeList: &cc.ParameterTypeList{
· · Case: ParameterTypeListList,
· · ParameterList: &cc.ParameterList{
· · · ParameterDeclaration: &cc.ParameterDeclaration{
· · · · Case: ParameterDeclarationDecl,
· · · · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · · · 0: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierInt,
· · · · · · Name: example.c:1:7: 'int' "int",
· · · · · },
· · · · },
· · · · Declarator: &cc.Declarator{
· · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · Case: DirectDeclaratorIdent,
· · · · · · Token: example.c:1:11: identifier "i",
· · · · · },
· · · · },
· · · },
· · },
· },
· Token: example.c:1:6: '(' "(",
· Token2: example.c:1:12: ')' ")",
}
Example (Ident)
fmt.Println(exampleAST(173, "int i;"))
Output:

&cc.DirectDeclarator{
· Case: DirectDeclaratorIdent,
· Token: example.c:1:5: identifier "i",
}
Example (Star)
fmt.Println(exampleAST(178, "int i[const *];"))
Output:

&cc.DirectDeclarator{
· Case: DirectDeclaratorStar,
· DirectDeclarator: &cc.DirectDeclarator{
· · Case: DirectDeclaratorIdent,
· · Token: example.c:1:5: identifier "i",
· },
· Token: example.c:1:6: '[' "[",
· Token2: example.c:1:13: '*' "*",
· Token3: example.c:1:14: ']' "]",
· TypeQualifiers: []*cc.TypeQualifier{ // len 1
· · 0: &cc.TypeQualifier{
· · · Case: TypeQualifierConst,
· · · Token: example.c:1:7: 'const' "const",
· · },
· },
}
Example (StaticArr)
fmt.Println(exampleAST(176, "int i[static const 42];"))
Output:

&cc.DirectDeclarator{
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionInt,
· · Token: example.c:1:20: integer constant "42",
· },
· Case: DirectDeclaratorStaticArr,
· DirectDeclarator: &cc.DirectDeclarator{
· · Case: DirectDeclaratorIdent,
· · Token: example.c:1:5: identifier "i",
· },
· Token: example.c:1:6: '[' "[",
· Token2: example.c:1:7: 'static' "static",
· Token3: example.c:1:22: ']' "]",
· TypeQualifiers: []*cc.TypeQualifier{ // len 1
· · 0: &cc.TypeQualifier{
· · · Case: TypeQualifierConst,
· · · Token: example.c:1:14: 'const' "const",
· · },
· },
}

func (*DirectDeclarator) Position

func (n *DirectDeclarator) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*DirectDeclarator) String

func (n *DirectDeclarator) String() string

String implements fmt.Stringer.

type DirectDeclaratorCase

type DirectDeclaratorCase int

DirectDeclaratorCase represents case numbers of production DirectDeclarator

const (
	DirectDeclaratorIdent DirectDeclaratorCase = iota
	DirectDeclaratorDecl
	DirectDeclaratorArr
	DirectDeclaratorStaticArr
	DirectDeclaratorArrStatic
	DirectDeclaratorStar
	DirectDeclaratorFuncParam
	DirectDeclaratorFuncIdent
)

Values of type DirectDeclaratorCase

func (DirectDeclaratorCase) String

func (n DirectDeclaratorCase) String() string

String implements fmt.Stringer

type EnumSpecifier

type EnumSpecifier struct {
	Case           EnumSpecifierCase `PrettyPrint:"stringer,zero"`
	EnumeratorList *EnumeratorList
	Token          Token
	Token2         Token
	Token3         Token
	Token4         Token
	Token5         Token
	// contains filtered or unexported fields
}

EnumSpecifier represents data reduced by productions:

EnumSpecifier:
        "enum" IDENTIFIER '{' EnumeratorList ',' '}'  // Case EnumSpecifierDef
|       "enum" IDENTIFIER                             // Case EnumSpecifierTag
Example (Def)
fmt.Println(exampleAST(155, "enum e {a};"))
Output:

&cc.EnumSpecifier{
· Case: EnumSpecifierDef,
· EnumeratorList: &cc.EnumeratorList{
· · Enumerator: &cc.Enumerator{
· · · Case: EnumeratorIdent,
· · · Token: example.c:1:9: identifier "a",
· · },
· },
· Token: example.c:1:1: 'enum' "enum",
· Token2: example.c:1:6: identifier "e",
· Token3: example.c:1:8: '{' "{",
· Token5: example.c:1:10: '}' "}",
}
Example (Tag)
fmt.Println(exampleAST(156, "enum e i;"))
Output:

&cc.EnumSpecifier{
· Case: EnumSpecifierTag,
· Token: example.c:1:1: 'enum' "enum",
· Token2: example.c:1:6: identifier "e",
}

func (EnumSpecifier) LexicalScope

func (n EnumSpecifier) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*EnumSpecifier) Position

func (n *EnumSpecifier) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*EnumSpecifier) String

func (n *EnumSpecifier) String() string

String implements fmt.Stringer.

func (EnumSpecifier) Type

func (t EnumSpecifier) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (EnumSpecifier) Visible

func (v EnumSpecifier) Visible() int

Visible reports the token sequence number where the visibility of a name starts.

type EnumSpecifierCase

type EnumSpecifierCase int

EnumSpecifierCase represents case numbers of production EnumSpecifier

const (
	EnumSpecifierDef EnumSpecifierCase = iota
	EnumSpecifierTag
)

Values of type EnumSpecifierCase

func (EnumSpecifierCase) String

func (n EnumSpecifierCase) String() string

String implements fmt.Stringer

type EnumType

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

func (*EnumType) Align

func (n *EnumType) Align() int

Align implements Type.

func (*EnumType) Attributes

func (n *EnumType) Attributes() *Attributes

Attributes implemets Type.

func (*EnumType) Decay

func (n *EnumType) Decay() Type

Decay implements Type.

func (*EnumType) Enumerators

func (n *EnumType) Enumerators() []*Enumerator

Enumerators returns enumerators defined by n.

func (*EnumType) FieldAlign

func (n *EnumType) FieldAlign() int

FieldAlign implements Type.

func (*EnumType) IsCompatible

func (n *EnumType) IsCompatible(t Type) bool

func (*EnumType) IsIncomplete

func (n *EnumType) IsIncomplete() bool

IsIncomplete implements Type.

func (*EnumType) Kind

func (n *EnumType) Kind() Kind

Kind implements Type.

func (*EnumType) LexicalScope

func (n *EnumType) LexicalScope() *Scope

LexicalScope provides the scope the definition of n appears in.

func (*EnumType) Pointer

func (n *EnumType) Pointer() Type

Pointer implements Type.

func (*EnumType) Size

func (n *EnumType) Size() int64

Size implements Type.

func (*EnumType) String

func (n *EnumType) String() string

String implements Type.

func (*EnumType) Tag

func (n *EnumType) Tag() Token

Tag returns n's tag, if any.

func (EnumType) Typedef

func (n EnumType) Typedef() *Declarator

Typedef implements Type

func (*EnumType) Undecay

func (n *EnumType) Undecay() Type

Undecay implements Type.

func (*EnumType) UnderlyingType

func (n *EnumType) UnderlyingType() Type

Type returns n's underlying integer type.

func (EnumType) VectorSize

func (EnumType) VectorSize() int64

VectorSize implements Type.

type Enumerator

type Enumerator struct {
	Case       EnumeratorCase `PrettyPrint:"stringer,zero"`
	Expression Expression
	Token      Token
	Token2     Token
	// contains filtered or unexported fields
}

Enumerator represents data reduced by productions:

Enumerator:
        IDENTIFIER                         // Case EnumeratorIdent
|       IDENTIFIER '=' ConstantExpression  // Case EnumeratorExpr
Example (Expr)
fmt.Println(exampleAST(160, "enum e {a = 42};"))
Output:

&cc.Enumerator{
· Case: EnumeratorExpr,
· Expression: &cc.ConstantExpression{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:13: integer constant "42",
· · },
· },
· Token: example.c:1:9: identifier "a",
· Token2: example.c:1:11: '=' "=",
}
Example (Ident)
fmt.Println(exampleAST(159, "enum e {a};"))
Output:

&cc.Enumerator{
· Case: EnumeratorIdent,
· Token: example.c:1:9: identifier "a",
}

func (*Enumerator) Position

func (n *Enumerator) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (Enumerator) ResolvedIn

func (n Enumerator) ResolvedIn() *Scope

ResolvedIn returns the scope an identifier was resolved in, if any.

func (*Enumerator) String

func (n *Enumerator) String() string

String implements fmt.Stringer.

func (Enumerator) Type

func (t Enumerator) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (Enumerator) Value

func (v Enumerator) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

func (Enumerator) Visible

func (v Enumerator) Visible() int

Visible reports the token sequence number where the visibility of a name starts.

type EnumeratorCase

type EnumeratorCase int

EnumeratorCase represents case numbers of production Enumerator

const (
	EnumeratorIdent EnumeratorCase = iota
	EnumeratorExpr
)

Values of type EnumeratorCase

func (EnumeratorCase) String

func (n EnumeratorCase) String() string

String implements fmt.Stringer

type EnumeratorList

type EnumeratorList struct {
	Enumerator     *Enumerator
	EnumeratorList *EnumeratorList
	Token          Token
}

EnumeratorList represents data reduced by productions:

EnumeratorList:
        Enumerator
|       EnumeratorList ',' Enumerator
Example (Case0)
fmt.Println(exampleAST(157, "enum e {a};"))
Output:

&cc.EnumeratorList{
· Enumerator: &cc.Enumerator{
· · Case: EnumeratorIdent,
· · Token: example.c:1:9: identifier "a",
· },
}
Example (Case1)
fmt.Println(exampleAST(158, "enum e {a, b};"))
Output:

&cc.EnumeratorList{
· Enumerator: &cc.Enumerator{
· · Case: EnumeratorIdent,
· · Token: example.c:1:9: identifier "a",
· },
· EnumeratorList: &cc.EnumeratorList{
· · Enumerator: &cc.Enumerator{
· · · Case: EnumeratorIdent,
· · · Token: example.c:1:12: identifier "b",
· · },
· · Token: example.c:1:10: ',' ",",
· },
}

func (*EnumeratorList) Position

func (n *EnumeratorList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*EnumeratorList) String

func (n *EnumeratorList) String() string

String implements fmt.Stringer.

type Expression

type Expression interface {
	Node
	Type() Type
	Value() Value
	// contains filtered or unexported methods
}

type ExpressionList

type ExpressionList struct {
	List   []Expression
	Tokens []Token
	// contains filtered or unexported fields
}

ExpressionList represents data reduced by productions:

ExpressionList:
        AssignmentExpression
|       ExpressionList ',' AssignmentExpression
Example (Assign)
fmt.Println(exampleAST(86, "int f() { i = x; };"))
Output:

<nil>
Example (Comma)
fmt.Println(exampleAST(87, "int f() { x, y; };"))
Output:

&cc.ExpressionList{
· List: []*cc.PrimaryExpression{ // len 2
· · 0: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:11: identifier "x",
· · },
· · 1: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:14: identifier "y",
· · },
· },
· Tokens: []cc.Token{ // len 1
· · 0: example.c:1:12: ',' ",",
· },
}

func (*ExpressionList) Position

func (n *ExpressionList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*ExpressionList) String

func (n *ExpressionList) String() string

String implements fmt.Stringer.

func (ExpressionList) Type

func (t ExpressionList) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (ExpressionList) Value

func (v ExpressionList) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type ExpressionStatement

type ExpressionStatement struct {
	AttributeSpecifiers []*AttributeSpecifier

	ExpressionList Expression
	Token          Token
	// contains filtered or unexported fields
}

ExpressionStatement represents data reduced by production:

ExpressionStatement:
        ExpressionList ';'
Example (Case0)
fmt.Println(exampleAST(233, "int f() { g(); }"))
Output:

&cc.ExpressionStatement{
· ExpressionList: &cc.CallExpr{
· · Func: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:11: identifier "g",
· · },
· · LeftParen: example.c:1:12: '(' "(",
· · RightParen: example.c:1:13: ')' ")",
· },
· Token: example.c:1:14: ';' ";",
}

func (*ExpressionStatement) Position

func (n *ExpressionStatement) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*ExpressionStatement) String

func (n *ExpressionStatement) String() string

String implements fmt.Stringer.

type ExternalDeclaration

type ExternalDeclaration interface {
	Node
	fmt.Stringer
	// contains filtered or unexported methods
}

ExternalDeclaration represents data reduced by productions:

ExternalDeclaration:
        FunctionDefinition  // Case ExternalDeclarationFuncDef
|       Declaration         // Case ExternalDeclarationDecl
|       AsmStatement        // Case ExternalDeclarationAsmStmt
|       ';'                 // Case ExternalDeclarationEmpty
Example (AsmStmt)
fmt.Println(exampleAST(250, "__asm__(\"nop\");"))
Output:

&cc.AsmStatement{
· Asm: &cc.Asm{
· · Token: example.c:1:1: '__asm__' "__asm__",
· · Token2: example.c:1:8: '(' "(",
· · Token3: example.c:1:9: string literal "\"nop\"",
· · Token4: example.c:1:14: ')' ")",
· },
· Token: example.c:1:15: ';' ";",
}
Example (Case0)
ast := exampleASTRaw("int i;")
fmt.Println(ast.Declarations[0])
Output:

&cc.CommonDeclaration{
· DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:1: 'int' "int",
· · },
· },
· InitDeclarators: []*cc.InitDeclarator{ // len 1
· · 0: &cc.InitDeclarator{
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:5: identifier "i",
· · · · },
· · · },
· · },
· },
· Token: example.c:1:6: ';' ";",
}
Example (Case1)
ast := exampleASTRaw("int i; int j;")
fmt.Println(ast.Declarations[0])
fmt.Println(ast.Declarations[1])
Output:

&cc.CommonDeclaration{
· DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:1: 'int' "int",
· · },
· },
· InitDeclarators: []*cc.InitDeclarator{ // len 1
· · 0: &cc.InitDeclarator{
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:5: identifier "i",
· · · · },
· · · },
· · },
· },
· Token: example.c:1:6: ';' ";",
}
&cc.CommonDeclaration{
· DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:8: 'int' "int",
· · },
· },
· InitDeclarators: []*cc.InitDeclarator{ // len 1
· · 0: &cc.InitDeclarator{
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:12: identifier "j",
· · · · },
· · · },
· · },
· },
· Token: example.c:1:13: ';' ";",
}
Example (Decl)
fmt.Println(exampleAST(249, "register int i __asm__(\"r0\");"))
Output:

&cc.CommonDeclaration{
· DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 2
· · 0: &cc.StorageClassSpecifier{
· · · Case: StorageClassSpecifierRegister,
· · · Token: example.c:1:1: 'register' "register",
· · },
· · 1: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:10: 'int' "int",
· · },
· },
· InitDeclarators: []*cc.InitDeclarator{ // len 1
· · 0: &cc.InitDeclarator{
· · · Asm: &cc.Asm{
· · · · Token: example.c:1:16: '__asm__' "__asm__",
· · · · Token2: example.c:1:23: '(' "(",
· · · · Token3: example.c:1:24: string literal "\"r0\"",
· · · · Token4: example.c:1:28: ')' ")",
· · · },
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:14: identifier "i",
· · · · },
· · · },
· · },
· },
· Token: example.c:1:29: ';' ";",
}
Example (Empty)
fmt.Println(exampleAST(251, ";"))
Output:

&cc.CommonDeclaration{
· Token: example.c:1:1: ';' ";",
}
Example (FuncDef)
fmt.Println(exampleAST(248, "int f() {}"))
Output:

&cc.FunctionDefinition{
· Specifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:1: 'int' "int",
· · },
· },
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorFuncParam,
· · · DirectDeclarator: &cc.DirectDeclarator{
· · · · Case: DirectDeclaratorIdent,
· · · · Token: example.c:1:5: identifier "f",
· · · },
· · · Token: example.c:1:6: '(' "(",
· · · Token2: example.c:1:7: ')' ")",
· · },
· },
· Body: &cc.CompoundStatement{
· · Lbrace: example.c:1:9: '{' "{",
· · List: []*cc.CommonDeclaration{ // len 1
· · · 0: &cc.CommonDeclaration{
· · · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · · 0: &cc.StorageClassSpecifier{
· · · · · · Case: StorageClassSpecifierStatic,
· · · · · · Token: example.c:1:9: 'static' "static",
· · · · · },
· · · · · 1: &cc.TypeQualifier{
· · · · · · Case: TypeQualifierConst,
· · · · · · Token: example.c:1:9: 'const' "const",
· · · · · },
· · · · · 2: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierChar,
· · · · · · Name: example.c:1:9: 'char' "char",
· · · · · },
· · · · },
· · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · 0: &cc.InitDeclarator{
· · · · · · Declarator: &cc.Declarator{
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorArr,
· · · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · · },
· · · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · · },
· · · · · · },
· · · · · · Initializer: &cc.Initializer{
· · · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · · Case: PrimaryExpressionString,
· · · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · · },
· · · · · · · Case: InitializerExpr,
· · · · · · },
· · · · · · Token: example.c:1:9: '=' "=",
· · · · · },
· · · · },
· · · · Token: example.c:1:9: ';' ";",
· · · },
· · },
· · Rbrace: example.c:1:10: '}' "}",
· },
}

type Field

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

func (*Field) AccessBytes

func (n *Field) AccessBytes() int64

AccessBytes reports the size in bytes used to access n. AccessBytes can be smaller than size of n's type when n is a bit field.

func (*Field) Declarator

func (n *Field) Declarator() *Declarator

Declarator reports n's declarator, if any.

func (*Field) GroupSize

func (n *Field) GroupSize() int

GroupSize is the maximum .AccessByte() of a group.

A bitfield group is the set of bit fields that share the same .Offset(). Consider:

struct {
	int a:7, b:2;
}

field	.Offset()	group	.AccessBytes()	.GroupSize()
  a	    0		  0	      1		     2
  b	    0		  0	      2		     2

func (*Field) InOverlapGroup

func (n *Field) InOverlapGroup() bool

InOverlapGroup reports whether n is emdedded in a preceding larger bit field group.

A bitfield group is the set of bit fields that share the same .Offset(). Consider:

struct {
	int a:7, b:2, c:1;
}

field	.Offset()	group	.AccessBytes()
  a	    0		  0	      1
  b	    0		  0	      2
  c	    1		  1	      1

Because field b has offset 0 and access bytes 2, group 0 overlaps with group 1. Field c will report InOverlapGroup() == true.

func (*Field) Index

func (n *Field) Index() int

Index returns the zero based field declaration index.

func (*Field) IsBitfield

func (n *Field) IsBitfield() bool

IsBitfield reports whether n is a bit field.

func (*Field) IsFlexibleArrayMember

func (n *Field) IsFlexibleArrayMember() bool

IsFlexibleArrayMember reports whether n is a flexible array member.

https://en.wikipedia.org/wiki/Flexible_array_member

func (*Field) Mask

func (n *Field) Mask() uint64

Mask reports the mask used to access n. It is non zero only for bit fields.

func (*Field) Name

func (n *Field) Name() string

Name reports the name of f, if any.

func (*Field) Offset

func (n *Field) Offset() int64

Offset reports the offset of n in bytes.

func (*Field) OffsetBits

func (n *Field) OffsetBits() int

OffsetBits report n's additional bit offset to Offset. Non zero only for bit fields but can be zero even for a bit field, for example, the first bit field after a non bit field will have OffsetBits zero.

func (*Field) OuterGroupOffset

func (n *Field) OuterGroupOffset() int64

OuterGroupOffset reports the non-overlapping group offset of n in bytes. If n is not a bit field the value is the same as Offset(). If n is a bit field the value differs from Offset for bit fields reporting InOverlapGroup() == true.

func (*Field) Parent

func (n *Field) Parent() *Field

Parent reports the parent of n, if any. A field has a parent when it's resolved in certain contexts, for example:

struct {
	int a;
	struct {
		int b;
		int c;
		int d;
	} e;
	int f;
} g;

A postfix expression node for 'g.a' will have the field 'a' attached, with no parent. A postfix expression node for 'g.c' will have the field 'c' attached, with parent field 'e'.

func (*Field) Type

func (n *Field) Type() Type

Type reports the type of f.

func (*Field) ValueBits

func (n *Field) ValueBits() int64

ValueBits reports n's size in bits.

type Float64Value

type Float64Value float64

func (Float64Value) Convert

func (n Float64Value) Convert(to Type) Value

type FunctionDefinition

type FunctionDefinition struct {
	Specifiers   DeclarationSpecifiers
	Declarator   *Declarator
	Declarations []Declaration
	Body         *CompoundStatement
	// contains filtered or unexported fields
}

FunctionDefinition represents data reduced by production:

FunctionDefinition:
        DeclarationSpecifiers Declarator DeclarationList CompoundStatement
Example (Case0)
fmt.Println(exampleAST(252, "int f() {}"))
Output:

&cc.FunctionDefinition{
· Specifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:1: 'int' "int",
· · },
· },
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorFuncParam,
· · · DirectDeclarator: &cc.DirectDeclarator{
· · · · Case: DirectDeclaratorIdent,
· · · · Token: example.c:1:5: identifier "f",
· · · },
· · · Token: example.c:1:6: '(' "(",
· · · Token2: example.c:1:7: ')' ")",
· · },
· },
· Body: &cc.CompoundStatement{
· · Lbrace: example.c:1:9: '{' "{",
· · List: []*cc.CommonDeclaration{ // len 1
· · · 0: &cc.CommonDeclaration{
· · · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · · 0: &cc.StorageClassSpecifier{
· · · · · · Case: StorageClassSpecifierStatic,
· · · · · · Token: example.c:1:9: 'static' "static",
· · · · · },
· · · · · 1: &cc.TypeQualifier{
· · · · · · Case: TypeQualifierConst,
· · · · · · Token: example.c:1:9: 'const' "const",
· · · · · },
· · · · · 2: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierChar,
· · · · · · Name: example.c:1:9: 'char' "char",
· · · · · },
· · · · },
· · · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · · 0: &cc.InitDeclarator{
· · · · · · Declarator: &cc.Declarator{
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorArr,
· · · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · · },
· · · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · · },
· · · · · · },
· · · · · · Initializer: &cc.Initializer{
· · · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · · Case: PrimaryExpressionString,
· · · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · · },
· · · · · · · Case: InitializerExpr,
· · · · · · },
· · · · · · Token: example.c:1:9: '=' "=",
· · · · · },
· · · · },
· · · · Token: example.c:1:9: ';' ";",
· · · },
· · },
· · Rbrace: example.c:1:10: '}' "}",
· },
}

func (*FunctionDefinition) Position

func (n *FunctionDefinition) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*FunctionDefinition) String

func (n *FunctionDefinition) String() string

String implements fmt.Stringer.

type FunctionSpecifier

type FunctionSpecifier struct {
	Case  FunctionSpecifierCase `PrettyPrint:"stringer,zero"`
	Token Token
}

FunctionSpecifier represents data reduced by productions:

FunctionSpecifier:
        "inline"     // Case FunctionSpecifierInline
|       "_Noreturn"  // Case FunctionSpecifierNoreturn
Example (Inline)
fmt.Println(exampleAST(168, "inline int f() {}"))
Output:

&cc.FunctionSpecifier{
· Case: FunctionSpecifierInline,
· Token: example.c:1:1: 'inline' "inline",
}
Example (Noreturn)
fmt.Println(exampleAST(169, "_Noreturn int f() {}"))
Output:

&cc.FunctionSpecifier{
· Case: FunctionSpecifierNoreturn,
· Token: example.c:1:1: '_Noreturn' "_Noreturn",
}

func (*FunctionSpecifier) Position

func (n *FunctionSpecifier) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*FunctionSpecifier) String

func (n *FunctionSpecifier) String() string

String implements fmt.Stringer.

type FunctionSpecifierCase

type FunctionSpecifierCase int

FunctionSpecifierCase represents case numbers of production FunctionSpecifier

const (
	FunctionSpecifierInline FunctionSpecifierCase = iota
	FunctionSpecifierNoreturn
)

Values of type FunctionSpecifierCase

func (FunctionSpecifierCase) String

func (n FunctionSpecifierCase) String() string

String implements fmt.Stringer

type FunctionType

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

func (*FunctionType) Align

func (n *FunctionType) Align() int

Align implements Type.

func (FunctionType) Attributes

func (n FunctionType) Attributes() *Attributes

Attributes implemets Type.

func (*FunctionType) Decay

func (n *FunctionType) Decay() Type

Decay implements Type.

func (*FunctionType) FieldAlign

func (n *FunctionType) FieldAlign() int

FieldAlign implements Type.

func (*FunctionType) IsCompatible

func (n *FunctionType) IsCompatible(t Type) bool

func (*FunctionType) IsIncomplete

func (n *FunctionType) IsIncomplete() bool

IsIncomplete implements Type.

func (*FunctionType) IsVariadic

func (n *FunctionType) IsVariadic() bool

IsVariadic reports whether n is variadic.

func (*FunctionType) Kind

func (n *FunctionType) Kind() Kind

Kind implements Type.

func (*FunctionType) MaxArgs

func (n *FunctionType) MaxArgs() int

MaxArgs returns the maximum number of arguments n expects. Variadic functions return a negative value.

func (*FunctionType) MinArgs

func (n *FunctionType) MinArgs() int

MinArgs returns the minimum number of arguments n expects.

func (*FunctionType) Parameters

func (n *FunctionType) Parameters() []*Parameter

Parameters returns function type parameters.

func (*FunctionType) Pointer

func (n *FunctionType) Pointer() Type

Pointer implements Type.

func (*FunctionType) Result

func (n *FunctionType) Result() Type

Result reports the result type of n.

func (*FunctionType) Size

func (n *FunctionType) Size() int64

Size implements Type.

func (*FunctionType) String

func (n *FunctionType) String() string

String implements Type.

func (FunctionType) Typedef

func (n FunctionType) Typedef() *Declarator

Typedef implements Type

func (*FunctionType) Undecay

func (n *FunctionType) Undecay() Type

Undecay implements Type.

func (FunctionType) VectorSize

func (FunctionType) VectorSize() int64

VectorSize implements Type.

type GenericAssociation

type GenericAssociation struct {
	Expression Expression
	Case       GenericAssociationCase `PrettyPrint:"stringer,zero"`
	Token      Token
	Token2     Token
	TypeName   *TypeName
}

GenericAssociation represents data reduced by productions:

GenericAssociation:
        TypeName ':' AssignmentExpression   // Case GenericAssociationType
|       "default" ':' AssignmentExpression  // Case GenericAssociationDefault
Example (Default)
fmt.Println(exampleAST(15, "int i = _Generic(x, default: y)(42);"))
Output:

&cc.GenericAssociation{
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:30: identifier "y",
· },
· Case: GenericAssociationDefault,
· Token: example.c:1:21: 'default' "default",
· Token2: example.c:1:28: ':' ":",
}
Example (Type)
fmt.Println(exampleAST(14, "int i = _Generic(x, int: y)(42);"))
Output:

&cc.GenericAssociation{
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:26: identifier "y",
· },
· Case: GenericAssociationType,
· Token: example.c:1:24: ':' ":",
· TypeName: &cc.TypeName{
· · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · 0: &cc.TypeSpecName{
· · · · Case: TypeSpecifierInt,
· · · · Name: example.c:1:21: 'int' "int",
· · · },
· · },
· },
}

func (*GenericAssociation) Position

func (n *GenericAssociation) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*GenericAssociation) String

func (n *GenericAssociation) String() string

String implements fmt.Stringer.

type GenericAssociationCase

type GenericAssociationCase int

GenericAssociationCase represents case numbers of production GenericAssociation

const (
	GenericAssociationType GenericAssociationCase = iota
	GenericAssociationDefault
)

Values of type GenericAssociationCase

func (GenericAssociationCase) String

func (n GenericAssociationCase) String() string

String implements fmt.Stringer

type GenericAssociationList

type GenericAssociationList struct {
	GenericAssociation     *GenericAssociation
	GenericAssociationList *GenericAssociationList
	Token                  Token
}

GenericAssociationList represents data reduced by productions:

GenericAssociationList:
        GenericAssociation
|       GenericAssociationList ',' GenericAssociation
Example (Case0)
fmt.Println(exampleAST(12, "int i = _Generic(x, int: y)(42);"))
Output:

&cc.GenericAssociationList{
· GenericAssociation: &cc.GenericAssociation{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:26: identifier "y",
· · },
· · Case: GenericAssociationType,
· · Token: example.c:1:24: ':' ":",
· · TypeName: &cc.TypeName{
· · · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · · 0: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierInt,
· · · · · Name: example.c:1:21: 'int' "int",
· · · · },
· · · },
· · },
· },
}
Example (Case1)
fmt.Println(exampleAST(13, "int i = _Generic(x, int: y, float: z)(42);"))
Output:

&cc.GenericAssociationList{
· GenericAssociation: &cc.GenericAssociation{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:26: identifier "y",
· · },
· · Case: GenericAssociationType,
· · Token: example.c:1:24: ':' ":",
· · TypeName: &cc.TypeName{
· · · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · · 0: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierInt,
· · · · · Name: example.c:1:21: 'int' "int",
· · · · },
· · · },
· · },
· },
· GenericAssociationList: &cc.GenericAssociationList{
· · GenericAssociation: &cc.GenericAssociation{
· · · Expression: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:36: identifier "z",
· · · },
· · · Case: GenericAssociationType,
· · · Token: example.c:1:34: ':' ":",
· · · TypeName: &cc.TypeName{
· · · · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · · · 0: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierFloat,
· · · · · · Name: example.c:1:29: 'float' "float",
· · · · · },
· · · · },
· · · },
· · },
· · Token: example.c:1:27: ',' ",",
· },
}

func (*GenericAssociationList) Position

func (n *GenericAssociationList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*GenericAssociationList) String

func (n *GenericAssociationList) String() string

String implements fmt.Stringer.

type GenericSelection

type GenericSelection struct {
	Expression             Expression
	GenericAssociationList *GenericAssociationList
	Token                  Token
	Token2                 Token
	Token3                 Token
	Token4                 Token
	// contains filtered or unexported fields
}

GenericSelection represents data reduced by production:

GenericSelection:
        "_Generic" '(' AssignmentExpression ',' GenericAssociationList ')'
Example (Case0)
fmt.Println(exampleAST(11, "int i = _Generic(x, int: y)(42);"))
Output:

&cc.GenericSelection{
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:18: identifier "x",
· },
· GenericAssociationList: &cc.GenericAssociationList{
· · GenericAssociation: &cc.GenericAssociation{
· · · Expression: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:26: identifier "y",
· · · },
· · · Case: GenericAssociationType,
· · · Token: example.c:1:24: ':' ":",
· · · TypeName: &cc.TypeName{
· · · · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · · · 0: &cc.TypeSpecName{
· · · · · · Case: TypeSpecifierInt,
· · · · · · Name: example.c:1:21: 'int' "int",
· · · · · },
· · · · },
· · · },
· · },
· },
· Token: example.c:1:9: '_Generic' "_Generic",
· Token2: example.c:1:17: '(' "(",
· Token3: example.c:1:19: ',' ",",
· Token4: example.c:1:27: ')' ")",
}

func (*GenericSelection) Associated

func (n *GenericSelection) Associated() *GenericAssociation

Associated returns the selected association of n, if any.

func (*GenericSelection) Position

func (n *GenericSelection) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*GenericSelection) String

func (n *GenericSelection) String() string

String implements fmt.Stringer.

func (GenericSelection) Type

func (t GenericSelection) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

type IdentifierList

type IdentifierList struct {
	IdentifierList *IdentifierList
	Token          Token
	Token2         Token
	// contains filtered or unexported fields
}

IdentifierList represents data reduced by productions:

IdentifierList:
        IDENTIFIER
|       IdentifierList ',' IDENTIFIER
Example (Case0)
fmt.Println(exampleAST(192, "int f(i) int i; {}"))
Output:

&cc.IdentifierList{
· Token2: example.c:1:7: identifier "i",
}
Example (Case1)
fmt.Println(exampleAST(193, "int f(i, j) int i, j; {}"))
Output:

&cc.IdentifierList{
· IdentifierList: &cc.IdentifierList{
· · Token: example.c:1:8: ',' ",",
· · Token2: example.c:1:10: identifier "j",
· },
· Token2: example.c:1:7: identifier "i",
}

func (*IdentifierList) Position

func (n *IdentifierList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*IdentifierList) String

func (n *IdentifierList) String() string

String implements fmt.Stringer.

type IndexExpr

type IndexExpr struct {
	Expr       Expression
	LeftBrace  Token
	Index      Expression
	RightBrace Token
	// contains filtered or unexported fields
}
Example (Index)
fmt.Println(exampleAST(17, "int i = x[y];"))
Output:

&cc.IndexExpr{
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· LeftBrace: example.c:1:10: '[' "[",
· Index: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "y",
· },
· RightBrace: example.c:1:12: ']' "]",
}

func (*IndexExpr) Position

func (n *IndexExpr) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*IndexExpr) String

func (n *IndexExpr) String() string

String implements fmt.Stringer.

func (IndexExpr) Type

func (t IndexExpr) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (IndexExpr) Value

func (v IndexExpr) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type InitDeclarator

type InitDeclarator struct {
	AttributeSpecifiers []*AttributeSpecifier
	Asm                 *Asm
	Declarator          *Declarator
	Initializer         *Initializer
	Token               Token
	Token2              Token
}

InitDeclarator represents data reduced by productions:

InitDeclarator:
        Declarator Asm                  // Case InitDeclaratorDecl
|       Declarator Asm '=' Initializer  // Case InitDeclaratorInit
Example (Case0)
fmt.Println(exampleAST(99, "int i;"))
Output:

&cc.InitDeclarator{
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorIdent,
· · · Token: example.c:1:5: identifier "i",
· · },
· },
}
Example (Case1)
fmt.Println(exampleAST(100, "int i, __attribute__((a)) j;"))
Output:

&cc.InitDeclarator{
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorIdent,
· · · Token: example.c:1:5: identifier "i",
· · },
· },
· Token2: example.c:1:6: ',' ",",
}
&cc.InitDeclarator{
· AttributeSpecifiers: []*cc.AttributeSpecifier{ // len 1
· · 0: &cc.AttributeSpecifier{
· · · AttributeValueList: &cc.AttributeValueList{
· · · · AttributeValue: &cc.AttributeValue{
· · · · · Case: AttributeValueIdent,
· · · · · Token: example.c:1:23: identifier "a",
· · · · },
· · · },
· · · Token: example.c:1:8: '__attribute__' "__attribute__",
· · · Token2: example.c:1:21: '(' "(",
· · · Token3: example.c:1:22: '(' "(",
· · · Token4: example.c:1:24: ')' ")",
· · · Token5: example.c:1:25: ')' ")",
· · },
· },
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorIdent,
· · · Token: example.c:1:27: identifier "j",
· · },
· },
}
Example (Decl)
fmt.Println(exampleAST(101, "register int i __asm__(\"r0\");"))
Output:

&cc.InitDeclarator{
· Asm: &cc.Asm{
· · Token: example.c:1:16: '__asm__' "__asm__",
· · Token2: example.c:1:23: '(' "(",
· · Token3: example.c:1:24: string literal "\"r0\"",
· · Token4: example.c:1:28: ')' ")",
· },
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorIdent,
· · · Token: example.c:1:14: identifier "i",
· · },
· },
}
Example (Init)
fmt.Println(exampleAST(102, "register int i __asm__(\"r0\") = x;"))
Output:

&cc.InitDeclarator{
· Asm: &cc.Asm{
· · Token: example.c:1:16: '__asm__' "__asm__",
· · Token2: example.c:1:23: '(' "(",
· · Token3: example.c:1:24: string literal "\"r0\"",
· · Token4: example.c:1:28: ')' ")",
· },
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorIdent,
· · · Token: example.c:1:14: identifier "i",
· · },
· },
· Initializer: &cc.Initializer{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:32: identifier "x",
· · },
· · Case: InitializerExpr,
· },
· Token: example.c:1:30: '=' "=",
}

func (*InitDeclarator) Position

func (n *InitDeclarator) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*InitDeclarator) String

func (n *InitDeclarator) String() string

String implements fmt.Stringer.

type Initializer

type Initializer struct {
	Expression      Expression
	Case            InitializerCase `PrettyPrint:"stringer,zero"`
	InitializerList *InitializerList
	Token           Token
	Token2          Token
	Token3          Token
	// contains filtered or unexported fields
}

Initializer represents data reduced by productions:

Initializer:
        AssignmentExpression         // Case InitializerExpr
|       '{' InitializerList ',' '}'  // Case InitializerInitList
Example (Expr)
fmt.Println(exampleAST(203, "int i = x;"))
Output:

&cc.Initializer{
· Expression: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Case: InitializerExpr,
}
Example (InitList)
fmt.Println(exampleAST(204, "int i[] = { x };"))
Output:

&cc.Initializer{
· Case: InitializerInitList,
· InitializerList: &cc.InitializerList{
· · Initializer: &cc.Initializer{
· · · Expression: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:13: identifier "x",
· · · },
· · · Case: InitializerExpr,
· · },
· },
· Token: example.c:1:11: '{' "{",
· Token3: example.c:1:15: '}' "}",
}

func (*Initializer) Field

func (n *Initializer) Field() *Field

Field returns the field associated with n, if any.

func (*Initializer) Len

func (n *Initializer) Len() int64

Len returns the number of array elements initialized. It's normally one, but can be more using the [lo ... hi] designator.

func (*Initializer) Offset

func (n *Initializer) Offset() int64

Offset returns the offset of n within it's containing type.

func (*Initializer) Parent

func (n *Initializer) Parent() *Initializer

Parent returns Initalizer m that has n on its InitializerList, if any.

func (*Initializer) Position

func (n *Initializer) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*Initializer) String

func (n *Initializer) String() string

String implements fmt.Stringer.

func (Initializer) Type

func (t Initializer) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (Initializer) Value

func (v Initializer) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type InitializerCase

type InitializerCase int

InitializerCase represents case numbers of production Initializer

const (
	InitializerExpr InitializerCase = iota
	InitializerInitList
)

Values of type InitializerCase

func (InitializerCase) String

func (n InitializerCase) String() string

String implements fmt.Stringer

type InitializerList

type InitializerList struct {
	Designation     *Designation
	Initializer     *Initializer
	InitializerList *InitializerList
	Token           Token
	// contains filtered or unexported fields
}

InitializerList represents data reduced by productions:

InitializerList:
        Designation Initializer
|       InitializerList ',' Designation Initializer
Example (Case0)
fmt.Println(exampleAST(205, "int i[] = { [10] = x };"))
Output:

&cc.InitializerList{
· Designation: &cc.Designation{
· · Designators: []*cc.Designator{ // len 1
· · · 0: &cc.Designator{
· · · · Case: DesignatorIndex,
· · · · ConstantExpression: &cc.ConstantExpression{
· · · · · Expression: &cc.PrimaryExpression{
· · · · · · Case: PrimaryExpressionInt,
· · · · · · Token: example.c:1:14: integer constant "10",
· · · · · },
· · · · },
· · · · Token: example.c:1:13: '[' "[",
· · · · Token2: example.c:1:16: ']' "]",
· · · },
· · },
· · Token: example.c:1:18: '=' "=",
· },
· Initializer: &cc.Initializer{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:20: identifier "x",
· · },
· · Case: InitializerExpr,
· },
}
Example (Case1)
fmt.Println(exampleAST(206, "int i[] = { [10] = x, [20] = y };"))
Output:

&cc.InitializerList{
· Designation: &cc.Designation{
· · Designators: []*cc.Designator{ // len 1
· · · 0: &cc.Designator{
· · · · Case: DesignatorIndex,
· · · · ConstantExpression: &cc.ConstantExpression{
· · · · · Expression: &cc.PrimaryExpression{
· · · · · · Case: PrimaryExpressionInt,
· · · · · · Token: example.c:1:14: integer constant "10",
· · · · · },
· · · · },
· · · · Token: example.c:1:13: '[' "[",
· · · · Token2: example.c:1:16: ']' "]",
· · · },
· · },
· · Token: example.c:1:18: '=' "=",
· },
· Initializer: &cc.Initializer{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:20: identifier "x",
· · },
· · Case: InitializerExpr,
· },
· InitializerList: &cc.InitializerList{
· · Designation: &cc.Designation{
· · · Designators: []*cc.Designator{ // len 1
· · · · 0: &cc.Designator{
· · · · · Case: DesignatorIndex,
· · · · · ConstantExpression: &cc.ConstantExpression{
· · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · Case: PrimaryExpressionInt,
· · · · · · · Token: example.c:1:24: integer constant "20",
· · · · · · },
· · · · · },
· · · · · Token: example.c:1:23: '[' "[",
· · · · · Token2: example.c:1:26: ']' "]",
· · · · },
· · · },
· · · Token: example.c:1:28: '=' "=",
· · },
· · Initializer: &cc.Initializer{
· · · Expression: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:30: identifier "y",
· · · },
· · · Case: InitializerExpr,
· · },
· · Token: example.c:1:21: ',' ",",
· },
}

func (*InitializerList) Position

func (n *InitializerList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*InitializerList) String

func (n *InitializerList) String() string

String implements fmt.Stringer.

func (InitializerList) Type

func (t InitializerList) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (*InitializerList) UnionField

func (n *InitializerList) UnionField() *Field

UnionField reports the union field initilized by n.

type Int64Value

type Int64Value int64

func (Int64Value) Convert

func (n Int64Value) Convert(to Type) Value

type InvalidType

type InvalidType struct{}

func (*InvalidType) Align

func (n *InvalidType) Align() int

Align implements Type.

func (*InvalidType) Attributes

func (n *InvalidType) Attributes() *Attributes

Attributes implements Type.

func (*InvalidType) Decay

func (n *InvalidType) Decay() Type

Decay implements Type.

func (*InvalidType) FieldAlign

func (n *InvalidType) FieldAlign() int

FieldAlign implements Type.

func (*InvalidType) IsCompatible

func (n *InvalidType) IsCompatible(Type) bool

func (*InvalidType) IsIncomplete

func (n *InvalidType) IsIncomplete() bool

IsIncomplete implements Type.

func (*InvalidType) Kind

func (n *InvalidType) Kind() Kind

Kind implements Type.

func (*InvalidType) Pointer

func (n *InvalidType) Pointer() Type

Pointer implements Type.

func (*InvalidType) Size

func (n *InvalidType) Size() int64

Size implements Type.

func (*InvalidType) String

func (n *InvalidType) String() string

String implements Type.

func (*InvalidType) Typedef

func (n *InvalidType) Typedef() *Declarator

Name implements Type.

func (*InvalidType) Undecay

func (n *InvalidType) Undecay() Type

Undecay implements Type.

func (*InvalidType) VectorSize

func (n *InvalidType) VectorSize() int64

VectorSize implements Type.

type IterationStatement

type IterationStatement struct {
	Case            IterationStatementCase `PrettyPrint:"stringer,zero"`
	Declaration     Declaration
	ExpressionList  Expression
	ExpressionList2 Expression
	ExpressionList3 Expression
	Statement       Statement
	Token           Token
	Token2          Token
	Token3          Token
	Token4          Token
	Token5          Token
	// contains filtered or unexported fields
}

IterationStatement represents data reduced by productions:

IterationStatement:
        "while" '(' ExpressionList ')' Statement                                      // Case IterationStatementWhile
|       "do" Statement "while" '(' ExpressionList ')' ';'                             // Case IterationStatementDo
|       "for" '(' ExpressionList ';' ExpressionList ';' ExpressionList ')' Statement  // Case IterationStatementFor
|       "for" '(' Declaration ExpressionList ';' ExpressionList ')' Statement         // Case IterationStatementForDecl
Example (Do)
fmt.Println(exampleAST(238, "int f() { do x(); while(y); }"))
Output:

&cc.IterationStatement{
· Case: IterationStatementDo,
· ExpressionList: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:25: identifier "y",
· },
· Statement: &cc.ExpressionStatement{
· · ExpressionList: &cc.CallExpr{
· · · Func: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:14: identifier "x",
· · · },
· · · LeftParen: example.c:1:15: '(' "(",
· · · RightParen: example.c:1:16: ')' ")",
· · },
· · Token: example.c:1:17: ';' ";",
· },
· Token: example.c:1:11: 'do' "do",
· Token2: example.c:1:19: 'while' "while",
· Token3: example.c:1:24: '(' "(",
· Token4: example.c:1:26: ')' ")",
· Token5: example.c:1:27: ';' ";",
}
Example (For)
fmt.Println(exampleAST(239, "int f() { for( i = 0; i < 10; i++) x(); }"))
Output:

&cc.IterationStatement{
· Case: IterationStatementFor,
· ExpressionList: &cc.AssignmentExpression{
· · Lhs: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:16: identifier "i",
· · },
· · Op: AssignmentOperationAssign,
· · Token: example.c:1:18: '=' "=",
· · Rhs: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:20: integer constant "0",
· · },
· },
· ExpressionList2: &cc.BinaryExpression{
· · Lhs: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:23: identifier "i",
· · },
· · Op: BinaryOperationLt,
· · Token: example.c:1:25: '<' "<",
· · Rhs: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:27: integer constant "10",
· · },
· },
· ExpressionList3: &cc.PostfixExpr{
· · Expr: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:31: identifier "i",
· · },
· · Token: example.c:1:32: '++' "++",
· },
· Statement: &cc.ExpressionStatement{
· · ExpressionList: &cc.CallExpr{
· · · Func: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:36: identifier "x",
· · · },
· · · LeftParen: example.c:1:37: '(' "(",
· · · RightParen: example.c:1:38: ')' ")",
· · },
· · Token: example.c:1:39: ';' ";",
· },
· Token: example.c:1:11: 'for' "for",
· Token2: example.c:1:14: '(' "(",
· Token3: example.c:1:21: ';' ";",
· Token4: example.c:1:29: ';' ";",
· Token5: example.c:1:34: ')' ")",
}
Example (ForDecl)
fmt.Println(exampleAST(240, "int f() { for( int i = 0; i < 10; i++) x(); }"))
Output:

&cc.IterationStatement{
· Case: IterationStatementForDecl,
· Declaration: &cc.CommonDeclaration{
· · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · 0: &cc.TypeSpecName{
· · · · Case: TypeSpecifierInt,
· · · · Name: example.c:1:16: 'int' "int",
· · · },
· · },
· · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · 0: &cc.InitDeclarator{
· · · · Declarator: &cc.Declarator{
· · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · Case: DirectDeclaratorIdent,
· · · · · · Token: example.c:1:20: identifier "i",
· · · · · },
· · · · },
· · · · Initializer: &cc.Initializer{
· · · · · Expression: &cc.PrimaryExpression{
· · · · · · Case: PrimaryExpressionInt,
· · · · · · Token: example.c:1:24: integer constant "0",
· · · · · },
· · · · · Case: InitializerExpr,
· · · · },
· · · · Token: example.c:1:22: '=' "=",
· · · },
· · },
· · Token: example.c:1:25: ';' ";",
· },
· ExpressionList: &cc.BinaryExpression{
· · Lhs: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:27: identifier "i",
· · },
· · Op: BinaryOperationLt,
· · Token: example.c:1:29: '<' "<",
· · Rhs: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:31: integer constant "10",
· · },
· },
· ExpressionList2: &cc.PostfixExpr{
· · Expr: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:35: identifier "i",
· · },
· · Token: example.c:1:36: '++' "++",
· },
· Statement: &cc.ExpressionStatement{
· · ExpressionList: &cc.CallExpr{
· · · Func: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:40: identifier "x",
· · · },
· · · LeftParen: example.c:1:41: '(' "(",
· · · RightParen: example.c:1:42: ')' ")",
· · },
· · Token: example.c:1:43: ';' ";",
· },
· Token: example.c:1:11: 'for' "for",
· Token2: example.c:1:14: '(' "(",
· Token3: example.c:1:33: ';' ";",
· Token4: example.c:1:38: ')' ")",
}
Example (While)
fmt.Println(exampleAST(237, "int f() { while(x) y(); }"))
Output:

&cc.IterationStatement{
· Case: IterationStatementWhile,
· ExpressionList: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:17: identifier "x",
· },
· Statement: &cc.ExpressionStatement{
· · ExpressionList: &cc.CallExpr{
· · · Func: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:20: identifier "y",
· · · },
· · · LeftParen: example.c:1:21: '(' "(",
· · · RightParen: example.c:1:22: ')' ")",
· · },
· · Token: example.c:1:23: ';' ";",
· },
· Token: example.c:1:11: 'while' "while",
· Token2: example.c:1:16: '(' "(",
· Token3: example.c:1:18: ')' ")",
}

func (IterationStatement) LexicalScope

func (n IterationStatement) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*IterationStatement) Position

func (n *IterationStatement) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*IterationStatement) String

func (n *IterationStatement) String() string

String implements fmt.Stringer.

type IterationStatementCase

type IterationStatementCase int

IterationStatementCase represents case numbers of production IterationStatement

const (
	IterationStatementWhile IterationStatementCase = iota
	IterationStatementDo
	IterationStatementFor
	IterationStatementForDecl
)

Values of type IterationStatementCase

func (IterationStatementCase) String

func (n IterationStatementCase) String() string

String implements fmt.Stringer

type JumpStatement

type JumpStatement struct {
	Case           JumpStatementCase `PrettyPrint:"stringer,zero"`
	ExpressionList Expression
	Token          Token
	Token2         Token
	Token3         Token
	// contains filtered or unexported fields
}

JumpStatement represents data reduced by productions:

JumpStatement:
        "goto" IDENTIFIER ';'          // Case JumpStatementGoto
|       "goto" '*' ExpressionList ';'  // Case JumpStatementGotoExpr
|       "continue" ';'                 // Case JumpStatementContinue
|       "break" ';'                    // Case JumpStatementBreak
|       "return" ExpressionList ';'    // Case JumpStatementReturn
Example (Break)
fmt.Println(exampleAST(244, "int f() { for(;;) if (i) break; }"))
Output:

&cc.JumpStatement{
· Case: JumpStatementBreak,
· Token: example.c:1:26: 'break' "break",
· Token2: example.c:1:31: ';' ";",
}
Example (Continue)
fmt.Println(exampleAST(243, "int f() { for(;;) if (i) continue; }"))
Output:

&cc.JumpStatement{
· Case: JumpStatementContinue,
· Token: example.c:1:26: 'continue' "continue",
· Token2: example.c:1:34: ';' ";",
}
Example (Goto)
fmt.Println(exampleAST(241, "int f() { L: goto L; }"))
Output:

&cc.JumpStatement{
· Case: JumpStatementGoto,
· Token: example.c:1:14: 'goto' "goto",
· Token2: example.c:1:19: identifier "L",
· Token3: example.c:1:20: ';' ";",
}
Example (GotoExpr)
fmt.Println(exampleAST(242, "int f() { L: x(); void *p = &&L; goto *p; }"))
Output:

&cc.JumpStatement{
· Case: JumpStatementGotoExpr,
· ExpressionList: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:40: identifier "p",
· },
· Token: example.c:1:34: 'goto' "goto",
· Token2: example.c:1:39: '*' "*",
· Token3: example.c:1:41: ';' ";",
}
Example (Return)
fmt.Println(exampleAST(245, "int f() { if (i) return x; }"))
Output:

&cc.JumpStatement{
· Case: JumpStatementReturn,
· ExpressionList: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:25: identifier "x",
· },
· Token: example.c:1:18: 'return' "return",
· Token2: example.c:1:26: ';' ";",
}

func (*JumpStatement) Label

func (n *JumpStatement) Label() Node

Label returns the labeled statement or a label declaration n, case JumpStatementGoto, refers to.

func (JumpStatement) LexicalScope

func (n JumpStatement) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*JumpStatement) Position

func (n *JumpStatement) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*JumpStatement) String

func (n *JumpStatement) String() string

String implements fmt.Stringer.

type JumpStatementCase

type JumpStatementCase int

JumpStatementCase represents case numbers of production JumpStatement

const (
	JumpStatementGoto JumpStatementCase = iota
	JumpStatementGotoExpr
	JumpStatementContinue
	JumpStatementBreak
	JumpStatementReturn
)

Values of type JumpStatementCase

func (JumpStatementCase) String

func (n JumpStatementCase) String() string

String implements fmt.Stringer

type Kind

type Kind int
const (
	InvalidKind Kind = iota

	Array             // array
	Bool              // _Bool
	Char              // char
	ComplexChar       // _Complex char
	ComplexDouble     // _Complex double
	ComplexFloat      // _Complex float
	ComplexInt        // _Complex int
	ComplexLong       // _Complex long
	ComplexLongDouble // _Complex long double
	ComplexLongLong   // _Complex long long
	ComplexShort      // _Complex short
	ComplexUInt       // _Complex unsigned
	ComplexUShort     // _Complex unsigned short
	Decimal128        // _Decimal128
	Decimal32         // _Decimal32
	Decimal64         // _Decimal64
	Double            // double
	Enum              // enum
	Float             // float
	Float128          // _Float128
	Float128x         // _Float128x
	Float16           // _Float16
	Float32           // _Float32
	Float32x          // _Float32x
	Float64           // _Float64
	Float64x          // _Float64x
	Function          // function
	Int               // int
	Int8              // __int8
	Int16             // __int16
	Int32             // __int32
	Int64             // __int64
	Int128            // __int128
	Long              // long
	LongDouble        // long double
	LongLong          // long long
	Ptr               // pointer
	SChar             // signed char
	Short             // short
	Struct            // struct
	UChar             // unsigned char
	UInt              // unsigned
	UInt8             // unsigned __int8
	UInt16            // unsigned __int16
	UInt32            // unsigned __int32
	UInt64            // unsigned __int64
	UInt128           // unsigned __int128
	ULong             // unsigned long
	ULongLong         // unsigned long long
	UShort            // unsigned short
	Union             // union
	Void              // void

)

func (Kind) String

func (i Kind) String() string

type LabelAddrExpr

type LabelAddrExpr struct {
	Token Token
	Label Token
	// contains filtered or unexported fields
}
Example (LabelAddr)
fmt.Println(exampleAST(37, "int f() { L: &&L; }"))
Output:

&cc.LabelAddrExpr{
· Token: example.c:1:14: '&&' "&&",
· Label: example.c:1:16: identifier "L",
}

func (*LabelAddrExpr) Position

func (n *LabelAddrExpr) Position() (r token.Position)

func (*LabelAddrExpr) String

func (n *LabelAddrExpr) String() string

String implements fmt.Stringer.

func (LabelAddrExpr) Type

func (t LabelAddrExpr) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (LabelAddrExpr) Value

func (v LabelAddrExpr) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type LabelDeclaration

type LabelDeclaration struct {
	IdentifierList *IdentifierList
	Token          Token
	Token2         Token
}

LabelDeclaration represents data reduced by production:

LabelDeclaration:
        "__label__" IdentifierList ';'
Example (Case0)
fmt.Println(exampleAST(226, "int f() { __label__ L, M; L: x(); M: y(); }"))
Output:

&cc.LabelDeclaration{
· IdentifierList: &cc.IdentifierList{
· · IdentifierList: &cc.IdentifierList{
· · · Token: example.c:1:22: ',' ",",
· · · Token2: example.c:1:24: identifier "M",
· · },
· · Token2: example.c:1:21: identifier "L",
· },
· Token: example.c:1:11: '__label__' "__label__",
· Token2: example.c:1:25: ';' ";",
}

func (*LabelDeclaration) Position

func (n *LabelDeclaration) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*LabelDeclaration) String

func (n *LabelDeclaration) String() string

String implements fmt.Stringer.

type LabeledStatement

type LabeledStatement struct {
	Case        LabeledStatementCase `PrettyPrint:"stringer,zero"`
	Expression  Expression
	Expression2 Expression
	Statement   Statement
	Token       Token
	Token2      Token
	Token3      Token
	// contains filtered or unexported fields
}

LabeledStatement represents data reduced by productions:

LabeledStatement:
        IDENTIFIER ':' Statement                                          // Case LabeledStatementLabel
|       "case" ConstantExpression ':' Statement                           // Case LabeledStatementCaseLabel
|       "case" ConstantExpression "..." ConstantExpression ':' Statement  // Case LabeledStatementRange
|       "default" ':' Statement                                           // Case LabeledStatementDefault
Example (CaseLabel)
fmt.Println(exampleAST(222, "int f() { switch(i) case 42: x(); }"))
Output:

&cc.LabeledStatement{
· Case: LabeledStatementCaseLabel,
· Expression: &cc.ConstantExpression{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:26: integer constant "42",
· · },
· },
· Statement: &cc.ExpressionStatement{
· · ExpressionList: &cc.CallExpr{
· · · Func: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:30: identifier "x",
· · · },
· · · LeftParen: example.c:1:31: '(' "(",
· · · RightParen: example.c:1:32: ')' ")",
· · },
· · Token: example.c:1:33: ';' ";",
· },
· Token: example.c:1:21: 'case' "case",
· Token2: example.c:1:28: ':' ":",
}
Example (Default)
fmt.Println(exampleAST(224, "int f() { switch(i) default: x(); }"))
Output:

&cc.LabeledStatement{
· Case: LabeledStatementDefault,
· Statement: &cc.ExpressionStatement{
· · ExpressionList: &cc.CallExpr{
· · · Func: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:30: identifier "x",
· · · },
· · · LeftParen: example.c:1:31: '(' "(",
· · · RightParen: example.c:1:32: ')' ")",
· · },
· · Token: example.c:1:33: ';' ";",
· },
· Token: example.c:1:21: 'default' "default",
· Token2: example.c:1:28: ':' ":",
}
Example (Label)
fmt.Println(exampleAST(221, "int f() { L: goto L; }"))
Output:

&cc.LabeledStatement{
· Case: LabeledStatementLabel,
· Statement: &cc.JumpStatement{
· · Case: JumpStatementGoto,
· · Token: example.c:1:14: 'goto' "goto",
· · Token2: example.c:1:19: identifier "L",
· · Token3: example.c:1:20: ';' ";",
· },
· Token: example.c:1:11: identifier "L",
· Token2: example.c:1:12: ':' ":",
}
Example (Range)
fmt.Println(exampleAST(223, "int f() { switch(i) case 42 ... 56: x(); }"))
Output:

&cc.LabeledStatement{
· Case: LabeledStatementRange,
· Expression: &cc.ConstantExpression{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:26: integer constant "42",
· · },
· },
· Expression2: &cc.ConstantExpression{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:33: integer constant "56",
· · },
· },
· Statement: &cc.ExpressionStatement{
· · ExpressionList: &cc.CallExpr{
· · · Func: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:37: identifier "x",
· · · },
· · · LeftParen: example.c:1:38: '(' "(",
· · · RightParen: example.c:1:39: ')' ")",
· · },
· · Token: example.c:1:40: ';' ";",
· },
· Token: example.c:1:21: 'case' "case",
· Token2: example.c:1:29: '...' "...",
· Token3: example.c:1:35: ':' ":",
}

func (*LabeledStatement) CaseOrdinal

func (n *LabeledStatement) CaseOrdinal() int

CaseOrdinal returns the zero based ordinal number of a labeled statement within a switch statement. Valid only for Case LabeledStatementCaseLabel and LabeledStatementDefault.

func (LabeledStatement) LexicalScope

func (n LabeledStatement) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*LabeledStatement) Position

func (n *LabeledStatement) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*LabeledStatement) String

func (n *LabeledStatement) String() string

String implements fmt.Stringer.

func (*LabeledStatement) Switch

func (n *LabeledStatement) Switch() *SelectionStatement

Switch returns the switch associated with n, case LabeledStatementCaseLabel, LabeledStatementDefault, LabeledStatementRange.

type LabeledStatementCase

type LabeledStatementCase int

LabeledStatementCase represents case numbers of production LabeledStatement

const (
	LabeledStatementLabel LabeledStatementCase = iota
	LabeledStatementCaseLabel
	LabeledStatementRange
	LabeledStatementDefault
)

Values of type LabeledStatementCase

func (LabeledStatementCase) String

func (n LabeledStatementCase) String() string

String implements fmt.Stringer

type Linkage

type Linkage int

Linkage describes linkage of identifiers ([0]6.2.2).

const (
	External Linkage = iota
	Internal
	None
)

Values of type Linkage

func (Linkage) String

func (i Linkage) String() string

type LongDoubleValue

type LongDoubleValue big.Float

func (*LongDoubleValue) Convert

func (n *LongDoubleValue) Convert(to Type) Value

type Macro

type Macro struct {
	Name   Token
	Params []Token

	MinArgs int // m x: 0, m() x: 0, m(...): 0, m(a) a: 1, m(a, ...): 1, m(a, b): 2, m(a, b, ...): 2.
	VarArg  int // m(a): -1, m(...): 0, m(a, ...): 1, m(a...): 0, m(a, b...): 1.

	IsConst  bool // Defined only once or all definitions are the same.
	IsFnLike bool // m: false, m(): true, m(x): true.
	// contains filtered or unexported fields
}

Macro represents a preprocessor #define.

func (*Macro) Position

func (m *Macro) Position() token.Position

Position implements Node.

func (*Macro) ReplacementList

func (m *Macro) ReplacementList() (r []Token)

ReplacementList returns the tokens m is substitued with.

func (Macro) Type

func (t Macro) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (Macro) Value

func (v Macro) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type Node

type Node interface {
	Position() token.Position
}

Node is implemented by Token and AST nodes.

type Parameter

type Parameter struct {
	Declarator         *Declarator         // Can be synthetic.
	AbstractDeclarator *AbstractDeclarator // Can be nil.
	// contains filtered or unexported fields
}

Parameter represents a function parameter.

func (*Parameter) Name

func (n *Parameter) Name() string

Name returns the name of n. The result can be a zero value, like in `void f(int) { ... }`.

func (*Parameter) Position

func (n *Parameter) Position() (r token.Position)

Position implements Node.

func (Parameter) ResolvedIn

func (n Parameter) ResolvedIn() *Scope

ResolvedIn returns the scope an identifier was resolved in, if any.

func (Parameter) Type

func (t Parameter) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (Parameter) Visible

func (v Parameter) Visible() int

Visible reports the token sequence number where the visibility of a name starts.

type ParameterDeclaration

type ParameterDeclaration struct {
	AttributeSpecifiers []*AttributeSpecifier

	AbstractDeclarator    *AbstractDeclarator
	Case                  ParameterDeclarationCase `PrettyPrint:"stringer,zero"`
	DeclarationSpecifiers DeclarationSpecifiers
	Declarator            *Declarator
	// contains filtered or unexported fields
}

ParameterDeclaration represents data reduced by productions:

ParameterDeclaration:
        DeclarationSpecifiers Declarator          // Case ParameterDeclarationDecl
|       DeclarationSpecifiers AbstractDeclarator  // Case ParameterDeclarationAbstract
Example (Abstract)
fmt.Println(exampleAST(191, "int f(int*) {}"))
Output:

&cc.ParameterDeclaration{
· AbstractDeclarator: &cc.AbstractDeclarator{
· · Case: AbstractDeclaratorPtr,
· · Pointer: &cc.Pointer{
· · · Case: PointerTypeQual,
· · · Token: example.c:1:10: '*' "*",
· · },
· },
· Case: ParameterDeclarationAbstract,
· DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:7: 'int' "int",
· · },
· },
}
Example (Decl)
fmt.Println(exampleAST(190, "int f(int i __attribute__((a))) {}"))
Output:

&cc.ParameterDeclaration{
· AttributeSpecifiers: []*cc.AttributeSpecifier{ // len 1
· · 0: &cc.AttributeSpecifier{
· · · AttributeValueList: &cc.AttributeValueList{
· · · · AttributeValue: &cc.AttributeValue{
· · · · · Case: AttributeValueIdent,
· · · · · Token: example.c:1:28: identifier "a",
· · · · },
· · · },
· · · Token: example.c:1:13: '__attribute__' "__attribute__",
· · · Token2: example.c:1:26: '(' "(",
· · · Token3: example.c:1:27: '(' "(",
· · · Token4: example.c:1:29: ')' ")",
· · · Token5: example.c:1:30: ')' ")",
· · },
· },
· Case: ParameterDeclarationDecl,
· DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:7: 'int' "int",
· · },
· },
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorIdent,
· · · Token: example.c:1:11: identifier "i",
· · },
· },
}

func (*ParameterDeclaration) Position

func (n *ParameterDeclaration) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*ParameterDeclaration) String

func (n *ParameterDeclaration) String() string

String implements fmt.Stringer.

func (ParameterDeclaration) Type

func (t ParameterDeclaration) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

type ParameterDeclarationCase

type ParameterDeclarationCase int

ParameterDeclarationCase represents case numbers of production ParameterDeclaration

const (
	ParameterDeclarationDecl ParameterDeclarationCase = iota
	ParameterDeclarationAbstract
)

Values of type ParameterDeclarationCase

func (ParameterDeclarationCase) String

func (n ParameterDeclarationCase) String() string

String implements fmt.Stringer

type ParameterList

type ParameterList struct {
	ParameterDeclaration *ParameterDeclaration
	ParameterList        *ParameterList
	Token                Token
}

ParameterList represents data reduced by productions:

ParameterList:
        ParameterDeclaration
|       ParameterList ',' ParameterDeclaration
Example (Case0)
fmt.Println(exampleAST(188, "int f(int i) {}"))
Output:

&cc.ParameterList{
· ParameterDeclaration: &cc.ParameterDeclaration{
· · Case: ParameterDeclarationDecl,
· · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · 0: &cc.TypeSpecName{
· · · · Case: TypeSpecifierInt,
· · · · Name: example.c:1:7: 'int' "int",
· · · },
· · },
· · Declarator: &cc.Declarator{
· · · DirectDeclarator: &cc.DirectDeclarator{
· · · · Case: DirectDeclaratorIdent,
· · · · Token: example.c:1:11: identifier "i",
· · · },
· · },
· },
}
Example (Case1)
fmt.Println(exampleAST(189, "int f(int i, int j) {}"))
Output:

&cc.ParameterList{
· ParameterDeclaration: &cc.ParameterDeclaration{
· · Case: ParameterDeclarationDecl,
· · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · 0: &cc.TypeSpecName{
· · · · Case: TypeSpecifierInt,
· · · · Name: example.c:1:7: 'int' "int",
· · · },
· · },
· · Declarator: &cc.Declarator{
· · · DirectDeclarator: &cc.DirectDeclarator{
· · · · Case: DirectDeclaratorIdent,
· · · · Token: example.c:1:11: identifier "i",
· · · },
· · },
· },
· ParameterList: &cc.ParameterList{
· · ParameterDeclaration: &cc.ParameterDeclaration{
· · · Case: ParameterDeclarationDecl,
· · · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · · 0: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierInt,
· · · · · Name: example.c:1:14: 'int' "int",
· · · · },
· · · },
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:18: identifier "j",
· · · · },
· · · },
· · },
· · Token: example.c:1:12: ',' ",",
· },
}

func (*ParameterList) Position

func (n *ParameterList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*ParameterList) String

func (n *ParameterList) String() string

String implements fmt.Stringer.

type ParameterTypeList

type ParameterTypeList struct {
	Case          ParameterTypeListCase `PrettyPrint:"stringer,zero"`
	ParameterList *ParameterList
	Token         Token
	Token2        Token
}

ParameterTypeList represents data reduced by productions:

ParameterTypeList:
        ParameterList            // Case ParameterTypeListList
|       ParameterList ',' "..."  // Case ParameterTypeListVar
Example (List)
fmt.Println(exampleAST(186, "int f(int i) {}"))
Output:

&cc.ParameterTypeList{
· Case: ParameterTypeListList,
· ParameterList: &cc.ParameterList{
· · ParameterDeclaration: &cc.ParameterDeclaration{
· · · Case: ParameterDeclarationDecl,
· · · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · · 0: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierInt,
· · · · · Name: example.c:1:7: 'int' "int",
· · · · },
· · · },
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:11: identifier "i",
· · · · },
· · · },
· · },
· },
}
Example (Var)
fmt.Println(exampleAST(187, "int f(int i, ...) {}"))
Output:

&cc.ParameterTypeList{
· Case: ParameterTypeListVar,
· ParameterList: &cc.ParameterList{
· · ParameterDeclaration: &cc.ParameterDeclaration{
· · · Case: ParameterDeclarationDecl,
· · · DeclarationSpecifiers: []*cc.TypeSpecName{ // len 1
· · · · 0: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierInt,
· · · · · Name: example.c:1:7: 'int' "int",
· · · · },
· · · },
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:11: identifier "i",
· · · · },
· · · },
· · },
· },
· Token: example.c:1:12: ',' ",",
· Token2: example.c:1:14: '...' "...",
}

func (*ParameterTypeList) Position

func (n *ParameterTypeList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*ParameterTypeList) String

func (n *ParameterTypeList) String() string

String implements fmt.Stringer.

type ParameterTypeListCase

type ParameterTypeListCase int

ParameterTypeListCase represents case numbers of production ParameterTypeList

const (
	ParameterTypeListList ParameterTypeListCase = iota
	ParameterTypeListVar
)

Values of type ParameterTypeListCase

func (ParameterTypeListCase) String

func (n ParameterTypeListCase) String() string

String implements fmt.Stringer

type Pointer

type Pointer struct {
	Case           PointerCase `PrettyPrint:"stringer,zero"`
	Pointer        *Pointer
	Token          Token
	TypeQualifiers []*TypeQualifier
}

Pointer represents data reduced by productions:

Pointer:
        '*' TypeQualifiers          // Case PointerTypeQual
|       '*' TypeQualifiers Pointer  // Case PointerPtr
|       '^' TypeQualifiers          // Case PointerBlock
Example (Block)
fmt.Println(exampleAST(183, "int atexit_b(void (^ _Nonnull)(void));"))
Output:

&cc.Pointer{
· Case: PointerBlock,
· Token: example.c:1:20: '^' "^",
· TypeQualifiers: []*cc.TypeQualifier{ // len 1
· · 0: &cc.TypeQualifier{
· · · Case: TypeQualifierNonnull,
· · · Token: example.c:1:22: '_Nonnull' "_Nonnull",
· · },
· },
}
Example (Ptr)
fmt.Println(exampleAST(182, "int **p;"))
Output:

&cc.Pointer{
· Case: PointerPtr,
· Pointer: &cc.Pointer{
· · Case: PointerTypeQual,
· · Token: example.c:1:6: '*' "*",
· },
· Token: example.c:1:5: '*' "*",
}
Example (TypeQual)
fmt.Println(exampleAST(181, "int *p;"))
Output:

&cc.Pointer{
· Case: PointerTypeQual,
· Token: example.c:1:5: '*' "*",
}

func (*Pointer) Position

func (n *Pointer) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*Pointer) String

func (n *Pointer) String() string

String implements fmt.Stringer.

type PointerCase

type PointerCase int

PointerCase represents case numbers of production Pointer

const (
	PointerTypeQual PointerCase = iota
	PointerPtr
	PointerBlock
)

Values of type PointerCase

func (PointerCase) String

func (n PointerCase) String() string

String implements fmt.Stringer

type PointerType

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

func NewPointerType

func NewPointerType(elem Type) (r *PointerType)

NewPointerType returns an elem pointer.

func (*PointerType) Align

func (n *PointerType) Align() int

Align implements Type.

func (PointerType) Attributes

func (n PointerType) Attributes() *Attributes

Attributes implemets Type.

func (*PointerType) Decay

func (n *PointerType) Decay() Type

Decay implements Type.

func (*PointerType) Elem

func (n *PointerType) Elem() Type

Elem returns the type n points to.

func (*PointerType) FieldAlign

func (n *PointerType) FieldAlign() int

FieldAlign implements Type.

func (*PointerType) IsCompatible

func (n *PointerType) IsCompatible(t Type) bool

func (*PointerType) IsIncomplete

func (n *PointerType) IsIncomplete() bool

IsIncomplete implements Type.

func (*PointerType) Kind

func (n *PointerType) Kind() Kind

Kind implements Type.

func (*PointerType) Pointer

func (n *PointerType) Pointer() Type

Pointer implements Type.

func (*PointerType) Size

func (n *PointerType) Size() int64

Size implements Type.

func (*PointerType) String

func (n *PointerType) String() string

String implements Type.

func (PointerType) Typedef

func (n PointerType) Typedef() *Declarator

Typedef implements Type

func (*PointerType) Undecay

func (n *PointerType) Undecay() Type

Undecay implements Type.

func (PointerType) VectorSize

func (PointerType) VectorSize() int64

VectorSize implements Type.

type PostfixExpr

type PostfixExpr struct {
	Expr  Expression
	Token Token
	Dec   bool
	// contains filtered or unexported fields
}
Example (Dec)
fmt.Println(exampleAST(22, "int i = x--;"))
Output:

&cc.PostfixExpr{
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Token: example.c:1:10: '--' "--",
· Dec: true,
}
Example (Inc)
fmt.Println(exampleAST(21, "int i = x++;"))
Output:

&cc.PostfixExpr{
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Token: example.c:1:10: '++' "++",
}

func (*PostfixExpr) Position

func (n *PostfixExpr) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*PostfixExpr) String

func (n *PostfixExpr) String() string

String implements fmt.Stringer.

func (PostfixExpr) Type

func (t PostfixExpr) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (PostfixExpr) Value

func (v PostfixExpr) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type PredefinedType

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

func (*PredefinedType) Align

func (n *PredefinedType) Align() int

Align implements Type.

func (PredefinedType) Attributes

func (n PredefinedType) Attributes() *Attributes

Attributes implemets Type.

func (*PredefinedType) Decay

func (n *PredefinedType) Decay() Type

Decay implements Type.

func (*PredefinedType) FieldAlign

func (n *PredefinedType) FieldAlign() int

FieldAlign implements Type.

func (*PredefinedType) IsCompatible

func (n *PredefinedType) IsCompatible(t Type) bool

func (*PredefinedType) IsIncomplete

func (n *PredefinedType) IsIncomplete() bool

IsIncomplete implements Type.

func (*PredefinedType) Kind

func (n *PredefinedType) Kind() Kind

Kind implements Type.

func (*PredefinedType) Pointer

func (n *PredefinedType) Pointer() Type

Pointer implements Type.

func (*PredefinedType) Size

func (n *PredefinedType) Size() int64

Size implements Type.

func (*PredefinedType) String

func (n *PredefinedType) String() string

String implements Type.

func (PredefinedType) Typedef

func (n PredefinedType) Typedef() *Declarator

Typedef implements Type

func (*PredefinedType) Undecay

func (n *PredefinedType) Undecay() Type

Undecay implements Type.

func (*PredefinedType) VectorSize

func (n *PredefinedType) VectorSize() int64

VectorSize implements Type.

type PrefixExpr

type PrefixExpr struct {
	Token Token
	Expr  Expression
	Dec   bool
	// contains filtered or unexported fields
}
Example (Dec)
fmt.Println(exampleAST(28, "int i = --x;"))
Output:

&cc.PrefixExpr{
· Token: example.c:1:9: '--' "--",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
· Dec: true,
}
Example (Inc)
fmt.Println(exampleAST(27, "int i = ++x;"))
Output:

&cc.PrefixExpr{
· Token: example.c:1:9: '++' "++",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
}

func (*PrefixExpr) Position

func (n *PrefixExpr) Position() (r token.Position)

func (*PrefixExpr) String

func (n *PrefixExpr) String() string

String implements fmt.Stringer.

func (PrefixExpr) Type

func (t PrefixExpr) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (PrefixExpr) Value

func (v PrefixExpr) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type PrimaryExpression

type PrimaryExpression struct {
	Case              PrimaryExpressionCase `PrettyPrint:"stringer,zero"`
	CompoundStatement *CompoundStatement
	ExpressionList    Expression
	GenericSelection  *GenericSelection
	Token             Token
	Token2            Token
	// contains filtered or unexported fields
}

PrimaryExpression represents data reduced by productions:

PrimaryExpression:
        IDENTIFIER                 // Case PrimaryExpressionIdent
|       INTCONST                   // Case PrimaryExpressionInt
|       FLOATCONST                 // Case PrimaryExpressionFloat
|       CHARCONST                  // Case PrimaryExpressionChar
|       LONGCHARCONST              // Case PrimaryExpressionLChar
|       STRINGLITERAL              // Case PrimaryExpressionString
|       LONGSTRINGLITERAL          // Case PrimaryExpressionLString
|       '(' ExpressionList ')'     // Case PrimaryExpressionExpr
|       '(' CompoundStatement ')'  // Case PrimaryExpressionStmt
|       GenericSelection           // Case PrimaryExpressionGeneric
Example (Char)
fmt.Println(exampleAST(4, "int i = 'x';"))
Output:

&cc.PrimaryExpression{
· Case: PrimaryExpressionChar,
· Token: example.c:1:9: character constant "'x'",
}
Example (Expr)
fmt.Println(exampleAST(8, "int i = (x+y);"))
Output:

&cc.PrimaryExpression{
· Case: PrimaryExpressionExpr,
· ExpressionList: &cc.BinaryExpression{
· · Lhs: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:10: identifier "x",
· · },
· · Op: BinaryOperationAdd,
· · Token: example.c:1:11: '+' "+",
· · Rhs: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:12: identifier "y",
· · },
· },
· Token: example.c:1:9: '(' "(",
· Token2: example.c:1:13: ')' ")",
}
Example (Float)
fmt.Println(exampleAST(3, "int i = 3.14;"))
Output:

&cc.PrimaryExpression{
· Case: PrimaryExpressionFloat,
· Token: example.c:1:9: floating point constant "3.14",
}
Example (Generic)
fmt.Println(exampleAST(10, "int i = _Generic(x, int: y)(42);"))
Output:

&cc.PrimaryExpression{
· Case: PrimaryExpressionGeneric,
· GenericSelection: &cc.GenericSelection{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionIdent,
· · · Token: example.c:1:18: identifier "x",
· · },
· · GenericAssociationList: &cc.GenericAssociationList{
· · · GenericAssociation: &cc.GenericAssociation{
· · · · Expression: &cc.PrimaryExpression{
· · · · · Case: PrimaryExpressionIdent,
· · · · · Token: example.c:1:26: identifier "y",
· · · · },
· · · · Case: GenericAssociationType,
· · · · Token: example.c:1:24: ':' ":",
· · · · TypeName: &cc.TypeName{
· · · · · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · · · · 0: &cc.TypeSpecName{
· · · · · · · Case: TypeSpecifierInt,
· · · · · · · Name: example.c:1:21: 'int' "int",
· · · · · · },
· · · · · },
· · · · },
· · · },
· · },
· · Token: example.c:1:9: '_Generic' "_Generic",
· · Token2: example.c:1:17: '(' "(",
· · Token3: example.c:1:19: ',' ",",
· · Token4: example.c:1:27: ')' ")",
· },
}
&cc.PrimaryExpression{
· Case: PrimaryExpressionInt,
· Token: example.c:1:29: integer constant "42",
}
Example (Ident)
fmt.Println(exampleAST(1, "int i = x;"))
Output:

&cc.PrimaryExpression{
· Case: PrimaryExpressionIdent,
· Token: example.c:1:9: identifier "x",
}
Example (Int)
fmt.Println(exampleAST(2, "int i = 42;"))
Output:

&cc.PrimaryExpression{
· Case: PrimaryExpressionInt,
· Token: example.c:1:9: integer constant "42",
}
Example (LChar)
fmt.Println(exampleAST(5, "int i = L'x';"))
Output:

&cc.PrimaryExpression{
· Case: PrimaryExpressionLChar,
· Token: example.c:1:9: long character constant "L'x'",
}
Example (LString)
fmt.Println(exampleAST(7, "char *c = L\"x\" L\"y\";"))
Output:

&cc.PrimaryExpression{
· Case: PrimaryExpressionLString,
· Token: example.c:1:11: long string literal "L\"xy\"",
}
Example (Stmt)
fmt.Println(exampleAST(9, "int i = ({x();});"))
Output:

&cc.PrimaryExpression{
· Case: PrimaryExpressionStmt,
· CompoundStatement: &cc.CompoundStatement{
· · Lbrace: example.c:1:10: '{' "{",
· · List: []*cc.ExpressionStatement{ // len 1
· · · 0: &cc.ExpressionStatement{
· · · · ExpressionList: &cc.CallExpr{
· · · · · Func: &cc.PrimaryExpression{
· · · · · · Case: PrimaryExpressionIdent,
· · · · · · Token: example.c:1:11: identifier "x",
· · · · · },
· · · · · LeftParen: example.c:1:12: '(' "(",
· · · · · RightParen: example.c:1:13: ')' ")",
· · · · },
· · · · Token: example.c:1:14: ';' ";",
· · · },
· · },
· · Rbrace: example.c:1:15: '}' "}",
· },
· Token: example.c:1:9: '(' "(",
· Token2: example.c:1:16: ')' ")",
}
Example (String)
fmt.Println(exampleAST(6, "char *c = \"x\" \"y\";"))
Output:

&cc.PrimaryExpression{
· Case: PrimaryExpressionString,
· Token: example.c:1:11: string literal "\"xy\"",
}

func (PrimaryExpression) LexicalScope

func (n PrimaryExpression) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*PrimaryExpression) Macro

func (n *PrimaryExpression) Macro() *Macro

Macro returns the single token, object-like, constant macro that produced this node, if any.

func (*PrimaryExpression) Position

func (n *PrimaryExpression) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*PrimaryExpression) ResolvedTo

func (n *PrimaryExpression) ResolvedTo() Node

ResolvedTo returns the node n resolved to when n.Case is PrimaryExpressionIdent.

func (*PrimaryExpression) String

func (n *PrimaryExpression) String() string

String implements fmt.Stringer.

func (PrimaryExpression) Type

func (t PrimaryExpression) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (PrimaryExpression) Value

func (v PrimaryExpression) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type PrimaryExpressionCase

type PrimaryExpressionCase int

PrimaryExpressionCase represents case numbers of production PrimaryExpression

const (
	PrimaryExpressionIdent PrimaryExpressionCase = iota
	PrimaryExpressionInt
	PrimaryExpressionFloat
	PrimaryExpressionChar
	PrimaryExpressionLChar
	PrimaryExpressionString
	PrimaryExpressionLString
	PrimaryExpressionExpr
	PrimaryExpressionStmt
	PrimaryExpressionGeneric
)

Values of type PrimaryExpressionCase

func (PrimaryExpressionCase) String

func (n PrimaryExpressionCase) String() string

String implements fmt.Stringer

type Scope

type Scope struct {
	Children []*Scope
	Nodes    map[string][]Node
	Parent   *Scope
}

Scope binds names to declaring nodes.

The dynamic type of a Node in the Nodes map is one of

Node type                   Note
-----------------           ----
*Declarator
*EnumSpecifier              binds the tag
*Enumerator
*LabelDeclaration
*LabeledStatement           case LabeledStatementLabel
*Parameter
*StructOrUnionSpecifier     binds the tag

type SelectionStatement

type SelectionStatement struct {
	Case           SelectionStatementCase `PrettyPrint:"stringer,zero"`
	ExpressionList Expression
	Statement      Statement
	Statement2     Statement
	Token          Token
	Token2         Token
	Token3         Token
	Token4         Token
	// contains filtered or unexported fields
}

SelectionStatement represents data reduced by productions:

SelectionStatement:
        "if" '(' ExpressionList ')' Statement                   // Case SelectionStatementIf
|       "if" '(' ExpressionList ')' Statement "else" Statement  // Case SelectionStatementIfElse
|       "switch" '(' ExpressionList ')' Statement               // Case SelectionStatementSwitch
Example (If)
fmt.Println(exampleAST(234, "int f() { if(x) y(); }"))
Output:

&cc.SelectionStatement{
· Case: SelectionStatementIf,
· ExpressionList: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:14: identifier "x",
· },
· Statement: &cc.ExpressionStatement{
· · ExpressionList: &cc.CallExpr{
· · · Func: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:17: identifier "y",
· · · },
· · · LeftParen: example.c:1:18: '(' "(",
· · · RightParen: example.c:1:19: ')' ")",
· · },
· · Token: example.c:1:20: ';' ";",
· },
· Token: example.c:1:11: 'if' "if",
· Token2: example.c:1:13: '(' "(",
· Token3: example.c:1:15: ')' ")",
}
Example (IfElse)
fmt.Println(exampleAST(235, "int f() { if(x) y(); else z(); }"))
Output:

&cc.SelectionStatement{
· Case: SelectionStatementIfElse,
· ExpressionList: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:14: identifier "x",
· },
· Statement: &cc.ExpressionStatement{
· · ExpressionList: &cc.CallExpr{
· · · Func: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:17: identifier "y",
· · · },
· · · LeftParen: example.c:1:18: '(' "(",
· · · RightParen: example.c:1:19: ')' ")",
· · },
· · Token: example.c:1:20: ';' ";",
· },
· Statement2: &cc.ExpressionStatement{
· · ExpressionList: &cc.CallExpr{
· · · Func: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:27: identifier "z",
· · · },
· · · LeftParen: example.c:1:28: '(' "(",
· · · RightParen: example.c:1:29: ')' ")",
· · },
· · Token: example.c:1:30: ';' ";",
· },
· Token: example.c:1:11: 'if' "if",
· Token2: example.c:1:13: '(' "(",
· Token3: example.c:1:15: ')' ")",
· Token4: example.c:1:22: 'else' "else",
}
Example (Switch)
fmt.Println(exampleAST(236, "int f() { switch(i) case 42: x(); }"))
Output:

&cc.SelectionStatement{
· Case: SelectionStatementSwitch,
· ExpressionList: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:18: identifier "i",
· },
· Statement: &cc.LabeledStatement{
· · Case: LabeledStatementCaseLabel,
· · Expression: &cc.ConstantExpression{
· · · Expression: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionInt,
· · · · Token: example.c:1:26: integer constant "42",
· · · },
· · },
· · Statement: &cc.ExpressionStatement{
· · · ExpressionList: &cc.CallExpr{
· · · · Func: &cc.PrimaryExpression{
· · · · · Case: PrimaryExpressionIdent,
· · · · · Token: example.c:1:30: identifier "x",
· · · · },
· · · · LeftParen: example.c:1:31: '(' "(",
· · · · RightParen: example.c:1:32: ')' ")",
· · · },
· · · Token: example.c:1:33: ';' ";",
· · },
· · Token: example.c:1:21: 'case' "case",
· · Token2: example.c:1:28: ':' ":",
· },
· Token: example.c:1:11: 'switch' "switch",
· Token2: example.c:1:17: '(' "(",
· Token3: example.c:1:19: ')' ")",
}

func (*SelectionStatement) Cases

func (n *SelectionStatement) Cases() int

Cases returns the combined number of "case" and "default" labels in a switch statement. Valid for Case == SelectionStatementSwitch.

func (*SelectionStatement) LabeledStatements

func (n *SelectionStatement) LabeledStatements() []*LabeledStatement

LabeledStatements returns labeled statements appearing within n, case SelectionStatementSwitch.

func (SelectionStatement) LexicalScope

func (n SelectionStatement) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*SelectionStatement) Position

func (n *SelectionStatement) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*SelectionStatement) String

func (n *SelectionStatement) String() string

String implements fmt.Stringer.

type SelectionStatementCase

type SelectionStatementCase int

SelectionStatementCase represents case numbers of production SelectionStatement

const (
	SelectionStatementIf SelectionStatementCase = iota
	SelectionStatementIfElse
	SelectionStatementSwitch
)

Values of type SelectionStatementCase

func (SelectionStatementCase) String

func (n SelectionStatementCase) String() string

String implements fmt.Stringer

type SelectorExpr

type SelectorExpr struct {
	Expr  Expression
	Token Token
	Sel   Token
	Ptr   bool
	// contains filtered or unexported fields
}
Example (PSelect)
fmt.Println(exampleAST(20, "int i = x->y;"))
Output:

&cc.SelectorExpr{
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Token: example.c:1:10: '->' "->",
· Sel: example.c:1:12: identifier "y",
· Ptr: true,
}
Example (Select)
fmt.Println(exampleAST(19, "int i = x.y;"))
Output:

&cc.SelectorExpr{
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:9: identifier "x",
· },
· Token: example.c:1:10: '.' ".",
· Sel: example.c:1:11: identifier "y",
}

func (*SelectorExpr) Field

func (n *SelectorExpr) Field() *Field

Field reports the resolved field.

func (*SelectorExpr) Position

func (n *SelectorExpr) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*SelectorExpr) String

func (n *SelectorExpr) String() string

String implements fmt.Stringer.

func (SelectorExpr) Type

func (t SelectorExpr) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (SelectorExpr) Value

func (v SelectorExpr) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type SizeOfExpr

type SizeOfExpr struct {
	Token Token
	Expr  Expression
	// contains filtered or unexported fields
}
Example (SizeofExpr)
fmt.Println(exampleAST(35, "int i = sizeof x;"))
Output:

&cc.SizeOfExpr{
· Token: example.c:1:9: 'sizeof' "sizeof",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:16: identifier "x",
· },
}

func (*SizeOfExpr) Position

func (n *SizeOfExpr) Position() (r token.Position)

func (*SizeOfExpr) String

func (n *SizeOfExpr) String() string

String implements fmt.Stringer.

func (SizeOfExpr) Type

func (t SizeOfExpr) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (SizeOfExpr) Value

func (v SizeOfExpr) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type SizeOfTypeExpr

type SizeOfTypeExpr struct {
	Token      Token
	LeftParen  Token
	TypeName   *TypeName
	RightParen Token
	// contains filtered or unexported fields
}
Example (SizeofType)
fmt.Println(exampleAST(36, "int i = sizeof(int);"))
Output:

&cc.SizeOfTypeExpr{
· Token: example.c:1:9: 'sizeof' "sizeof",
· LeftParen: example.c:1:15: '(' "(",
· TypeName: &cc.TypeName{
· · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · 0: &cc.TypeSpecName{
· · · · Case: TypeSpecifierInt,
· · · · Name: example.c:1:16: 'int' "int",
· · · },
· · },
· },
· RightParen: example.c:1:19: ')' ")",
}

func (*SizeOfTypeExpr) Position

func (n *SizeOfTypeExpr) Position() (r token.Position)

func (*SizeOfTypeExpr) String

func (n *SizeOfTypeExpr) String() string

String implements fmt.Stringer.

func (SizeOfTypeExpr) Type

func (t SizeOfTypeExpr) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (SizeOfTypeExpr) Value

func (v SizeOfTypeExpr) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type Source

type Source struct {
	Name  string
	Value interface{}
	FS    fs.FS
}

Source is a named part of a translation unit. The name argument is used for reporting Token positions. The value argument can be a string, []byte, fs.File, io.ReadCloser, io.Reader or nil. If the value argument is nil an attempt is made to open a file using the name argument.

When the value argument is an *os.File, io.ReadCloser or fs.File, Value.Close() is called before returning from Preprocess, Parse or Translate.

If FS is not nil it overrides the FS from Config.

type SpecifierQualifier

type SpecifierQualifier interface {
	Node
	fmt.Stringer
	// contains filtered or unexported methods
}

SpecifierQualifier represents data reduced by productions:

SpecifierQualifierList:
        TypeSpecifier SpecifierQualifierList       // Case SpecifierQualifierListTypeSpec
|       TypeQualifier SpecifierQualifierList       // Case SpecifierQualifierListTypeQual
|       AlignmentSpecifier SpecifierQualifierList  // Case SpecifierQualifierListAlignSpec

type Statement

type Statement interface {
	Node
	fmt.Stringer

	BlockItem
	// contains filtered or unexported methods
}

Statement represents data reduced by productions:

Statement:
        LabeledStatement     // Case StatementLabeled
|       CompoundStatement    // Case StatementCompound
|       ExpressionStatement  // Case StatementExpr
|       SelectionStatement   // Case StatementSelection
|       IterationStatement   // Case StatementIteration
|       JumpStatement        // Case StatementJump
|       AsmStatement         // Case StatementAsm
Example (Asm)
fmt.Println(exampleAST(220, "int f() { __asm__(\"nop\"); }"))
Output:

&cc.CompoundStatement{
· Lbrace: example.c:1:9: '{' "{",
· List: []*cc.CommonDeclaration{ // len 2
· · 0: &cc.CommonDeclaration{
· · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · 0: &cc.StorageClassSpecifier{
· · · · · Case: StorageClassSpecifierStatic,
· · · · · Token: example.c:1:9: 'static' "static",
· · · · },
· · · · 1: &cc.TypeQualifier{
· · · · · Case: TypeQualifierConst,
· · · · · Token: example.c:1:9: 'const' "const",
· · · · },
· · · · 2: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierChar,
· · · · · Name: example.c:1:9: 'char' "char",
· · · · },
· · · },
· · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · 0: &cc.InitDeclarator{
· · · · · Declarator: &cc.Declarator{
· · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · Case: DirectDeclaratorArr,
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · },
· · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · },
· · · · · },
· · · · · Initializer: &cc.Initializer{
· · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · Case: PrimaryExpressionString,
· · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · },
· · · · · · Case: InitializerExpr,
· · · · · },
· · · · · Token: example.c:1:9: '=' "=",
· · · · },
· · · },
· · · Token: example.c:1:9: ';' ";",
· · },
· · 1: &cc.AsmStatement{
· · · Asm: &cc.Asm{
· · · · Token: example.c:1:11: '__asm__' "__asm__",
· · · · Token2: example.c:1:18: '(' "(",
· · · · Token3: example.c:1:19: string literal "\"nop\"",
· · · · Token4: example.c:1:24: ')' ")",
· · · },
· · · Token: example.c:1:25: ';' ";",
· · },
· },
· Rbrace: example.c:1:27: '}' "}",
}
Example (Compound)
fmt.Println(exampleAST(215, "int f() { { y(); } }"))
Output:

&cc.CompoundStatement{
· Lbrace: example.c:1:9: '{' "{",
· List: []*cc.CommonDeclaration{ // len 2
· · 0: &cc.CommonDeclaration{
· · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · 0: &cc.StorageClassSpecifier{
· · · · · Case: StorageClassSpecifierStatic,
· · · · · Token: example.c:1:9: 'static' "static",
· · · · },
· · · · 1: &cc.TypeQualifier{
· · · · · Case: TypeQualifierConst,
· · · · · Token: example.c:1:9: 'const' "const",
· · · · },
· · · · 2: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierChar,
· · · · · Name: example.c:1:9: 'char' "char",
· · · · },
· · · },
· · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · 0: &cc.InitDeclarator{
· · · · · Declarator: &cc.Declarator{
· · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · Case: DirectDeclaratorArr,
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · },
· · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · },
· · · · · },
· · · · · Initializer: &cc.Initializer{
· · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · Case: PrimaryExpressionString,
· · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · },
· · · · · · Case: InitializerExpr,
· · · · · },
· · · · · Token: example.c:1:9: '=' "=",
· · · · },
· · · },
· · · Token: example.c:1:9: ';' ";",
· · },
· · 1: &cc.CompoundStatement{
· · · Lbrace: example.c:1:11: '{' "{",
· · · List: []*cc.ExpressionStatement{ // len 1
· · · · 0: &cc.ExpressionStatement{
· · · · · ExpressionList: &cc.CallExpr{
· · · · · · Func: &cc.PrimaryExpression{
· · · · · · · Case: PrimaryExpressionIdent,
· · · · · · · Token: example.c:1:13: identifier "y",
· · · · · · },
· · · · · · LeftParen: example.c:1:14: '(' "(",
· · · · · · RightParen: example.c:1:15: ')' ")",
· · · · · },
· · · · · Token: example.c:1:16: ';' ";",
· · · · },
· · · },
· · · Rbrace: example.c:1:18: '}' "}",
· · },
· },
· Rbrace: example.c:1:20: '}' "}",
}
Example (Expr)
fmt.Println(exampleAST(216, "int f() { __attribute__((a)); }"))
Output:

&cc.CompoundStatement{
· Lbrace: example.c:1:9: '{' "{",
· List: []*cc.CommonDeclaration{ // len 2
· · 0: &cc.CommonDeclaration{
· · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · 0: &cc.StorageClassSpecifier{
· · · · · Case: StorageClassSpecifierStatic,
· · · · · Token: example.c:1:9: 'static' "static",
· · · · },
· · · · 1: &cc.TypeQualifier{
· · · · · Case: TypeQualifierConst,
· · · · · Token: example.c:1:9: 'const' "const",
· · · · },
· · · · 2: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierChar,
· · · · · Name: example.c:1:9: 'char' "char",
· · · · },
· · · },
· · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · 0: &cc.InitDeclarator{
· · · · · Declarator: &cc.Declarator{
· · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · Case: DirectDeclaratorArr,
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · },
· · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · },
· · · · · },
· · · · · Initializer: &cc.Initializer{
· · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · Case: PrimaryExpressionString,
· · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · },
· · · · · · Case: InitializerExpr,
· · · · · },
· · · · · Token: example.c:1:9: '=' "=",
· · · · },
· · · },
· · · Token: example.c:1:9: ';' ";",
· · },
· · 1: &cc.ExpressionStatement{
· · · Token: example.c:1:29: ';' ";",
· · },
· },
· Rbrace: example.c:1:31: '}' "}",
}
Example (Iteration)
fmt.Println(exampleAST(218, "int f() { for(;;) x(); }"))
Output:

&cc.CompoundStatement{
· Lbrace: example.c:1:9: '{' "{",
· List: []*cc.CommonDeclaration{ // len 2
· · 0: &cc.CommonDeclaration{
· · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · 0: &cc.StorageClassSpecifier{
· · · · · Case: StorageClassSpecifierStatic,
· · · · · Token: example.c:1:9: 'static' "static",
· · · · },
· · · · 1: &cc.TypeQualifier{
· · · · · Case: TypeQualifierConst,
· · · · · Token: example.c:1:9: 'const' "const",
· · · · },
· · · · 2: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierChar,
· · · · · Name: example.c:1:9: 'char' "char",
· · · · },
· · · },
· · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · 0: &cc.InitDeclarator{
· · · · · Declarator: &cc.Declarator{
· · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · Case: DirectDeclaratorArr,
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · },
· · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · },
· · · · · },
· · · · · Initializer: &cc.Initializer{
· · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · Case: PrimaryExpressionString,
· · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · },
· · · · · · Case: InitializerExpr,
· · · · · },
· · · · · Token: example.c:1:9: '=' "=",
· · · · },
· · · },
· · · Token: example.c:1:9: ';' ";",
· · },
· · 1: &cc.IterationStatement{
· · · Case: IterationStatementFor,
· · · Statement: &cc.ExpressionStatement{
· · · · ExpressionList: &cc.CallExpr{
· · · · · Func: &cc.PrimaryExpression{
· · · · · · Case: PrimaryExpressionIdent,
· · · · · · Token: example.c:1:19: identifier "x",
· · · · · },
· · · · · LeftParen: example.c:1:20: '(' "(",
· · · · · RightParen: example.c:1:21: ')' ")",
· · · · },
· · · · Token: example.c:1:22: ';' ";",
· · · },
· · · Token: example.c:1:11: 'for' "for",
· · · Token2: example.c:1:14: '(' "(",
· · · Token3: example.c:1:15: ';' ";",
· · · Token4: example.c:1:16: ';' ";",
· · · Token5: example.c:1:17: ')' ")",
· · },
· },
· Rbrace: example.c:1:24: '}' "}",
}
Example (Jump)
fmt.Println(exampleAST(219, "int f() { return x; }"))
Output:

&cc.CompoundStatement{
· Lbrace: example.c:1:9: '{' "{",
· List: []*cc.CommonDeclaration{ // len 2
· · 0: &cc.CommonDeclaration{
· · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · 0: &cc.StorageClassSpecifier{
· · · · · Case: StorageClassSpecifierStatic,
· · · · · Token: example.c:1:9: 'static' "static",
· · · · },
· · · · 1: &cc.TypeQualifier{
· · · · · Case: TypeQualifierConst,
· · · · · Token: example.c:1:9: 'const' "const",
· · · · },
· · · · 2: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierChar,
· · · · · Name: example.c:1:9: 'char' "char",
· · · · },
· · · },
· · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · 0: &cc.InitDeclarator{
· · · · · Declarator: &cc.Declarator{
· · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · Case: DirectDeclaratorArr,
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · },
· · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · },
· · · · · },
· · · · · Initializer: &cc.Initializer{
· · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · Case: PrimaryExpressionString,
· · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · },
· · · · · · Case: InitializerExpr,
· · · · · },
· · · · · Token: example.c:1:9: '=' "=",
· · · · },
· · · },
· · · Token: example.c:1:9: ';' ";",
· · },
· · 1: &cc.JumpStatement{
· · · Case: JumpStatementReturn,
· · · ExpressionList: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:18: identifier "x",
· · · },
· · · Token: example.c:1:11: 'return' "return",
· · · Token2: example.c:1:19: ';' ";",
· · },
· },
· Rbrace: example.c:1:21: '}' "}",
}
Example (Labeled)
fmt.Println(exampleAST(214, "int f() { L: x(); }"))
Output:

&cc.CompoundStatement{
· Lbrace: example.c:1:9: '{' "{",
· List: []*cc.CommonDeclaration{ // len 2
· · 0: &cc.CommonDeclaration{
· · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · 0: &cc.StorageClassSpecifier{
· · · · · Case: StorageClassSpecifierStatic,
· · · · · Token: example.c:1:9: 'static' "static",
· · · · },
· · · · 1: &cc.TypeQualifier{
· · · · · Case: TypeQualifierConst,
· · · · · Token: example.c:1:9: 'const' "const",
· · · · },
· · · · 2: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierChar,
· · · · · Name: example.c:1:9: 'char' "char",
· · · · },
· · · },
· · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · 0: &cc.InitDeclarator{
· · · · · Declarator: &cc.Declarator{
· · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · Case: DirectDeclaratorArr,
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · },
· · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · },
· · · · · },
· · · · · Initializer: &cc.Initializer{
· · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · Case: PrimaryExpressionString,
· · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · },
· · · · · · Case: InitializerExpr,
· · · · · },
· · · · · Token: example.c:1:9: '=' "=",
· · · · },
· · · },
· · · Token: example.c:1:9: ';' ";",
· · },
· · 1: &cc.LabeledStatement{
· · · Case: LabeledStatementLabel,
· · · Statement: &cc.ExpressionStatement{
· · · · ExpressionList: &cc.CallExpr{
· · · · · Func: &cc.PrimaryExpression{
· · · · · · Case: PrimaryExpressionIdent,
· · · · · · Token: example.c:1:14: identifier "x",
· · · · · },
· · · · · LeftParen: example.c:1:15: '(' "(",
· · · · · RightParen: example.c:1:16: ')' ")",
· · · · },
· · · · Token: example.c:1:17: ';' ";",
· · · },
· · · Token: example.c:1:11: identifier "L",
· · · Token2: example.c:1:12: ':' ":",
· · },
· },
· Rbrace: example.c:1:19: '}' "}",
}
Example (Selection)
fmt.Println(exampleAST(217, "int f() { if(x) y(); }"))
Output:

&cc.CompoundStatement{
· Lbrace: example.c:1:9: '{' "{",
· List: []*cc.CommonDeclaration{ // len 2
· · 0: &cc.CommonDeclaration{
· · · DeclarationSpecifiers: []*cc.StorageClassSpecifier{ // len 3
· · · · 0: &cc.StorageClassSpecifier{
· · · · · Case: StorageClassSpecifierStatic,
· · · · · Token: example.c:1:9: 'static' "static",
· · · · },
· · · · 1: &cc.TypeQualifier{
· · · · · Case: TypeQualifierConst,
· · · · · Token: example.c:1:9: 'const' "const",
· · · · },
· · · · 2: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierChar,
· · · · · Name: example.c:1:9: 'char' "char",
· · · · },
· · · },
· · · InitDeclarators: []*cc.InitDeclarator{ // len 1
· · · · 0: &cc.InitDeclarator{
· · · · · Declarator: &cc.Declarator{
· · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · Case: DirectDeclaratorArr,
· · · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · · Token: example.c:1:9: identifier "__func__",
· · · · · · · },
· · · · · · · Token: example.c:1:9: '[' "[",
· · · · · · · Token2: example.c:1:9: ']' "]",
· · · · · · },
· · · · · },
· · · · · Initializer: &cc.Initializer{
· · · · · · Expression: &cc.PrimaryExpression{
· · · · · · · Case: PrimaryExpressionString,
· · · · · · · Token: example.c:1:9: string literal "\"f\"",
· · · · · · },
· · · · · · Case: InitializerExpr,
· · · · · },
· · · · · Token: example.c:1:9: '=' "=",
· · · · },
· · · },
· · · Token: example.c:1:9: ';' ";",
· · },
· · 1: &cc.SelectionStatement{
· · · Case: SelectionStatementIf,
· · · ExpressionList: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:14: identifier "x",
· · · },
· · · Statement: &cc.ExpressionStatement{
· · · · ExpressionList: &cc.CallExpr{
· · · · · Func: &cc.PrimaryExpression{
· · · · · · Case: PrimaryExpressionIdent,
· · · · · · Token: example.c:1:17: identifier "y",
· · · · · },
· · · · · LeftParen: example.c:1:18: '(' "(",
· · · · · RightParen: example.c:1:19: ')' ")",
· · · · },
· · · · Token: example.c:1:20: ';' ";",
· · · },
· · · Token: example.c:1:11: 'if' "if",
· · · Token2: example.c:1:13: '(' "(",
· · · Token3: example.c:1:15: ')' ")",
· · },
· },
· Rbrace: example.c:1:22: '}' "}",
}

type StaticAssertDeclaration

type StaticAssertDeclaration struct {
	Expression Expression
	Token      Token
	Token2     Token
	Token3     Token
	Token4     Token
	Token5     Token
}

StaticAssertDeclaration represents data reduced by production:

StaticAssertDeclaration:
        "_Static_assert" '(' ConstantExpression ',' STRINGLITERAL ')'
Example (Case0)
fmt.Println(exampleAST(92, "_Static_assert(x > y, \"abc\")"))
Output:

&cc.StaticAssertDeclaration{
· Expression: &cc.ConstantExpression{
· · Expression: &cc.BinaryExpression{
· · · Lhs: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:16: identifier "x",
· · · },
· · · Op: BinaryOperationGt,
· · · Token: example.c:1:18: '>' ">",
· · · Rhs: &cc.PrimaryExpression{
· · · · Case: PrimaryExpressionIdent,
· · · · Token: example.c:1:20: identifier "y",
· · · },
· · },
· },
· Token: example.c:1:1: _Static_assert "_Static_assert",
· Token2: example.c:1:15: '(' "(",
· Token3: example.c:1:21: ',' ",",
· Token4: example.c:1:23: string literal "\"abc\"",
· Token5: example.c:1:28: ')' ")",
}

func (*StaticAssertDeclaration) Position

func (n *StaticAssertDeclaration) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*StaticAssertDeclaration) String

func (n *StaticAssertDeclaration) String() string

String implements fmt.Stringer.

type StorageClassSpecifier

type StorageClassSpecifier struct {
	Declspecs []Token
	Case      StorageClassSpecifierCase `PrettyPrint:"stringer,zero"`
	Token     Token
	Token2    Token
	Token3    Token
}

StorageClassSpecifier represents data reduced by productions:

StorageClassSpecifier:
        "typedef"             // Case StorageClassSpecifierTypedef
|       "extern"              // Case StorageClassSpecifierExtern
|       "static"              // Case StorageClassSpecifierStatic
|       "auto"                // Case StorageClassSpecifierAuto
|       "register"            // Case StorageClassSpecifierRegister
|       "_Thread_local"       // Case StorageClassSpecifierThreadLocal
|       "__declspec" '(' ')'  // Case StorageClassSpecifierDeclspec
Example (Auto)
fmt.Println(exampleAST(106, "auto int i;"))
Output:

&cc.StorageClassSpecifier{
· Case: StorageClassSpecifierAuto,
· Token: example.c:1:1: 'auto' "auto",
}
Example (Declspec)
fmt.Println(exampleAST(109, "__declspec(foo) int i;"))
Output:

&cc.StorageClassSpecifier{
· Declspecs: []cc.Token{ // len 1
· · 0: example.c:1:12: identifier "foo",
· },
· Case: StorageClassSpecifierDeclspec,
· Token: example.c:1:1: '__declspec' "__declspec",
· Token2: example.c:1:11: '(' "(",
· Token3: example.c:1:15: ')' ")",
}
Example (Extern)
fmt.Println(exampleAST(104, "extern int i;"))
Output:

&cc.StorageClassSpecifier{
· Case: StorageClassSpecifierExtern,
· Token: example.c:1:1: 'extern' "extern",
}
Example (Register)
fmt.Println(exampleAST(107, "register int i;"))
Output:

&cc.StorageClassSpecifier{
· Case: StorageClassSpecifierRegister,
· Token: example.c:1:1: 'register' "register",
}
Example (Static)
fmt.Println(exampleAST(105, "static int i;"))
Output:

&cc.StorageClassSpecifier{
· Case: StorageClassSpecifierStatic,
· Token: example.c:1:1: 'static' "static",
}
Example (ThreadLocal)
fmt.Println(exampleAST(108, "_Thread_local int i;"))
Output:

&cc.StorageClassSpecifier{
· Case: StorageClassSpecifierThreadLocal,
· Token: example.c:1:1: '_Thread_local' "_Thread_local",
}
Example (Typedef)
fmt.Println(exampleAST(103, "typedef int int_t;"))
Output:

&cc.StorageClassSpecifier{
· Case: StorageClassSpecifierTypedef,
· Token: example.c:1:1: 'typedef' "typedef",
}

func (*StorageClassSpecifier) Position

func (n *StorageClassSpecifier) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*StorageClassSpecifier) String

func (n *StorageClassSpecifier) String() string

String implements fmt.Stringer.

type StorageClassSpecifierCase

type StorageClassSpecifierCase int

StorageClassSpecifierCase represents case numbers of production StorageClassSpecifier

const (
	StorageClassSpecifierTypedef StorageClassSpecifierCase = iota
	StorageClassSpecifierExtern
	StorageClassSpecifierStatic
	StorageClassSpecifierAuto
	StorageClassSpecifierRegister
	StorageClassSpecifierThreadLocal
	StorageClassSpecifierDeclspec
)

Values of type StorageClassSpecifierCase

func (StorageClassSpecifierCase) String

func (n StorageClassSpecifierCase) String() string

String implements fmt.Stringer

type StorageDuration

type StorageDuration int

StorageDuration describes storage duration of objects ([0]6.2.4).

const (
	Static StorageDuration = iota
	Automatic
	Allocated
)

Values of type StorageDuration

func (StorageDuration) String

func (i StorageDuration) String() string

type StringValue

type StringValue string

func (StringValue) Convert

func (n StringValue) Convert(to Type) Value

type StructDeclaration

type StructDeclaration struct {
	AttributeSpecifiers     []*AttributeSpecifier
	Case                    StructDeclarationCase `PrettyPrint:"stringer,zero"`
	SpecifierQualifiers     []SpecifierQualifier
	StaticAssertDeclaration *StaticAssertDeclaration
	StructDeclaratorList    *StructDeclaratorList
	Token                   Token
}

StructDeclaration represents data reduced by productions:

StructDeclaration:
        SpecifierQualifierList StructDeclaratorList ';'  // Case StructDeclarationDecl
|       StaticAssertDeclaration                          // Case StructDeclarationAssert
Example (Assert)
fmt.Println(exampleAST(147, "struct{ _Static_assert(x > y, \"abc\"); };"))
Output:

&cc.StructDeclaration{
· Case: StructDeclarationAssert,
· StaticAssertDeclaration: &cc.StaticAssertDeclaration{
· · Expression: &cc.ConstantExpression{
· · · Expression: &cc.BinaryExpression{
· · · · Lhs: &cc.PrimaryExpression{
· · · · · Case: PrimaryExpressionIdent,
· · · · · Token: example.c:1:24: identifier "x",
· · · · },
· · · · Op: BinaryOperationGt,
· · · · Token: example.c:1:26: '>' ">",
· · · · Rhs: &cc.PrimaryExpression{
· · · · · Case: PrimaryExpressionIdent,
· · · · · Token: example.c:1:28: identifier "y",
· · · · },
· · · },
· · },
· · Token: example.c:1:9: _Static_assert "_Static_assert",
· · Token2: example.c:1:23: '(' "(",
· · Token3: example.c:1:29: ',' ",",
· · Token4: example.c:1:31: string literal "\"abc\"",
· · Token5: example.c:1:36: ')' ")",
· },
· Token: example.c:1:37: ';' ";",
}
Example (Decl)
fmt.Println(exampleAST(146, "struct{ int i __attribute__((a)); };"))
Output:

&cc.StructDeclaration{
· AttributeSpecifiers: []*cc.AttributeSpecifier{ // len 1
· · 0: &cc.AttributeSpecifier{
· · · AttributeValueList: &cc.AttributeValueList{
· · · · AttributeValue: &cc.AttributeValue{
· · · · · Case: AttributeValueIdent,
· · · · · Token: example.c:1:30: identifier "a",
· · · · },
· · · },
· · · Token: example.c:1:15: '__attribute__' "__attribute__",
· · · Token2: example.c:1:28: '(' "(",
· · · Token3: example.c:1:29: '(' "(",
· · · Token4: example.c:1:31: ')' ")",
· · · Token5: example.c:1:32: ')' ")",
· · },
· },
· Case: StructDeclarationDecl,
· SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:9: 'int' "int",
· · },
· },
· StructDeclaratorList: &cc.StructDeclaratorList{
· · StructDeclarator: &cc.StructDeclarator{
· · · Case: StructDeclaratorDecl,
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:13: identifier "i",
· · · · },
· · · },
· · },
· },
· Token: example.c:1:33: ';' ";",
}

func (*StructDeclaration) Position

func (n *StructDeclaration) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*StructDeclaration) String

func (n *StructDeclaration) String() string

String implements fmt.Stringer.

type StructDeclarationCase

type StructDeclarationCase int

StructDeclarationCase represents case numbers of production StructDeclaration

const (
	StructDeclarationDecl StructDeclarationCase = iota
	StructDeclarationAssert
)

Values of type StructDeclarationCase

func (StructDeclarationCase) String

func (n StructDeclarationCase) String() string

String implements fmt.Stringer

type StructDeclarationList

type StructDeclarationList struct {
	StructDeclaration     *StructDeclaration
	StructDeclarationList *StructDeclarationList
}

StructDeclarationList represents data reduced by productions:

StructDeclarationList:
        StructDeclaration
|       StructDeclarationList StructDeclaration
Example (Case0)
fmt.Println(exampleAST(144, "struct{ __attribute__((a)) int i; };"))
Output:

&cc.StructDeclarationList{
· StructDeclaration: &cc.StructDeclaration{
· · Case: StructDeclarationDecl,
· · SpecifierQualifiers: []*cc.TypeQualifier{ // len 2
· · · 0: &cc.TypeQualifier{
· · · · AttributeSpecifiers: []*cc.AttributeSpecifier{ // len 1
· · · · · 0: &cc.AttributeSpecifier{
· · · · · · AttributeValueList: &cc.AttributeValueList{
· · · · · · · AttributeValue: &cc.AttributeValue{
· · · · · · · · Case: AttributeValueIdent,
· · · · · · · · Token: example.c:1:24: identifier "a",
· · · · · · · },
· · · · · · },
· · · · · · Token: example.c:1:9: '__attribute__' "__attribute__",
· · · · · · Token2: example.c:1:22: '(' "(",
· · · · · · Token3: example.c:1:23: '(' "(",
· · · · · · Token4: example.c:1:25: ')' ")",
· · · · · · Token5: example.c:1:26: ')' ")",
· · · · · },
· · · · },
· · · · Case: TypeQualifierAttr,
· · · },
· · · 1: &cc.TypeSpecName{
· · · · Case: TypeSpecifierInt,
· · · · Name: example.c:1:28: 'int' "int",
· · · },
· · },
· · StructDeclaratorList: &cc.StructDeclaratorList{
· · · StructDeclarator: &cc.StructDeclarator{
· · · · Case: StructDeclaratorDecl,
· · · · Declarator: &cc.Declarator{
· · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · Case: DirectDeclaratorIdent,
· · · · · · Token: example.c:1:32: identifier "i",
· · · · · },
· · · · },
· · · },
· · },
· · Token: example.c:1:33: ';' ";",
· },
}
Example (Case1)
fmt.Println(exampleAST(145, "struct{ int i; double d; };"))
Output:

&cc.StructDeclarationList{
· StructDeclaration: &cc.StructDeclaration{
· · Case: StructDeclarationDecl,
· · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · 0: &cc.TypeSpecName{
· · · · Case: TypeSpecifierInt,
· · · · Name: example.c:1:9: 'int' "int",
· · · },
· · },
· · StructDeclaratorList: &cc.StructDeclaratorList{
· · · StructDeclarator: &cc.StructDeclarator{
· · · · Case: StructDeclaratorDecl,
· · · · Declarator: &cc.Declarator{
· · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · Case: DirectDeclaratorIdent,
· · · · · · Token: example.c:1:13: identifier "i",
· · · · · },
· · · · },
· · · },
· · },
· · Token: example.c:1:14: ';' ";",
· },
· StructDeclarationList: &cc.StructDeclarationList{
· · StructDeclaration: &cc.StructDeclaration{
· · · Case: StructDeclarationDecl,
· · · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · · 0: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierDouble,
· · · · · Name: example.c:1:16: 'double' "double",
· · · · },
· · · },
· · · StructDeclaratorList: &cc.StructDeclaratorList{
· · · · StructDeclarator: &cc.StructDeclarator{
· · · · · Case: StructDeclaratorDecl,
· · · · · Declarator: &cc.Declarator{
· · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · Token: example.c:1:23: identifier "d",
· · · · · · },
· · · · · },
· · · · },
· · · },
· · · Token: example.c:1:24: ';' ";",
· · },
· },
}

func (*StructDeclarationList) Position

func (n *StructDeclarationList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*StructDeclarationList) String

func (n *StructDeclarationList) String() string

String implements fmt.Stringer.

type StructDeclarator

type StructDeclarator struct {
	Case       StructDeclaratorCase `PrettyPrint:"stringer,zero"`
	Expression Expression
	Declarator *Declarator
	Token      Token
}

StructDeclarator represents data reduced by productions:

StructDeclarator:
        Declarator                         // Case StructDeclaratorDecl
|       Declarator ':' ConstantExpression  // Case StructDeclaratorBitField
Example (BitField)
fmt.Println(exampleAST(154, "struct{ int i:3; };"))
Output:

&cc.StructDeclarator{
· Case: StructDeclaratorBitField,
· Expression: &cc.ConstantExpression{
· · Expression: &cc.PrimaryExpression{
· · · Case: PrimaryExpressionInt,
· · · Token: example.c:1:15: integer constant "3",
· · },
· },
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorIdent,
· · · Token: example.c:1:13: identifier "i",
· · },
· },
· Token: example.c:1:14: ':' ":",
}
Example (Decl)
fmt.Println(exampleAST(153, "struct{ int i; };"))
Output:

&cc.StructDeclarator{
· Case: StructDeclaratorDecl,
· Declarator: &cc.Declarator{
· · DirectDeclarator: &cc.DirectDeclarator{
· · · Case: DirectDeclaratorIdent,
· · · Token: example.c:1:13: identifier "i",
· · },
· },
}

func (*StructDeclarator) Position

func (n *StructDeclarator) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*StructDeclarator) String

func (n *StructDeclarator) String() string

String implements fmt.Stringer.

type StructDeclaratorCase

type StructDeclaratorCase int

StructDeclaratorCase represents case numbers of production StructDeclarator

const (
	StructDeclaratorDecl StructDeclaratorCase = iota
	StructDeclaratorBitField
)

Values of type StructDeclaratorCase

func (StructDeclaratorCase) String

func (n StructDeclaratorCase) String() string

String implements fmt.Stringer

type StructDeclaratorList

type StructDeclaratorList struct {
	StructDeclarator     *StructDeclarator
	StructDeclaratorList *StructDeclaratorList
	Token                Token
}

StructDeclaratorList represents data reduced by productions:

StructDeclaratorList:
        StructDeclarator
|       StructDeclaratorList ',' StructDeclarator
Example (Case0)
fmt.Println(exampleAST(151, "struct{ int i; };"))
Output:

&cc.StructDeclaratorList{
· StructDeclarator: &cc.StructDeclarator{
· · Case: StructDeclaratorDecl,
· · Declarator: &cc.Declarator{
· · · DirectDeclarator: &cc.DirectDeclarator{
· · · · Case: DirectDeclaratorIdent,
· · · · Token: example.c:1:13: identifier "i",
· · · },
· · },
· },
}
Example (Case1)
fmt.Println(exampleAST(152, "struct{ int i, j; };"))
Output:

&cc.StructDeclaratorList{
· StructDeclarator: &cc.StructDeclarator{
· · Case: StructDeclaratorDecl,
· · Declarator: &cc.Declarator{
· · · DirectDeclarator: &cc.DirectDeclarator{
· · · · Case: DirectDeclaratorIdent,
· · · · Token: example.c:1:13: identifier "i",
· · · },
· · },
· },
· StructDeclaratorList: &cc.StructDeclaratorList{
· · StructDeclarator: &cc.StructDeclarator{
· · · Case: StructDeclaratorDecl,
· · · Declarator: &cc.Declarator{
· · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · Case: DirectDeclaratorIdent,
· · · · · Token: example.c:1:16: identifier "j",
· · · · },
· · · },
· · },
· · Token: example.c:1:14: ',' ",",
· },
}

func (*StructDeclaratorList) Position

func (n *StructDeclaratorList) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*StructDeclaratorList) String

func (n *StructDeclaratorList) String() string

String implements fmt.Stringer.

type StructOrUnion

type StructOrUnion struct {
	Case  StructOrUnionCase `PrettyPrint:"stringer,zero"`
	Token Token
}

StructOrUnion represents data reduced by productions:

StructOrUnion:
        "struct"  // Case StructOrUnionStruct
|       "union"   // Case StructOrUnionUnion
Example (Struct)
fmt.Println(exampleAST(142, "struct { int i; } s;"))
Output:

&cc.StructOrUnion{
· Case: StructOrUnionStruct,
· Token: example.c:1:1: 'struct' "struct",
}
Example (Union)
fmt.Println(exampleAST(143, "union { int i; double d; } u;"))
Output:

&cc.StructOrUnion{
· Case: StructOrUnionUnion,
· Token: example.c:1:1: 'union' "union",
}

func (*StructOrUnion) Position

func (n *StructOrUnion) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*StructOrUnion) String

func (n *StructOrUnion) String() string

String implements fmt.Stringer.

type StructOrUnionCase

type StructOrUnionCase int

StructOrUnionCase represents case numbers of production StructOrUnion

const (
	StructOrUnionStruct StructOrUnionCase = iota
	StructOrUnionUnion
)

Values of type StructOrUnionCase

func (StructOrUnionCase) String

func (n StructOrUnionCase) String() string

String implements fmt.Stringer

type StructOrUnionSpecifier

type StructOrUnionSpecifier struct {
	AttributeSpecifiers  []*AttributeSpecifier
	AttributeSpecifiers2 []*AttributeSpecifier

	Case                  StructOrUnionSpecifierCase `PrettyPrint:"stringer,zero"`
	StructDeclarationList *StructDeclarationList
	StructOrUnion         *StructOrUnion
	Token                 Token
	Token2                Token
	Token3                Token
	// contains filtered or unexported fields
}

StructOrUnionSpecifier represents data reduced by productions:

StructOrUnionSpecifier:
        StructOrUnion IDENTIFIER '{' StructDeclarationList '}'  // Case StructOrUnionSpecifierDef
|       StructOrUnion IDENTIFIER                                // Case StructOrUnionSpecifierTag
Example (Def)
fmt.Println(exampleAST(140, "struct s { int i; } __attribute__((a));"))
Output:

&cc.StructOrUnionSpecifier{
· AttributeSpecifiers: []*cc.AttributeSpecifier{ // len 1
· · 0: &cc.AttributeSpecifier{
· · · AttributeValueList: &cc.AttributeValueList{
· · · · AttributeValue: &cc.AttributeValue{
· · · · · Case: AttributeValueIdent,
· · · · · Token: example.c:1:36: identifier "a",
· · · · },
· · · },
· · · Token: example.c:1:21: '__attribute__' "__attribute__",
· · · Token2: example.c:1:34: '(' "(",
· · · Token3: example.c:1:35: '(' "(",
· · · Token4: example.c:1:37: ')' ")",
· · · Token5: example.c:1:38: ')' ")",
· · },
· },
· Case: StructOrUnionSpecifierDef,
· StructDeclarationList: &cc.StructDeclarationList{
· · StructDeclaration: &cc.StructDeclaration{
· · · Case: StructDeclarationDecl,
· · · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · · 0: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierInt,
· · · · · Name: example.c:1:12: 'int' "int",
· · · · },
· · · },
· · · StructDeclaratorList: &cc.StructDeclaratorList{
· · · · StructDeclarator: &cc.StructDeclarator{
· · · · · Case: StructDeclaratorDecl,
· · · · · Declarator: &cc.Declarator{
· · · · · · DirectDeclarator: &cc.DirectDeclarator{
· · · · · · · Case: DirectDeclaratorIdent,
· · · · · · · Token: example.c:1:16: identifier "i",
· · · · · · },
· · · · · },
· · · · },
· · · },
· · · Token: example.c:1:17: ';' ";",
· · },
· },
· StructOrUnion: &cc.StructOrUnion{
· · Case: StructOrUnionStruct,
· · Token: example.c:1:1: 'struct' "struct",
· },
· Token: example.c:1:8: identifier "s",
· Token2: example.c:1:10: '{' "{",
· Token3: example.c:1:19: '}' "}",
}
Example (Tag)
fmt.Println(exampleAST(141, "struct __attribute__((a)) s v;"))
Output:

&cc.StructOrUnionSpecifier{
· AttributeSpecifiers: []*cc.AttributeSpecifier{ // len 1
· · 0: &cc.AttributeSpecifier{
· · · AttributeValueList: &cc.AttributeValueList{
· · · · AttributeValue: &cc.AttributeValue{
· · · · · Case: AttributeValueIdent,
· · · · · Token: example.c:1:23: identifier "a",
· · · · },
· · · },
· · · Token: example.c:1:8: '__attribute__' "__attribute__",
· · · Token2: example.c:1:21: '(' "(",
· · · Token3: example.c:1:22: '(' "(",
· · · Token4: example.c:1:24: ')' ")",
· · · Token5: example.c:1:25: ')' ")",
· · },
· },
· Case: StructOrUnionSpecifierTag,
· StructOrUnion: &cc.StructOrUnion{
· · Case: StructOrUnionStruct,
· · Token: example.c:1:1: 'struct' "struct",
· },
· Token: example.c:1:27: identifier "s",
}

func (StructOrUnionSpecifier) LexicalScope

func (n StructOrUnionSpecifier) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*StructOrUnionSpecifier) Position

func (n *StructOrUnionSpecifier) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*StructOrUnionSpecifier) String

func (n *StructOrUnionSpecifier) String() string

String implements fmt.Stringer.

func (StructOrUnionSpecifier) Type

func (t StructOrUnionSpecifier) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (StructOrUnionSpecifier) Visible

func (v StructOrUnionSpecifier) Visible() int

Visible reports the token sequence number where the visibility of a name starts.

type StructOrUnionSpecifierCase

type StructOrUnionSpecifierCase int

StructOrUnionSpecifierCase represents case numbers of production StructOrUnionSpecifier

const (
	StructOrUnionSpecifierDef StructOrUnionSpecifierCase = iota
	StructOrUnionSpecifierTag
)

Values of type StructOrUnionSpecifierCase

func (StructOrUnionSpecifierCase) String

String implements fmt.Stringer

type StructType

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

func (*StructType) Align

func (n *StructType) Align() int

Align implements Type.

func (*StructType) Attributes

func (n *StructType) Attributes() *Attributes

Attributes implemets Type.

func (*StructType) Decay

func (n *StructType) Decay() Type

Decay implements Type.

func (*StructType) FieldAlign

func (n *StructType) FieldAlign() int

FieldAlign implements Type.

func (*StructType) FieldByIndex

func (n *StructType) FieldByIndex(i int) *Field

FieldByIndex returns a member field by index, if any.

func (*StructType) FieldByName

func (n *StructType) FieldByName(nm string) *Field

FieldByName returns the shallowest member field by name, if any.

func (*StructType) FlexibleArrayMember

func (n *StructType) FlexibleArrayMember() *Field

FlexibleArrayMember returns the flexible array member of n, if any.

func (*StructType) HasFlexibleArrayMember

func (n *StructType) HasFlexibleArrayMember() bool

HasFlexibleArrayMember reports whether n has a flexible array member:

https://en.wikipedia.org/wiki/Flexible_array_member

func (*StructType) IsCompatible

func (n *StructType) IsCompatible(t Type) bool

func (*StructType) IsIncomplete

func (n *StructType) IsIncomplete() bool

IsIncomplete implements Type.

func (*StructType) Kind

func (n *StructType) Kind() Kind

Kind implements Type.

func (*StructType) LexicalScope

func (n *StructType) LexicalScope() *Scope

LexicalScope provides the scope the definition of n appears in.

func (*StructType) NamedFieldByIndex

func (n *StructType) NamedFieldByIndex(i int) (r *Field)

NamedFieldByIndex returns the first named member field at or after index, if any.

func (*StructType) NumFields

func (n *StructType) NumFields() int

NumFields reports the number of n's fields.

func (*StructType) Padding

func (n *StructType) Padding() int

Padding reports how many bytes at the end of a struct/union should be additionally reserved. Consider:

struct {
	int a:1;
}

Alignment of the above struct is that of an int, but the 'a' field uses only one byte. Padding will report 3 in this case.

func (*StructType) Pointer

func (n *StructType) Pointer() Type

Pointer implements Type.

func (*StructType) Size

func (n *StructType) Size() int64

Size implements Type.

func (*StructType) String

func (n *StructType) String() string

String implements Type.

func (*StructType) Tag

func (n *StructType) Tag() Token

Tag returns n's tag, if any.

func (StructType) Typedef

func (n StructType) Typedef() *Declarator

Typedef implements Type

func (*StructType) Undecay

func (n *StructType) Undecay() Type

Undecay implements Type.

func (StructType) VectorSize

func (StructType) VectorSize() int64

VectorSize implements Type.

type Token

type Token struct {
	Ch rune // '*' or IDENTIFIER etc.
	// contains filtered or unexported fields
}

Token is the lexical token produced by the scanner.

func NodeTokens

func NodeTokens(n Node) (r []Token)

NodeTokens returns the source tokens n consists of.

func (*Token) Name

func (t *Token) Name() string

Name returns a human readable representation of t.Ch.

func (Token) Position

func (t Token) Position() (r token.Position)

Position implements Node.

func (*Token) Sep

func (t *Token) Sep() []byte

Sep returns any white space, including comments, that precede t. The result is R/O but it's okay to append to it.

func (*Token) Seq

func (t *Token) Seq() int

Seq returns t's sequence number in the token stream. The information determines scope boundaries.

func (*Token) Set

func (t *Token) Set(sep, src []byte) error

Set sets the values Sep and Src will report.

func (*Token) Src

func (t *Token) Src() []byte

Src returns the source representation of t. The result is R/O but it's okay to append to it.

func (*Token) SrcStr

func (t *Token) SrcStr() string

SrcStr returns the source representation of t as a string. To avoid allocations, consider using Src.

func (Token) String

func (t Token) String() string

String implements fmt.Stringer.

type Type

type Type interface {
	// Align reports the minimum alignment required by a type.
	Align() int

	Attributes() *Attributes

	// Decay returns a pointer to array element for array types, a pointer to a
	// function for function types and itself for all other type kinds.
	Decay() Type

	// FieldAlign reports the minimum alignment required by a type when it's used
	// in a struct/union.
	FieldAlign() int

	// IsCompatible reports type compatibility as defined in [0]6.2.7/1.
	IsCompatible(Type) bool

	// IsIncomplete reports whether the size of a type is not determined.
	IsIncomplete() bool

	// Kind reports the kind of a type.
	Kind() Kind

	// Pointer returns a pointer to a type.
	Pointer() Type

	// Size reports the size of a type in bytes. Incomplete or invalid types may
	// report a negative size.
	Size() int64

	// String produces a human readable representation of a type or an
	// approximation of the same. The particular form is not specified and
	// may change. Namely, the returned value is not suitable for directly
	// determining type identity.
	String() string

	// Typedef returns the associated typedef declarator of this type, if any.
	Typedef() *Declarator

	// Undecay reverses Decay() if the type is a pointer and was produced by
	// Decay() and the result was different than the Decay() receiver. Otherwise
	// Undecay() returns its receiver.
	Undecay() Type

	// VectorSize reports N from __attribute__((vector_size(N))). Valid if
	// > 0.
	VectorSize() int64
	// contains filtered or unexported methods
}

Type is the representation of a C type.

The dynamic type of a Type is one of

*ArrayType
*EnumType
*FunctionType
*InvalidType
*PointerType
*PredefinedType
*StructType
*UnionType
var (
	// Invalid is a singleton representing an invalid/undetermined type.  Invalid
	// is comparable.
	Invalid Type = &InvalidType{}
)

func IntegerPromotion

func IntegerPromotion(t Type) Type

IntegerPromotion performs the type conversion defined in [0]6.3.1.1-2.

If an int can represent all values of the original type, the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions. All other types are unchanged by the integer promotions.

func UsualArithmeticConversions

func UsualArithmeticConversions(a, b Type) (r Type)

UsualArithmeticConversions returns the common type of a binary operation.

[0] 6.3.1.8 Usual arithmetic conversions

type TypeName

type TypeName struct {
	AbstractDeclarator  *AbstractDeclarator
	SpecifierQualifiers []SpecifierQualifier
	// contains filtered or unexported fields
}

TypeName represents data reduced by production:

TypeName:
        SpecifierQualifierList AbstractDeclarator
Example (Case0)
fmt.Println(exampleAST(194, "int i = (int)x;"))
Output:

&cc.TypeName{
· SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · 0: &cc.TypeSpecName{
· · · Case: TypeSpecifierInt,
· · · Name: example.c:1:10: 'int' "int",
· · },
· },
}

func (*TypeName) Position

func (n *TypeName) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*TypeName) String

func (n *TypeName) String() string

String implements fmt.Stringer.

func (TypeName) Type

func (t TypeName) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

type TypeQualifier

type TypeQualifier struct {
	AttributeSpecifiers []*AttributeSpecifier
	Case                TypeQualifierCase `PrettyPrint:"stringer,zero"`
	Token               Token
}

TypeQualifier represents data reduced by productions:

TypeQualifier:
        "const"          // Case TypeQualifierConst
|       "restrict"       // Case TypeQualifierRestrict
|       "volatile"       // Case TypeQualifierVolatile
|       "_Atomic"        // Case TypeQualifierAtomic
|       "_Nonnull"       // Case TypeQualifierNonnull
|       "__attribute__"  // Case TypeQualifierAttr
Example (Atomic)
fmt.Println(exampleAST(165, "_Atomic int i;"))
Output:

&cc.TypeQualifier{
· Case: TypeQualifierAtomic,
· Token: example.c:1:1: '_Atomic' "_Atomic",
}
Example (Attr)
fmt.Println(exampleAST(167, "struct { __attribute__((a)) int i; };"))
Output:

&cc.TypeQualifier{
· AttributeSpecifiers: []*cc.AttributeSpecifier{ // len 1
· · 0: &cc.AttributeSpecifier{
· · · AttributeValueList: &cc.AttributeValueList{
· · · · AttributeValue: &cc.AttributeValue{
· · · · · Case: AttributeValueIdent,
· · · · · Token: example.c:1:25: identifier "a",
· · · · },
· · · },
· · · Token: example.c:1:10: '__attribute__' "__attribute__",
· · · Token2: example.c:1:23: '(' "(",
· · · Token3: example.c:1:24: '(' "(",
· · · Token4: example.c:1:26: ')' ")",
· · · Token5: example.c:1:27: ')' ")",
· · },
· },
· Case: TypeQualifierAttr,
}
Example (Case1)
fmt.Println(exampleAST(185, "int * const volatile i;"))
Output:

&cc.TypeQualifier{
· Case: TypeQualifierConst,
· Token: example.c:1:7: 'const' "const",
}
&cc.TypeQualifier{
· Case: TypeQualifierVolatile,
· Token: example.c:1:13: 'volatile' "volatile",
}
Example (Const)
fmt.Println(exampleAST(162, "const int i;"))
Output:

&cc.TypeQualifier{
· Case: TypeQualifierConst,
· Token: example.c:1:1: 'const' "const",
}
Example (Nonnull)
fmt.Println(exampleAST(166, "_Nonnull int i;"))
Output:

&cc.TypeQualifier{
· Case: TypeQualifierNonnull,
· Token: example.c:1:1: '_Nonnull' "_Nonnull",
}
Example (Restrict)
fmt.Println(exampleAST(163, "restrict int i;"))
Output:

&cc.TypeQualifier{
· Case: TypeQualifierRestrict,
· Token: example.c:1:1: 'restrict' "restrict",
}
Example (SqTypeQual)
fmt.Println(exampleAST(149, "struct {const int i;};"))
Output:

&cc.TypeQualifier{
· Case: TypeQualifierConst,
· Token: example.c:1:9: 'const' "const",
}
Example (TypeQual)
fmt.Println(exampleAST(184, "int * __attribute__((a)) const i;"))
Output:

&cc.TypeQualifier{
· AttributeSpecifiers: []*cc.AttributeSpecifier{ // len 1
· · 0: &cc.AttributeSpecifier{
· · · AttributeValueList: &cc.AttributeValueList{
· · · · AttributeValue: &cc.AttributeValue{
· · · · · Case: AttributeValueIdent,
· · · · · Token: example.c:1:22: identifier "a",
· · · · },
· · · },
· · · Token: example.c:1:7: '__attribute__' "__attribute__",
· · · Token2: example.c:1:20: '(' "(",
· · · Token3: example.c:1:21: '(' "(",
· · · Token4: example.c:1:23: ')' ")",
· · · Token5: example.c:1:24: ')' ")",
· · },
· },
· Case: TypeQualifierAttr,
}
&cc.TypeQualifier{
· Case: TypeQualifierConst,
· Token: example.c:1:26: 'const' "const",
}
Example (Volatile)
fmt.Println(exampleAST(164, "volatile int i;"))
Output:

&cc.TypeQualifier{
· Case: TypeQualifierVolatile,
· Token: example.c:1:1: 'volatile' "volatile",
}

func (*TypeQualifier) Position

func (n *TypeQualifier) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*TypeQualifier) String

func (n *TypeQualifier) String() string

String implements fmt.Stringer.

type TypeQualifierCase

type TypeQualifierCase int

TypeQualifierCase represents case numbers of production TypeQualifier

const (
	TypeQualifierConst TypeQualifierCase = iota
	TypeQualifierRestrict
	TypeQualifierVolatile
	TypeQualifierAtomic
	TypeQualifierNonnull
	TypeQualifierAttr
)

Values of type TypeQualifierCase

func (TypeQualifierCase) String

func (n TypeQualifierCase) String() string

String implements fmt.Stringer

type TypeSpecAtomic

type TypeSpecAtomic struct {
	Atomic *AtomicTypeSpecifier
	// contains filtered or unexported fields
}
Example (Atomic)
fmt.Println(exampleAST(135, "_Atomic(int) i;"))
Output:

&cc.TypeSpecAtomic{
· Atomic: &cc.AtomicTypeSpecifier{
· · Token: example.c:1:1: '_Atomic' "_Atomic",
· · Token2: example.c:1:8: '(' "(",
· · Token3: example.c:1:12: ')' ")",
· · TypeName: &cc.TypeName{
· · · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · · 0: &cc.TypeSpecName{
· · · · · Case: TypeSpecifierInt,
· · · · · Name: example.c:1:9: 'int' "int",
· · · · },
· · · },
· · },
· },
}

func (TypeSpecAtomic) LexicalScope

func (n TypeSpecAtomic) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*TypeSpecAtomic) Position

func (n *TypeSpecAtomic) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*TypeSpecAtomic) String

func (n *TypeSpecAtomic) String() string

String implements fmt.Stringer.

func (*TypeSpecAtomic) TypeSpecifierCase

func (*TypeSpecAtomic) TypeSpecifierCase() TypeSpecifierCase

type TypeSpecEnum

type TypeSpecEnum struct {
	Enum *EnumSpecifier
	// contains filtered or unexported fields
}
Example (Enum)
fmt.Println(exampleAST(131, "enum e i;"))
Output:

&cc.TypeSpecEnum{
· Enum: &cc.EnumSpecifier{
· · Case: EnumSpecifierTag,
· · Token: example.c:1:1: 'enum' "enum",
· · Token2: example.c:1:6: identifier "e",
· },
}

func (TypeSpecEnum) LexicalScope

func (n TypeSpecEnum) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*TypeSpecEnum) Position

func (n *TypeSpecEnum) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*TypeSpecEnum) String

func (n *TypeSpecEnum) String() string

String implements fmt.Stringer.

func (*TypeSpecEnum) TypeSpecifierCase

func (*TypeSpecEnum) TypeSpecifierCase() TypeSpecifierCase

type TypeSpecName

type TypeSpecName struct {
	Case TypeSpecifierCase `PrettyPrint:"stringer,zero"`
	Name Token
	// contains filtered or unexported fields
}
Example (Bool)
fmt.Println(exampleAST(127, "_Bool i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierBool,
· Name: example.c:1:1: '_Bool' "_Bool",
}
Example (Char)
fmt.Println(exampleAST(111, "char i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierChar,
· Name: example.c:1:1: 'char' "char",
}
Example (Complex)
fmt.Println(exampleAST(128, "_Complex i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierComplex,
· Name: example.c:1:1: '_Complex' "_Complex",
}
Example (Decimal128)
fmt.Println(exampleAST(121, "_Decimal128 i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierDecimal128,
· Name: example.c:1:1: '_Decimal128' "_Decimal128",
}
Example (Decimal32)
fmt.Println(exampleAST(119, "_Decimal32 i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierDecimal32,
· Name: example.c:1:1: '_Decimal32' "_Decimal32",
}
Example (Decimal64)
fmt.Println(exampleAST(120, "_Decimal64 i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierDecimal64,
· Name: example.c:1:1: '_Decimal64' "_Decimal64",
}
Example (Double)
fmt.Println(exampleAST(124, "double i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierDouble,
· Name: example.c:1:1: 'double' "double",
}
Example (Float)
fmt.Println(exampleAST(117, "float i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierFloat,
· Name: example.c:1:1: 'float' "float",
}
Example (Float128)
fmt.Println(exampleAST(122, "_Float128 i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierFloat128,
· Name: example.c:1:1: '_Float128' "_Float128",
}
Example (Float128x)
fmt.Println(exampleAST(123, "_Float128x i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierFloat128x,
· Name: example.c:1:1: '_Float128x' "_Float128x",
}
Example (Float16)
fmt.Println(exampleAST(118, "_Float16 i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierFloat16,
· Name: example.c:1:1: '_Float16' "_Float16",
}
Example (Float32)
fmt.Println(exampleAST(136, "_Float32 i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierFloat32,
· Name: example.c:1:1: '_Float32' "_Float32",
}
Example (Float32x)
fmt.Println(exampleAST(138, "_Float32x i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierFloat32x,
· Name: example.c:1:1: '_Float32x' "_Float32x",
}
Example (Float64)
fmt.Println(exampleAST(137, "_Float64 i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierFloat64,
· Name: example.c:1:1: '_Float64' "_Float64",
}
Example (Float64x)
fmt.Println(exampleAST(139, "_Float64x i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierFloat64x,
· Name: example.c:1:1: '_Float64x' "_Float64x",
}
Example (Imaginary)
fmt.Println(exampleAST(129, "_Imaginary i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierImaginary,
· Name: example.c:1:1: '_Imaginary' "_Imaginary",
}
Example (Int)
fmt.Println(exampleAST(113, "int i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierInt,
· Name: example.c:1:1: 'int' "int",
}
Example (Int128)
fmt.Println(exampleAST(114, "__int128 i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierInt128,
· Name: example.c:1:1: '__int128' "__int128",
}
Example (Long)
fmt.Println(exampleAST(116, "long i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierLong,
· Name: example.c:1:1: 'long' "long",
}
Example (Short)
fmt.Println(exampleAST(112, "short i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierShort,
· Name: example.c:1:1: 'short' "short",
}
Example (Signed)
fmt.Println(exampleAST(125, "signed i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierSigned,
· Name: example.c:1:1: 'signed' "signed",
}
Example (SqTypeSpec)
fmt.Println(exampleAST(148, "struct {int i;};"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierInt,
· Name: example.c:1:9: 'int' "int",
}
Example (TypeName)
fmt.Println(exampleAST(132, "typedef int T; T i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierInt,
· Name: example.c:1:9: 'int' "int",
}
&cc.TypeSpecName{
· Case: TypeSpecifierTypeName,
· Name: example.c:1:16: type name "T",
}
Example (Uint128)
fmt.Println(exampleAST(115, "__uint128_t i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierUint128,
· Name: example.c:1:1: '__uint128_t' "__uint128_t",
}
Example (Unsigned)
fmt.Println(exampleAST(126, "unsigned i;"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierUnsigned,
· Name: example.c:1:1: 'unsigned' "unsigned",
}
Example (Void)
fmt.Println(exampleAST(110, "void i();"))
Output:

&cc.TypeSpecName{
· Case: TypeSpecifierVoid,
· Name: example.c:1:1: 'void' "void",
}

func (TypeSpecName) LexicalScope

func (n TypeSpecName) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*TypeSpecName) Position

func (n *TypeSpecName) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*TypeSpecName) String

func (n *TypeSpecName) String() string

String implements fmt.Stringer.

func (*TypeSpecName) TypeSpecifierCase

func (n *TypeSpecName) TypeSpecifierCase() TypeSpecifierCase

type TypeSpecStructOrUnion

type TypeSpecStructOrUnion struct {
	StructOrUnion *StructOrUnionSpecifier
	// contains filtered or unexported fields
}
Example (StructOrUnion)
fmt.Println(exampleAST(130, "struct s i;"))
Output:

&cc.TypeSpecStructOrUnion{
· StructOrUnion: &cc.StructOrUnionSpecifier{
· · Case: StructOrUnionSpecifierTag,
· · StructOrUnion: &cc.StructOrUnion{
· · · Case: StructOrUnionStruct,
· · · Token: example.c:1:1: 'struct' "struct",
· · },
· · Token: example.c:1:8: identifier "s",
· },
}

func (TypeSpecStructOrUnion) LexicalScope

func (n TypeSpecStructOrUnion) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*TypeSpecStructOrUnion) Position

func (n *TypeSpecStructOrUnion) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*TypeSpecStructOrUnion) String

func (n *TypeSpecStructOrUnion) String() string

String implements fmt.Stringer.

func (*TypeSpecStructOrUnion) TypeSpecifierCase

func (*TypeSpecStructOrUnion) TypeSpecifierCase() TypeSpecifierCase

type TypeSpecTypeOfExpr

type TypeSpecTypeOfExpr struct {
	TypeOf     Token
	LeftParen  Token
	Expr       Expression
	RightParen Token
	// contains filtered or unexported fields
}
Example (TypeofExpr)
fmt.Println(exampleAST(133, "typeof(42) i;"))
Output:

&cc.TypeSpecTypeOfExpr{
· TypeOf: example.c:1:1: 'typeof' "typeof",
· LeftParen: example.c:1:7: '(' "(",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionInt,
· · Token: example.c:1:8: integer constant "42",
· },
· RightParen: example.c:1:10: ')' ")",
}

func (TypeSpecTypeOfExpr) LexicalScope

func (n TypeSpecTypeOfExpr) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*TypeSpecTypeOfExpr) Position

func (n *TypeSpecTypeOfExpr) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*TypeSpecTypeOfExpr) String

func (n *TypeSpecTypeOfExpr) String() string

String implements fmt.Stringer.

func (*TypeSpecTypeOfExpr) TypeSpecifierCase

func (*TypeSpecTypeOfExpr) TypeSpecifierCase() TypeSpecifierCase

type TypeSpecTypeOfType

type TypeSpecTypeOfType struct {
	TypeOf     Token
	LeftParen  Token
	Name       *TypeName
	RightParen Token
	// contains filtered or unexported fields
}
Example (TypeofType)
fmt.Println(exampleAST(134, "typedef int T; typeof(T) i;"))
Output:

&cc.TypeSpecTypeOfType{
· TypeOf: example.c:1:16: 'typeof' "typeof",
· LeftParen: example.c:1:22: '(' "(",
· Name: &cc.TypeName{
· · SpecifierQualifiers: []*cc.TypeSpecName{ // len 1
· · · 0: &cc.TypeSpecName{
· · · · Case: TypeSpecifierTypeName,
· · · · Name: example.c:1:23: type name "T",
· · · },
· · },
· },
· RightParen: example.c:1:24: ')' ")",
}

func (TypeSpecTypeOfType) LexicalScope

func (n TypeSpecTypeOfType) LexicalScope() *Scope

LexicalScope provides the scope a node appears in.

func (*TypeSpecTypeOfType) Position

func (n *TypeSpecTypeOfType) Position() (r token.Position)

Position reports the position of the first component of n, if available.

func (*TypeSpecTypeOfType) String

func (n *TypeSpecTypeOfType) String() string

String implements fmt.Stringer.

func (*TypeSpecTypeOfType) TypeSpecifierCase

func (*TypeSpecTypeOfType) TypeSpecifierCase() TypeSpecifierCase

type TypeSpecifier

type TypeSpecifier interface {
	DeclarationSpecifier
	SpecifierQualifier
	LexicalScope() *Scope
	TypeSpecifierCase() TypeSpecifierCase
	// contains filtered or unexported methods
}

TypeSpecifier represents data reduced by productions:

TypeSpecifier:
        "void"                           // Case TypeSpecifierVoid
|       "char"                           // Case TypeSpecifierChar
|       "short"                          // Case TypeSpecifierShort
|       "int"                            // Case TypeSpecifierInt
|       "__int128"                       // Case TypeSpecifierInt128
|       "__uint128_t"                    // Case TypeSpecifierUint128
|       "long"                           // Case TypeSpecifierLong
|       "float"                          // Case TypeSpecifierFloat
|       "_Float16"                       // Case TypeSpecifierFloat16
|       "_Decimal32"                     // Case TypeSpecifierDecimal32
|       "_Decimal64"                     // Case TypeSpecifierDecimal64
|       "_Decimal128"                    // Case TypeSpecifierDecimal128
|       "_Float128"                      // Case TypeSpecifierFloat128
|       "_Float128x"                     // Case TypeSpecifierFloat128x
|       "double"                         // Case TypeSpecifierDouble
|       "signed"                         // Case TypeSpecifierSigned
|       "unsigned"                       // Case TypeSpecifierUnsigned
|       "_Bool"                          // Case TypeSpecifierBool
|       "_Complex"                       // Case TypeSpecifierComplex
|       "_Imaginary"                     // Case TypeSpecifierImaginary
|       StructOrUnionSpecifier           // Case TypeSpecifierStructOrUnion
|       EnumSpecifier                    // Case TypeSpecifierEnum
|       TYPENAME                         // Case TypeSpecifierTypeName
|       "typeof" '(' ExpressionList ')'  // Case TypeSpecifierTypeofExpr
|       "typeof" '(' TypeName ')'        // Case TypeSpecifierTypeofType
|       AtomicTypeSpecifier              // Case TypeSpecifierAtomic
|       "_Float32"                       // Case TypeSpecifierFloat32
|       "_Float64"                       // Case TypeSpecifierFloat64
|       "_Float32x"                      // Case TypeSpecifierFloat32x
|       "_Float64x"                      // Case TypeSpecifierFloat64x

type TypeSpecifierCase

type TypeSpecifierCase int

TypeSpecifierCase represents case numbers of production TypeSpecifier

const (
	TypeSpecifierVoid TypeSpecifierCase = iota
	TypeSpecifierChar
	TypeSpecifierShort
	TypeSpecifierInt
	TypeSpecifierInt8
	TypeSpecifierInt16
	TypeSpecifierInt32
	TypeSpecifierInt64
	TypeSpecifierInt128
	TypeSpecifierUint8
	TypeSpecifierUint16
	TypeSpecifierUint32
	TypeSpecifierUint64
	TypeSpecifierUint128
	TypeSpecifierLong
	TypeSpecifierFloat
	TypeSpecifierFloat16
	TypeSpecifierDecimal32
	TypeSpecifierDecimal64
	TypeSpecifierDecimal128
	TypeSpecifierFloat128
	TypeSpecifierFloat128x
	TypeSpecifierDouble
	TypeSpecifierSigned
	TypeSpecifierUnsigned
	TypeSpecifierBool
	TypeSpecifierComplex
	TypeSpecifierImaginary
	TypeSpecifierStructOrUnion
	TypeSpecifierEnum
	TypeSpecifierTypeName
	TypeSpecifierTypeofExpr
	TypeSpecifierTypeofType
	TypeSpecifierAtomic
	TypeSpecifierFloat32
	TypeSpecifierFloat64
	TypeSpecifierFloat32x
	TypeSpecifierFloat64x
)

Values of type TypeSpecifierCase

func (TypeSpecifierCase) String

func (n TypeSpecifierCase) String() string

String implements fmt.Stringer

type UInt64Value

type UInt64Value uint64

func (UInt64Value) Convert

func (n UInt64Value) Convert(to Type) Value

type UTF16StringValue

type UTF16StringValue []uint16

func (UTF16StringValue) Convert

func (n UTF16StringValue) Convert(to Type) Value

type UTF32StringValue

type UTF32StringValue []rune

func (UTF32StringValue) Convert

func (n UTF32StringValue) Convert(to Type) Value

type UnaryExpr

type UnaryExpr struct {
	Case  UnaryExpressionCase `PrettyPrint:"stringer,zero"`
	Token Token
	Expr  Expression
	// contains filtered or unexported fields
}
Example (Addrof)
fmt.Println(exampleAST(29, "int *i = &x;"))
Output:

&cc.UnaryExpr{
· Case: UnaryExpressionAddrof,
· Token: example.c:1:10: '&' "&",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:11: identifier "x",
· },
}
Example (Cpl)
fmt.Println(exampleAST(33, "int i = ~x;"))
Output:

&cc.UnaryExpr{
· Case: UnaryExpressionCpl,
· Token: example.c:1:9: '~' "~",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:10: identifier "x",
· },
}
Example (Deref)
fmt.Println(exampleAST(30, "int i = *x;"))
Output:

&cc.UnaryExpr{
· Case: UnaryExpressionDeref,
· Token: example.c:1:9: '*' "*",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:10: identifier "x",
· },
}
Example (Imag)
fmt.Println(exampleAST(40, "double i = __imag__ x;"))
Output:

&cc.UnaryExpr{
· Case: UnaryExpressionImag,
· Token: example.c:1:12: '__imag__' "__imag__",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:21: identifier "x",
· },
}
Example (Minus)
fmt.Println(exampleAST(32, "int i = -x;"))
Output:

&cc.UnaryExpr{
· Case: UnaryExpressionMinus,
· Token: example.c:1:9: '-' "-",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:10: identifier "x",
· },
}
Example (Not)
fmt.Println(exampleAST(34, "int i = !x;"))
Output:

&cc.UnaryExpr{
· Case: UnaryExpressionNot,
· Token: example.c:1:9: '!' "!",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:10: identifier "x",
· },
}
Example (Plus)
fmt.Println(exampleAST(31, "int i = +x;"))
Output:

&cc.UnaryExpr{
· Case: UnaryExpressionPlus,
· Token: example.c:1:9: '+' "+",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:10: identifier "x",
· },
}
Example (Real)
fmt.Println(exampleAST(41, "double i = __real__ x;"))
Output:

&cc.UnaryExpr{
· Case: UnaryExpressionReal,
· Token: example.c:1:12: '__real__' "__real__",
· Expr: &cc.PrimaryExpression{
· · Case: PrimaryExpressionIdent,
· · Token: example.c:1:21: identifier "x",
· },
}

func (*UnaryExpr) Position

func (n *UnaryExpr) Position() (r token.Position)

func (*UnaryExpr) String

func (n *UnaryExpr) String() string

String implements fmt.Stringer.

func (UnaryExpr) Type

func (t UnaryExpr) Type() Type

Type returns the type of a node or an *InvalidType type value, if the type is unknown/undetermined.

func (UnaryExpr) Value

func (v UnaryExpr) Value() Value

Value returns the value of a node or UnknownValue if it is undetermined. The dynamic type of a Value is one of

*ComplexLongDoubleValue
*LongDoubleValue
*UnknownValue
*ZeroValue
Complex128Value
Complex64Value
Float64Value
Int64Value
StringValue
UInt64Value
UTF16StringValue
UTF32StringValue
VoidValue

type UnaryExpressionCase

type UnaryExpressionCase int

UnaryExpressionCase represents case numbers of production UnaryExpression

const (
	UnaryExpressionAddrof UnaryExpressionCase = iota
	UnaryExpressionDeref
	UnaryExpressionPlus
	UnaryExpressionMinus
	UnaryExpressionCpl
	UnaryExpressionNot
	UnaryExpressionImag
	UnaryExpressionReal
)

Values of type UnaryExpressionCase

func (UnaryExpressionCase) String

func (n UnaryExpressionCase) String() string

String implements fmt.Stringer

type UnionType

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

func (*UnionType) Align

func (n *UnionType) Align() int

Align implements Type.

func (*UnionType) Attributes

func (n *UnionType) Attributes() *Attributes

Attributes implemets Type.

func (*UnionType) Decay

func (n *UnionType) Decay() Type

Decay implements Type.

func (*UnionType) FieldAlign

func (n *UnionType) FieldAlign() int

FieldAlign implements Type.

func (*UnionType) FieldByIndex

func (n *UnionType) FieldByIndex(i int) *Field

FieldByIndex returns a member field by index, if any.

func (*UnionType) FieldByName

func (n *UnionType) FieldByName(nm string) *Field

FieldByName returns member field nm of n or nil if n does not have such member.

func (*UnionType) IsCompatible

func (n *UnionType) IsCompatible(t Type) bool

func (*UnionType) IsIncomplete

func (n *UnionType) IsIncomplete() bool

IsIncomplete implements Type.

func (*UnionType) Kind

func (n *UnionType) Kind() Kind

Kind implements Type.

func (*UnionType) LexicalScope

func (n *UnionType) LexicalScope() *Scope

LexicalScope provides the scope the definition of n appears in.

func (*UnionType) NamedFieldByIndex

func (n *UnionType) NamedFieldByIndex(i int) (r *Field)

NamedFieldByIndex returns the first named member field at or after index, if any.

func (*UnionType) NumFields

func (n *UnionType) NumFields() int

NumFields reports the number of n's fields.

func (*UnionType) Padding

func (n *UnionType) Padding() int

Padding reports how many bytes at the end of a struct/union should be additionally reserved. Consider:

struct {
	int a:1;
}

Alignment of the above struct is that of an int, but the 'a' field uses only one byte. Padding will report 3 in this case.

func (*UnionType) Pointer

func (n *UnionType) Pointer() Type

Pointer implements Type.

func (*UnionType) Size

func (n *UnionType) Size() int64

Size implements Type.

func (*UnionType) String

func (n *UnionType) String() string

String implements Type.

func (*UnionType) Tag

func (n *UnionType) Tag() Token

Tag returns n's tag, if any.

func (UnionType) Typedef

func (n UnionType) Typedef() *Declarator

Typedef implements Type

func (*UnionType) Undecay

func (n *UnionType) Undecay() Type

Undecay implements Type.

func (UnionType) VectorSize

func (UnionType) VectorSize() int64

VectorSize implements Type.

type UnknownValue

type UnknownValue struct{}

func (*UnknownValue) Convert

func (*UnknownValue) Convert(to Type) Value

func (*UnknownValue) String

func (*UnknownValue) String() string

type Value

type Value interface {
	// Convert attempts to convert the value to a different type. It returns
	// Unknown values unchanged.  Convert returns Unknown for values it does not
	// support.
	Convert(to Type) Value
}
var (
	// Unknown is a singleton representing an undetermined value.  Unknown is
	// comparable.
	Unknown Value = &UnknownValue{}

	// Zero is a singleton representing a zero value of a type. Zero is comparable.
	Zero Value = &ZeroValue{}
)

type VoidValue

type VoidValue struct{}

func (VoidValue) Convert

func (n VoidValue) Convert(to Type) Value

type ZeroValue

type ZeroValue struct{}

func (*ZeroValue) Convert

func (n *ZeroValue) Convert(to Type) Value

Jump to

Keyboard shortcuts

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