首页 > 解决方案 > 如何将取消引用的指针与 CIL 模块完全匹配?

问题描述

我正在使用 https://people.eecs.berkeley.edu/~necula/cil/api/Cil.html

并想匹配指针并在某个表达式中提取变量名

示例(假设这是正确的)

int **p0,*p1,**p2,***p3;

我的表达:**p0 + *p1 + **p2 + **p3

我想匹配整个取消引用的指针,如:**p0, **p2, **p3而不是部分匹配:(*p0, *p2, *p3这就是我的代码所做的,因此它只会*p1根据需要匹配)

class lvalVisitor ctx = object (*f d as params*)
inherit nopCilVisitor
method vlval lval = 

  match lval with
  (*this will match only *pointer and not **pointer or ***pointer *)
  | Mem (Lval (Var v, _)), _ -> printf "derefed. var %s" v.vname
    SkipChildren

  | Mem e, _ ->  DoChildren

  | _ -> DoChildren
  end

TL;DR我想知道一个指针是否完全取消引用(计算它的星星不是一个好的选择)

标签: cocamlstatic-analysis

解决方案


我不熟悉 CIL Api,但是递归方法不能完成这项工作吗?

例如:

class lvalVisitor ctx = object (self)
  inherit nopCilVisitor
  method vlval lval =
  match lval with
  (*this will match only *pointer and not **pointer or ***pointer *)
  | Mem (Lval (Var v, _)), _ ->
     Format.printf "derefed. var %s" v.vname;
     SkipChildren

  | Mem (Lval e), _ -> self#vlval e 

  | _ -> DoChildren
  end;;

推荐阅读