c2go: rsc.io/c2go/cc Index | Files

package cc

import "rsc.io/c2go/cc"

Package cc implements parsing, type checking, and printing of C programs.

Index

Package Files

doc.go expr.go lex.go parse.go print.go stdhdr.go stmt.go type.go typecheck.go y.go

Variables

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}
)

func AddInclude Uses

func AddInclude(dir string)

func Postorder Uses

func Postorder(x Syntax, f func(Syntax))

Preorder calls f for each piece of syntax of x in a postorder traversal.

func Preorder Uses

func Preorder(x Syntax, f func(Syntax))

Preorder calls f for each piece of syntax of x in a preorder traversal.

func Walk Uses

func Walk(x Syntax, before, after func(Syntax))

Walk traverses the syntax x, calling before and after on entry to and exit from each Syntax encountered during the traversal. In case of cross-linked input, the traversal never visits a given Syntax more than once.

type Comment Uses

type Comment struct {
    Span
    Text   string
    Suffix bool
}

func (Comment) GetSpan Uses

func (c Comment) GetSpan() Span

type Comments Uses

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 Uses

type Decl struct {
    SyntaxInfo
    Name    string
    Type    *Type
    Storage Storage
    Init    *Init
    Body    *Stmt

    XOuter    *Decl
    CurFn     *Decl
    OuterType *Type
    GoPackage string
}

func (*Decl) String Uses

func (d *Decl) String() string

type Expr Uses

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.

func ParseExpr Uses

func ParseExpr(str string) (*Expr, error)

func (*Expr) String Uses

func (x *Expr) String() string

type ExprOp Uses

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
)

func (ExprOp) String Uses

func (op ExprOp) String() string
type Header struct {
    // contains filtered or unexported fields
}

type Init Uses

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 Label Uses

type Label struct {
    SyntaxInfo
    Op   LabelOp
    Expr *Expr
    Name string
}

type LabelOp Uses

type LabelOp int
const (
    Case LabelOp
    Default
    LabelName
)

type Pos Uses

type Pos struct {
    File string
    Line int
    Byte int
}

type Prefix Uses

type Prefix struct {
    Span  Span
    Dot   string // .Dot =
    XDecl *Decl  // for .Dot
    Index *Expr  // [Index] =
}

Prefix is an initializer prefix.

type Printer Uses

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

func (*Printer) Bytes Uses

func (p *Printer) Bytes() []byte

func (*Printer) EndHTML Uses

func (p *Printer) EndHTML()

func (*Printer) Print Uses

func (p *Printer) Print(args ...interface{})

func (*Printer) StartHTML Uses

func (p *Printer) StartHTML()

func (*Printer) String Uses

func (p *Printer) String() string

type Prog Uses

type Prog struct {
    SyntaxInfo
    Decls []*Decl
}

func Read Uses

func Read(name string, r io.Reader) (*Prog, error)

func ReadMany Uses

func ReadMany(names []string, readers []io.Reader) (*Prog, error)

type Scope Uses

type Scope struct {
    Decl map[string]*Decl
    Tag  map[string]*Type
    Next *Scope
}

type Span Uses

type Span struct {
    Start Pos
    End   Pos
}

func (Span) String Uses

func (l Span) String() string

type Stmt Uses

type Stmt struct {
    SyntaxInfo
    Op     StmtOp
    Pre    *Expr
    Expr   *Expr
    Post   *Expr
    Decl   *Decl
    Body   *Stmt
    Else   *Stmt
    Block  []*Stmt
    Labels []*Label
    Text   string
    Type   *Type
}

type StmtOp Uses

type StmtOp int
const (
    StmtDecl StmtOp
    StmtExpr
    Empty
    Block
    ARGBEGIN
    Break
    Continue
    Do
    For
    If
    Goto
    Return
    Switch
    While
)

type Storage Uses

type Storage int
const (
    Auto Storage = 1 << iota
    Static
    Extern
    Typedef
    Register
    Inline
)

func (Storage) String Uses

func (c Storage) String() string

type Syntax Uses

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 Uses

type SyntaxInfo struct {
    Span     Span // location of syntax in input
    Comments Comments
}

SyntaxInfo contains metadata about a piece of syntax.

func (*SyntaxInfo) GetComments Uses

func (s *SyntaxInfo) GetComments() *Comments

func (*SyntaxInfo) GetSpan Uses

func (s *SyntaxInfo) GetSpan() Span

type Type Uses

type Type struct {
    SyntaxInfo
    Kind     TypeKind
    Qual     TypeQual
    Base     *Type
    Tag      string
    Decls    []*Decl
    Width    *Expr
    Name     string
    TypeDecl *Decl
}

func (*Type) Def Uses

func (t *Type) Def() *Type

func (*Type) Is Uses

func (t *Type) Is(k TypeKind) bool

func (*Type) IsPtrVoid Uses

func (t *Type) IsPtrVoid() bool

func (*Type) String Uses

func (t *Type) String() string

type TypeKind Uses

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
)

func (TypeKind) String Uses

func (k TypeKind) String() string

type TypeQual Uses

type TypeQual int
const (
    Const TypeQual = 1 << iota
    Volatile
)

func (TypeQual) String Uses

func (q TypeQual) String() string

type TypedName Uses

type TypedName struct {
    Type *Type
    Name string
}

Package cc imports 9 packages (graph) and is imported by 2 packages. Updated 2016-07-15. Refresh now. Tools for package owners.