Method: AssignmentContext(AAssignmentStm, IPogAssistantFactory, IPOContextStack)

1: package org.overture.pog.contexts;
2:
3: import org.overture.ast.analysis.AnalysisException;
4: import org.overture.ast.definitions.AInstanceVariableDefinition;
5: import org.overture.ast.expressions.PExp;
6: import org.overture.ast.intf.lex.ILexNameToken;
7: import org.overture.ast.lex.LexNameToken;
8: import org.overture.ast.statements.AAssignmentStm;
9: import org.overture.pog.pub.IPOContextStack;
10: import org.overture.pog.pub.IPogAssistantFactory;
11: import org.overture.pog.utility.Substitution;
12: import org.overture.pog.visitors.IVariableSubVisitor;
13:
14: public class AssignmentContext extends StatefulContext
15: {
16:         Substitution subLast;
17:         Substitution sub;
18:         PExp newVal_exp;
19:         ILexNameToken t;
20:         IVariableSubVisitor visitor;
21:
22:         public AssignmentContext(AAssignmentStm node, IPogAssistantFactory af,
23:                         IPOContextStack ctxt) throws AnalysisException
24:         {
25:                 super(ctxt);
26:                 String hash = node.getTarget().apply(af.getStateDesignatorNameGetter());
27:
28:                 t = null;
29:
30:•                for (ILexNameToken n : last_vars.keySet())
31:                 {
32:•                        if (n.getName().equals(hash))
33:                         {
34:                                 t = last_vars.get(n).getName().clone();
35:                                 break;
36:                         }
37:                 }
38:•                if (t == null)
39:                 {
40:                         t = new LexNameToken("", hash, null);
41:                 }
42:                 subLast = new Substitution(new LexNameToken("", hash, null), node.getExp().clone());
43:                 sub = new Substitution(t, node.getExp().clone());
44:
45:                 this.visitor = af.getVarSubVisitor();
46:         }
47:
48:         public AssignmentContext(AInstanceVariableDefinition node,
49:                         IVariableSubVisitor visitor, IPOContextStack ctxt)
50:         {
51:                 super(ctxt);
52:                 sub = new Substitution(node.getName(), node.getExpression());
53:                 subLast = sub;
54:                 this.visitor = visitor;
55:         }
56:
57:         @Override
58:         public String getContext()
59:         {
60:                 return null;
61:         }
62:
63:         @Override
64:         public PExp getContextNode(PExp stitch)
65:         {
66:
67:                 PExp r = null;
68:                 try
69:                 {
70:                         if (first)
71:                         {
72:                                 r = stitch.apply(visitor, subLast);
73:                                 first = false;
74:                         } else
75:                         {
76:                                 r = stitch.apply(visitor, sub);
77:                         }
78:                         return r;
79:                 } catch (AnalysisException e)
80:                 {
81:                         e.printStackTrace();
82:                         return null;
83:                 }
84:         }
85:
86:         @Override
87:         public String toString()
88:         {
89:                 return sub.toString();
90:         }
91:
92: }