Documentation ¶
Overview ¶
Package cc implements parsing, type checking, and printing of C programs.
Index ¶
- Variables
- func AddInclude(dir string)
- func Postorder(x Syntax, f func(Syntax))
- func Preorder(x Syntax, f func(Syntax))
- func Walk(x Syntax, before, after func(Syntax))
- type Comment
- type Comments
- type Decl
- type Expr
- type ExprOp
- type Header
- type Init
- type Label
- type LabelOp
- type Pos
- type Prefix
- type Printer
- type Prog
- type Scope
- type Span
- type Stmt
- type StmtOp
- type Storage
- type Syntax
- type SyntaxInfo
- type Type
- type TypeKind
- type TypeQual
- type TypedName
Constants ¶
This section is empty.
Variables ¶
View Source
var ( CharType = newType(Char) UcharType = newType(Uchar) ShortType = newType(Short) UshortType = newType(Ushort) IntType = newType(Int) UintType = newType(Uint) LongType = newType(Long) UlongType = newType(Ulong) LonglongType = newType(Longlong) UlonglongType = newType(Ulonglong) FloatType = newType(Float) DoubleType = newType(Double) VoidType = newType(Void) BoolType = &Type{Kind: TypedefType, Name: "bool", Base: IntType} )
Functions ¶
func AddInclude ¶
func AddInclude(dir string)
Types ¶
type Comments ¶
type Comments struct { Before []Comment // whole-line comments before this syntax Suffix []Comment // end-of-line comments after this syntax // For top-level syntax elements only, After lists whole-line // comments following the syntax. After []Comment }
Comments collects the comments associated with a syntax element.
type Decl ¶
type Expr ¶
type Expr struct { SyntaxInfo Op ExprOp // operator Left *Expr // left (or only) operand Right *Expr // right operand List []*Expr // operand list, for Comma, Cond, Call Text string // name or literal, for Name, Number, Goto, Arrow, Dot Texts []string // list of literals, for String Type *Type // type operand, for SizeofType, Offsetof, Cast, CastInit, VaArg Init *Init // initializer, for CastInit Block []*Stmt // for c2go // derived information XDecl *Decl XType *Type // expression type, derived }
An Expr is a parsed C expression.
type ExprOp ¶
type ExprOp int
const ( Add ExprOp // Left + Right AddEq // Left += Right Addr // &Left And // Left & Right AndAnd // Left && Right AndEq // Left &= Right Arrow // Left->Text Call // Left(List) Cast // (Type)Left CastInit // (Type){Init} Comma // x, y, z; List = {x, y, z} Cond // x ? y : z; List = {x, y, z} Div // Left / Right DivEq // Left /= Right Dot // Left.Name Eq // Left = Right EqEq // Left == Right Gt // Left > Right GtEq // Left >= Right Index // Left[Right] Indir // *Left Lsh // Left << Right LshEq // Left <<= Right Lt // Left < Right LtEq // Left <= Right Minus // -Left Mod // Left % Right ModEq // Left %= Right Mul // Left * Right MulEq // Left *= Right Name // Text (function, variable, or enum name) Not // !Left NotEq // Left != Right Number // Text (numeric or chraracter constant) Offsetof // offsetof(Type, Left) Or // Left | Right OrEq // Left |= Right OrOr // Left || Right Paren // (Left) Plus // +Left PostDec // Left-- PostInc // Left++ PreDec // --Left PreInc // ++Left Rsh // Left >> Right RshEq // Left >>= Right SizeofExpr // sizeof(Left) SizeofType // sizeof(Type) String // Text (quoted string literal) Sub // Left - Right SubEq // Left -= Right Twid // ~Left VaArg // va_arg(Left, Type) Xor // Left ^ Right XorEq // Left ^= Right )
type Init ¶
type Init struct { SyntaxInfo Prefix []*Prefix // list of prefixes Expr *Expr // Expr Braced []*Init // {Braced} XType *Type // derived type }
Init is an initializer expression.
type Prefix ¶
type Prefix struct { Span Span Dot string // .Dot = XDecl *Decl // for .Dot Index *Expr // [Index] = }
Prefix is an initializer prefix.
type Prog ¶
type Prog struct { SyntaxInfo Decls []*Decl }
type StmtOp ¶
type StmtOp int
const ( StmtDecl StmtOp StmtExpr Empty Block ARGBEGIN Break Continue Do For If Goto Return Switch While )
type Syntax ¶
type Syntax interface { // GetSpan returns the start and end position of the syntax, // excluding leading or trailing comments. // The use of a Get prefix is non-standard but avoids a conflict // with the field named Span in most implementations. GetSpan() Span // GetComments returns the comments attached to the syntax. // This method would normally be named 'Comments' but that // would interfere with embedding a type of the same name. // The use of a Get prefix is non-standard but avoids a conflict // with the field named Comments in most implementations. GetComments() *Comments }
A Syntax represents any syntax element.
type SyntaxInfo ¶
SyntaxInfo contains metadata about a piece of syntax.
func (*SyntaxInfo) GetComments ¶
func (s *SyntaxInfo) GetComments() *Comments
func (*SyntaxInfo) GetSpan ¶
func (s *SyntaxInfo) GetSpan() Span
type Type ¶
type TypeKind ¶
type TypeKind int
const ( Void TypeKind Char Uchar Short Ushort Int Uint Long Ulong Longlong Ulonglong Float Double Enum Ptr Struct Union Array Func TypedefType )
Click to show internal directories.
Click to hide internal directories.