Module Kernel_function


module Kernel_function: sig .. end
Operations on kernel function.
Consult the Plugin Development Guide for additional details.


Kernel functions are comparable and hashable


include Datatype.S_with_collections
val id : t -> int
val self : State.t

Searching


exception No_Statement
val find_first_stmt : t -> Cil_types.stmt
Find the first statement in a kernel function.
Raises No_Statement if there is no first statement for the given function.
val find_return : t -> Cil_types.stmt
Find the return statement of a kernel function.
Raises No_Statement is there is no return statement for the given function.
Change in Nitrogen-20111001: may raise No_Statement
val find_label : t -> string -> Cil_types.stmt Pervasives.ref
Find a given label in a kernel function.
Raises Not_found if the label does not exist in the given function.
val clear_sid_info : unit -> unit
removes any information related to statements in kernel functions. ( the table used by the function below).
val find_from_sid : int -> Cil_types.stmt * t
Raises Not_found if there is no statement with such an identifier.
Returns the stmt and its kernel function from its identifier. Complexity: the first call to this function is linear in the size of the cil file.
Consult the Plugin Development Guide for additional details.
val find_englobing_kf : Cil_types.stmt -> t
Returns the function to which the statement belongs. Same complexity as find_from_sid
val find_enclosing_block : Cil_types.stmt -> Cil_types.block
Returns the innermost block to which the given statement belongs.
val find_all_enclosing_blocks : Cil_types.stmt -> Cil_types.block list
same as above, but returns all enclosing blocks, starting with the innermost one.
val blocks_closed_by_edge : Cil_types.stmt -> Cil_types.stmt -> Cil_types.block list
blocks_closed_by_edge s1 s2 returns the (possibly empty) list of blocks that are closed when going from s1 to s2.
Since Carbon-20101201
Raises Invalid_argument if the statements do not belong to the same function or s2 is not a successor of s1 in the cfg.
val find_syntactic_callsites : t -> (t * Cil_types.stmt) list
callsites f collect the statements where f is called. Same complexity as find_from_sid.
Since Carbon-20110201
Returns a list of f',s where function f' calls f at statement stmt.

Checkers


val is_definition : t -> bool
val returns_void : t -> bool

Getters


val dummy : unit -> t
val get_vi : t -> Cil_types.varinfo
val get_id : t -> int
val get_name : t -> string
val get_type : t -> Cil_types.typ
val get_return_type : t -> Cil_types.typ
val get_location : t -> Cil_types.location
val get_global : t -> Cil_types.global
val get_formals : t -> Cil_types.varinfo list
val get_locals : t -> Cil_types.varinfo list
exception No_Definition
val get_definition : t -> Cil_types.fundec
Raises No_Definition if the given function is not a definition.

Membership of variables


val is_formal : Cil_types.varinfo -> t -> bool
Returns true if the given varinfo is a formal parameter of the given function. If possible, use this function instead of Ast_info.Function.is_formal.
val get_formal_position : Cil_types.varinfo -> t -> int
get_formal_position v kf is the position of v as parameter of kf.
Raises Not_found if v is not a formal of kf.
val is_local : Cil_types.varinfo -> t -> bool
Returns true if the given varinfo is a local variable of the given function. If possible, use this function instead of Ast_info.Function.is_local.
val is_formal_or_local : Cil_types.varinfo -> t -> bool
Returns true if the given varinfo is a formal parameter or a local variable of the given function. If possible, use this function instead of Ast_info.Function.is_formal_or_local.

Specifications


val get_spec : ?populate:bool -> t -> Cil_types.funspec
get_spec f returns the spec of the function. You should use it instead of f.spec. If populate is set to false (default is true), then you get the spec without the default behavior generated when expected by the Frama-C kernel (assuming that this behavior was not already generated).
val set_spec : t -> (Cil_types.funspec -> Cil_types.funspec) -> unit
set_spec kf how_to_modify replaces the old spec s of kf by f s. The function s is allowed to modify s in place and to return s at the end. You must call this function to modify a spec and you must not modify directly the 'spec' field of the record yourself.
Since Nitrogen-20111001
val postcondition : t -> Cil_types.termination_kind -> Cil_types.predicate Cil_types.named
Change in Boron-20100401: added argument to select desired termination kind
val precondition : t -> Cil_types.predicate Cil_types.named
val code_annotations : t -> (Cil_types.stmt * Cil_types.rooted_code_annotation) list
val internal_function_behaviors : t -> string list
Returns the list of behavior names that are defined in statement contracts within the function.
val spec_function_behaviors : t -> string list
Returns the list of behavior names defined in the spec of the function.
val all_function_behaviors : t -> string list
Returns the list of all behavior names defined in the function (either in the spec or in statement contracts)
val fresh_behavior_name : t -> string -> string
Returns a behavior name based on the 2nd argument which is guaranteed not to clash with an existing behavior.
val populate_spec : (t -> unit) Pervasives.ref
Should not be used by casual users.

Collections


module Make_Table: 
functor (Data : Datatype.S) ->
functor (Info : State_builder.Info_with_size) -> State_builder.Hashtbl with type key = t and type data = Data.t
Hashtable indexed by kernel functions and dealing with project.
module Hptset: Hptset.S  with type elt = t
Set of kernel functions.

Setters

Use carefully the following functions.

val register_stmt : t -> Cil_types.stmt -> Cil_types.block list -> unit
Register a new statement in a kernel function, with the list of blocks that contain the statement (innermost first).

Pretty printer


val pretty_name : Format.formatter -> t -> unit
Deprecated.since Nitrogen-20111001 Use pretty instead.
Print the name of a kernel function.