Hi Vu,

On Wed, Jul 08, 2009 at 12:39:22AM -0600, ThanhVu (Vu) Nguyen wrote:
> Hi, can I find out what kind of statement  (e.g., a single statement,  a
> block of statements, etc) from a given Cil.stmtkind?

        To distinguish between the kinds of
statments (Instr, Return, Goto, etc.) you can
just use "match" with the appropriate value.
Here is one of my statement visitors:

  method vstmt (a_statement: Cil.stmt): Cil.stmt Cil.visitAction =
    begin
      match a_statement.Cil.skind with
          Cil.Instr _instruction_list -> ()
        | Cil.Return (optional_expression, location) ->
            begin
              match optional_expression with
                  Some expression ->
                    Trace.trace trace_identifier
                      (Pretty.dprintf "+ vstmt: expression = %a\n" Cil.dn_exp 
expression);
                    self#traverse expression location
                | None -> ()
            end
        | Cil.Goto (_statement_ref, _location) -> ()
        | Cil.Break _location -> ()
        | Cil.Continue _location -> ()
        | Cil.If (expression, _if_block, _else_block, location) ->
            Trace.trace trace_identifier
              (Pretty.dprintf "+ vstmt: expression = %a\n" Cil.dn_exp 
expression);
            self#traverse expression location
        | Cil.Switch (expression, _block, _statement_list, location) ->
            Trace.trace trace_identifier
              (Pretty.dprintf "+ vstmt: expression = %a\n" Cil.dn_exp 
expression);
            self#traverse expression location
        | Cil.Loop (_block, _location, _opt_statement1, _opt_statement2) -> ()
        | Cil.Block _block -> ()
        | Cil.TryFinally (_block1, _block2, _location) -> ()
        | Cil.TryExcept (_block1, _, _block2, _location) -> ()
    end;
    Cil.DoChildren


> For example if my Cil.stmtkind c has the content {a single
> statement} vs c has the content {a; block; of; many; statements;}?

        A "match" on a Cil.stmtkind (as shown
above) dissects all statement kinds so that you
can take care of them.  For the case of
Cil.Blocks you could look at the length of the
statement list inside of it, like, e.g.,
    List.length a_block.Cil.bstmts


HTH,
        Chris

--
Dr. Christoph L. Spiel

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users

Reply via email to