示例#1
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;
  }
示例#2
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;
  }