Пример #1
0
 private static void generateInterfaceStructs(Table table, PrintWriter outData) {
   if (table.fields.size() > 0) {
     if (table.comments.size() > 0) {
       for (int i = 0; i < table.comments.size(); i++) {
         String s = (String) table.comments.elementAt(i);
         outData.println("// " + s);
       }
     }
     generateInterfaceTableStructs(table.fields, table.useName(), outData);
     generateEnumOrdinals(table, outData);
   }
   for (int i = 0; i < table.procs.size(); i++) {
     Proc proc = (Proc) table.procs.elementAt(i);
     if (proc.isData || proc.isStd || proc.isStdExtended() || proc.hasNoData()) continue;
     if (proc.comments.size() > 0) {
       for (int j = 0; j < proc.comments.size(); j++) {
         String s = (String) proc.comments.elementAt(j);
         outData.println("// " + s);
       }
     }
     generateInterfaceStructPairs(proc, table.useName() + proc.upperFirst(), outData);
   }
 }
Пример #2
0
 /** Build of all required standard procedures */
 static void generateOther(Table table, String output, PrintWriter outLog) {
   for (int i = 0; i < table.procs.size(); i++) {
     Proc proc = (Proc) table.procs.elementAt(i);
     if (proc.isData || proc.isStd || proc.hasNoData()) continue;
     try {
       outLog.println("Code: " + output + table.useName() + proc.upperFirst() + ".cls");
       OutputStream outFile =
           new FileOutputStream(output + table.useName() + proc.upperFirst() + ".cls");
       try {
         PrintWriter outData = new PrintWriter(outFile);
         outData.println("VERSION 1.0 CLASS");
         outData.println("BEGIN");
         outData.println("  MultiUse = -1");
         outData.println("END");
         outData.println("ATTRIBUTE VB_NAME=\"t" + table.useName() + proc.upperFirst() + "\"");
         outData.println("Option explicit");
         outData.println(
             "' This code was generated, do not modify it, modify it at source and regenerate it.");
         for (int j = 0; j < proc.comments.size(); j++) {
           String comment = (String) proc.comments.elementAt(j);
           outData.println("'" + comment);
         }
         boolean hasMulti = true;
         if (proc.inputs.size() > 0) {}
         if (proc.outputs.size() == 0 || proc.isSingle == true) hasMulti = false;
         outData.println();
         outData.println("Private Type TRec");
         for (int j = 0; j < proc.inputs.size(); j++) {
           Field field = (Field) proc.inputs.elementAt(j);
           String io;
           if (!proc.hasOutput(field.name)) io = "input";
           else io = "input-output";
           outData.println("  " + varType(field) + " '" + io);
           for (int c = 0; c < field.comments.size(); c++) {
             String s = (String) field.comments.elementAt(c);
             outData.println("'" + s);
           }
           if (field.isNull && notString(field))
             outData.println("  " + field.useName() + "IsNull as Boolean");
         }
         for (int j = 0; j < proc.outputs.size(); j++) {
           Field field = (Field) proc.outputs.elementAt(j);
           if (!proc.hasInput(field.name)) {
             outData.println("  " + varType(field) + " 'output");
             for (int c = 0; c < field.comments.size(); c++) {
               String s = (String) field.comments.elementAt(c);
               outData.println("'" + s);
             }
             if (field.isNull && notString(field))
               outData.println("  " + field.useName() + "IsNull as Boolean");
           }
         }
         for (int j = 0; j < proc.dynamics.size(); j++) {
           String s = (String) proc.dynamics.elementAt(j);
           outData.println("  " + s + " As String 'dynamic");
         }
         outData.println("End Type");
         outData.println();
         if (hasMulti) {
           outData.println("Private Rec() as TRec");
           outData.println("Public RecCount as Long");
           outData.println("Private " + proc.name + "Cursor As TCursor");
         } else outData.println("Private Rec as TRec");
         outData.println();
         generateCopy(table.useName() + proc.upperFirst(), outData, hasMulti);
         String optZero = hasMulti ? "(0)" : "";
         String optIndex = hasMulti ? "Optional aIndex as Long" : "";
         String optIndex1 = hasMulti ? ", Optional aIndex as Long" : "";
         String optIndex2 = hasMulti ? "Optional aIndex as Long, " : "";
         String optUseIndex = hasMulti ? "(aIndex)" : "";
         outData.println("Private Sub Class_Initialize()");
         if (hasMulti) outData.println("  RecClear");
         for (int j = 0; j < proc.inputs.size(); j++) {
           Field field = (Field) proc.inputs.elementAt(j);
           outData.println("  Rec" + optZero + "." + initVBVar(field));
           if (field.isNull && notString(field))
             outData.println("  Rec" + optZero + "." + field.useName() + "IsNull = false");
         }
         for (int j = 0; j < proc.outputs.size(); j++) {
           Field field = (Field) proc.outputs.elementAt(j);
           if (proc.hasInput(field.name)) continue;
           outData.println("  Rec" + optZero + "." + initVBVar(field));
           if (field.isNull && notString(field))
             outData.println("  Rec" + optZero + "." + field.useName() + "IsNull = false");
         }
         for (int j = 0; j < proc.dynamics.size(); j++) {
           String s = (String) proc.dynamics.elementAt(j);
           outData.println("  Rec" + optZero + "." + s + " = \"\"");
         }
         outData.println("End Sub");
         outData.println();
         if (ioRoutines) {
           outData.println("Public Sub Class_PutFile(OutFile as Long" + optIndex1 + ")");
           outData.println("  Put OutFile,, Rec" + optUseIndex);
           outData.println("End Sub");
           outData.println();
           outData.println("Public Sub Class_GetFile(InFile as Long" + optIndex1 + ")");
           outData.println("  Get InFile,, Rec" + optUseIndex);
           outData.println("End Sub");
           outData.println();
         }
         for (int j = 0; j < proc.inputs.size(); j++) {
           Field field = (Field) proc.inputs.elementAt(j);
           generateProperties(field, outData, optIndex, optIndex2, optUseIndex);
         }
         for (int j = 0; j < proc.outputs.size(); j++) {
           Field field = (Field) proc.outputs.elementAt(j);
           if (proc.hasInput(field.name)) continue;
           generateProperties(field, outData, optIndex, optIndex2, optUseIndex);
         }
         for (int j = 0; j < proc.dynamics.size(); j++) {
           String s = (String) proc.dynamics.elementAt(j);
           outData.println("Public Property Get " + s + "(" + optIndex + ") as String");
           outData.println("  " + s + " = Rec" + optUseIndex + "." + s);
           outData.println("End Property");
           outData.println();
           outData.println("Public Property Let " + s + "(" + optIndex2 + "aValue as String)");
           outData.println("  Rec" + optUseIndex + "." + s + " = aValue");
           outData.println("End Property");
           outData.println();
         }
         emitCode(proc, outData, table.useName(), optIndex1, optUseIndex);
         outData.flush();
       } finally {
         outFile.close();
       }
     } catch (IOException e1) {
       outLog.println("Generate Procs IO Error");
     }
   }
 }
Пример #3
0
 /** Build of all required standard procedures */
 public static void generateStd(Table table, PrintWriter outData) {
   outData.println("VERSION 1.0 CLASS");
   outData.println("BEGIN");
   outData.println("  MultiUse = -1");
   outData.println("END");
   outData.println("ATTRIBUTE VB_NAME=\"T" + table.useName() + "\"");
   outData.println("Option explicit");
   outData.println(
       "' This code was generated, do not modify it, modify it at source and regenerate it.");
   for (int i = 0; i < table.comments.size(); i++) {
     String s = (String) table.comments.elementAt(i);
     outData.println("'" + s);
   }
   boolean hasMulti = false;
   for (int i = 0; i < table.procs.size(); i++) {
     Proc proc = (Proc) table.procs.elementAt(i);
     if (proc.isData || proc.hasNoData() || proc.isStd == false) continue;
     if (proc.inputs.size() > 0) {}
     if (proc.outputs.size() == 0 || proc.isSingle == true) continue;
     hasMulti = true;
     outData.println("Private " + proc.name + "Cursor As TCursor");
   }
   outData.println();
   outData.println("Private Type TRec");
   generateRec(table.fields, outData);
   outData.println("End Type");
   outData.println();
   if (hasMulti) {
     outData.println("Private Rec() as TRec");
     outData.println("Public RecCount as Long");
   } else outData.println("Private Rec as TRec");
   outData.println();
   generateCopy(table.useName(), outData, hasMulti);
   String optZero = hasMulti ? "(0)" : "";
   String optIndex = hasMulti ? "Optional aIndex as Long" : "";
   String optIndex1 = hasMulti ? ", Optional aIndex as Long" : "";
   String optIndex2 = hasMulti ? "Optional aIndex as Long, " : "";
   String optUseIndex = hasMulti ? "(aIndex)" : "";
   outData.println("Private Sub Class_Initialize()");
   outData.println("  RecClear");
   for (int i = 0; i < table.fields.size(); i++) {
     Field field = (Field) table.fields.elementAt(i);
     outData.println("  Rec" + optZero + "." + initVBVar(field));
     if (field.isNull && notString(field))
       outData.println("  Rec" + optZero + "." + field.useName() + "IsNull = false");
   }
   outData.println("End Sub");
   outData.println();
   if (ioRoutines) {
     outData.println("Public Sub Class_PutFile(OutFile as Long" + optIndex1 + ")");
     outData.println("  Put OutFile,, Rec" + optUseIndex);
     outData.println("End Sub");
     outData.println();
     outData.println("Public Sub Class_GetFile(InFile as Long" + optIndex1 + ")");
     outData.println("  Get InFile,, Rec" + optUseIndex);
     outData.println("End Sub");
     outData.println();
   }
   for (int i = 0; i < table.fields.size(); i++) {
     Field field = (Field) table.fields.elementAt(i);
     generateProperties(field, outData, optIndex, optIndex2, optUseIndex);
   }
   for (int i = 0; i < table.procs.size(); i++) {
     Proc proc = (Proc) table.procs.elementAt(i);
     if (proc.isData) continue;
     if (proc.hasNoData()) emitCode(proc, outData, table.useName(), "", "");
     else if (proc.isStd) emitCode(proc, outData, table.useName(), optIndex1, optUseIndex);
   }
 }
Пример #4
0
  /** Build of output data rec for user procedures */
  static void generateUserOutputRecs(Table table, PrintWriter outData) {
    for (int i = 0; i < table.procs.size(); i++) {
      Proc proc = (Proc) table.procs.elementAt(i);
      if (proc.isData || proc.isStd || proc.hasNoData()) continue;
      if (proc.isStdExtended()) continue;
      String work = "(object)";
      String superName = "";
      if (proc.outputs.size() > 0) {
        for (int j = 0; j < proc.comments.size(); j++)
          outData.println("##" + (String) proc.comments.elementAt(j));
        String typeChar = "D";
        if (proc.hasDiscreteInput()) typeChar = "O";
        work = "(" + typeChar + table.useName() + proc.upperFirst() + ")";
        superName = typeChar + table.useName() + proc.upperFirst();
        outData.println("## \\class " + typeChar + table.useName() + proc.upperFirst());
        outData.println("class " + typeChar + table.useName() + proc.upperFirst() + "(object):");
        outData.println(
            "    def _make(self): return " + typeChar + table.useName() + proc.upperFirst() + "()");
        if (proc.hasDiscreteInput())
          outData.println(
              "    def _name(self): return ('"
                  + typeChar
                  + table.useName()
                  + proc.upperFirst()
                  + "')");
        else
          outData.println(
              "    def _name(self): return ('D"
                  + table.useName()
                  + proc.upperFirst()
                  + "', 'O"
                  + table.useName()
                  + proc.upperFirst()
                  + "')");
        generateDataFields(
            proc.outputs,
            "",
            typeChar + table.useName() + proc.upperFirst(),
            table.useName(),
            outData);
        outData.println();
      }
      if (proc.hasDiscreteInput()) {
        outData.println("## \\class D" + table.useName() + proc.upperFirst());
        outData.println("class D" + table.useName() + proc.upperFirst() + work + ":");
        outData.println(
            "    def _make(self): return D" + table.useName() + proc.upperFirst() + "()");
        outData.println(
            "    def _name(self): return ('D" + table.useName() + proc.upperFirst() + "')");
        Vector<Field> discreteInputs = new Vector<Field>();
        for (int j = 0; j < proc.inputs.size(); j++) {
          Field field = (Field) proc.inputs.elementAt(j);
          if (!proc.hasOutput(field.name)) discreteInputs.addElement(field);
        }

        for (int j = 0; j < proc.dynamics.size(); j++) {
          Field f = new Field();
          Integer length = (Integer) proc.dynamicSizes.elementAt(j);
          f.name = (String) proc.dynamics.elementAt(j);
          f.type = Field.CHAR;
          f.length = length.intValue();
          discreteInputs.addElement(f);
        }
        generateDataFields(
            discreteInputs,
            superName,
            "D" + table.useName() + proc.upperFirst(),
            table.useName(),
            outData);
        outData.println();
      } else if (proc.outputs.size() > 0) {
        outData.println("## \\class O" + table.useName() + proc.upperFirst());
        outData.println("## \\field see:O" + table.useName() + proc.upperFirst());
        outData.println(
            "O"
                + table.useName()
                + proc.upperFirst()
                + " = D"
                + table.useName()
                + proc.upperFirst());
        outData.println();
      }
      if (pymodName.length() > 0) {
        coverFunctions = new Vector<String>();
        outData.println(
            "class "
                + table.useName()
                + proc.upperFirst()
                + "(D"
                + table.useName()
                + proc.upperFirst()
                + "):");
        outData.println(
            "    def __init__(self): D" + table.useName() + proc.upperFirst() + ".__init__(self)");
        if (proc.isMultipleInput) generateBulkAction(table, proc, outData);
        else if (proc.isInsert && proc.hasReturning) generateAction(table, proc, outData);
        else if (proc.outputs.size() > 0)
          if (proc.isSingle) generateSingle(table, proc, outData);
          else generateMultiple(table, proc, outData);
        else generateAction(table, proc, outData);
        outData.println();
        for (int j = 0; j < coverFunctions.size(); j++)
          outData.println((String) coverFunctions.elementAt(j));
      }
    }
  }