@Override public PType defaultPStateDesignator(PStateDesignator node, TypeCheckInfo question) throws AnalysisException { return node.apply(tcOthers, question); }
public MapApplyObligation(PStateDesignator root, PExp arg, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { super(root, POType.MAP_APPLY, ctxt, root.getLocation(), af); AMapDomainUnaryExp dom_exp = new AMapDomainUnaryExp(); dom_exp.setExp(root.clone().apply(new StateDesignatorToExpVisitor())); // We don't care about type of the exp. This is just for the CGP to not crash. dom_exp.setType(new AUnknownType()); AInSetBinaryExp inSetExp = AstExpressionFactory.newAInSetBinaryExp(arg.clone(), dom_exp); stitch = inSetExp; valuetree.setPredicate(ctxt.getPredWithContext(inSetExp)); } }
/** * Sets the {@code _mapseq} child of this {@link AMapSeqStateDesignator} node. * @param value the new {@code _mapseq} child of this {@link AMapSeqStateDesignator} node */ public void setMapseq(PStateDesignator value) { if (this._mapseq != null) { this._mapseq.parent(null); } if (value != null) { if (value.parent() != null) { value.parent().removeChild(value); } value.parent(this); } this._mapseq = value; }
public SeqApplyObligation(PStateDesignator root, PExp arg, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { super(root, POType.SEQ_APPLY, ctxt, root.getLocation(), af); // arg >0 AIntLiteralExp zeroExp = new AIntLiteralExp(); zeroExp.setValue(new LexIntegerToken(0, null)); AGreaterNumericBinaryExp grExp = AstExpressionFactory.newAGreaterNumericBinaryExp(arg.clone(), zeroExp); // len(root) ALenUnaryExp lenExp = new ALenUnaryExp(); PExp stateExp = root.apply(new StateDesignatorToExpVisitor()); lenExp.setExp(stateExp.clone()); // len(root)+1 AIntLiteralExp oneExp = new AIntLiteralExp(); oneExp.setValue(new LexIntegerToken(1, null)); APlusNumericBinaryExp plusExp = AstExpressionFactory.newAPlusNumericBinaryExp(lenExp, oneExp); // arg <= len(root) +1 ALessEqualNumericBinaryExp lteExp = AstExpressionFactory.newALessEqualNumericBinaryExp(arg.clone(), plusExp); // arg > 0 and arg <= len(root)+1 AAndBooleanBinaryExp andExp = AstExpressionFactory.newAAndBooleanBinaryExp(grExp, lteExp); stitch = andExp; valuetree.setPredicate(ctxt.getPredWithContext(stitch)); } }
@Override public ILexLocation defaultPStateDesignator(PStateDesignator node) throws AnalysisException { return node.getLocation(); }
@Override public PType caseAAssignmentStm(AAssignmentStm node, TypeCheckInfo question) throws AnalysisException { node.setTargetType(node.getTarget().apply(THIS, new TypeCheckInfo(question.assistantFactory, question.env))); node.setExpType(node.getExp().apply(THIS, new TypeCheckInfo(question.assistantFactory, question.env, question.scope, null, node.getTargetType(), null))); if (!question.assistantFactory.getTypeComparator().compatible(node.getTargetType(), node.getExpType())) { TypeCheckerErrors.report(3239, "Incompatible types in assignment", node.getLocation(), node); TypeCheckerErrors.detail2("Target", node.getTarget().getType(), "Expression", node.getExp().getType()); } node.setClassDefinition(question.env.findClassDefinition()); node.setStateDefinition(question.env.findStateDefinition()); AClassTypeAssistantTC assist = question.assistantFactory.createAClassTypeAssistant(); node.setInConstructor(assist.inConstructor(question.env)); if (node.getInConstructor()) { // Mark assignment target as initialized (so no warnings) PDefinition state; state = targetDefinition(node.getTarget(), question); if (state instanceof AInstanceVariableDefinition) { AInstanceVariableDefinition iv = (AInstanceVariableDefinition) state; iv.setInitialized(true); } } node.setType(AstFactory.newAVoidType(node.getLocation())); return node.getType(); }
private static void initStateDesignator(PStateDesignator result, ILexLocation location) { result.setLocation(location); }
PType type = node.getObject().apply(THIS, question); PTypeSet result = new PTypeSet(question.assistantFactory); boolean unique = !question.assistantFactory.createPTypeAssistant().isUnion(type); String cname = ctype.getName().getName(); node.setObjectfield(new LexNameToken(cname, field.getName(), node.getObject().getLocation())); PDefinition fdef = question.assistantFactory.createPDefinitionAssistant().findName(ctype.getClassdef(), node.getObjectfield(), NameScope.STATE);
public static void beforeAssignmentSet(AAssignmentStm assignStmt, Value oldval, Value newval) { if (checker != null && checker.reuiresCheck(assignStmt.getTarget())) { synchronized (values) { values.add(assignStmt.getTarget().getLocation()); } } }
@Override public String caseAMapSeqStateDesignator(AMapSeqStateDesignator node) throws AnalysisException { return node.getMapseq().apply(this) + node.getExp().toString(); }
public static AMapSeqStateDesignator newAMapSeqStateDesignator( PStateDesignator mapseq, PExp exp) { AMapSeqStateDesignator result = new AMapSeqStateDesignator(); initStateDesignator(result, mapseq.getLocation()); result.setMapseq(mapseq); result.setExp(exp); return result; }
/** * Sets the {@code _target} child of this {@link AAssignmentStm} node. * @param value the new {@code _target} child of this {@link AAssignmentStm} node */ public void setTarget(PStateDesignator value) { if (this._target != null) { this._target.parent(null); } if (value != null) { if (value.parent() != null) { value.parent().removeChild(value); } value.parent(this); } this._target = value; }
@Override public PExp caseAMapSeqStateDesignator(AMapSeqStateDesignator node) throws AnalysisException { AApplyExp applyExp = new AApplyExp(); applyExp.setRoot(node.getMapseq().apply(this).clone()); List<PExp> args = new LinkedList<PExp>(); args.add(node.getExp().clone()); applyExp.setArgs(args); return applyExp; }
public static AFieldStateDesignator newAFieldStateDesignator( PStateDesignator object, ILexIdentifierToken field) { AFieldStateDesignator result = new AFieldStateDesignator(); initStateDesignator(result, object.getLocation()); result.setObject(object); result.setField(field); return result; }
/** * Sets the {@code _object} child of this {@link AFieldStateDesignator} node. * @param value the new {@code _object} child of this {@link AFieldStateDesignator} node */ public void setObject(PStateDesignator value) { if (this._object != null) { this._object.parent(null); } if (value != null) { if (value.parent() != null) { value.parent().removeChild(value); } value.parent(this); } this._object = value; }
@Override public SStmIR caseAAssignmentStm(AAssignmentStm node, IRInfo question) throws AnalysisException { PStateDesignator target = node.getTarget(); PExp exp = node.getExp(); SStateDesignatorIR targetCg = target.apply(question.getStateDesignatorVisitor(), question); SExpIR expCg = exp.apply(question.getExpVisitor(), question); AAssignmentStmIR assignment = new AAssignmentStmIR(); assignment.setTarget(targetCg); assignment.setExp(expCg); return assignment; }
public StateInvariantObligation(AAtomicStm atom, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { super(atom, POType.STATE_INV, ctxt, atom.getLocation(), af); assistantFactory = af; PExp invApplyExp = makeInvApplyExp(atom); PExp invApplyExpForSub = invApplyExp.clone(); List<Substitution> subs = new LinkedList<Substitution>(); for (AAssignmentStm asgn : atom.getAssignments()) { String hash = asgn.getTarget().apply(af.getStateDesignatorNameGetter()); subs.add(new Substitution(hash, asgn.getExp().clone())); } IVariableSubVisitor varSubVisitor = af.getVarSubVisitor(); for (Substitution sub : subs) { invApplyExpForSub = invApplyExpForSub.apply(varSubVisitor, sub); } stitch = AstExpressionFactory.newAImpliesBooleanBinaryExp(invApplyExp, invApplyExpForSub); valuetree.setPredicate(stitch); }
public AssignmentContext(AAssignmentStm node, IPogAssistantFactory af, IPOContextStack ctxt) throws AnalysisException { super(ctxt); String hash = node.getTarget().apply(af.getStateDesignatorNameGetter()); t = null; for (ILexNameToken n : last_vars.keySet()) { if (n.getName().equals(hash)) { t = last_vars.get(n).getName().clone(); break; } } if (t == null) { t = new LexNameToken("", hash, null); } subLast = new Substitution(new LexNameToken("", hash, null), node.getExp().clone()); sub = new Substitution(t, node.getExp().clone()); this.visitor = af.getVarSubVisitor(); }
/** * Called by the {@link AMapSeqStateDesignator} node from {@link AMapSeqStateDesignator#apply(IPOFAnalysis)}. * @param node the calling {@link AMapSeqStateDesignator} node */ public void caseAMapSeqStateDesignator(AMapSeqStateDesignator node) throws AnalysisException { _visitedNodes.add(node); inAMapSeqStateDesignator(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } if(node.getMapseq() != null && !_visitedNodes.contains(node.getMapseq())) { node.getMapseq().apply(this); } if(node.getExp() != null && !_visitedNodes.contains(node.getExp())) { node.getExp().apply(this); } if(node.getMapType() != null && !_visitedNodes.contains(node.getMapType())) { node.getMapType().apply(this); } if(node.getSeqType() != null && !_visitedNodes.contains(node.getSeqType())) { node.getSeqType().apply(this); } outAMapSeqStateDesignator(node); }