123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596(* Yoann Padioleau
*
* Copyright (C) 2014 Facebook
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation, with the
* special exception on linking described in file license.txt.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
* license.txt for more details.
*)openAst_c(*****************************************************************************)(* Prelude *)(*****************************************************************************)(*
* Normalized expressions (converted into instructions and lvalues/rvalues).
*
* Ast_cpp -> Ast_c -> Ast_cil ...
*
* We are doing flow-insensitive analysis so the goal here is just
* to convert Ast_c.expr into something that is easier to work-on
* to generate datalog facts.
*
* related work:
* - CIL :)
* - SIL
*
* See also pfff/mini/ast_minic.ml
*)(*****************************************************************************)(* CIL-expr types *)(*****************************************************************************)(* ------------------------------------------------------------------------- *)(* Names *)(* ------------------------------------------------------------------------- *)(* for functions, constants, fields, builtins, types *)typename=stringwrap(* for globals, locals, parameters *)typevar=name(* ------------------------------------------------------------------------- *)(* Lvalue *)(* ------------------------------------------------------------------------- *)(* Used to be inlined in expr (now called rvalue), but it is cleaner
* to separate rvalue and lvalue. Note that 'Call' is not there, it's
* not an lvalue (you can not do 'foo() = x' in C).
*)typelvalue=|Idofname(* actually a var or name *)|ObjFieldofvar*name(* x->fld *)|ArrayAccessofvar*var(* x[y] *)(* hmm mv? *)|DeRefofvar(* *x *)(* with tarzan *)(* ------------------------------------------------------------------------- *)(* Rvalue *)(* ------------------------------------------------------------------------- *)(* see ast_minic.ml for more comments about this CIL-like AST *)typervalue=|Intofstringwrap|Floatofstringwrap|Stringofstringwrap(* string or char *)|StaticCallofname*varlist(* foo(...) *)|DynamicCallof(*Deref*)var*varlist(* ( *f)(...) *)|BuiltinCallofname*varlist(* e.g. v + 1 *)(* could be a lvalue, but weird to do (malloc(...)[x] = ...) *)|Allocoftype_(* malloc(sizeof(type)) *)|AllocArrayofvar*type_(* malloc(n*sizeof(type)) *)|Lvoflvalue(* with tarzan *)(* ------------------------------------------------------------------------- *)(* Stmt *)(* ------------------------------------------------------------------------- *)typeinstr=|Assignofvar(* or name *)*rvalue(* x = e *)|AssignAddressofvar*lvalue(* except Deref (no sense to do &*x) *)|AssignLvalueoflvalue*var(* Except Id, done by Assign *)(* with tarzan *)