package FrontC

  1. Overview
  2. Docs
val version : string
exception BadModifier
exception BadType
exception UnconsistentDef

* Thrown when an unconsistent C abstract syntax is found.

type size =
  1. | NO_SIZE
    (*

    No size modifier

    *)
  2. | SHORT
    (*

    "short" modifier

    *)
  3. | LONG
    (*

    "long" modifier

    *)
  4. | LONG_LONG
    (*

    GNU "long long" modifier

    *)

Size of int

and sign =
  1. | NO_SIGN
    (*

    No sign modifier

    *)
  2. | SIGNED
    (*

    "signed" modifier

    *)
  3. | UNSIGNED
    (*

    "unsigned" modifier

    *)

Signess of int and bitfields

and storage =
  1. | NO_STORAGE
    (*

    No storage modifier

    *)
  2. | AUTO
    (*

    "auto" modifier

    *)
  3. | STATIC
    (*

    "static" modifier

    *)
  4. | EXTERN
    (*

    "extern" modifier

    *)
  5. | REGISTER
    (*

    "register" modifier

    *)

Storage of names

and base_type =
  1. | NO_TYPE
    (*

    Old K&R declaration without type

    *)
  2. | VOID
    (*

    "void" type

    *)
  3. | BOOL
    (*

    C99 boolean (_Bool) type

    *)
  4. | CHAR of sign
    (*

    "char" type with sign modifier

    *)
  5. | INT of size * sign
    (*

    "int" type with size and sign modifiers

    *)
  6. | BITFIELD of sign * expression
    (*

    Bitfield with sign modifier and size expression

    *)
  7. | FLOAT of bool
    (*

    "float" type with long (true) modifier

    *)
  8. | DOUBLE of bool
    (*

    "double" type with long (true) modifier

    *)
  9. | COMPLEX_FLOAT
    (*

    float complex

    *)
  10. | COMPLEX_DOUBLE
    (*

    double complex

    *)
  11. | COMPLEX_LONG_DOUBLE
    (*

    long double complex

    *)
  12. | PTR of base_type
    (*

    Pointer "*" to the given type

    *)
  13. | RESTRICT_PTR of base_type
    (*

    REstricted pointer "*" to the given type.

    *)
  14. | ARRAY of base_type * expression
    (*

    Array of the given type with the given expression size (may be NOTHING)

    *)
  15. | STRUCT of string * name_group list
    (*

    "struct" of the given name (may be empty) with given fields (may also be empty)

    *)
  16. | UNION of string * name_group list
    (*

    "union" of the given name (may be empty) with given fields (may also be empty)

    *)
  17. | PROTO of proto
    (*

    Prototype of a function

    *)
  18. | OLD_PROTO of old_proto
    (*

    Old-style K&R prototype

    *)
  19. | NAMED_TYPE of string
    (*

    Named type coming from typedef

    *)
  20. | ENUM of string * enum_item list
    (*

    "union" of the given name (may be empty) with given values (may also be empty)

    *)
  21. | CONST of base_type
    (*

    "const" modifier

    *)
  22. | VOLATILE of base_type
    (*

    "volatile" modifier

    *)
  23. | GNU_TYPE of gnu_attrs * base_type
    (*

    a type annotated with GNU attributes

    *)
  24. | BUILTIN_TYPE of string
    (*

    a machine-specific or complier-specific builtin type

    *)
  25. | TYPE_LINE of string * int * base_type
    (*

    Not a type, just to record the file/line of an identifier.

    *)

Base type

and name = string * base_type * gnu_attrs * expression

A name in a declaration with identifier, full type, GNU attributes and * initialization expression.

and name_group = base_type * storage * name list

A name group, that is, a simple type following by many name * declaration as int v, *p, t[256];.

and single_name = base_type * storage * name

A single name, as above, but with only one declaration.

and enum_item = string * expression

Definition of an enumerated value.

and proto = base_type * single_name list * bool

Prototype of a function with return type, function declaration and * variable argument "..." boolean.

and old_proto = base_type * string list * bool

Old-C K&R function prototype with root type, list of arguments and * variable argument "..." boolean.

and definition =
  1. | FUNDEF of single_name * body
    (*

    Definition of a function.

    *)
  2. | OLDFUNDEF of single_name * name_group list * body
    (*

    Definition of an old-C K&R style function.

    *)
  3. | DECDEF of name_group
    (*

    Declaration of function or definition of a variable.

    *)
  4. | TYPEDEF of name_group * gnu_attrs
    (*

    Definition of a typedef.

    *)
  5. | ONLYTYPEDEF of name_group
    (*

    Definition of lonely "struct", "union" or "enum".

    *)

Definitions found in a C file.

and file = definition list

A C files is composed of C definitions

and body = definition list * statement

The body of a function is composed as a list of variable declaration * and of a statement.

and statement =
  1. | NOP
    (*

    No operation. Useful for empty else-part in condition.

    *)
  2. | COMPUTATION of expression
    (*

    A simple expression, usually an assignment.

    *)
  3. | BLOCK of body
    (*

    A block between braces

    *)
  4. | SEQUENCE of statement * statement
    (*

    Two statement separated by ";"

    *)
  5. | IF of expression * statement * statement
    (*

    "if" statement with or without else-part.

    *)
  6. | WHILE of expression * statement
    (*

    "while" statement.

    *)
  7. | DOWHILE of expression * statement
    (*

    "do ... while" statement

    *)
  8. | FOR of expression * expression * expression * statement
    (*

    "for" statement.

    *)
  9. | BREAK
    (*

    "break" statement.

    *)
  10. | CONTINUE
    (*

    "continue" statement.

    *)
  11. | RETURN of expression
    (*

    "return" statement with an expression or with NOTHING.

    *)
  12. | SWITCH of expression * statement
    (*

    "switch" statement. Cases are put in the sub-statement as labels.

    *)
  13. | CASE of expression * statement
    (*

    "case" statement as a label.

    *)
  14. | DEFAULT of statement
    (*

    "default" statement as a label.

    *)
  15. | LABEL of string * statement
    (*

    "label" statement whose sub-statement follows colon ":".

    *)
  16. | GOTO of string
    (*

    "goto" statement.

    *)
  17. | ASM of string
    (*

    Classical "asm" support.

    *)
  18. | GNU_ASM of string * gnu_asm_arg list * gnu_asm_arg list * string list
    (*

    GNU "asm" support.

    *)
  19. | STAT_LINE of statement * string * int
    (*

    Information the filename and the line number of the contained statement.

    *)

Statement changes the flow of control.

and gnu_asm_arg = string * string * expression
and binary_operator =
  1. | ADD
    (*

    "+" operator.

    *)
  2. | SUB
    (*

    "-" operator.

    *)
  3. | MUL
    (*

    "*" operator.

    *)
  4. | DIV
    (*

    "/" operator.

    *)
  5. | MOD
    (*

    "%" operator.

    *)
  6. | AND
    (*

    "&&" operator.

    *)
  7. | OR
    (*

    "||" operator.

    *)
  8. | BAND
    (*

    "&" operator.

    *)
  9. | BOR
    (*

    "|" operator.

    *)
  10. | XOR
    (*

    "^" operator.

    *)
  11. | SHL
    (*

    "<<" operator.

    *)
  12. | SHR
    (*

    ">>" operator.

    *)
  13. | EQ
    (*

    "==" operator.

    *)
  14. | NE
    (*

    "!=" operator.

    *)
  15. | LT
    (*

    "<" operator.

    *)
  16. | GT
    (*

    ">" operator.

    *)
  17. | LE
    (*

    "<=" operator.

    *)
  18. | GE
    (*

    ">=" operator.

    *)
  19. | ASSIGN
    (*

    "=" operator.

    *)
  20. | ADD_ASSIGN
    (*

    "+=" operator.

    *)
  21. | SUB_ASSIGN
    (*

    "-=" operator.

    *)
  22. | MUL_ASSIGN
    (*

    "*=" operator.

    *)
  23. | DIV_ASSIGN
    (*

    "/=" operator.

    *)
  24. | MOD_ASSIGN
    (*

    "%=" operator.

    *)
  25. | BAND_ASSIGN
    (*

    "&=" operator.

    *)
  26. | BOR_ASSIGN
    (*

    "|=" operator.

    *)
  27. | XOR_ASSIGN
    (*

    "^=" operator.

    *)
  28. | SHL_ASSIGN
    (*

    "<<=" operator.

    *)
  29. | SHR_ASSIGN
    (*

    ">>=" operator.

    *)
and unary_operator =
  1. | MINUS
    (*

    "-" operator.

    *)
  2. | PLUS
    (*

    "+" operator.

    *)
  3. | NOT
    (*

    "!" operator.

    *)
  4. | BNOT
    (*

    "~" operator.

    *)
  5. | MEMOF
    (*

    "*" operator.

    *)
  6. | ADDROF
    (*

    "&" operator.

    *)
  7. | PREINCR
    (*

    "++" pre-incrementation.

    *)
  8. | PREDECR
    (*

    "--" pre-decrementation.

    *)
  9. | POSINCR
    (*

    "++" post-incrementation.

    *)
  10. | POSDECR
    (*

    "--" post-decrementation.

    *)

Unary operators identifiers.

and expression =
  1. | NOTHING
    (*

    Null-expression. Useful for return with no value or table declaration without size.

    *)
  2. | UNARY of unary_operator * expression
    (*

    Unary operator use.

    *)
  3. | BINARY of binary_operator * expression * expression
    (*

    Binary operator use.

    *)
  4. | QUESTION of expression * expression * expression
    (*

    "condition ? then-expression : else-expression" operator.

    *)
  5. | CAST of base_type * expression
    (*

    "(type)expresson" type casting.

    *)
  6. | CALL of expression * expression list
    (*

    Function call.

    *)
  7. | COMMA of expression list
    (*

    Sequence of expression separated with ",".

    *)
  8. | CONSTANT of constant
    (*

    Constant value.

    *)
  9. | VARIABLE of string
    (*

    Access to an identifier.

    *)
  10. | EXPR_SIZEOF of expression
    (*

    "sizeof" with expression.

    *)
  11. | TYPE_SIZEOF of base_type
    (*

    "sizeof" with type.

    *)
  12. | INDEX of expression * expression
    (*

    Access to an array item;

    *)
  13. | MEMBEROF of expression * string
    (*

    Indirection through ".".

    *)
  14. | MEMBEROFPTR of expression * string
    (*

    Pointer indirection through "->".

    *)
  15. | GNU_BODY of body
    (*

    GNU braces inside an expression.

    *)
  16. | DESIGNATED of string * expression
    (*

    Designated initialization, in compound constants only.

    *)
  17. | EXPR_LINE of expression * string * int
    (*

    Record the file and line of the expression.

    *)

Expressions.

and constant =
  1. | CONST_INT of string
    (*

    Integer constant.

    *)
  2. | CONST_FLOAT of string
    (*

    Float constant.

    *)
  3. | CONST_CHAR of string
    (*

    Character constant with escapes resolved.

    *)
  4. | CONST_STRING of string
    (*

    String constant with escapes resolved.

    *)
  5. | CONST_COMPOUND of expression list
    (*

    Compound values between braces. Only valid for variable initialization.

    *)

Constant values.

and gnu_attrs = gnu_attr list

GNU special attribute list.

and gnu_attr =
  1. | GNU_NONE
    (*

    No attribute "()".

    *)
  2. | GNU_CALL of string * gnu_attr list
    (*

    Function call.

    *)
  3. | GNU_ID of string
    (*

    Single identifier.

    *)
  4. | GNU_CST of constant
    (*

    Constant value.

    *)
  5. | GNU_EXTENSION
    (*

    Support of __extension__ keyword

    *)
  6. | GNU_INLINE
    (*

    Support of __inline keyword

    *)
  7. | GNU_TYPE_ARG of base_type * storage

GNU special attribute.

OCaml

Innovation. Community. Security.