public QualifiedDefinition(PDefinition qualifies, PType type) { this.def = qualifies; this.type = type; this.original = qualifies.getType(); }
@Override public PType findType(String typename) { for (SClassDefinition cDef : classes) { for (PDefinition def : cDef.getDefinitions()) { if (def instanceof ATypeDefinition) { if (def.getName().equals(typename)) { return def.getType(); } } } } return null; } }
@Override public PType findType(String typename) { for (AModuleModules module : modules) { for (PDefinition def : module.getDefs()) { if (def instanceof ATypeDefinition) { if (def.getName().equals(typename)) { return def.getType(); } } } } return null; } }
protected List<PMultipleBind> stateInvBinds(AClassInvariantDefinition node) { List<PMultipleBind> binds = new LinkedList<PMultipleBind>(); for (PDefinition p : node.getClassDefinition().getDefinitions()) { if (p instanceof AInstanceVariableDefinition) { binds.add(getMultipleTypeBind(p.getType().clone(), p.getName().clone())); } } return binds; }
/** * Check a DefinitionList for incompatible duplicate pattern definitions. * * @param d * @param defs * @return */ public List<PDefinition> checkDuplicatePatterns(PDefinition d, List<PDefinition> defs) { Set<PDefinition> noDuplicates = new HashSet<PDefinition>(); for (PDefinition d1 : defs) { for (PDefinition d2 : defs) { if (d1 != d2 && d1.getName() != null && d2.getName() != null && d1.getName().equals(d2.getName())) { if (!af.getTypeComparator().compatible(d1.getType(), d2.getType())) { TypeCheckerErrors.report(3322, "Duplicate patterns bind to different types", d.getLocation(), d); TypeCheckerErrors.detail2(d1.getName().getName(), d1.getType(), d2.getName().getName(), d2.getType()); } } } noDuplicates.add(d1); } return new Vector<PDefinition>(noDuplicates); }
@Override public PType caseAMultiBindListDefinition(AMultiBindListDefinition node) throws AnalysisException { PTypeList types = new PTypeList(); for (PDefinition definition : node.getDefs()) { types.add(definition.getType()); } AUnionType result = AstFactory.newAUnionType(node.getLocation(), types); return result; }
protected void stateInPost(List<PMultipleBind> exists_binds, List<PExp> postArglist, PDefinition stateDefinition) { AVariableExp varExp; // replace with super call if (stateDefinition instanceof AStateDefinition) { varExp = getVarExp(NEW_STATE_ARG,stateDefinition.clone()); AStateDefinition aStateDefinition = (AStateDefinition) stateDefinition; varExp.setType(aStateDefinition.getRecordType().clone()); exists_binds.addAll(getMultipleTypeBindList(aStateDefinition.getRecordType().clone(), NEW_STATE_ARG)); } else { varExp = getVarExp(NEW_SELF_ARG,stateDefinition.clone()); varExp.setType(stateDefinition.getType().clone()); exists_binds.addAll(getMultipleTypeBindList(stateDefinition.getType().clone(), NEW_SELF_ARG)); } postArglist.add(varExp); }
protected void stateInPre(List<PExp> args, PDefinition stateDefinition) { AVariableExp varExp; if (stateDefinition instanceof AStateDefinition) { varExp = getVarExp(OLD_STATE_ARG,stateDefinition.clone()); varExp.setType(((AStateDefinition) stateDefinition).getRecordType().clone()); } else { varExp = getVarExp(OLD_SELF_ARG,stateDefinition.clone()); varExp.setType(stateDefinition.getType().clone()); } args.add(varExp); }
@Override public PType caseABlockSimpleBlockStm(ABlockSimpleBlockStm node, TypeCheckInfo question) throws AnalysisException { // Each dcl definition is in scope for later definitions... Environment local = question.env; for (PDefinition d : node.getAssignmentDefs()) { local = new FlatCheckedEnvironment(question.assistantFactory, d, local, question.scope); // cumulative question.assistantFactory.createPDefinitionAssistant().implicitDefinitions(d, local); d.setType(question.assistantFactory.createPTypeAssistant().typeResolve(d.getType(), null, THIS, question)); d.apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope, question.qualifiers, d.getType(), question.returnType)); } // For type checking purposes, the definitions are treated as // local variables. At runtime (below) they have to be treated // more like (updatable) state. PType r = defaultSSimpleBlockStm(node, new TypeCheckInfo(question.assistantFactory, local, question.scope, null, null, question.returnType)); local.unusedCheck(question.env); node.setType(r); return r; }
@Override public IProofObligationList caseAIsExp(AIsExp node, IPOContextStack question) throws AnalysisException { PDefinition typeDef = node.getTypedef(); PType basicType = node.getBasicType(); if (typeDef != null) { question.noteType(node.getTest(), typeDef.getType()); } else if (basicType != null) { question.noteType(node.getTest(), basicType); } return node.getTest().apply(mainVisitor, question); }
private static PType getType(String module, String name) throws ValueException { Interpreter i = Interpreter.getInstance(); LexNameToken tcname = new LexNameToken(module, name,new LexLocation()); PDefinition def = i.getGlobalEnvironment(module).findType(tcname, i.getDefaultName()); if (def == null) { throw new ValueException(70, "Definition " + tcname.getExplicit(true) + " not found", null); } return def.getType(); } }
public TraceVariableList(Context ctxt, List<PDefinition> localDefs) { Environment local = new FlatEnvironment(ctxt.assistantFactory, localDefs); for (ILexNameToken key : ctxt.keySet()) { Value value = ctxt.get(key); PDefinition d = local.findName(key, NameScope.NAMES); boolean clone = false; if (value.isType(ObjectValue.class)) { ObjectValue obj = (ObjectValue) value.deref(); ObjectValue self = ctxt.getSelf(); // We have to clone new objects that were created within the trace, // while using other (local instance variable) objects unchanged. clone = self != null && obj.objectReference > self.objectReference; } add(new TraceVariable(key.getLocation(), key, value, d.getType(), clone)); } }
PDefinition def = readOperationDefinition(); def.setAccess(access); ((AOperationType)def.getType()).setPure(access.getPure()); list.add(def);
@Override public PType caseASelfExp(ASelfExp node, TypeCheckInfo question) { PDefinition cdef = question.env.findName(node.getName(), question.scope); if (cdef == null) { TypeCheckerErrors.report(3154, node.getName() + " not in scope", node.getLocation(), node); node.setType(AstFactory.newAUnknownType(node.getLocation())); return node.getType(); } node.setType(cdef.getType()); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
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; }
PType exptype = question.assistantFactory.createPTypeAssistant().typeResolve(expdef.getType(), null, THIS, question); if (!question.assistantFactory.getTypeComparator().compatible(def.getType(), exptype)) TypeCheckerErrors.detail2("Import", def.getType().toString() // TODO: .toDetailedString() , "Export", exptype.toString()); // TODO:
public PType caseAOperationExport(AOperationExport exp, TypeCheckInfo question) throws AnalysisException { ITypeCheckerAssistantFactory af = question.assistantFactory; ModuleEnvironment menv = (ModuleEnvironment)question.env; for (ILexNameToken name : exp.getNameList()) { PDefinition def = af.createPDefinitionListAssistant().findName(menv.getDefinitions(), name, NameScope.NAMES); if (def == null) { TypeCheckerErrors.report(3185, "Exported operation " + name + " not defined in module", name.getLocation(), exp); } else { PType act = def.getType(); PType type = question.assistantFactory.createPTypeAssistant().typeResolve(exp.getExportType(), null, THIS, question); exp.setExportType(type); if (act != null && !af.createPTypeAssistant().equals(act, type)) { TypeCheckerErrors.report(3186, "Exported operation type does not match actual type", name.getLocation(), exp); TypeCheckerErrors.detail2("Exported", type, "Actual", act); } } } return null; }
PType act = question.assistantFactory.createPTypeAssistant().typeResolve(def.getType(), null, THIS, question);
@Override public PType caseAIsOfClassExp(AIsOfClassExp node, TypeCheckInfo question) throws AnalysisException { ILexNameToken classname = node.getClassName(); PDefinition cls = question.env.findType(classname, null); if (cls == null || !(cls instanceof SClassDefinition)) { TypeCheckerErrors.report(3115, "Undefined class type: " + classname.getName(), node.getLocation(), node); } else { node.setClassType((AClassType) cls.getType()); } question.qualifiers = null; PType rt = node.getExp().apply(THIS, question.newConstraint(null)); if (!question.assistantFactory.createPTypeAssistant().isClass(rt, question.env)) { TypeCheckerErrors.report(3266, "Argument is not an object", node.getExp().getLocation(), node.getExp()); } node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public PType caseAStateDefinition(AStateDefinition node, TypeCheckInfo question) throws AnalysisException { Environment base = question.env; if (base.findStateDefinition() != node) { TypeCheckerErrors.report(3047, "Only one state definition allowed per module", node.getLocation(), node); return null; } for (PDefinition def : node.getStateDefs()) { if (!def.getName().getOld()) // Don't check old names { question.assistantFactory.getTypeComparator().checkComposeTypes(def.getType(), question.env, false); } } question.assistantFactory.createPDefinitionListAssistant().typeCheck(node.getStateDefs(), THIS, question); if (node.getInvdef() != null) { node.getInvdef().apply(THIS, question); question.assistantFactory.createPPatternAssistant().typeResolve(node.getInvPattern(), THIS, question); } if (node.getInitdef() != null) { node.getInitdef().apply(THIS, question); question.assistantFactory.createPPatternAssistant().typeResolve(node.getInitPattern(), THIS, question); } return null; }