astparse

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessFuncs

func ProcessFuncs(context *errors.ParseContext, functions []*ast.FunctionDecl,
	structs []*CStruct, types []*CType) ([]*CFuncDef, []*CStruct)

ProcessFuncs parses the function list and builds a set of function descriptions. It also figures out the minimal used set of structs and returns this.

func ProcessTypes

func ProcessTypes(context *errors.ParseContext, recordDeclarations []*ast.RecordDecl,
	typeDeclarations []*ast.TypedefDecl) (structs []*CStruct, types []*CType)

ProcessTypes parses the AST information and converts it into lists of CStructs and CTypes. If errors are encountered during processing, they are recorded in the context and processing continues.

func ReadAst

func ReadAst(headerFile string) ([]*ast.FunctionDecl, []*ast.RecordDecl,
	[]*ast.TypedefDecl, error)

ReadAst processes the header file and converts it into the AST types used by the c2go project.

Types

type CFuncDef

type CFuncDef struct {

	// Name is the name of the function in the header file.
	Name string

	// Params defines the parameters and their type.
	Params []*CStructInstance

	// ReturnType is the function return type, or nil for void functions.
	ReturnType *CStructInstance
}

CFuncDef describes a function found in the C header file.

type CStruct

type CStruct struct {

	// Basic indicates if this is a pseudo-struct representing a basic type (e.g. int, char etc.).
	Basic bool

	// Name contains the name of the struct, which may be empty for anonymous structs.
	Name string

	// TypeName contains the type name for this struct, if one exists. During processing, if there are any typedefs
	// which alias this struct (without pointers), one of them will be stored in this field.
	TypeName string

	// Fields contains the fields defined in this struct.
	Fields []*CStructInstance
}

A CStruct represents a C struct.

type CStructInstance

type CStructInstance struct {

	// Name contains the name of the variable or parameter. This will be empty in contexts where a name is not
	// associated with the struct (e.g. return types).
	Name string

	// PointerCount counts how many pointers were used in this instance. E.g. "int *foo" would result in a PointerCount
	// of 1.
	PointerCount uint

	// ArrayCount indicates if the struct was used in a fixed-sized array. E.g. "int foo[4]" would result in an
	// ArrayCount of 4, where as "int foo" would result in 0.
	ArrayCount uint

	// Struct is the type that was used in this instance.
	Struct *CStruct
}

A CStructInstance contains information about a specific use of a struct, for instance as a field in another struct, as a parameter in a function or as a return type.

type CType

type CType struct {

	// Name is the typedef name.
	Name string

	// PointerCount describes the number of pointers this typedef introduces, on top of the underlying struct.
	PointerCount uint

	// Struct is the underlying struct this typedef references. The parsing phase will resolve any intermediate
	// typdefs, ensuring we can directly tie each CType to a CStruct.
	Struct *CStruct
}

A CType describes a typedef for a CStruct.

Jump to

Keyboard shortcuts

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