package frama-clang

  1. Overview
  2. Docs

Managing conversion environment

type env
val empty_env : env
val add_c_global : env -> Frama_c_kernel.Cabs.definition -> env

add a global c definition to the list of translated items. The ghost status of the definition is given by the env itself (see Convert_env.is_ghost)

val get_c_globals : env -> (bool * Frama_c_kernel.Cabs.definition) list

get the list of translated global definitions, in the order in which they were added.

val fatal : env -> ('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 -> 'a
val temp_name : env -> string -> string

temp_name env prefix returns a fresh name based on prefix.

val add_namespace : env -> Intermediate_format.qualification -> env

enter a new, inner namespace

val set_namespace : env -> Intermediate_format.qualified_name -> env

Sets the namespace to the one enclosing the corresponding symbol

val set_namespace_from_class : env -> (Intermediate_format.qualified_name * Intermediate_format.tkind) -> env

given the fully qualified name of a class, set the namespace to the inner of it

val get_namespace : env -> Intermediate_format.qualification list

give the names of the nammespaces currently opened. Newest is last.

val reset_namespace : env -> env

close the most recently opened namespace.

val class_type_from_qualifications : env -> Intermediate_format.qualification list -> Intermediate_format.typ
val add_local_var : env -> string -> Intermediate_format.typ -> env
val add_formal_parameters : env -> Intermediate_format.arg_decl list -> env

add_global_var env name is_extern_c typ

val get_local_var : env -> string -> Intermediate_format.typ
  • raises AbortFatal

    if not found

val unscope : env -> env -> env

unscope current old returns the same environment as current except for local vars, that are reset to the ones of old.

returns the type and whether the variable is an extern C one or not.

  • raises AbortFatal

    if not found

val get_clang_loc : env -> Intermediate_format.location
val set_extern_c : env -> bool -> env
val is_extern_c : env -> bool
val set_ghost : env -> bool -> env
val is_ghost : env -> bool
val qualify : env -> string -> Intermediate_format.qualified_name
val set_current_func_name : env -> Intermediate_format.qualified_name -> env

set the current function name. Might also change the namespace if the function is fully qualified.

val get_current_func_name : env -> string
val set_current_return_type : env -> Intermediate_format.typ -> env
val get_current_return_type : env -> Intermediate_format.typ
val reset_func : env -> env

also reset the namespace if needed

val get_current_class : env -> Fclang_datatype.Qualified_name.t option
val set_current_class : env -> Fclang_datatype.Qualified_name.t -> env

also performs a set_namespace_from_class

val reset_current_class : env -> env

also reset the namespace

  • raises AbortFatal

    if not found

val has_typedef : env -> Intermediate_format.qualified_name -> bool
val memo_wchar : env -> env

adds a definition of wchar_t if not already present. Used when encountering wchar_t on the C++ side.

indicates that the given struct has some virtual member functions.

changes only the template parameters in the qualification. This function should be used for mangling.

val struct_has_virtual : env -> (Intermediate_format.qualified_name * Intermediate_format.tkind) -> bool

adds the given constructor as the default constructor for the appropriate class. Does nothing if such a constructor already exists.

val add_default_constructor_base : env -> Intermediate_format.qualified_name -> Intermediate_format.signature -> env

adds the given constructor as the default constructor for the appropriate class when used as a base class of a parent. Does nothing if such a constructor already exists. The distinction is only meaningful for classes that have virtual bases.

given a class name, returns the name and signature of its default constructor if it exists.

  • raises AbortFatal

    if no default constructor has been set for this class.

given a class name, returns the name and signature of its default constructor if it exists or None if no default constructor has been set for this class.

given a class name, returns the name and signature of its default constructor when used as a base class of a parent, if it exists, or None if no default constructor has been set for this class.

add a copy constructor for the class when it is used as a base class called from a parent. Only useful when the current class has virtual base classes.

gets the copy constructor for the given class when used as a base class of a parent. Only used if the current class has virtual base classes.

val add_destructor : env -> Intermediate_format.qualification list -> env
val add_destructor_base : env -> Intermediate_format.qualification list -> env
val has_destructor_base : env -> (Intermediate_format.qualified_name * Intermediate_format.tkind) -> bool

adds an aggregate type of the given kind. The boolean flag indicates whether the aggregate is an extern C type.

  • raises AbortFatal

    if not found

val is_extern_c_aggregate : env -> Intermediate_format.qualified_name -> Intermediate_format.tkind -> bool

@ raise AbortFatal if not found.

returns the corresponding C++ typ, namely Struct name t or Union name t. name must be an aggregate

  • raises AbortFatal

    if not found

val current_struct_or_union : env -> Intermediate_format.ckind
val is_anonymous : env -> bool

whether current class/union is anonymous

returns the name of the class bound to the given typ, which can be either a class or a typedef.

get_class_name_from_pointer env ty returns the name of the class ty points to, unrolling typedefs if needed.

get_class_name_from_reference env ty returns the name of the class ty is bound to, either directly (returned boolean flag is false or through a reference (returned flag is true). Typedefs are unrolled as needed.

get the name of the given aggregate (or pointer/ref to aggregate) type unfold typedef if needed.

get the signature of the given functional type.

get the name of the aggregate type of the given object.

gets the dynamic type of the given expression.

val closure_var_kind : env -> string -> bool option

Some is_ref if the given string (that may be "this") is a captured identifier, where is_ref is true iff the capture is done by reference. None otherwise.

val reset_closure : env -> env

remove information about captured identifiers.

val add_closure_info : env -> Intermediate_format.capture list -> env

Associates the given identifiers to the appropriate closure kind.

val env_map : (env -> 'a -> env * 'b) -> env -> 'a list -> env * 'b list

iterates a function that might change the environment over a list, and returns the final environment together with the list of results

val env_opt : (env -> 'a -> env * 'b) -> env -> 'a option -> env * 'b option

env_opt f env opt applies f if opt has a value, and None, without changing the environment otherwise.

OCaml

Innovation. Community. Security.