public static String getDefinitionListString( NodeList<? extends PDefinition> _definitions) { StringBuilder sb = new StringBuilder(); for (PDefinition d : _definitions) { if (d.getAccess() != null) { sb.append(d.getAccess()); sb.append(" "); } // sb.append(d.getClass().getName() + " " + getVariableNames(d) + ":" + d.getType()); sb.append(d.toString()); sb.append("\n"); } return sb.toString(); }
public boolean isStatic(PDefinition fdef) { return af.createPAccessSpecifierAssistant().isStatic(fdef.getAccess()); }
public boolean narrowerThanBaseCase(PType type, AAccessSpecifierAccessSpecifier accessSpecifier) { if (type.getDefinitions() != null) { boolean result = false; for (PDefinition d : type.getDefinitions()) { result = result || af.createPAccessSpecifierAssistant().narrowerThan(d.getAccess(), accessSpecifier); } return result; } else { return false; } }
public AAccessSpecifierAccessSpecifier getStatic(PDefinition d, boolean asStatic) { AAccessSpecifierAccessSpecifier paccess = d.getAccess(); if (paccess instanceof AAccessSpecifierAccessSpecifier) { return AstFactory.newAAccessSpecifierAccessSpecifier(paccess.getAccess().clone(), asStatic && paccess.getStatic() != null, paccess.getAsync() != null, false); } assert false : "PAccessSpecifier must be instance of AAccessSpecifierAccessSpecifier"; return null; }
@Override public PDefinition findType(ILexNameToken name, String fromModule) { PDefinition def = af.createSClassDefinitionAssistant().findType(classes, name); if (def != null && af.createPAccessSpecifierAssistant().isPublic(def.getAccess())) { return def; } return outer == null ? null : outer.findType(name, null); }
@Override public PDefinition findName(ILexNameToken name, NameScope scope) { PDefinition def = af.createSClassDefinitionAssistant().findName(classes, name, scope); if (def != null && af.createPAccessSpecifierAssistant().isPublic(def.getAccess()) && !ExcludedDefinitions.isExcluded(def)) { return def; } return outer == null ? null : outer.findName(name, scope); }
return af.createPAccessSpecifierAssistant().isPublic(field.getAccess()); } else return !af.createPAccessSpecifierAssistant().isPrivate(field.getAccess()); } else return af.createPAccessSpecifierAssistant().isPublic(field.getAccess()) && (needStatic ? af.createPAccessSpecifierAssistant().isStatic(field.getAccess()) : true);
if (af.createPAccessSpecifierAssistant().narrowerThan(d.getAccess(), accessSpecifier))
if (!af.createPAccessSpecifierAssistant().isPrivate(d.getAccess()))
+ override.getName(), override.getName().getLocation(), override); TypeCheckerErrors.detail2("This", af.createPDefinitionAssistant().kind(override), "Super", af.createPDefinitionAssistant().kind(indef)); } else if (af.createPAccessSpecifierAssistant().narrowerThan(override.getAccess(), indef.getAccess())) TypeCheckerErrors.detail2("This", override.getAccess().getAccess()+" "+ override.getName(), "Super",indef.getAccess().getAccess()+" "+ indef.getName()); else if (override.getAccess().getPure() != indef.getAccess().getPure()) TypeCheckerErrors.report(3341, "Overriding definition must " + (override.getAccess().getPure() ? "not" : "also") + " be pure", override.getName().getLocation(),override); } else
public static AInheritedDefinition newAInheritedDefinition( ILexNameToken localname, PDefinition d) { AInheritedDefinition result = new AInheritedDefinition(); initDefinition(result, d.getPass(), d.getLocation(), localname, d.getNameScope()); result.setSuperdef(d); result.setOldname(localname.getOldName()); result.setType(d.getType()); af.createPDefinitionAssistant().setClassDefinition(result, d.getClassDefinition()); result.setAccess(d.getAccess().clone()); return result; }
@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); }
private void setStaticDefinitions(SClassDefinition node, LinkedList<PDefinition> defs, Context initCtxt) { for (PDefinition d : defs) { if (af.createPDefinitionAssistant().isStatic(d) && af.createPDefinitionAssistant().isFunctionOrOperation(d) || af.createPDefinitionAssistant().isTypeDefinition(d)) { // Note function and operation values are not updatable. // Type invariants are implicitly static, but not updatable // The context here is just used for free variables, of // which there are none at static func/op creation... Context empty = new Context(af, node.getLocation(), "empty", null); NameValuePairList nvl = af.createPDefinitionAssistant().getNamedValues(d, empty); PAccess pAccess = d.getAccess().getAccess(); if (pAccess instanceof APrivateAccess || pAccess instanceof AProtectedAccess) { VdmRuntime.getNodeState(af, node).privateStaticValues.putAllNew(nvl); initCtxt.putList(nvl); } else if (pAccess instanceof APublicAccess) { VdmRuntime.getNodeState(af, node).publicStaticValues.putAllNew(nvl); initCtxt.putList(nvl); } } } }
if (encl != null && encl.getAccess().getPure())
if (encl != null && encl.getAccess().getPure())