public PDefinition getEnclosingDefinition() { if (enclosingDefinition != null) { return enclosingDefinition; } return outer == null ? null : outer.getEnclosingDefinition(); }
/** * Test whether the calling environment indicates that we are within a constructor. */ public boolean inConstructor(Environment env) { PDefinition encl = env.getEnclosingDefinition(); if (encl != null) { return isConstructor(encl); } return false; } }
@Override public PType caseATimeExp(ATimeExp node, TypeCheckInfo question) { PDefinition encl = question.env.getEnclosingDefinition(); if (encl != null && encl.getAccess().getPure()) { TypeCheckerErrors.report(3346, "Cannot use 'time' in pure operations", node.getLocation(), node); } if (Settings.release == Release.VDM_10 && question.env.isFunctional()) { TypeCheckerErrors.report(3348, "Cannot use 'time' in a functional context", node.getLocation(), node); } node.setType(AstFactory.newANatNumericBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public PType caseAThreadIdExp(AThreadIdExp node, TypeCheckInfo question) { PDefinition encl = question.env.getEnclosingDefinition(); if (encl != null && encl.getAccess().getPure()) { TypeCheckerErrors.report(3346, "Cannot use 'threadid' in pure operations", node.getLocation(), node); } if (Settings.release == Release.VDM_10 && question.env.isFunctional()) { TypeCheckerErrors.report(3348, "Cannot use 'threadid' in a functional context", node.getLocation(), node); } node.setType(AstFactory.newANatNumericBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
@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); }
@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); }
@Override public PType caseAReturnStm(AReturnStm node, TypeCheckInfo question) throws AnalysisException { PDefinition encl = question.env.getEnclosingDefinition(); boolean inConstructor = false; if (encl instanceof AExplicitOperationDefinition) { AExplicitOperationDefinition op = (AExplicitOperationDefinition) encl; inConstructor = op.getIsConstructor(); } else if (encl instanceof AImplicitOperationDefinition) { AImplicitOperationDefinition op = (AImplicitOperationDefinition) encl; inConstructor = op.getIsConstructor(); } if (inConstructor && !(node.getExpression() instanceof ASelfExp)) { TypeCheckerErrors.report(3326, "Constructor can only return 'self'", node.getLocation(), node); } if (node.getExpression() == null) { node.setType(AstFactory.newAVoidReturnType(node.getLocation())); } else { node.setType(node.getExpression().apply(THIS, question)); } return question.assistantFactory.createPTypeAssistant().checkReturnType(question.returnType, node.getType(), node.getLocation()); }
throws AnalysisException PDefinition encl = question.env.getEnclosingDefinition();
PDefinition encl = question.env.getEnclosingDefinition();
throws AnalysisException PDefinition encl = question.env.getEnclosingDefinition();
PDefinition encl = env.getEnclosingDefinition();
PDefinition func = question.env.getEnclosingDefinition(); boolean inFunction = question.env.isFunctional(); boolean inOperation = !inFunction;
PDefinition encl = question.env.getEnclosingDefinition();
PDefinition encl = question.env.getEnclosingDefinition(); NameScope findScope = question.scope;