if(node.getName() != null ) node.getName().apply(this); if(node.getClassDefinition() != null && !_visitedNodes.contains(node.getClassDefinition())) node.getClassDefinition().apply(this); if(node.getAccess() != null && !_visitedNodes.contains(node.getAccess())) node.getAccess().apply(this); if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().apply(this); if(node.getPattern() != null && !_visitedNodes.contains(node.getPattern())) node.getPattern().apply(this); if(node.getExpression() != null && !_visitedNodes.contains(node.getExpression())) node.getExpression().apply(this); List<PDefinition> copy = new ArrayList<PDefinition>(node.getDefs()); for( PDefinition e : copy) if(node.getExpType() != null && !_visitedNodes.contains(node.getExpType()))
public static AValueDefinition newAValueDefinition(PPattern p, NameScope scope, PType type, PExp readExpression) { AValueDefinition result = new AValueDefinition(); // Definition initialization initDefinition(result, Pass.VALUES, p.getLocation(), null, scope); result.setPattern(p); result.setType(type); result.setExpression(readExpression); List<PDefinition> defs = new Vector<PDefinition>(); for (ILexNameToken var : af.createPPatternAssistant().getVariableNames(p)) { defs.add(AstFactory.newAUntypedDefinition(result.getLocation(), var, scope)); } result.setDefs(defs); return result; }
public ValueBindingObligation(AValueDefinition def, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { this(def.getPattern(), def.getType(), def.getExpression(), ctxt, af); }
@Override public PType caseAValueDefinition(AValueDefinition node) throws AnalysisException { // return AValueDefinitionAssistantTC.getType((AValueDefinition) node); return node.getType() != null ? node.getType() : node.getExpType() != null ? node.getExpType() : AstFactory.newAUnknownType(node.getLocation()); }
@Override public void caseAValueDefinition(AValueDefinition node) throws AnalysisException { if (node.getUsed()) // Indicates all definitions exported (used) { return; } if (node.getDefs() != null) { for (PDefinition def : node.getDefs()) { // PDefinitionAssistantTC.unusedCheck(def); def.apply(THIS); } } }
if (node.getType() != null) question.assistantFactory.getTypeComparator().checkComposeTypes(node.getType(), question.env, false); question = question.newConstraint(node.getType()); ExcludedDefinitions.setExcluded(node.getDefs()); PType expType = node.getExpression().apply(THIS, question); ExcludedDefinitions.clearExcluded(); node.setExpType(expType); PType type = node.getType(); // PDefinitionAssistant.getType(node); node.setPass(Pass.FINAL); // Do it again later TypeCheckerErrors.report(3048, "Expression does not return a value", node.getExpression().getLocation(), node.getExpression()); } else if (type != null && !(type instanceof AUnknownType)) TypeCheckerErrors.report(3051, "Expression does not match declared type", node.getLocation(), node); TypeCheckerErrors.detail2("Declared", type, "Expression", expType); node.setType(expType); PDefinition typedef = base.findType(named.getName(), node.getLocation().getModule()); return node.getType(); if (question.assistantFactory.createPAccessSpecifierAssistant().narrowerThan(typedef.getAccess(), node.getAccess())) TypeCheckerErrors.report(3052, "Value type visibility less than value definition", node.getLocation(), node);
public void updateDefs(AValueDefinition node, TypeCheckInfo question) { PType type = node.getType(); PPattern pattern = node.getPattern(); List<PDefinition> newdefs = af.createPPatternAssistant().getDefinitions(pattern, type, node.getNameScope()); // The untyped definitions may have had "used" markers, so we copy // those into the new typed definitions, lest we get warnings. We // also mark the local definitions as "ValueDefintions" (proxies), // so that classes can be constructed correctly (values are statics). for (PDefinition d : newdefs) { for (PDefinition u : node.getDefs()) { if (u.getName().equals(d.getName())) { if (af.createPDefinitionAssistant().isUsed(u)) { af.createPDefinitionAssistant().markUsed(d); } break; } } ALocalDefinition ld = (ALocalDefinition) d; ld.setValueDefinition(node.clone()); } node.setDefs(newdefs); List<PDefinition> defs = node.getDefs(); af.createPDefinitionListAssistant().setAccessibility(defs, node.getAccess().clone()); af.createPDefinitionListAssistant().setClassDefinition(defs, node.getClassDefinition()); }
PExp exp = node.getExpression(); obligations.addAll(exp.apply(rootVisitor, question)); PPattern pattern = node.getPattern(); PType type = node.getType(); PType compatible = set.getType(node.getLocation()); if (!assistantFactory.getTypeComparator().isSubType(type, compatible)) if (!assistantFactory.getTypeComparator().isSubType(question.checkType(exp, node.getExpType()), type)) TypeCompatibilityObligation sto = TypeCompatibilityObligation.newInstance(exp, type, node.getExpType(), question, assistantFactory); if (sto != null)
@Override public SDeclIR caseAValueDefinition(AValueDefinition node, IRInfo question) throws AnalysisException { String access = node.getAccess().getAccess().toString(); String name = node.getPattern().toString(); boolean isStatic = true; boolean isFinal = true; PType type = node.getType(); PExp exp = node.getExpression(); STypeIR typeCg = type.apply(question.getTypeVisitor(), question); SExpIR expCg = exp.apply(question.getExpVisitor(), question); return question.getDeclAssistant().constructField(access, name, isStatic, isFinal, typeCg, expCg); }
@Override public NameValuePairList caseAValueDefinition(AValueDefinition def, Context initialContext) throws AnalysisException { Value v = null; try { // UpdatableValues are constantized as they cannot be updated. v = def.getExpression().apply(VdmRuntime.getExpressionEvaluator(), initialContext).convertTo(af.createPDefinitionAssistant().getType(def), initialContext).getConstant(); return af.createPPatternAssistant().getNamedValues(def.getPattern(), v, initialContext); } catch (ValueException e) { VdmRuntimeError.abort(def.getLocation(), e); } catch (PatternMatchException e) { VdmRuntimeError.abort(e, initialContext); } catch (AnalysisException e) { } return null; }
@Override public void caseAValueDefinition(AValueDefinition node, NewQuestion question) throws AnalysisException { if (node.getType() != null) { node.setType(af.createPTypeAssistant().typeResolve(node.getType(), null, question.rootVisitor, question.question)); af.createPPatternAssistant().typeResolve(node.getPattern(), question.rootVisitor, question.question); // af.createAValueDefinitionAssistant().updateDefs(node, question.question); updateDefs(node, question.question); } }
@Override public LexNameSet caseAValueDefinition(AValueDefinition node, FreeVarInfo info) throws AnalysisException { LexNameSet names = new LexNameSet(); if (node.getType() != null) { names.addAll(node.getType().apply(this, info)); } names.addAll(node.getExpression().apply(this, info)); return names; }
private AValueDefinition buildValueDef(PExp exp, String name) { AValueDefinition valDef = new AValueDefinition(); valDef.setType(exp.getType().clone()); valDef.setExpression(exp.clone()); AIdentifierPattern pattern = new AIdentifierPattern(); pattern.setName(new LexNameToken(null, name, null)); valDef.setPattern(pattern); return valDef; }
@Override public PExp caseAValueDefinition(AValueDefinition def, Integer lineno) throws AnalysisException { return af.createPExpAssistant().findExpression(def.getExpression(), lineno); }
@Override public List<PDefinition> caseAValueDefinition(AValueDefinition node) throws AnalysisException { return node.getDefs(); }
@Override public Boolean caseAValueDefinition(AValueDefinition node) throws AnalysisException { if (!(node.getPattern() != null && node.getPattern() instanceof AIdentifierPattern && isValidName(((AIdentifierPattern) node.getPattern()).getName()))) { invalidNodes.add(node); return false; } return true; }
@Override public LexNameSet caseALocalDefinition(ALocalDefinition node, FreeVarInfo info) throws AnalysisException { LexNameSet names = node.getType().apply(this, info); if (node.getValueDefinition() != null) { names.addAll(node.getValueDefinition().apply(this, info)); } return names; }
@Override public String caseAValueDefinition(AValueDefinition node, PrettyPrinterEnv question) throws AnalysisException { StringBuilder sb = new StringBuilder(question.getIdent()); sb.append(node.getPattern() + (node.getType() == null ? "" : ":" + node.getType().apply(typePrinter, question)) + (node.getExpression() != null ? " = " + node.getExpression() : ""));// node.toString()); return sb.toString() + ";"; }
@Override public ValueList caseAValueDefinition(AValueDefinition def, ObjectContext ctxt) throws AnalysisException { return af.createPExpAssistant().getValues(def.getExpression(), ctxt); }
@Override public Boolean caseAValueDefinition(AValueDefinition node, Object other) throws AnalysisException { if (other instanceof AValueDefinition) { AValueDefinition vdo = (AValueDefinition) other; if (node.getDefs().size() == vdo.getDefs().size()) { Iterator<PDefinition> diter = vdo.getDefs().iterator(); for (PDefinition d : node.getDefs()) { if (!af.createPDefinitionAssistant().equals(diter.next(), d)) { return false; } } return true; } } return false; }