Exemple #1
0
  @Override
  public SStmCG caseAIfStm(AIfStm node, IRInfo question) throws AnalysisException {
    SExpCG ifExp = node.getIfExp().apply(question.getExpVisitor(), question);
    SStmCG thenStm = node.getThenStm().apply(question.getStmVisitor(), question);

    AIfStmCG ifStm = new AIfStmCG();

    ifStm.setIfExp(ifExp);
    ifStm.setThenStm(thenStm);

    LinkedList<AElseIfStm> elseIfs = node.getElseIf();

    for (AElseIfStm stm : elseIfs) {
      ifExp = stm.getElseIf().apply(question.getExpVisitor(), question);
      thenStm = stm.getThenStm().apply(question.getStmVisitor(), question);

      AElseIfStmCG elseIfStm = new AElseIfStmCG();
      elseIfStm.setElseIf(ifExp);
      elseIfStm.setThenStm(thenStm);

      ifStm.getElseIf().add(elseIfStm);
    }

    if (node.getElseStm() != null) {
      SStmCG elseStm = node.getElseStm().apply(question.getStmVisitor(), question);
      ifStm.setElseStm(elseStm);
    }

    return ifStm;
  }
Exemple #2
0
  @Override
  public SStmCG caseAForPatternBindStm(AForPatternBindStm node, IRInfo question)
      throws AnalysisException {
    // Example for mk_(a,b) in [mk_(1,2), mk_(3,4)] do skip;
    PPattern pattern = node.getPatternBind().getPattern();
    PExp exp = node.getExp();
    PStm stm = node.getStatement();
    Boolean reverse = node.getReverse();

    SPatternCG patternCg = pattern.apply(question.getPatternVisitor(), question);
    SExpCG seqExpCg = exp.apply(question.getExpVisitor(), question);
    SStmCG stmCg = stm.apply(question.getStmVisitor(), question);

    AForAllStmCG forAll = new AForAllStmCG();
    forAll.setPattern(patternCg);
    forAll.setBody(stmCg);

    if (reverse != null && reverse) {
      AReverseUnaryExpCG reversedExp = new AReverseUnaryExpCG();
      reversedExp.setType(seqExpCg.getType().clone());
      reversedExp.setExp(seqExpCg);
      forAll.setExp(reversedExp);
    } else {
      forAll.setExp(seqExpCg);
    }

    return forAll;
  }
Exemple #3
0
  @Override
  public SStmCG caseAWhileStm(AWhileStm node, IRInfo question) throws AnalysisException {
    PStm stm = node.getStatement();
    PExp exp = node.getExp();

    SStmCG bodyCg = stm.apply(question.getStmVisitor(), question);
    SExpCG expCg = exp.apply(question.getExpVisitor(), question);

    AWhileStmCG whileStm = new AWhileStmCG();
    whileStm.setExp(expCg);
    whileStm.setBody(bodyCg);

    return whileStm;
  }
Exemple #4
0
  @Override
  public SStmCG caseACaseAlternativeStm(ACaseAlternativeStm node, IRInfo question)
      throws AnalysisException {
    PPattern pattern = node.getPattern();
    PStm result = node.getResult();

    SPatternCG patternCg = pattern.apply(question.getPatternVisitor(), question);
    SStmCG resultCg = result.apply(question.getStmVisitor(), question);

    ACaseAltStmStmCG caseCg = new ACaseAltStmStmCG();
    caseCg.setPattern(patternCg);
    caseCg.setResult(resultCg);

    return caseCg;
  }
Exemple #5
0
  @Override
  public SStmCG caseALetStm(ALetStm node, IRInfo question) throws AnalysisException {
    ABlockStmCG block = new ABlockStmCG();
    block.setScoped(question.getStmAssistant().isScoped(node));

    question.getDeclAssistant().setLocalDefs(node.getLocalDefs(), block.getLocalDefs(), question);

    SStmCG stm = node.getStatement().apply(question.getStmVisitor(), question);

    if (stm != null) {
      block.getStatements().add(stm);
    }

    return block;
  }
Exemple #6
0
  @Override
  public SStmCG caseAAtomicStm(AAtomicStm node, IRInfo question) throws AnalysisException {
    AAtomicStmCG atomicBlock = new AAtomicStmCG();

    for (AAssignmentStm assignment : node.getAssignments()) {
      SStmCG stmCg = assignment.apply(question.getStmVisitor(), question);

      if (stmCg != null) {
        atomicBlock.getStatements().add(stmCg);
      } else {
        return null;
      }
    }

    return atomicBlock;
  }
Exemple #7
0
  @Override
  public SStmCG caseAForAllStm(AForAllStm node, IRInfo question) throws AnalysisException {
    // Example: for all x in set {1,2,3} do skip;
    PPattern pattern = node.getPattern();
    PExp set = node.getSet();
    PStm body = node.getStatement();

    SPatternCG patternCg = pattern.apply(question.getPatternVisitor(), question);
    SExpCG setExpCg = set.apply(question.getExpVisitor(), question);
    SStmCG bodyCg = body.apply(question.getStmVisitor(), question);

    AForAllStmCG forAll = new AForAllStmCG();
    forAll.setPattern(patternCg);
    forAll.setExp(setExpCg);
    forAll.setBody(bodyCg);

    return forAll;
  }
Exemple #8
0
  @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;
  }
Exemple #9
0
  @Override
  public SStmCG caseACasesStm(ACasesStm node, IRInfo question) throws AnalysisException {
    PExp exp = node.getExp();
    PStm others = node.getOthers();
    LinkedList<ACaseAlternativeStm> cases = node.getCases();

    SExpCG expCg = exp.apply(question.getExpVisitor(), question);
    SStmCG othersCg = others != null ? others.apply(question.getStmVisitor(), question) : null;

    ACasesStmCG casesStmCg = new ACasesStmCG();
    casesStmCg.setExp(expCg);
    casesStmCg.setOthers(othersCg);

    question
        .getStmAssistant()
        .handleAlternativesCasesStm(question, exp, cases, casesStmCg.getCases());

    return casesStmCg;
  }
Exemple #10
0
  @Override
  public SStmCG caseALetBeStStm(ALetBeStStm node, IRInfo question) throws AnalysisException {
    PMultipleBind multipleBind = node.getBind();

    if (!(multipleBind instanceof ASetMultipleBind)) {
      question.addUnsupportedNode(
          node,
          "Generation of the let be st statement is only supported for a multiple set bind. Got: "
              + multipleBind);
      return null;
    }

    ASetMultipleBind multipleSetBind = (ASetMultipleBind) multipleBind;

    SMultipleBindCG multipleBindCg =
        multipleSetBind.apply(question.getMultipleBindVisitor(), question);

    if (!(multipleBindCg instanceof ASetMultipleBindCG)) {
      return null;
    }

    ASetMultipleBindCG multipleSetBindCg = (ASetMultipleBindCG) multipleBindCg;

    PExp suchThat = node.getSuchThat();
    PStm stm = node.getStatement();

    SExpCG suchThatCg =
        suchThat != null ? suchThat.apply(question.getExpVisitor(), question) : null;
    SStmCG stmCg = stm.apply(question.getStmVisitor(), question);

    ALetBeStStmCG letBeSt = new ALetBeStStmCG();

    AHeaderLetBeStCG header = question.getExpAssistant().consHeader(multipleSetBindCg, suchThatCg);

    letBeSt.setHeader(header);
    letBeSt.setStatement(stmCg);

    return letBeSt;
  }
Exemple #11
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;
  }