From 831465faad83338af964c09fe89141b51c13c8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20B=C3=BChler?= <david.buhler@cea.fr> Date: Mon, 24 Jan 2022 13:46:13 +0100 Subject: [PATCH] [kernel] Rmtmps: optimizes markReferenced visitor. --- src/kernel_internals/typing/rmtmps.ml | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/kernel_internals/typing/rmtmps.ml b/src/kernel_internals/typing/rmtmps.ml index 0bef4ca0188..83a59cde83f 100644 --- a/src/kernel_internals/typing/rmtmps.ml +++ b/src/kernel_internals/typing/rmtmps.ml @@ -581,7 +581,7 @@ let global_type_and_name = function | GText _ -> "<text>" | GAnnot _ -> "<annot>" -class markReferencedVisitor = object +class markReferencedVisitor = object (self) inherit nopCilVisitor val dkey = Kernel.dkey_referenced @@ -589,6 +589,13 @@ class markReferencedVisitor = object val inside_exp : exp Stack.t = Stack.create () val inside_typ : typ Stack.t = Stack.create () + method private reference varinfo loc = + if not (hasAttribute "FC_BUILTIN" varinfo.vattr) then begin + Kernel.debug ~dkey "referenced: var/fun %s@." varinfo.vname; + Kernel.debug ~source:(fst loc) ~dkey "referenced: fun %s" varinfo.vname; + varinfo.vreferenced <- true; + end + method! vglob = function | GType (typeinfo, loc) -> Kernel.debug ~source:(fst loc) ~dkey "referenced: type %s" typeinfo.tname; @@ -604,19 +611,14 @@ class markReferencedVisitor = object Kernel.debug ~source:(fst loc) ~dkey "referenced: enum %s" enuminfo.ename; enuminfo.ereferenced <- true; DoChildren - | GVar (varinfo, _, loc) - | GVarDecl (varinfo, loc) - | GFunDecl (_,varinfo, loc) - | GFun ({svar = varinfo}, loc) -> - if not (hasAttribute "FC_BUILTIN" varinfo.vattr) then begin - Kernel.debug ~dkey "referenced: var/fun %s@." varinfo.vname; - Kernel.debug ~source:(fst loc) ~dkey "referenced: fun %s" varinfo.vname; - varinfo.vreferenced <- true; - end; + | GVar (varinfo, _, loc) | GFun ({svar = varinfo}, loc) -> + self#reference varinfo loc; DoChildren - | GAnnot _ -> DoChildren - | _ -> + | GVarDecl (varinfo, loc) + | GFunDecl (_,varinfo, loc) -> + self#reference varinfo loc; SkipChildren + | _ -> SkipChildren method! vtype = function | TNamed (ti, _) -> @@ -661,6 +663,8 @@ class markReferencedVisitor = object end; SkipChildren + method! vspec _ = SkipChildren + method! vcode_annot _ = SkipChildren end let markReferenced ast = -- GitLab