Esempio n. 1
0
  @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;
  }
Esempio n. 2
0
  public AssignmentContext(AAssignmentStm node, IPogAssistantFactory af, IPOContextStack ctxt)
      throws AnalysisException {
    super(ctxt);
    String hash = node.getTarget().apply(af.getStateDesignatorNameGetter());

    t = null;

    for (ILexNameToken n : last_vars.keySet()) {
      if (n.getName().equals(hash)) {
        t = last_vars.get(n).getName().clone();
        break;
      }
    }
    if (t == null) {
      t = new LexNameToken("", hash, null);
    }
    subLast = new Substitution(new LexNameToken("", hash, null), node.getExp().clone());
    sub = new Substitution(t, node.getExp().clone());

    this.visitor = af.getVarSubVisitor();
  }
Esempio n. 3
0
  @Override
  public SStmCG caseAForIndexStm(AForIndexStm node, IRInfo question) throws AnalysisException {
    ILexNameToken var = node.getVar();
    PExp from = node.getFrom();
    PExp to = node.getTo();
    PExp by = node.getBy();
    PStm stm = node.getStatement();

    String varCg = var.getName();
    SExpCG fromCg = from.apply(question.getExpVisitor(), question);
    SExpCG toCg = to.apply(question.getExpVisitor(), question);
    SExpCG byCg = by != null ? by.apply(question.getExpVisitor(), question) : null;
    SStmCG bodyCg = stm.apply(question.getStmVisitor(), question);

    AForIndexStmCG forStm = new AForIndexStmCG();
    forStm.setVar(varCg);
    forStm.setFrom(fromCg);
    forStm.setTo(toCg);
    forStm.setBy(byCg);
    forStm.setBody(bodyCg);

    return forStm;
  }
Esempio n. 4
0
  @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;
  }
Esempio n. 5
0
 public boolean matches(ILexNameToken other) {
   return module.equals(other.getModule())
       && name.equals(other.getName())
       && old == other.getOld();
 }