Download the Plugin Development Guide - Frama-C

Transcript
CHAPTER 4. ADVANCED PLUG-IN DEVELOPMENT
Type
Index
varinfo
compinfo
enuminfo
typeinfo
stmt
logic_info
logic_var
fieldinfo
vid
ckey
ename
tname
sid
l_var_info.lv_id
lv_id
fname and fcomp.ckey
Figure 4.5: Indices of AST nodes.
SkipChildren
Last, when using a copy visitor, the actions (see previous section)
ChangeTo
must be used with care, i.e.
and
one has to ensure that the children are fresh.
Otherwise, the new AST will share some nodes with the old one.
Even worse, in such
a situation the new AST might very well be left in an inconsistent state, with uses of
shared node (e.g. a
varinfo
for a function
in a function call) which do not match the
f).
JustCopy instead
ChangeDoChildrenPost(x,fun x -> x) instead of ChangeTo(x).
corresponding declaration (e.g the
When in doubt,
GFun
f
denition of
a safe solution is to use
of
SkipChildren
and
4.16.6 Dierences Between the Cil and Frama-C Visitors
As said in Section 4.16.2,
vglob_aux
instead.
vstmt
and
vglob
should not be redened.
vstmt_aux
and
Be aware that the entries corresponding to statements and globals in
Frama-C tables are considered more or less as children of the node.
method returns
Use
ChangeTo
In particular, if the
action (see Section 4.16.3), it is assumed that it has taken care
file from a
SkipChildren
of updating the tables accordingly, which can be a little tricky when copying a
project to another one. Prefer
ChangeDoChildrenPost.
On the other hand, a
action implies that the visit will stop, but the information associated to the old value will be
associated to the new one. If the children are to be visited, it is undened whether the table
entries are visited before or after the children in the AST.
4.16.7 Example
Here is a small copy visitor that adds an assertion for each division in the program, stating
that the divisor is not zero:
open C i l _ t y p e s
open C i l
module M = P l u g i n . R e g i s t e r
( * Each annotation
We c r e a t e
annotations ,
line
i n Frama−C has an emitter ,
thus our own,
and that
and says
these
that
it
for
will
traceability .
only be used to emit code
annotations do not depend on Frama−C' s command
parameters .
*)
l e t syntax_alarm =
Emitter . c r e a t e
" Syntactic check " [ Emitter .Code_annot ]
84
∼correctness
:[]
∼ t u n i n g :[]