Method: TraceVariableList(Context, List)

1: /*******************************************************************************
2: *
3: *        Copyright (c) 2009 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.interpreter.traces;
25:
26: import java.util.List;
27: import java.util.Vector;
28:
29: import org.overture.ast.definitions.PDefinition;
30: import org.overture.ast.intf.lex.ILexNameToken;
31: import org.overture.ast.typechecker.NameScope;
32: import org.overture.interpreter.runtime.Context;
33: import org.overture.interpreter.values.ObjectValue;
34: import org.overture.interpreter.values.Value;
35: import org.overture.typechecker.Environment;
36: import org.overture.typechecker.FlatEnvironment;
37:
38: public class TraceVariableList extends Vector<TraceVariable>
39: {
40:         private static final long serialVersionUID = 1L;
41:
42:         public TraceVariableList()
43:         {
44:                 super();
45:         }
46:
47:         public TraceVariableList(Context ctxt, List<PDefinition> localDefs)
48:         {
49:                 Environment local = new FlatEnvironment(ctxt.assistantFactory, localDefs);
50:
51:•                for (ILexNameToken key : ctxt.keySet())
52:                 {
53:                         Value value = ctxt.get(key);
54:                         PDefinition d = local.findName(key, NameScope.NAMES);
55:                         boolean clone = false;
56:
57:•                        if (value.isType(ObjectValue.class))
58:                         {
59:                                 ObjectValue obj = (ObjectValue) value.deref();
60:                                 ObjectValue self = ctxt.getSelf();
61:
62:                                 // We have to clone new objects that were created within the trace,
63:                                 // while using other (local instance variable) objects unchanged.
64:•                                clone = self != null
65:                                                 && obj.objectReference > self.objectReference;
66:                         }
67:
68:                         add(new TraceVariable(key.getLocation(), key, value, d.getType(), clone));
69:                 }
70:         }
71:
72:         public CallSequence getVariables()
73:         {
74:                 CallSequence seq = new CallSequence();
75:
76:                 for (TraceVariable var : this)
77:                 {
78:                         seq.add(new TraceVariableStatement(var));
79:                 }
80:
81:                 return seq;
82:         }
83: }