package mopsa
Install
Dune Dependency
Authors
Maintainers
Sources
md5=fdee20e988343751de440b4f6b67c0f4
sha512=f5cbf1328785d3f5ce40155dada2d95e5de5cce4f084ea30cfb04d1ab10cc9403a26cfb3fa55d0f9da72244482130fdb89c286a9aed0d640bba46b7c00e09500
doc/c_lang/C_lang/Lang/Ast/index.html
Module Lang.Ast
Source
AST of the C language.
Types
type c_typedef = {
c_typedef_org_name : string;
(*name as in source
*)c_typedef_unique_name : string;
(*unique name
*)mutable c_typedef_def : Mopsa.typ;
(*declaration
*)c_typedef_range : Mopsa.Location.range;
(*declaration location
*)
}
Type definition.
and c_record_type = {
c_record_kind : c_record_kind;
c_record_org_name : string;
(*name as in source, may be empty
*)c_record_unique_name : string;
(*unique, non-empty name
*)c_record_defined : bool;
(*false if only declared
*)c_record_sizeof : Z.t;
(*size of record, in bytes
*)c_record_alignof : Z.t;
(*alignment, in bytes
*)mutable c_record_fields : c_record_field list;
c_record_range : Mopsa.Location.range;
(*declaration location
*)
}
Struct or union type.
and c_record_field = {
c_field_org_name : string;
(*may be empty for anonymous or padding fields
*)c_field_name : string;
(*non-empty name
*)c_field_offset : int;
c_field_bit_offset : int;
c_field_type : Mopsa.typ;
c_field_range : Mopsa.Location.range;
(*declaration location
*)c_field_index : int;
}
Struct or union field.
and c_enum_type = {
c_enum_org_name : string;
(*name as in source, may be empty
*)c_enum_unique_name : string;
(*unique, non-empty name
*)c_enum_defined : bool;
(*false if only declared
*)c_enum_values : c_enum_value list;
c_enum_integer_type : c_integer_type;
c_enum_range : Mopsa.Location.range;
(*declaration location
*)
}
Enumerated type.
and c_enum_value = {
c_enum_val_org_name : string;
(*name as in source
*)c_enum_val_unique_name : string;
(*unique name
*)c_enum_val_value : Z.t;
c_enum_val_range : Mopsa.range;
}
A possible value in an enumerated type.
and c_array_length =
| C_array_no_length
| C_array_length_cst of Z.t
| C_array_length_expr of Mopsa.expr
(*Cases of arrays length.
*)
Type qualifiers.
Function type.
type Mopsa.typ +=
| T_c_void
(*Void type.
*)| T_c_bool
| T_c_integer of c_integer_type
| T_c_float of c_float_type
| T_c_pointer of Mopsa.typ
(*Scalar types.
*)| T_c_array of Mopsa.typ * c_array_length
(*Arrays.
*)| T_c_bitfield of Mopsa.typ * int
(*Bitfields, with bit-width, only used in struct.
*)| T_c_function of c_function_type option
(*Function, with or without a prototype
*)| T_c_builtin_fn
(*Built-in functions
*)| T_c_typedef of c_typedef
(*Typedefs
*)| T_c_record of c_record_type
(*struct and union
*)| T_c_enum of c_enum_type
(*enums
*)| T_c_qualified of c_qual * Mopsa.typ
(*Qualified type.
*)| T_c_block_object of Mopsa.typ
(*Type of block objects.
*)| T_c_unknown_builtin of string
(*Unknown builtin type.
*)
Function descriptor
***********************
type c_fundec = {
mutable c_func_uid : int;
(*unique identifier
*)mutable c_func_org_name : string;
(*original name
*)mutable c_func_unique_name : string;
(*unique name for globals and statics
*)c_func_is_static : bool;
mutable c_func_return : Mopsa.typ;
(*type of returned value
*)mutable c_func_parameters : Mopsa.var list;
(*function parameters
*)mutable c_func_body : Mopsa.stmt option;
(*function body
*)mutable c_func_static_vars : Mopsa.var list;
(*static variables declared in the function
*)mutable c_func_local_vars : Mopsa.var list;
(*local variables declared in the function (excluding parameters)
*)mutable c_func_variadic : bool;
(*whether the has a variable number of arguments
*)mutable c_func_range : Mopsa.range;
(*location range of the declaration
*)mutable c_func_name_range : Mopsa.range;
(*location range of the name in the declaration
*)mutable c_func_stub : Stubs.Ast.stub_func option;
(*stub comment
*)
}
Function descriptor.
C variables
type c_var_scope =
| Variable_global
(*global shared among translation units
*)| Variable_extern
(*declared but not defined
*)| Variable_local of c_fundec
(*local to a function
*)| Variable_parameter of c_fundec
(*formal argument
*)| Variable_file_static of string
(*restricted to a translation unit
*)| Variable_func_static of c_fundec
(*restricted to a function
*)
type c_var_init =
| C_init_expr of Mopsa.expr
| C_init_list of c_var_init list * c_var_init option
(*filler
*)| C_init_implicit of Mopsa.typ
Variable initialization.
type cvar = {
cvar_scope : c_var_scope;
(*life-time scope of the variable
*)cvar_range : Mopsa.range;
(*declaration range
*)cvar_uid : int;
cvar_orig_name : string;
cvar_uniq_name : string;
cvar_before_stmts : Mopsa.stmt list;
(*list of statements to execute before the declaration of a variable
*)cvar_after_stmts : Mopsa.stmt list;
(*list of statements to execute after the declaration of a variable
*)
}
C expressions
type Mopsa.constant +=
| C_c_character of Z.t * c_character_kind
(*Constant character
*)| C_c_string of string * c_character_kind
(*Constant string literal
*)| C_c_invalid
(*Invalid pointer value
*)
type Mopsa.expr_kind +=
| E_c_conditional of Mopsa.expr * Mopsa.expr * Mopsa.expr
(*else
*)| E_c_array_subscript of Mopsa.expr * Mopsa.expr
(*index
*)| E_c_member_access of Mopsa.expr * int * string
(*field
*)| E_c_function of c_fundec
| E_c_builtin_function of string
| E_c_builtin_call of string * Mopsa.expr list
| E_c_arrow_access of Mopsa.expr * int * string
(*field
*)| E_c_assign of Mopsa.expr * Mopsa.expr
(*rvalue
*)| E_c_compound_assign of Mopsa.expr * Mopsa.typ * Mopsa.operator * Mopsa.expr * Mopsa.typ
(*type of the result, before converting back to lvalue type
*)| E_c_comma of Mopsa.expr * Mopsa.expr
(*, operator
*)| E_c_increment of c_inc_direction * c_inc_location * Mopsa.expr
| E_c_address_of of Mopsa.expr
(*& operator (address of lvalue)
*)| E_c_deref of Mopsa.expr
(** operator (pointer dereference)
*)| E_c_cast of Mopsa.expr * bool
(*explicitness
*)| E_c_statement of Mopsa.stmt
| E_c_predefined of string
(*predefined identifier
*)| E_c_var_args of Mopsa.expr
(*__builtin_va_arg
*)| E_c_atomic of int * Mopsa.expr * Mopsa.expr
| E_c_block_object of Mopsa.expr
(*Block objects are useful to distinguish between operations on the block itself and its content. For, expanding the contents of a block will duplicate every cell in the block, while expanding the block object will update the pointers that point to the block.
*)
Scope update
Scope update information for jump statements
Statements
type Mopsa.stmt_kind +=
| S_c_goto_stab of Mopsa.stmt
(*stabilization point for goto statement
*)| S_c_declaration of Mopsa.var * c_var_init option * c_var_scope
(*declaration of a variable
*)| S_c_do_while of Mopsa.stmt * Mopsa.expr
(*condition
*)| S_c_for of Mopsa.stmt * Mopsa.expr option * Mopsa.expr option * Mopsa.stmt
(*body
*)| S_c_return of Mopsa.expr option * c_scope_update
(*return statement
*)| S_c_break of c_scope_update
(*break statement
*)| S_c_continue of c_scope_update
(*continue statement
*)| S_c_goto of string * c_scope_update
(*goto statements.
*)| S_c_switch of Mopsa.expr * Mopsa.stmt
(*switch statement.
*)| S_c_label of string
(*statement label.
*)| S_c_switch_case of Mopsa.expr list * c_scope_update
(*case of a switch statement.
case a: case b: stmt;
is represented through S_c_switch_case
a; b
to factor in some casesFor integer cases, we use the interval
*)a, b
to simplify expressions, similar to the GCC C extension for ranges| S_c_switch_default of c_scope_update
(*default case of switch statements.
*)| S_c_asm of string
(*inline assembly for now, we keep only a string representation to display warnings; see C_AST.asm_kind for a more usable representation when support is added
*)
type c_program = {
c_globals : (Mopsa.var * c_var_init option) list;
(*global variables of the program
*)c_functions : c_fundec list;
(*functions of the program
*)c_stub_directives : Stubs.Ast.stub_directive list;
(*list of stub directives
*)
}
module CProgramKey : sig ... end
Flow-insensitive context to keep the analyzed C program
Set the C program in the flow
Get the C program from the flow
Conversion to/from Clang parser types
Target information
module TargetCtx : sig ... end
val set_c_target_info :
Mopsa_c_parser.Clang_AST.target_info ->
'a Mopsa.Flow.flow ->
'a Mopsa.Flow.flow
Sizes and alignments
sizeof t
computes the size (in bytes) of a C type t
Size (in bytes) of a type, as an expression. Handles variable-length ararys.
range t
computes the interval range of type t
range t
computes the interval range of type t
as integers
wrap_expr e (l,h)
expression needed to bring back e
in range (l
,h
)
is_c_int_type t
tests whether t
is a floating point type
Get the float precision from a C type
val mk_c_member_access :
Mopsa.expr ->
c_record_field ->
Mopsa_utils.Location.range ->
Mopsa.expr
val mk_c_arrow_access :
Mopsa.expr ->
c_record_field ->
Mopsa_utils.Location.range ->
Mopsa.expr
val mk_c_member_access_by_name :
Mopsa.expr ->
string ->
Mopsa_utils.Location.range ->
Mopsa.expr
val mk_c_arrow_access_by_name :
Mopsa.expr ->
string ->
Mopsa_utils.Location.range ->
Mopsa.expr
val mk_c_subscript_access :
Mopsa.expr ->
Mopsa.expr ->
Mopsa_utils.Location.range ->
Mopsa.expr
val mk_c_multibyte_integer :
string ->
int ->
Mopsa.typ ->
'a Mopsa.Flow.flow ->
Mopsa_utils.Location.range ->
Mopsa.expr
val mk_c_string :
?kind:c_character_kind ->
string ->
Mopsa_utils.Location.range ->
Mopsa.expr
val mk_c_builtin_call :
string ->
Mopsa.expr list ->
Ast.Typ.typ ->
Mopsa_utils.Location.range ->
Mopsa.expr
val mk_c_declaration :
Mopsa.var ->
c_var_init option ->
c_var_scope ->
Mopsa_utils.Location.range ->
Mopsa.stmt
Statement comparison *
Simplify C constant expressions to constants
Check if v is declared as a variable length array
Check if v is declared as an array without length (as for many auxiliary variables)
Find the definition of a C function
val assert_valid_string :
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Post.post
Check if a pointer points to a nul-terminated array
val assert_valid_wide_string :
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Post.post
Check if a pointer points to a nul-terminated wide char array
val assert_valid_stream :
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Post.post
Check if a pointer points to a valid stream
val assert_valid_file_descriptor :
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Post.post
Check if a pointer points to a valid file descriptor
val assert_valid_ptr :
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Post.post
Check if a pointer is valid
val memrand :
Mopsa.expr ->
Mopsa.expr ->
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Post.post
Randomize an entire array
val strrand :
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Post.post
Randomize a string
val strnrand :
Mopsa.expr ->
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Post.post
Randomize a substring
val wcsnrand :
Mopsa.expr ->
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Post.post
Randomize a wide substring
val memset :
Mopsa.expr ->
Mopsa.expr ->
Mopsa.expr ->
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Post.post
Set elements of an array with the same value c
val memcpy :
Mopsa.expr ->
Mopsa.expr ->
Mopsa.expr ->
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Post.post
Copy elements of an array
val error_error :
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Post.post
Exit if status is non-zero
val error_error_at_line :
Mopsa.expr ->
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Post.post
Exit if status is non-zero
val asprintf_stub :
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Eval.eval
val vasprintf_stub :
bool ->
Mopsa.expr ->
Mopsa.expr ->
Mopsa_utils.Location.range ->
('a, 'b) Mopsa.man ->
'a Mopsa.Flow.flow ->
'a Core.Eval.eval
Stack variables
This vkind is used to attach the callstack to local variables
Create a stack variable