package mopsa
Install
Dune Dependency
Authors
Maintainers
Sources
md5=fdee20e988343751de440b4f6b67c0f4
sha512=f5cbf1328785d3f5ce40155dada2d95e5de5cce4f084ea30cfb04d1ab10cc9403a26cfb3fa55d0f9da72244482130fdb89c286a9aed0d640bba46b7c00e09500
doc/mopsa.mopsa_c_parser/Mopsa_c_parser/C_AST/index.html
Module Mopsa_c_parser.C_AST
Source
C_AST - Simpler C AST
Provides a simpler version of the AST converted from Clang.
The goal of this AST is to:
- be independent from Clang's version
- support linking of several translation units into a single AST
- only support C for now
Unique identifiers (for variables and functions).
module RangeMap : sig ... end
Source locations.
Comments in file.
preprocessor macros
Operators
Types
type integer_type =
| Char of signedness
(*plain '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_INT128
(*Integer types.
*)
Type qualifiers. For now, only 'const' is useful.
type typ =
| T_void
(*Void type.
*)| T_bool
| T_integer of integer_type
| T_float of float_type
| T_complex of float_type
| T_pointer of type_qual
(*Scalar types.
*)| T_array of type_qual * array_length
(*Arrays.
*)| T_bitfield of typ * int
(*Bitfields, with bit-width, only used in struct.
*)| T_function of function_type option
(*Function, with or without a prototype
*)| T_builtin_fn
(*Built-in functions
*)| T_typedef of typedef
(*Typedefs
*)| T_record of record_type
(*struct and union
*)| T_enum of enum_type
(*enums
*)| T_vector of vector_type
(*GCC vectors
*)| T_unknown_builtin of string
(*unknown 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
*)
}
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
*)
}
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
*)
}
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
*)
}
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
*)
}
A possible value in an enumerated type.
Type of functions and prototypes.
GCC vector types.
Variables and functions
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
*)
}
and variable_kind =
| Variable_global
(*global shared among translation units
*)| Variable_extern
(*declared but not defined
*)| Variable_local of func
(*local to a function
*)| Variable_parameter of func
(*formal argument
*)| Variable_file_static of translation_unit
(*restricted to a translation unit
*)| Variable_func_static of func
(*restricted 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
*)
}
Statements and expressions
and statement_kind =
| S_local_declaration of variable
(*local variable declaration
*)| S_expression of expr
(*expression statement
*)| S_block of block
(*statement block
*)| S_if of expr * block * block
(*else branch
*)| S_while of expr * block
(*body
*)| S_do_while of block * expr
(*condition
*)| S_for of block * expr option * expr option * block
(*body
*)| S_jump of jump_kind
(*jump instruction
*)| S_target of target_kind
(*target of a jump
*)| S_asm of asm_kind
(*asm statement
*)
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 * block
(*various ways to jump
*)
and target_kind =
| S_label of string
| S_case of expr list * scope_update
| S_default of scope_update
(*various 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 * expr
(*else
*)| E_binary_conditional of expr * expr
(*else
*)| E_array_subscript of expr * expr
(*index
*)| E_member_access of expr * int * string
(*field
*)| E_arrow_access of expr * int * string
(*field
*)| E_compound_assign of expr * type_qual * binary_arithmetic * expr * type_qual
(*type of the result, before converting back to lvalue type
*)| E_binary of binary_operator * expr * expr
(*right argument
*)| E_assign of expr * expr
(*rvalue
*)| 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 array
(*actual arguments
*)| E_character_literal of Z.t * character_kind
(*literal character
*)| E_integer_literal of Z.t
(*literal integer
*)| E_float_literal of string
(*literal float, in binary string notation
*)| E_string_literal of string * character_kind
| E_compound_literal of init
| E_variable of variable
| E_function of func
| E_predefined of string
(*predefined identifier
*)| E_statement of block
(*a 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 * string
(*accessor
*)| E_shuffle_vector of expr array
and 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
*)
}
A project is a set of translation units linked together.
Useful definitions
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
Variable utilities
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.