Cnorm AST

This module provide all AST nodes.

Inheritance diagram of cnorm.nodes

class cnorm.nodes.Expr[source]

Bases: pyrser.parsing.node.Node

All expression

class cnorm.nodes.Func(call_expr: cnorm.nodes.Expr, params: list)[source]

Bases: cnorm.nodes.Expr

For almost everything

__init__(self, call_expr: Expr, params: list)[source]
to_c(self)
class cnorm.nodes.BlockInit(body: [<class 'cnorm.nodes.Expr'>])[source]

Bases: cnorm.nodes.Expr

Initializer Block Expression

__init__(self, body)[source]
to_c(self)
class cnorm.nodes.BlockExpr(body: [<class 'cnorm.nodes.Expr'>])[source]

Bases: cnorm.nodes.Expr

Compound Block Expression

__init__(self, body)[source]
to_c(self)
class cnorm.nodes.Unary(call_expr: cnorm.nodes.Expr, params: list)[source]

Bases: cnorm.nodes.Func

For unary operator

to_c(self)
class cnorm.nodes.Paren(call_expr: cnorm.nodes.Expr, params: list)[source]

Bases: cnorm.nodes.Unary

For () expression

to_c(self)
class cnorm.nodes.Array(call_expr: cnorm.nodes.Expr, params: list)[source]

Bases: cnorm.nodes.Unary

For [] expression

to_c(self)
class cnorm.nodes.Dot(call_expr: cnorm.nodes.Expr, params: list)[source]

Bases: cnorm.nodes.Unary

For . expression

to_c(self)
class cnorm.nodes.Arrow(call_expr: cnorm.nodes.Expr, params: list)[source]

Bases: cnorm.nodes.Unary

For -> expression

to_c(self)
class cnorm.nodes.Post(call_expr: cnorm.nodes.Expr, params: list)[source]

Bases: cnorm.nodes.Unary

For post{inc,dec} expression

to_c(self)
class cnorm.nodes.Sizeof(call_expr: cnorm.nodes.Expr, params: list)[source]

Bases: cnorm.nodes.Unary

For sizeof expr/type expression

to_c(self)
class cnorm.nodes.Binary(call_expr: cnorm.nodes.Expr, params: list)[source]

Bases: cnorm.nodes.Func

For binary operator

to_c(self)
class cnorm.nodes.Cast(call_expr: cnorm.nodes.Expr, params: list)[source]

Bases: cnorm.nodes.Binary

For cast operator

to_c(self)
class cnorm.nodes.Range(call_expr: cnorm.nodes.Expr, params: list)[source]

Bases: cnorm.nodes.Binary

For range expression

class cnorm.nodes.Ternary(call_expr: cnorm.nodes.Expr, params: list)[source]

Bases: cnorm.nodes.Func

For ternary operator

to_c(self)
class cnorm.nodes.Terminal(value: str)[source]

Bases: cnorm.nodes.Expr

For Terminal expression

__init__(self, value: str)[source]
to_c(self)
class cnorm.nodes.Id(value: str)[source]

Bases: cnorm.nodes.Terminal

Terminal Id

class cnorm.nodes.Literal(value: str)[source]

Bases: cnorm.nodes.Terminal

Terminal Literal

class cnorm.nodes.Raw(value: str)[source]

Bases: cnorm.nodes.Terminal

Terminal Raw

class cnorm.nodes.Enumerator(ident: str, expr: cnorm.nodes.Expr)[source]

Bases: pyrser.parsing.node.Node

Enumerator A=x in enums

__init__(self, ident: str, expr: Expr)[source]
class cnorm.nodes.DeclType[source]

Bases: pyrser.parsing.node.Node

For type in declaration

__init__(self)[source]
push(self, t= None)[source]
class cnorm.nodes.PointerType[source]

Bases: cnorm.nodes.DeclType

For pointer in declaration

class cnorm.nodes.ArrayType(expr=None)[source]

Bases: cnorm.nodes.DeclType

For array in declaration

__init__(self, expr= None)[source]
expr
class cnorm.nodes.ParenType(params=None)[source]

Bases: cnorm.nodes.DeclType

For parenthesis in declaration

__init__(self, params= None)[source]
params
class cnorm.nodes.QualType(qualifier: pyrser.meta.Enum=0)[source]

Bases: cnorm.nodes.DeclType

For qualifier in declaration

__init__(self, qualifier: Enum= 0)[source]
class cnorm.nodes.AttrType(raw: str)[source]

Bases: cnorm.nodes.DeclType

For attribute specifier in declaration

__init__(self, raw: str)[source]
class cnorm.nodes.CType[source]

Bases: pyrser.parsing.node.Node

Base for primary/func

__init__(self)[source]
copy(self)[source]
push(self, t: DeclType= None)[source]
ctype_to_c(self, func_var_name= '')
class cnorm.nodes.PrimaryType(identifier: str)[source]

Bases: cnorm.nodes.CType

For primary type in declaration

__init__(self, identifier: str)[source]
identifier
class cnorm.nodes.ComposedType(identifier: str)[source]

Bases: cnorm.nodes.CType

For composed type in declaration

__init__(self, identifier: str)[source]
identifier
class cnorm.nodes.FuncType(identifier: str, params=[], decltype=None)[source]

Bases: cnorm.nodes.PrimaryType

For function in declaration

__init__(self, identifier: str, params= [], decltype= None)[source]
params
cnorm.nodes.makeCType(declspecifier: str, ctype= None)[source]
class cnorm.nodes.Decl(name: str, ct=None)[source]

Bases: cnorm.nodes.Expr

For basic declaration

A declaration contains the following attributes:

  • _name: name of the declaration
  • _ctype: the CType describing the type of the declaration
  • _assign_expr: when the declaration have a value
  • _colon_expr: When it’s a bitfield
  • body: when it’s function definition
__init__(self, name: str, ct= None)[source]
ctype
assign_expr(self, expr= None)[source]
colon_expr(self, expr= None)[source]
to_c(self)
class cnorm.nodes.Stmt[source]

Bases: pyrser.parsing.node.Node

For statement

class cnorm.nodes.ExprStmt(expr: cnorm.nodes.Expr)[source]

Bases: cnorm.nodes.Stmt

Expression statement

__init__(self, expr: Expr)[source]
to_c(self)
class cnorm.nodes.BlockStmt(body: [<class 'cnorm.nodes.ExprStmt'>])[source]

Bases: cnorm.nodes.Stmt

Block statement

__init__(self, body)[source]
func(self, name: str)[source]

return the first func defined named name

var(self, name: str)[source]

return the first var instancied named name

type(self, name: str)[source]

return the first complete definition of type ‘name’

declfuncs(self, name: str)[source]

generator on all declaration of function ‘name’

declvars(self, name: str)[source]

generator on all declaration of variable ‘name’

decltypes(self, name: str)[source]

generator on all declaration of type ‘name’

declallfuncs(self)[source]

generator on all declaration of function

declallvars(self)[source]

generator on all declaration of variable

declalltypes(self)[source]

generator on all declaration of type

to_c(self)
class cnorm.nodes.RootBlockStmt(body: [<class 'cnorm.nodes.ExprStmt'>])[source]

Bases: cnorm.nodes.BlockStmt

Root Block statement

__init__(self, body)[source]
to_c(self)
class cnorm.nodes.Label(value: str)[source]

Bases: cnorm.nodes.Stmt

Label statement

__init__(self, value: str)[source]
to_c(self)
class cnorm.nodes.Branch(value: str, expr: cnorm.nodes.Expr)[source]

Bases: cnorm.nodes.Label

branch statement

__init__(self, value: str, expr: Expr)[source]
to_c(self)
class cnorm.nodes.Case(expr: cnorm.nodes.Expr)[source]

Bases: cnorm.nodes.Branch

Case statement

__init__(self, expr: Expr)[source]
to_c(self)
class cnorm.nodes.Return(expr: cnorm.nodes.Expr)[source]

Bases: cnorm.nodes.Branch

Return statement

__init__(self, expr: Expr)[source]
class cnorm.nodes.Goto(expr: cnorm.nodes.Expr)[source]

Bases: cnorm.nodes.Branch

Goto statement

__init__(self, expr: Expr)[source]
class cnorm.nodes.LoopControl(value: str)[source]

Bases: cnorm.nodes.Label

loop control statement

to_c(self)
class cnorm.nodes.Break[source]

Bases: cnorm.nodes.LoopControl

break statement

__init__(self)[source]
class cnorm.nodes.Continue[source]

Bases: cnorm.nodes.LoopControl

continue statement

__init__(self)[source]
class cnorm.nodes.Conditional(condition: cnorm.nodes.Expr)[source]

Bases: cnorm.nodes.Stmt

Conditional statement

__init__(self, condition: Expr)[source]
class cnorm.nodes.If(condition: cnorm.nodes.Expr, thencond: cnorm.nodes.Stmt, elsecond: cnorm.nodes.Stmt=None)[source]

Bases: cnorm.nodes.Conditional

If statement

__init__(self, condition: Expr, thencond: Stmt, elsecond: Stmt= None)[source]
to_c(self)
class cnorm.nodes.While(condition: cnorm.nodes.Expr, body: cnorm.nodes.Stmt)[source]

Bases: cnorm.nodes.Conditional

While statement

__init__(self, condition: Expr, body: Stmt)[source]
to_c(self)
class cnorm.nodes.Switch(condition: cnorm.nodes.Expr, body: cnorm.nodes.Stmt)[source]

Bases: cnorm.nodes.Conditional

Switch statement

__init__(self, condition: Expr, body: Stmt)[source]
to_c(self)
class cnorm.nodes.Do(condition: cnorm.nodes.Expr, body: cnorm.nodes.Stmt)[source]

Bases: cnorm.nodes.Conditional

Do statement

__init__(self, condition: Expr, body: Stmt)[source]
to_c(self)
class cnorm.nodes.For(init: cnorm.nodes.Expr, condition: cnorm.nodes.Expr, increment: cnorm.nodes.Expr, body: cnorm.nodes.Stmt)[source]

Bases: cnorm.nodes.Stmt

For statement

__init__(self, init: Expr, condition: Expr, increment: Expr, body: Stmt)[source]
to_c(self)