public TypeCheckInfo newScope(NameScope newScope) { TypeCheckInfo info = new TypeCheckInfo(assistantFactory, env, newScope, qualifiers, constraint, returnType); return info; }
/** * Returns the value associated with key, and removes that binding from the context. * * @param <T> * @param key * @return value */ public <T> T contextRem(Class<T> key) { synchronized (TypeCheckInfo.class) { Stack<T> contextStack = lookupListForType(key); if (contextStack != null) { return contextStack.pop(); } } return null; }
@Override public PType caseAPreOpExp(APreOpExp node, TypeCheckInfo question) throws AnalysisException { node.setType(node.getExpression().apply(THIS, question.newConstraint(null))); return node.getType(); }
@Override public PType caseASetCompSetExp(ASetCompSetExp node, TypeCheckInfo question) throws AnalysisException { PDefinition def = AstFactory.newAMultiBindListDefinition(node.getFirst().getLocation(), node.getBindings()); def.apply(THIS, question.newConstraint(null)); Environment local = new FlatCheckedEnvironment(question.assistantFactory, def, question.env, question.scope); question = new TypeCheckInfo(question.assistantFactory, local, question.scope); PType etype = node.getFirst().apply(THIS, question.newConstraint(null)); PExp predicate = node.getPredicate(); if (predicate != null) { TypeCheckInfo pquestion = new TypeCheckInfo(question.assistantFactory, local, question.scope, null, AstFactory.newABooleanBasicType(node.getLocation()), null); if (!question.assistantFactory.createPTypeAssistant().isType(predicate.apply(THIS, pquestion), ABooleanBasicType.class)) { TypeCheckerErrors.report(3159, "Predicate is not boolean", predicate.getLocation(), predicate); } } local.unusedCheck(); SSetType setType = AstFactory.newASetSetType(node.getLocation(), etype); node.setType(setType); node.setSetType(setType); return setType; }
@Override public PType caseAMapCompMapExp(AMapCompMapExp node, TypeCheckInfo question) throws AnalysisException { PDefinition def = AstFactory.newAMultiBindListDefinition(node.getLocation(), node.getBindings()); def.apply(THIS, question.newConstraint(null)); Environment local = new FlatCheckedEnvironment(question.assistantFactory, def, question.env, question.scope); PExp predicate = node.getPredicate(); TypeCheckInfo pquestion = new TypeCheckInfo(question.assistantFactory, local, question.scope, null, AstFactory.newABooleanBasicType(node.getLocation()), null); if (predicate != null && !question.assistantFactory.createPTypeAssistant().isType(predicate.apply(THIS, pquestion), ABooleanBasicType.class)) { TypeCheckerErrors.report(3118, "Predicate is not boolean", predicate.getLocation(), predicate); } node.setType(node.getFirst().apply(THIS, question.newInfo(local))); local.unusedCheck(); return node.getType(); }
@Override public PType caseALambdaExp(ALambdaExp node, TypeCheckInfo question) throws AnalysisException question = question.newScope(NameScope.NAMES); // Lambdas are always functions def.apply(THIS, question.newConstraint(null)); Environment local = new FlatCheckedEnvironment(question.assistantFactory, def, question.env, question.scope); local.setFunctional(true); TypeCheckInfo newInfo = new TypeCheckInfo(question.assistantFactory, local, question.scope);
question.assistantFactory.createPPatternAssistant().typeResolve(c.getPattern(), rootVisitor, new TypeCheckInfo(question.assistantFactory, question.env)); PType ptype = ep.getExp().apply(rootVisitor, new TypeCheckInfo(question.assistantFactory, question.env, question.scope)); question.assistantFactory.createPPatternAssistant().typeResolve(c.getPattern(), rootVisitor, new TypeCheckInfo(question.assistantFactory, question.env)); c.getDefs().addAll(question.assistantFactory.createPPatternAssistant().getDefinitions(c.getPattern(), expType, NameScope.LOCAL)); } catch (TypeCheckException e) question.assistantFactory.createPDefinitionListAssistant().typeCheck(c.getDefs(), rootVisitor, new TypeCheckInfo(question.assistantFactory, question.env, question.scope)); question = question.newInfo(local); c.setType(c.getResult().apply(rootVisitor, question)); local.unusedCheck();
@Override public PType caseAClassInvariantDefinition(AClassInvariantDefinition node, TypeCheckInfo question) throws AnalysisException { Environment newEnv = new FlatEnvironment(question.assistantFactory, question.env, true); newEnv.setEnclosingDefinition(node); TypeCheckInfo functional = question.newInfo(newEnv); functional.qualifiers = null; functional.scope = NameScope.NAMESANDSTATE; PType type = node.getExpression().apply(THIS, functional); if (!question.assistantFactory.createPTypeAssistant().isType(type, ABooleanBasicType.class)) { TypeCheckerErrors.report(3013, "Class invariant is not a boolean expression", node.getLocation(), node); } node.setType(type); return node.getType(); }
public TypeCheckInfo newScope(List<PDefinition> definitions) { return newScope(definitions, scope); }
def.apply(THIS, question.newConstraint(null)); TypeCheckInfo newInfo = new TypeCheckInfo(question.assistantFactory, local, question.scope, question.qualifiers, question.constraint, null); && !question.assistantFactory.createPTypeAssistant().isType(suchThat.apply(THIS, newInfo.newConstraint(null)), ABooleanBasicType.class))
PType actual = node.getMeasure().apply(THIS, question.newInfo(local)); node.setMeasureName(node.getName().getMeasureName(node.getName().getLocation())); checkMeasure(question, node, node.getMeasureName(), actual);
public TypeCheckInfo newConstraint(PType newConstraint) { TypeCheckInfo info = new TypeCheckInfo(assistantFactory, env, scope, qualifiers, newConstraint, returnType); return info; }
@Override public PType caseAForAllExp(AForAllExp node, TypeCheckInfo question) throws AnalysisException { PDefinition def = AstFactory.newAMultiBindListDefinition(node.getLocation(), node.getBindList()); def.apply(THIS, question.newConstraint(null)); Environment local = new FlatCheckedEnvironment(question.assistantFactory, def, question.env, question.scope); if (!question.assistantFactory.createPTypeAssistant().isType(node.getPredicate().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope, null, AstFactory.newABooleanBasicType(node.getLocation()), null)), ABooleanBasicType.class)) { TypeCheckerErrors.report(3097, "Predicate is not boolean", node.getPredicate().getLocation(), node.getPredicate()); } local.unusedCheck(); node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public PType caseAPostOpExp(APostOpExp node, TypeCheckInfo question) throws AnalysisException { node.setType(node.getPostexpression().apply(THIS, question.newConstraint(null))); return node.getType(); }
@Override public PType caseACyclesStm(ACyclesStm node, TypeCheckInfo question) throws AnalysisException { PDefinition encl = question.env.getEnclosingDefinition(); if (encl != null && encl.getAccess().getPure()) { TypeCheckerErrors.report(3346, "Cannot use cycles in pure operations", node.getLocation(), node); } Environment newEnv = new FlatEnvironment(question.assistantFactory, question.env, true); TypeCheckInfo functional = question.newInfo(newEnv); PType argType = node.getCycles().apply(THIS, functional); if (!question.assistantFactory.getTypeComparator().compatible(AstFactory.newANatNumericBasicType(node.getLocation()), argType)) { TypeCheckerErrors.report(3282, "Arguments to cycles must be a nat", node.getLocation(), node); TypeCheckerErrors.detail("Actual", argType); } return node.getStatement().apply(THIS, question); }
/** * Returns the value associated with key. Implementation detail: Notice the map is shared between all instances. * * @param <T> * @param key * @return */ public <T> T contextGet(Class<T> key) { synchronized (TypeCheckInfo.class) { Stack<T> contextStack = lookupListForType(key); if (contextStack != null) { return contextStack.peek(); } } return null; }
public TypeCheckInfo newInfo(Environment newEnv) { TypeCheckInfo info = new TypeCheckInfo(assistantFactory, newEnv, scope, qualifiers, constraint, returnType); return info; }
@Override public PType caseAExistsExp(AExistsExp node, TypeCheckInfo question) throws AnalysisException { PDefinition def = AstFactory.newAMultiBindListDefinition(node.getLocation(), node.getBindList()); def.apply(THIS, question.newConstraint(null)); def.setNameScope(NameScope.LOCAL); Environment local = new FlatCheckedEnvironment(question.assistantFactory, def, question.env, question.scope); question = new TypeCheckInfo(question.assistantFactory, local, question.scope, null, AstFactory.newABooleanBasicType(node.getLocation()), null); if (!question.assistantFactory.createPTypeAssistant().isType(node.getPredicate().apply(THIS, question), ABooleanBasicType.class)) { TypeCheckerErrors.report(3089, "Predicate is not boolean", node.getPredicate().getLocation(), node.getPredicate()); } local.unusedCheck(); node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public PType caseAPreExp(APreExp node, TypeCheckInfo question) throws AnalysisException { node.getFunction().apply(THIS, question.newConstraint(null)); for (PExp a : node.getArgs()) { question.qualifiers = null; a.apply(THIS, question.newConstraint(null)); } node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return node.getType(); }
@Override public PType caseADurationStm(ADurationStm node, TypeCheckInfo question) throws AnalysisException { PDefinition encl = question.env.getEnclosingDefinition(); if (encl != null && encl.getAccess().getPure()) { TypeCheckerErrors.report(3346, "Cannot use duration in pure operations", node.getLocation(), node); } Environment newEnv = new FlatEnvironment(question.assistantFactory, question.env, true); TypeCheckInfo functional = question.newInfo(newEnv); PType argType = node.getDuration().apply(THIS, functional); if (!question.assistantFactory.getTypeComparator().compatible(AstFactory.newANatNumericBasicType(node.getLocation()), argType)) { TypeCheckerErrors.report(3281, "Arguments to duration must be a nat", node.getLocation(), node); TypeCheckerErrors.detail("Actual", argType); } return node.getStatement().apply(THIS, question); }