Beispiel #1
0
  /**
   * This function prints a parsed TCRL refinement law. Only for debug purposes
   *
   * @param r The AST object
   */
  public static void printRefFunction(TCRL_AST r) {

    System.out.println();
    System.out.println("**************************************************");
    System.out.println("RefFunction");
    System.out.println("**************************************************");
    System.out.println("Nombre: " + r.getName());
    System.out.println("Preambulo: " + r.getPreamble());
    System.out.println("Reglas: ");

    NodeRules rules = r.getRules();
    NodeRule rule;

    Set<String> keys = rules.getKeys();
    Iterator<String> iter = keys.iterator();

    while (iter.hasNext()) {
      rule = rules.getRule(iter.next());

      if (rule instanceof RuleSynonym) {
        printRuleSynonym((RuleSynonym) rule);
      } else {
        printRuleRefinement((RuleRefinement) rule);
      }
    }
  }
Beispiel #2
0
  public static String printCTCC(String testName, ConcreteTCase ctc) {
    String ctcString = "";
    ctcString = ctcString.concat(ctc.getPreamble() + "\n");
    ctcString += "main(){\n";
    if (ctc.getInitDeclarations() != null) ctcString += ctc.getInitDeclarations();

    List<TCaseAssignment> assigs = ctc.getAssigments();
    Iterator<TCaseAssignment> iter = assigs.iterator();
    while (iter.hasNext()) ctcString = ctcString.concat((iter.next()).getRefText() + "\n");
    ctcString = ctcString.concat(ctc.getEpilogue() + "\n");
    ctcString += "}\n";
    return ctcString;
  }
Beispiel #3
0
  /**
   * This function obtains the refinement rule associated with a specification ID
   *
   * @param specID The identifier of a variable in the specification
   * @param rules A list with refinement rules
   * @return the rule associated with the variable
   */
  public static RuleRefinement getRefinementRule(String specID, NodeRules rules) {
    RuleRefinement ruleRefinement = null;
    Set<String> setRuleNames = rules.getKeys();
    Iterator<String> iterRuleNames = setRuleNames.iterator();

    boolean found = false;
    while (iterRuleNames.hasNext() && !found) {
      String ruleName = iterRuleNames.next();
      NodeRule rule = rules.getRule(ruleName);

      List<String> ruleSpecIDs = ((RuleRefinement) rule).getSpecIDs();
      Iterator<String> iterRuleSpecIDs = ruleSpecIDs.iterator();

      while (iterRuleSpecIDs.hasNext() && !found) {
        String ruleSpecID = iterRuleSpecIDs.next();
        if (specID.equals(ruleSpecID)) {
          found = true;
          if (rule instanceof RuleRefinement) ruleRefinement = (RuleRefinement) rule;
        }
      }
    }
    return ruleRefinement;
  }
Beispiel #4
0
  public static String printCTCJava(String testName, ConcreteTCase ctc) {
    String ctcString = ""; // EMPTY STRING

    // --------------------------------------------------------------------------------
    // CONCATENATES the TESTNAME
    // --------------------------------------------------------------------------------
    ctcString =
        ctcString.concat(
            "//--------------------------------------------------------------------------------"
                + "\n");
    ctcString = ctcString.concat("// " + testName + "\n");
    ctcString =
        ctcString.concat(
            "//--------------------------------------------------------------------------------"
                + "\n");
    ctcString = ctcString.concat("\n");
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    String preamble = ctc.getPreamble();
    String preambleWithOutPackageAndImports = "";

    BufferedReader preambleReader = new BufferedReader(new StringReader(preamble));

    CharSequence packageChar = new StringBuffer("package");
    CharSequence importChar = new StringBuffer("import");

    String preambleLine;
    try {
      while ((preambleLine = preambleReader.readLine()) != null) {
        if (preambleLine.contains(packageChar) || preambleLine.contains(importChar)) {
          ctcString = ctcString.concat(preambleLine);
          ctcString = ctcString.concat("\n");
        } else {
          preambleWithOutPackageAndImports =
              preambleWithOutPackageAndImports.concat(preambleLine) + "\n";
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    // PRINT the TEST CLASS HEADER
    // --------------------------------------------------------------------------------
    ctcString = ctcString.concat("\n");
    ctcString = ctcString.concat("public class ");
    ctcString = ctcString.concat(testName); // SCHEMA NAME
    ctcString = ctcString.concat("\n");
    ctcString = ctcString.concat("{");
    ctcString = ctcString.concat("\n");
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    // CONCATENATES the PREAMBLE WITHOUT PACKAGE and IMPORTS
    // --------------------------------------------------------------------------------
    ctcString = ctcString.concat(preambleWithOutPackageAndImports);
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    // PRINT the RUNTEST CLASS HEADER
    // --------------------------------------------------------------------------------
    ctcString = ctcString.concat("\n");
    ctcString = ctcString.concat("\t");
    ctcString = ctcString.concat("public static void main(String[] args)");
    // ctcString = ctcString.concat("public static void runTest_");
    // ctcString = ctcString.concat(testName);			// SCHEMA NAME
    // ctcString = ctcString.concat("_TCASE()");
    ctcString = ctcString.concat("\n");
    ctcString = ctcString.concat("\t");
    ctcString = ctcString.concat("{");
    ctcString = ctcString.concat("\n");
    ctcString = ctcString.concat("try{\n");
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    // CONCATENATES the REFINEMENT TEXT of ALL ASSIGNMENTS
    // --------------------------------------------------------------------------------
    List<TCaseAssignment> assignments = ctc.getAssigments();
    Iterator<TCaseAssignment> iterAssignments = assignments.iterator();
    TCaseAssignment assignment;
    String assignmentRefText;

    while (iterAssignments.hasNext()) {
      assignment = iterAssignments.next();

      assignmentRefText = assignment.getRefText();

      // CONCATS the REFIMENT TEXT of ASSIGNMENT
      ctcString =
          ctcString.concat(
              "\t\t" // INDENTATION
                  + assignmentRefText
                  + "\n"
                  + "\n");
    }
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    // CONCATS the EPILOGUE
    // --------------------------------------------------------------------------------
    ctcString =
        ctcString.concat(
            "\t\t"
                + "//--------------------------------------------------------------------------------"
                + "\n");
    ctcString = ctcString.concat("\t\t" + "//                                   EPILOGUE" + "\n");
    ctcString =
        ctcString.concat(
            "\t\t"
                + "//--------------------------------------------------------------------------------"
                + "\n");

    String epilogue = ctc.getEpilogue();
    BufferedReader epilogueReader = new BufferedReader(new StringReader(epilogue));
    String epilogueLine;

    try {
      while ((epilogueLine = epilogueReader.readLine()) != null) {
        ctcString =
            ctcString.concat(
                "\t\t" // INDENTATION
                    + epilogueLine
                    + "\n");
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    // CLOSE the CATCH BLOCK.
    // --------------------------------------------------------------------------------
    ctcString = ctcString.concat("}\n");
    ctcString = ctcString.concat("catch(Exception e){\n");
    ctcString = ctcString.concat("\te.printStackTrace(System.out);\n}");
    // --------------------------------------------------------------------------------
    // CLOSE the RUNTEST CLASS.
    // --------------------------------------------------------------------------------
    ctcString = ctcString.concat("\t");
    ctcString = ctcString.concat("}");
    ctcString = ctcString.concat("\n");
    // --------------------------------------------------------------------------------

    // --------------------------------------------------------------------------------
    // CLOSE the TEST CLASS.
    // --------------------------------------------------------------------------------
    ctcString = ctcString.concat("}");
    // --------------------------------------------------------------------------------

    return ctcString;
  }
Beispiel #5
0
  public static void printType(NodeType type) {
    if (type instanceof NodeSynonym) {
      System.out.println("NodeSynonym: " + ((NodeSynonym) type).getID());
    } // System.out.println("NodeSynonym: " + ((NodeSynonym)type).getType());
    else if (type instanceof NodePLType) {
      System.out.println("PLType: " + ((NodePLType) type).getType());
    } else if (type instanceof NodePointer) {
      System.out.println("Puntero a");
      System.out.print("  ");
      printType(((NodePointer) type).getType());
    } else if (type instanceof NodeArray) {
      System.out.print("Arreglo de tamaño " + ((NodeArray) type).getSize() + " de tipo: ");
      printType(((NodeArray) type).getType());
    } else if (type instanceof NodeStructure) {
      NodeStructure structure = (NodeStructure) type;
      // List<NodeElement>	elements =	record.getElements(); CHANGE
      List<NodeElement> elements = structure.getElements();
      Iterator<NodeElement> iter = elements.iterator();

      // System.out.println("Estructura: " + "Nombre: " + record.getName()); CHANGE
      System.out.println("Estructura: " + "Nombre: " + structure.getName());

      int i = 1;
      NodeElement element;

      while (iter.hasNext()) {
        element = iter.next();

        System.out.println("Campo " + i + ": ");
        i++;

        // System.out.println("Nombre: " + (element.getName())); CHANGE
        System.out.println("Nombre: " + (element.getID()));
        System.out.print("Tipo: ");
        printType(element.getType());
      }
    } else if (type instanceof NodeList) {
      NodeList list = (NodeList) type;
      // List<NodeField>		fields	=	list.getFields(); CHANGE
      List<NodeElement> fields = list.getFields();
      // Iterator<NodeField> iter	= fields.iterator(); CHANGE
      Iterator<NodeElement> iter = fields.iterator();

      System.out.println("Lista");
      System.out.println("Nombre: " + list.getName());
      System.out.println("LinkType: " + list.getLinkType());
      System.out.println("LinkNexName: " + list.getLinkNextName());

      if (list.getLinkPrevName() != null) {
        System.out.println("LinkPrevName: " + list.getLinkPrevName());
      }

      int i = 1;

      NodeElement field;
      while (iter.hasNext()) {
        field = iter.next();
        System.out.println("Campo " + i + ":");
        i++;
        // System.out.println("Nombre: " + (field.getName())); CHANGE
        System.out.println("Nombre: " + (field.getID()));
        System.out.print("Tipo: ");
        printType(field.getType());
      }
      // if (list.getMemalloc() != null ) CHANGE
      if (list.getMemAlloc() != null) {
        System.out.println("MemallocFunction: ");
        // System.out.println(list.getMemalloc()); CHANGE
        System.out.println(list.getMemAlloc());
      }
    } else if (type instanceof NodeFile) {
      NodeFile file = (NodeFile) type;

      System.out.println("Archivo");
      System.out.println("Nombre: " + file.getName());
      System.out.println("Ruta: " + file.getPath());
      System.out.println("Delimitador: " + file.getDelimiter());

      if (file.getEof() != null) {
        System.out.println("EOF: " + file.getEof());
      }
      if (file.getEol() != null) {
        System.out.println("EOL: " + file.getEol());
      }
      if (file.getStructure() != null) {
        System.out.println("Estructura: " + file.getStructure());
      }
    } else if (type instanceof NodeDB) {
      NodeDB db = (NodeDB) type;
      List<NodeDBColumn> regs = db.getColumns();
      Iterator<NodeDBColumn> iter = regs.iterator();

      System.out.println("Base de Datos");
      System.out.println("DBMS: " + db.getDBMSID());
      // System.out.println("connectionID "		+ db.getConnID()); CHANGE
      System.out.println("connectionID " + db.getConnectionID());

      // System.out.println("Table name: "		+ db.getTable()); CHANGE
      System.out.println("Table name: " + db.getTableName());
      System.out.println("Registros:");

      int i = 1;

      while (iter.hasNext()) {
        NodeDBColumn rec = iter.next();
        System.out.println(
            "Registro " + i + ": " + rec.getColType() + " tipo: " + rec.getColType());
        i++;
      }
    }
  }