From c4d4f4f0cd19f1780f515a8ef330925684ad35a2 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Wed, 15 Jan 2014 11:55:57 -0500 Subject: [PATCH] debugger: Added method to clean the object model when injecting code at runtime. Signed-off-by: Lucas Bajolet --- src/debugger.nit | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/debugger.nit b/src/debugger.nit index 17fe06b..eea8820 100644 --- a/src/debugger.nit +++ b/src/debugger.nit @@ -24,6 +24,45 @@ intrude import local_var_init intrude import scope intrude import toolcontext +redef class Model + # Cleans the model to remove a module and what it defines when semantic analysis fails on injected code + private fun try_remove_module(m: MModule): Bool + do + var index = -1 + for i in [0 .. mmodules.length[ do + if mmodules[i] == m then + index = i + break + end + end + if index == -1 then return false + var mmodule = mmodules[index] + mmodules.remove_at(index) + for classdef in mmodule.mclassdefs do + var mclass = classdef.mclass + for i in [0 .. mclass.mclassdefs.length[ do + if mclass.mclassdefs[i] == classdef then + index = i + break + end + end + mclass.mclassdefs.remove_at(index) + var propdefs = classdef.mpropdefs + for propdef in propdefs do + var prop = propdef.mproperty + for i in [0..prop.mpropdefs.length[ do + if prop.mpropdefs[i] == propdef then + index = i + break + end + end + prop.mpropdefs.remove_at(index) + end + end + return true + end +end + redef class ScopeVisitor redef init(toolcontext) -- 1.7.9.5