c

package
v0.0.0-...-546480d Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: Unlicense Imports: 5 Imported by: 0

Documentation

Overview

Package c provides an AST for a subset of C.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsFakeTag

func IsFakeTag(tag string) bool

IsFakeTag reports whether the tag name is fake (generated by the compiler for symbols lacking a tag name).

Types

type ArrayType

type ArrayType struct {
	// Element type.
	Elem Type
	// Array length.
	Len int
}

ArrayType is an array type.

func (*ArrayType) Def

func (t *ArrayType) Def() string

Def returns the C syntax representation of the definition of the type.

func (*ArrayType) String

func (t *ArrayType) String() string

String returns the string representation of the array type.

type BaseType

type BaseType uint8

BaseType is a base type.

const (
	Void   BaseType = iota + 1 // void
	Char                       // char
	Short                      // short
	Int                        // int
	Long                       // long
	UChar                      // unsigned char
	UShort                     // unsigned short
	UInt                       // unsigned int
	ULong                      // unsigned long
)

Base types.

func (BaseType) Def

func (t BaseType) Def() string

Def returns the C syntax representation of the definition of the type.

func (BaseType) String

func (i BaseType) String() string

type Block

type Block struct {
	// Start line number (relative to the function).
	LineStart uint32
	// End line number (relative to the function).
	LineEnd uint32
	// Local variables.
	Locals []*VarDecl
}

A Block encapsulates a block scope.

type EnumMember

type EnumMember struct {
	// Enum value.
	Value uint32
	// Enum name.
	Name string
}

EnumMember is an enum member.

type EnumType

type EnumType struct {
	// Enum tag.
	Tag string
	// Enum members.
	Members []*EnumMember
}

EnumType is a enum type.

func (*EnumType) Def

func (t *EnumType) Def() string

Def returns the C syntax representation of the definition of the type.

func (*EnumType) String

func (t *EnumType) String() string

String returns the string representation of the enum type.

type Field

type Field struct {
	// Offset (optional).
	Offset uint32
	// Size in bytes (optional).
	Size uint32
	// Underlying variable.
	Var
}

A Field represents a field in a structure type or union type.

type FuncDecl

type FuncDecl struct {
	// Source file.
	Path string
	// Address (optional).
	Addr uint32
	// Size (optional).
	Size uint32
	// Start line number.
	LineStart uint32
	// End line number.
	LineEnd uint32
	// Underlying function variable.
	Var
	// Scope blocks.
	Blocks []*Block
}

A FuncDecl is a function declaration.

func (*FuncDecl) Def

func (f *FuncDecl) Def() string

Def returns the C syntax representation of the definition of the function declaration.

func (*FuncDecl) String

func (f *FuncDecl) String() string

String returns the string representation of the function declaration.

type FuncType

type FuncType struct {
	// Return type.
	RetType Type
	// Function parameters.
	Params []*VarDecl
	// Variadic function.
	Variadic bool
}

FuncType is a function type.

func (*FuncType) Def

func (t *FuncType) Def() string

Def returns the C syntax representation of the definition of the type.

func (*FuncType) String

func (t *FuncType) String() string

String returns the string representation of the function type.

type PointerType

type PointerType struct {
	// Element type.
	Elem Type
}

PointerType is a pointer type.

func (*PointerType) Def

func (t *PointerType) Def() string

Def returns the C syntax representation of the definition of the type.

func (*PointerType) String

func (t *PointerType) String() string

String returns the string representation of the pointer type.

type StorageClass

type StorageClass uint8

A StorageClass is a storage class.

const (
	Auto     StorageClass = iota + 1 // auto
	Extern                           // extern
	Static                           // static
	Register                         // register
	Typedef                          // typedef
)

Base types.

func (StorageClass) String

func (i StorageClass) String() string

type StructType

type StructType struct {
	// Size in bytes (optional).
	Size uint32
	// Structure tag.
	Tag string
	// Structure fields.
	Fields []Field
	// Struct methods.
	Methods []Field
}

StructType is a structure type.

func (*StructType) Def

func (t *StructType) Def() string

Def returns the C syntax representation of the definition of the type.

func (*StructType) String

func (t *StructType) String() string

String returns the string representation of the structure type.

type Type

type Type interface {
	fmt.Stringer
	// Def returns the C syntax representation of the definition of the type.
	Def() string
}

Type is a C type.

type UnionType

type UnionType struct {
	// Size in bytes (optional).
	Size uint32
	// Union tag.
	Tag string
	// Union fields.
	Fields []Field
}

UnionType is a union type.

func (*UnionType) Def

func (t *UnionType) Def() string

Def returns the C syntax representation of the definition of the type.

func (*UnionType) String

func (t *UnionType) String() string

String returns the string representation of the union type.

type Var

type Var struct {
	// Variable type.
	Type Type
	// Variable name.
	Name string
}

A Var represents a variable declaration or function parameter.

func (Var) String

func (v Var) String() string

String returns the string representation of the variable.

type VarDecl

type VarDecl struct {
	// Address, frame pointer delta, or register depending on storage class
	// (optional).
	Addr uint32
	// Size (optional).
	Size uint32
	// Storage class.
	Class StorageClass
	// Underlying variable.
	Var
}

A VarDecl is a variable declaration.

func (*VarDecl) Def

func (v *VarDecl) Def() string

Def returns the C syntax representation of the definition of the variable declaration.

func (*VarDecl) String

func (v *VarDecl) String() string

String returns the string representation of the variable declaration.

Jump to

Keyboard shortcuts

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