Mopsa_c_parser.C_ASTSourceC_AST - Simpler C AST
Provides a simpler version of the AST converted from Clang.
The goal of this AST is to:
Unique identifiers (for variables and functions).
module RangeMap : sig ... endSource locations.
Comments in file.
preprocessor macros
type integer_type = | Char of signednessplain 'char', where the signeness is defined by the platform
*)| SIGNED_CHAR| UNSIGNED_CHAR| SIGNED_SHORT| UNSIGNED_SHORT| SIGNED_INT| UNSIGNED_INT| SIGNED_LONG| UNSIGNED_LONG| SIGNED_LONG_LONG| UNSIGNED_LONG_LONG| SIGNED_INT128| UNSIGNED_INT128Integer types.
*)Type qualifiers. For now, only 'const' is useful.
type typ = | T_voidVoid type.
*)| T_bool| T_integer of integer_type| T_float of float_type| T_complex of float_type| T_pointer of type_qualScalar types.
*)| T_array of type_qual * array_lengthArrays.
*)| T_bitfield of typ * intBitfields, with bit-width, only used in struct.
*)| T_function of function_type optionFunction, with or without a prototype
*)| T_builtin_fnBuilt-in functions
*)| T_typedef of typedefTypedefs
*)| T_record of record_typestruct and union
*)| T_enum of enum_typeenums
*)| T_vector of vector_typeGCC vectors
*)| T_attributed of typ * attr| T_unknown_builtin of stringunknown builtin
*)Types.
and typedef = {typedef_org_name : string;name as in source
*)mutable typedef_uid : uid;mutable typedef_unique_name : string;unique name
*)mutable typedef_def : type_qual;declaration
*)mutable typedef_range : range;declaration location
*)mutable typedef_com : comment list;comments associated to the declaration
*)mutable typedef_attrs : attr list;attributes
*)}and record_type = {record_kind : record_kind;record_org_name : string;name as in source, may be empty
*)mutable record_uid : uid;unique identifier
*)mutable record_unique_name : string;unique, non-empty name
*)mutable record_defined : bool;false if only declared
*)mutable record_sizeof : Z.t;size of record, in bytes
*)mutable record_alignof : Z.t;alignment, in bytes
*)mutable record_fields : record_field array;mutable record_range : range;declaration location
*)mutable record_com : comment list;comments associated to the declaration
*)mutable record_attrs : attr list;attributes
*)}Struct or union type.
and record_field = {field_uid : uid;unique identifier
*)field_org_name : string;may be empty for anonymous or padding fields
*)field_name : string;non-empty name
*)field_offset : int;field_bit_offset : int;mutable field_type : type_qual;field_range : range;declaration location
*)field_record : record_type;field_index : int;mutable field_com : comment list;comments associated to the declaration
*)mutable field_attrs : attr list;attributes
*)}Struct or union field.
and enum_type = {enum_org_name : string;name as in source, may be empty
*)mutable enum_uid : uid;unoque identifier
*)mutable enum_unique_name : string;unique, non-empty name
*)mutable enum_defined : bool;false if only declared
*)mutable enum_values : enum_value list;mutable enum_integer_type : integer_type option;mutable enum_range : range;declaration location
*)mutable enum_com : comment list;comments associated to the declaration
*)mutable enum_attrs : attr list;attributes
*)}Enumerated type.
and enum_value = {enum_val_uid : uid;unique identifier
*)enum_val_org_name : string;name as in source
*)enum_val_unique_name : string;unique name
*)enum_val_value : Z.t;enum_val_enum : enum_type;enum_val_range : range;mutable enum_val_com : comment list;comments associated to the declaration
*)mutable enum_val_attrs : attr list;attributes
*)}A possible value in an enumerated type.
Type of functions and prototypes.
and vector_type = {vector_type : type_qual;element type
*)vector_size : int;size, in elements
*)vector_kind : int;vector_sizeof : Z.t;size, in bytes
*)}GCC vector types.
and variable = {var_uid : uid;unique identifier
*)var_org_name : string;original name
*)var_unique_name : string;unique name for globals and statics
*)mutable var_kind : variable_kind;variable kind and life-time
*)mutable var_type : type_qual;mutable var_init : init option;mutable var_before_stmts : statement list;statements executed before the declaration of the variable
*)mutable var_after_stmts : statement list;statements executed after the declaration of the variable
*)mutable var_range : range;mutable var_com : comment list;comments associated to the declaration
*)mutable var_init_org : init option;initialisation _before_ simplification, if different from var_init; used for printing
*)mutable var_attrs : attr list;attributes
*)}and variable_kind = | Variable_globalglobal shared among translation units
*)| Variable_externdeclared but not defined
*)| Variable_local of funclocal to a function
*)| Variable_parameter of funcformal argument
*)| Variable_file_static of translation_unitrestricted to a translation unit
*)| Variable_func_static of funcrestricted to a function
*)and func = {func_uid : uid;unique identifier
*)func_org_name : string;original name
*)func_unique_name : string;unique name for globals and statics
*)func_is_static : bool;mutable func_return : type_qual;type of returned value
*)mutable func_parameters : variable array;function parameters
*)mutable func_body : block option;function body
*)mutable func_static_vars : variable list;static variables declared in the function
*)mutable func_local_vars : variable list;local variables declared in the function (excluding parameters)
*)mutable func_variadic : bool;whether the has a variable number of arguments
*)mutable func_range : range;range of the full declaration
*)mutable func_name_range : range;range of the name part of the declaration
*)mutable func_com : (comment * macro StringMap.t) list;comments associated to the declaration
*)mutable func_attrs : attr list;function attributes
*)}and statement_kind = | S_local_declaration of variablelocal variable declaration
*)| S_expression of exprexpression statement
*)| S_block of blockstatement block
*)| S_if of expr * block * blockelse branch
*)| S_while of expr * blockbody
*)| S_do_while of block * exprcondition
*)| S_for of block * expr option * expr option * blockbody
*)| S_jump of jump_kindjump instruction
*)| S_target of target_kindtarget of a jump
*)| S_asm of asm_kindasm statement
*)| S_attributed of statement * attr liststatement with attributes
*)and jump_kind = | S_goto of string * scope_update| S_break of scope_update| S_continue of scope_update| S_return of expr option * scope_update| S_switch of expr * blockvarious ways to jump
*)and target_kind = | S_label of string| S_case of expr list * scope_update| S_default of scope_updatevarious targets of jumps
*)variables to remove and to add (uninitialized) when jumping into another scope; may be attached to a jump source (break, continue, return, goto) or a jump target (switch case and default), depending on what's more convinient
and asm_kind = {asm_style : asm_style;asm_is_simple : bool;asm_is_volatile : bool;asm_body : string;asm_outputs : asm_output array;asm_inputs : asm_input array;asm_clobbers : string array;asm_labels : string array;}and asm statement
and asm_output = {asm_output_string : string;asm_output_expr : expr;asm_output_constraint : asm_output_constraint;}and expr_kind = | E_conditional of expr * expr * exprelse
*)| E_binary_conditional of expr * exprelse
*)| E_array_subscript of expr * exprindex
*)| E_member_access of expr * int * stringfield
*)| E_arrow_access of expr * int * stringfield
*)| E_compound_assign of expr * type_qual * binary_arithmetic * expr * type_qualtype of the result, before converting back to lvalue type
*)| E_binary of binary_operator * expr * exprright argument
*)| E_assign of expr * exprrvalue
*)| E_comma of expr * expr, operator
*)| E_unary of unary_operator * expr| E_increment of inc_direction * inc_location * expr| E_address_of of expr& operator (address of lvalue)
*)| E_deref of expr* operator (pointer dereference)
*)| E_cast of expr * explicitness| E_call of expr * expr arrayactual arguments
*)| E_character_literal of Z.t * character_kindliteral character
*)| E_integer_literal of Z.tliteral integer
*)| E_float_literal of stringliteral float, in binary string notation
*)| E_string_literal of string * character_kind| E_null_ptr| E_compound_literal of init| E_variable of variable| E_function of func| E_predefined of stringpredefined identifier
*)| E_statement of blocka block of statements viewed as an expression (GCC extension)
*)| E_var_args of expr__builtin_va_arg
*)| E_atomic of int * expr * expr| E_convert_vector of expr| E_vector_element of expr * stringaccessor
*)| E_shuffle_vector of expr arrayand project = {proj_name : string;project name
*)proj_tu : translation_unit list;translation units composing the project
*)proj_target : target_info;proj_typedefs : typedef StringMap.t;typedefs, by unique name
*)proj_enums : enum_type StringMap.t;enums, by unique name
*)proj_records : record_type StringMap.t;records, by unique name
*)proj_vars : variable StringMap.t;variables with global lifetime, by unique name
*)proj_funcs : func StringMap.t;functions, by unique name
*)proj_file_scope_asm : string RangeMap.t;file-scope assembly directives
*)proj_files : string list;list of parsed files
*)proj_comments : (comment * macro StringMap.t) list RangeMap.t;all comments
*)proj_macros : macro StringMap.t;macros, by name
*)proj_opts : string list;selected options pased to the compiler we'd like to keep
*)}A project is a set of translation units linked together.
Replace toplevel occurences of typedefs with their definition.
Interprets the type as an integer type, if possible
Interprets the type as an integer type, if possible
Whether variables of this kind have global lifetime or not.
Whether variables of this kind are static or not.
Whether variables of this kind are file-level static.