@Override
  public PExp caseARecordPattern(ARecordPattern pattern) throws AnalysisException {
    List<PExp> list = new LinkedList<PExp>();

    for (PPattern p : pattern.getPlist()) {
      list.add(af.createPPatternAssistant().getMatchingExpression(p));
    }

    ILexNameToken tpName = pattern.getTypename();
    return AstFactory.newAMkTypeExp(tpName.clone(), list);
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
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();
  }
Exemplo n.º 4
0
  /**
   * Basic equals method for LexNameTokens. This method does not handle type qualifiers in that case
   * use {@link HackLexNameToken}
   */
  @SuppressWarnings("javadoc")
  @Override
  public boolean equals(Object other) {
    if (!(other instanceof ILexNameToken)) {
      return false;
    }

    ILexNameToken lother = (ILexNameToken) other;

    if (typeQualifier != null && lother.getTypeQualifier() != null) {
      // For testing purpose the following line can be uncommented. The Type Checker is not supose
      // to rely on this
      // equal method but use the HelpLexNameToken class for that
      // throw new InternalException(-1, "Use HelpLexNameToken.isEqual to compare");

    } else if (typeQualifier != null && lother.getTypeQualifier() == null
        || typeQualifier == null && lother.getTypeQualifier() != null) {
      return false;
    }

    return matches(lother);
  }
Exemplo n.º 5
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;
  }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
0
 public int compareTo(ILexNameToken o) {
   return toString().compareTo(o.toString());
 }
Exemplo n.º 8
0
 public boolean matches(ILexNameToken other) {
   return module.equals(other.getModule())
       && name.equals(other.getName())
       && old == other.getOld();
 }