@Override public SStmCG caseAStartStm(AStartStm node, IRInfo question) throws AnalysisException { PType type = node.getType(); PExp exp = node.getObj(); if (exp.getType() instanceof ASetType) { STypeCG typeCG = type.apply(question.getTypeVisitor(), question); SExpCG expCG = exp.apply(question.getExpVisitor(), question); AStartlistStmCG s = new AStartlistStmCG(); s.setType(typeCG); s.setExp(expCG); return s; } else { STypeCG typeCG = type.apply(question.getTypeVisitor(), question); SExpCG expCG = exp.apply(question.getExpVisitor(), question); AStartStmCG thread = new AStartStmCG(); thread.setType(typeCG); thread.setExp(expCG); return thread; } }
// FIXME used in a single class. move it there public ValueList getAllValues(List<PType> linkedList, Context ctxt) throws AnalysisException { QuantifierList quantifiers = new QuantifierList(); int n = 0; for (PType t : linkedList) { LexNameToken name = new LexNameToken("#", String.valueOf(n), t.getLocation()); PPattern p = AstFactory.newAIdentifierPattern(name); Quantifier q = new Quantifier(p, af.createPTypeAssistant().getAllValues(t, ctxt)); quantifiers.add(q); } quantifiers.init(ctxt, true); ValueList results = new ValueList(); while (quantifiers.hasNext()) { NameValuePairList nvpl = quantifiers.next(); ValueList list = new ValueList(); for (NameValuePair nvp : nvpl) { list.add(nvp.value); } results.add(new TupleValue(list)); } return results; }
@Override public String toString() { if (optional) { return "[" + type.toString() + "]"; } else { return type.toString(); } }
@Override public SStmCG caseACallObjectStm(ACallObjectStm node, IRInfo question) throws AnalysisException { PType type = node.getType(); PObjectDesignator objectDesignator = node.getDesignator(); ILexNameToken field = node.getField(); LinkedList<PExp> args = node.getArgs(); STypeCG typeCg = type.apply(question.getTypeVisitor(), question); SObjectDesignatorCG objectDesignatorCg = objectDesignator.apply(question.getObjectDesignatorVisitor(), question); if (node.getExplicit()) { SClassDefinition enclosingClass = node.getAncestor(SClassDefinition.class); if (enclosingClass != null) { if (!field.getModule().equals(enclosingClass.getName().getName())) { // A quoted method call is only supported if the explicit // module name is equal to that of the enclosing class. Say A // is a sub class of S and 'a' is an instance of A then a.A`op(); // is allowed (although it is the same as a.op()). However, // a.S`op(); is not allowed. question.addUnsupportedNode( node, "A quoted object call statement is only supported if the explicit module name is equal to that of the enclosing class"); } } else { Logger.getLog() .printErrorln( "Could not find enclosing the statement of call a call object statement."); } } String fieldNameCg = field.getName(); ACallObjectStmCG callObject = new ACallObjectStmCG(); callObject.setType(typeCg); callObject.setDesignator(objectDesignatorCg); callObject.setFieldName(fieldNameCg); for (PExp arg : args) { SExpCG argCg = arg.apply(question.getExpVisitor(), question); if (argCg != null) { callObject.getArgs().add(argCg); } else { return null; } } return callObject; }
@Override public SStmCG caseABlockSimpleBlockStm(ABlockSimpleBlockStm node, IRInfo question) throws AnalysisException { ABlockStmCG blockStm = new ABlockStmCG(); blockStm.setScoped(question.getStmAssistant().isScoped(node)); LinkedList<AAssignmentDefinition> assignmentDefs = node.getAssignmentDefs(); for (AAssignmentDefinition def : assignmentDefs) { PType type = def.getType(); String name = def.getName().getName(); PExp exp = def.getExpression(); STypeCG typeCg = type.apply(question.getTypeVisitor(), question); AIdentifierPatternCG idPattern = new AIdentifierPatternCG(); idPattern.setName(name); SExpCG expCg = exp.apply(question.getExpVisitor(), question); AVarDeclCG localDecl = question.getDeclAssistant().consLocalVarDecl(def, typeCg, idPattern, expCg); if (expCg instanceof AUndefinedExpCG) { question.getDeclAssistant().setDefaultValue(localDecl, typeCg); } else { localDecl.setExp(expCg); } blockStm.getLocalDefs().add(localDecl); } LinkedList<PStm> stms = node.getStatements(); for (PStm pStm : stms) { SStmCG stmCg = pStm.apply(question.getStmVisitor(), question); if (stmCg != null) { blockStm.getStatements().add(stmCg); } else { return null; } } return blockStm; }
@Override public SSeqType caseAUnionType(AUnionType type) throws AnalysisException { // return AUnionTypeAssistantTC.getSeq(type); if (!type.getSeqDone()) { type.setSeqDone(true); // Mark early to avoid recursion. // type.setSeqType(PTypeAssistantTC.getSeq(AstFactory.newAUnknownType(type.getLocation()))); type.setSeqType( af.createPTypeAssistant().getSeq(AstFactory.newAUnknownType(type.getLocation()))); PTypeSet set = new PTypeSet(af); for (PType t : type.getTypes()) { if (af.createPTypeAssistant().isSeq(t)) { set.add(t.apply(THIS).getSeqof()); } } type.setSeqType( set.isEmpty() ? null : AstFactory.newASeqSeqType(type.getLocation(), set.getType(type.getLocation()))); } return type.getSeqType(); }
public TupleSelectObligation(PExp exp, PType type, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { // not is_(exp, type) super(exp, POType.TUPLE_SELECT, ctxt, exp.getLocation(), af); ANotUnaryExp notExp = new ANotUnaryExp(); AIsExp isExp = new AIsExp(); isExp.setTest(exp.clone()); isExp.setBasicType( type.clone()); // Do we need the type definition instead? If so, the visitor must provide // it. notExp.setExp(isExp); stitch = notExp; valuetree.setPredicate(ctxt.getPredWithContext(stitch)); }
public STypeCG toIrType(IRInfo info) { try { STypeCG irType = type.apply(info.getTypeVisitor(), info); if (irType != null) { irType.setOptional(optional); } return irType; } catch (AnalysisException e) { Logger.getLog() .printErrorln( "Problems encountered while attempting " + "to construct the IR type from a VDM type: " + e.getMessage() + " in '" + this.getClass().getSimpleName() + "'"); e.printStackTrace(); } return null; }
@Override public SStmCG caseACallStm(ACallStm node, IRInfo question) throws AnalysisException { PDefinition rootdef = node.getRootdef(); LinkedList<PExp> args = node.getArgs(); List<SExpCG> argsCg = new LinkedList<SExpCG>(); for (PExp arg : args) { SExpCG argCg = arg.apply(question.getExpVisitor(), question); if (argCg != null) { argsCg.add(argCg); } else { return null; } } boolean isStaticOrSl = Settings.dialect == Dialect.VDM_SL || question.getTcFactory().createPDefinitionAssistant().isStatic(rootdef); while (rootdef instanceof AInheritedDefinition) { rootdef = ((AInheritedDefinition) rootdef).getSuperdef(); } if (rootdef instanceof AExplicitOperationDefinition) { AExplicitOperationDefinition op = (AExplicitOperationDefinition) rootdef; if (op.getIsConstructor()) { String initName = question.getObjectInitializerCall(op); APlainCallStmCG callStm = new APlainCallStmCG(); callStm.setType(new AVoidTypeCG()); callStm.setClassType(null); callStm.setName(initName); callStm.setArgs(argsCg); return callStm; } } PType type = node.getType(); ILexNameToken nameToken = node.getName(); String name = nameToken.getName(); AClassTypeCG classType = null; STypeCG typeCg = type.apply(question.getTypeVisitor(), question); if (!isStaticOrSl) { ILexNameToken rootDefClassName = node.getRootdef().getClassDefinition().getName(); ILexNameToken enclosingClassName = node.getAncestor(SClassDefinition.class).getName(); if (!rootDefClassName.equals(enclosingClassName)) { ASuperCallStmCG superCall = new ASuperCallStmCG(); superCall.setIsStatic(isStaticOrSl); superCall.setType(typeCg); superCall.setName(name); superCall.setArgs(argsCg); return superCall; } } else if (nameToken != null && nameToken.getExplicit() && isStaticOrSl) { String className = nameToken.getModule(); classType = new AClassTypeCG(); classType.setName(className); } APlainCallStmCG callStm = new APlainCallStmCG(); callStm.setType(typeCg); callStm.setIsStatic(isStaticOrSl); callStm.setName(name); callStm.setClassType(classType); callStm.setArgs(argsCg); return callStm; }
public List<AFieldField> readFieldList() throws ParserException, LexException { List<AFieldField> list = new Vector<AFieldField>(); while (lastToken().isNot(VDMToken.END) && lastToken().isNot(VDMToken.SEMICOLON) && lastToken().isNot(VDMToken.INV)) { reader.push(); LexToken tag = lastToken(); LexToken separator = nextToken(); if (separator.is(VDMToken.COLON)) { if (tag.isNot(VDMToken.IDENTIFIER)) { throwMessage(2071, "Expecting field identifier before ':'"); } nextToken(); LexIdentifierToken tagid = (LexIdentifierToken) tag; if (tagid.isOld()) { throwMessage(2295, "Can't use old name here", tag); } LexNameToken tagname = idToName(tagid); list.add(AstFactory.newAFieldField(tagname, tagid.getName(), readType(), false)); reader.unpush(); } else if (separator.is(VDMToken.EQABST)) { if (tag.isNot(VDMToken.IDENTIFIER)) { throwMessage(2072, "Expecting field name before ':-'"); } nextToken(); LexIdentifierToken tagid = (LexIdentifierToken) tag; if (tagid.isOld()) { throwMessage(2295, "Can't use old name here", tag); } LexNameToken tagname = idToName(tagid); list.add(AstFactory.newAFieldField(tagname, tagid.getName(), readType(), true)); reader.unpush(); } else // Anonymous field or end of fields { try { reader.retry(); String anon = Integer.toString(list.size() + 1); PType ftype = readType(); LexNameToken tagname = new LexNameToken(getCurrentModule(), anon, ftype.getLocation()); list.add(AstFactory.newAFieldField(tagname, anon, ftype, false)); reader.unpush(); } catch (Exception e) { // End? EOF? Or badly formed type, fails elsewhere... reader.pop(); break; } } } for (PField f1 : list) { for (PField f2 : list) { if (f1 != f2 && ((AFieldField) f1).getTag().equals(((AFieldField) f2).getTag())) { throwMessage(2073, "Duplicate field names in record type"); } } } return list; }