private static void generateSingle(Table table, Proc proc, PrintWriter outData) {
   String dataStruct;
   if (proc.isStd || proc.isStdExtended()) dataStruct = table.useName();
   else dataStruct = table.useName() + proc.upperFirst();
   String parameters = "";
   boolean hasInput = (proc.inputs.size() > 0 || proc.dynamics.size() > 0);
   outData.println("    def " + proc.name + "(self):");
   outData.println("        ''' Single returns boolean and record");
   if (hasInput == true) {
     outData.println("        Input:");
     for (int f = 0; f < proc.inputs.size(); f++) {
       Field field = (Field) proc.inputs.elementAt(f);
       outData.println("            " + field.useName());
       parameters += ", " + field.useName() + "=" + defValue(field);
     }
     for (int f = 0; f < proc.dynamics.size(); f++) {
       String field = (String) proc.dynamics.elementAt(f);
       outData.println("            " + field);
       parameters += ", " + field + "=''";
     }
   }
   outData.println("        Output:");
   for (int f = 0; f < proc.outputs.size(); f++) {
     Field field = (Field) proc.outputs.elementAt(f);
     outData.println("            " + field.useName());
   }
   outData.println("        '''");
   outData.println(
       "        return " + pymodFront + table.useName() + proc.upperFirst() + "(self)");
   if (hasInput == true)
     generateInput(table.useName(), dataStruct, proc.name, parameters, outData);
   else generateCover(table.useName(), dataStruct, proc.name, outData);
 }
Exemple #2
0
 /**
  * Constructor.
  *
  * @param procs The procs
  * @param variables The variables.
  */
 public Program(final List<Proc> procs, final Variables variables) {
   for (final Proc proc : procs)
     if (!proc.isEmpty()) {
       this.procs.add(proc);
     }
   this.variables = variables;
 }
 /** Build of output data rec for standard procedures */
 static void generateStdOutputRec(Table table, PrintWriter outData) {
   for (int i = 0; i < table.comments.size(); i++) {
     String s = (String) table.comments.elementAt(i);
     outData.println("## " + s);
   }
   outData.println("## \\class D" + table.useName());
   outData.println("class D" + table.useName() + "(object):");
   outData.println("    def _make(self): return D" + table.useName() + "()");
   outData.println(
       "    def _name(self): return ('D" + table.useName() + "','O" + table.useName() + "')");
   generateDataFields(table.fields, "", "D" + table.useName(), table.useName(), outData);
   outData.println();
   outData.println("## \\class O" + table.useName());
   outData.println("## \\field see:D" + table.useName());
   outData.println("O" + table.useName() + " = D" + table.useName());
   outData.println();
   if (pymodName.length() > 0) {
     outData.println("class " + table.useName() + "(D" + table.useName() + "):");
     outData.println("    def __init__(self): D" + table.useName() + ".__init__(self)");
     coverFunctions = new Vector<String>();
     for (int i = 0; i < table.procs.size(); i++) {
       Proc proc = (Proc) table.procs.elementAt(i);
       if (proc.isData == true || (proc.isStd == false && proc.isStdExtended() == false)) continue;
       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 i = 0; i < coverFunctions.size(); i++)
       outData.println((String) coverFunctions.elementAt(i));
   }
 }
	/**
	 * Grammar production:
	 * f0 -> Label()
	 * f1 -> "["
	 * f2 -> IntegerLiteral()
	 * f3 -> "]"
	 * f4 -> StmtExp()
	 */
	public void visit(Procedure n, ARGU argu)
	{
		Proc currProc = ProcTable.SearchProc(n.f0.f0.toString());
        FuncBegin(n.f0.f0.toString(),(ARGU)currProc,currProc.GetParaNum(), currProc.GetMaxStack(), currProc.GetMaxPara());
		n.f4.accept(this, (ARGU)currProc);
		FuncEnd((ARGU)currProc, currProc.GetParaNum());
	}
	public void visit(Goal n,ARGU argu)
	{
		Proc currProc = ProcTable.SearchProc("MAIN");
		FuncBegin("MAIN",(ARGU)currProc, 0, currProc.GetMaxStack(), currProc.GetMaxPara());
        n.f1.accept(this,(ARGU)currProc);
        FuncEnd((ARGU)currProc, 0);
		n.f3.accept(this,(ARGU)currProc);
	}
Exemple #6
0
 @Override
 public String toString() {
   final StringBuilder builder = new StringBuilder();
   for (final Proc proc : this.procs) {
     builder.append(proc.toString());
     builder.append("\n");
   }
   return builder.toString();
 }
	   	public String WriteTemp(Temp n, ARGU argu,int vRegister)
	   {
         Proc currProc = (Proc)argu;
		 String t1 = currProc.GetReg(Integer.parseInt(n.f1.f0.tokenImage));
         if(t1.equals("OverFlow"))
		   return RegPlan.RegList[vRegister+4];
		 else//如果当前temp 占用寄存器的话
            return t1;
		
       }
	public String SimpleExpCode(SimpleExp n,ARGU argu,int vRegister)///////////////////////////
	{
		Proc currProc=(Proc)argu;
		switch(n.f0.which)
		{
			case 0:	return ReadTemp((Temp)n.f0.choice,argu, vRegister);
			case 1: return ((IntegerLiteral)n.f0.choice).f0.toString();
			case 2:return currProc.GetLab(((Label)n.f0.choice).f0.toString());
		}
		return null;
	}
		public String ReadTemp(Temp n,ARGU argu, int vRegister)
	   {
         Proc currProc = (Proc)argu;
		 String t1 = currProc.GetReg(Integer.parseInt(n.f1.f0.tokenImage));
		 if(t1.equals("OverFlow"))
		 {
		  	OutPut.con(" ALOAD " + RegPlan.RegList[vRegister+4] + " SPILLEDARG " +currProc.StackRecorder.indexOf(Integer.parseInt(n.f1.f0.tokenImage))+ "\n");
			return RegPlan.RegList[vRegister+4];
		 }
		 else//如果当前temp 要占用寄存器的话
            return t1;
	   }
	public void visit(Label n,  ARGU argu)
	{
		String s = n.f0.toString();
		if (argu==null)
		{
			OutPut.con(" "+s+" ");
		}
		else
		{
			Proc currProc=(Proc)argu;
			OutPut.con(" " +currProc.GetLab( s )+ " ");
		}
	}
	public void FuncEnd(ARGU argu,int ParaNum)
	{//函数结束,恢复所有的寄存器
		Proc currProc = (Proc)argu;
		Vector<String> Registers= currProc.TakenRegs();
		if(ParaNum-4>0)
		//如果参数数目大于4,因为大于4的参数在栈里面,所以恢复寄存器的时候要从f1-3开始往下恢复,f1代表参数数目
		  for(int i=ParaNum-4,j=0;i<ParaNum-4+Registers.size();i++,j++)
		   OutPut.con(" ALOAD " +  Registers.get(j) + " SPILLEDARG " + i + "\n");
		else//如果参数数目小于等于4,因为没有参数在栈里面,所以恢复寄存器的时候从0开始往下恢复即可
		  for(int i=0,j=0;i<Registers.size();i++,j++)
			OutPut.con(" ALOAD " +  Registers.get(j) + " SPILLEDARG " + i + "\n");	
		  OutPut.con("END\n");
	}
       	public void SpillToStack(Temp n, ARGU argu,int vRegister)
	    {//如果转换之前HLOAD的第一个寄存器是注定要溢出的,那么用v0或v1先存放HLOAD进来的值,然后把该值溢出到栈里
	     Proc currProc = (Proc)argu;
		 String t1 = currProc.GetReg(Integer.parseInt(n.f1.f0.tokenImage));
		 if(t1.equals("OverFlow"))
		 {
		   if( !currProc.StackRecorder.contains(Integer.parseInt(n.f1.f0.tokenImage)))
		   {
		    OutPut.con(" ASTORE " + " SPILLEDARG " + currProc.StackRecorder.size()+ " " + RegPlan.RegList[vRegister+4] + "\n");
		    currProc.StackRecorder.add(Integer.parseInt(n.f1.f0.tokenImage));
		   }
		   else  
			OutPut.con(" ASTORE " + " SPILLEDARG " + currProc.StackRecorder.indexOf(Integer.parseInt(n.f1.f0.tokenImage))+ " " + RegPlan.RegList[vRegister+4] + "\n");
		 }
		 return ;
	    }
Exemple #13
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    RequestDispatcher dispatcher =
        request.getRequestDispatcher(proc.selectResponse(request, response));
    dispatcher.forward(request, response);
  }
	/**
	 * Grammar production:
	 * f0 -> "HLOAD"
	 * f1 -> Temp()
	 * f2 -> Temp()
	 * f3 -> IntegerLiteral()
	 */
	public void visit(HLoadStmt n,ARGU argu)
	{
		Proc currProc = (Proc)argu;
		String t = currProc.GetReg(Integer.parseInt(n.f1.f1.f0.tokenImage));
        if(t==null)  
        {
    		OutPut.con(" NOOP \n");
        	return;
        }            
        String t1 = WriteTemp(n.f1,argu, 0);
		String t2 = ReadTemp(n.f2,argu, 0);
		OutPut.con(" HLOAD " + t1 + " " + t2 + " ");
		n.f3.accept(this, argu);
		OutPut.con("\n");
		SpillToStack(n.f1,argu,0);
	}
	/**
	 * Grammar production:
	 * f0 -> "MOVE"
	 * f1 -> Temp()
	 * f2 -> Exp()	
	 *				 Exp() Grammar production:
	 						* f0 -> Call()
	 						*       | HAllocate()
	 						*       | BinOp()
	 						*       | SimpleExp()
 */
	public void visit(MoveStmt n,ARGU argu)
	{
		Proc currProc = (Proc)argu;
		String t = currProc.GetReg(Integer.parseInt(n.f1.f1.f0.tokenImage));;
		if(t==null)                //************************************************
		{
			OutPut.con(" NOOP  \n" );
			return;
		}                        //*************************************************
		int i = n.f2.f0.which;
		
		if(i == 0)//是call语句
		{
			n.f2.accept(this, argu);
			OutPut.con("\n");
			String t1 = WriteTemp(n.f1,argu, 0);
			OutPut.con(" MOVE " + t1 + " v0\n" );
			SpillToStack(n.f1,argu,0);
			return;
		}
		else if(i == 1)//是HALLOCATE
		{
            String t1 = SimpleExpCode(((HAllocate)n.f2.f0.choice).f1, argu,0);//s1 返回的是个数值
			String t2 = WriteTemp(n.f1, argu, 0);
			OutPut.con(" MOVE " + t2 + " HALLOCATE " + t1 + "\n");
			SpillToStack(n.f1,argu,0);
			return;			
		}
		else if(i == 2)//是binop
		{
			String t1 = ReadTemp(((BinOp)n.f2.f0.choice).f1, argu, 0);//b.f1是个寄存器
			String t2 = SimpleExpCode(((BinOp)n.f2.f0.choice).f2, argu,1);//s1 返回的是个数值
			String t3 = WriteTemp(n.f1, argu, 0);
			OutPut.con(" MOVE " + t3 + " ");
			((BinOp)n.f2.f0.choice).f0.accept(this, argu);//b.f0是个运算符
			OutPut.con(" " + t1 + " " + t2 + "\n");
			SpillToStack(n.f1,argu,0);
	    }
		else if(i == 3)//是简单表达式
		{
            String t1 = WriteTemp(n.f1,argu, 0);
			String t2 = SimpleExpCode(((SimpleExp)n.f2.f0.choice), argu,0);//s1 返回的是个数值
			OutPut.con(" MOVE " + t1 + " " + t2 + "\n");
			SpillToStack(n.f1,argu,0);
		}
		return;		
	}
	/*public void visit(Call n, ARGU argu)////////////////////
	{
		int size = n.f3.size();
		int i;
		Proc currProc = (Proc)argu;
		Iterator<Node> Itr = n.f3.nodes.iterator();
		    if(currProc.ParaNum>4)//在call语句之后要恢复a0-a3,如果这个函数的参数数目大于4,那么(参数数目-4+使用的寄存器数目)->(参数数目+使用的寄存器数目+ParaStack)为存放a0->a3的栈单元
			 for(int k=0;k<currProc.ParaStack.size();k++)
			  OutPut.con(" ASTORE  "  + " SPILLEDARG "+(currProc.ParaNum-4+currProc.TakenRegs().size()+k)+" "+ currProc.ParaStack.get(k)+ "\n");
			else //如果这个函数的参数数目小于等于4,那么(使用的寄存器数目)->(使用的寄存器数目+ParaStack)为存放a0->a3的栈单元
			 for(int k=0;k<currProc.ParaStack.size();k++)
			  OutPut.con(" ASTORE  "  + " SPILLEDARG "+(currProc.TakenRegs().size()+k)+" "+ currProc.ParaStack.get(k)+ "\n");
		    
		    for(i=0;i<4&&i<size;i++)
		    {//将参数放在a0-a3里
		    	String t1 = ReadTemp((Temp)Itr.next(), argu, 0);
		    	if (t1.charAt(0)=='a')
		    	{
		    		String s =""+t1.charAt(1);
                    if(currProc.ParaNum>4)
			    	 OutPut.con("ALOAD v0 SPILLEDARG "+(currProc.ParaNum-4+currProc.TakenRegs().size()+ Integer.parseInt(s))+"\n");
                    else 
                     OutPut.con("ALOAD v0 SPILLEDARG "+(currProc.TakenRegs().size()+ Integer.parseInt(s))+"\n");
		    		OutPut.con("MOVE "+"a" +i+" v0\n");
		    	}
		    	else
		    	{
			    	OutPut.con(" MOVE " + "a" + i + " "+t1+"\n");
		    	}
		    }
		int j=1;
		for(;i<size;i++,j++)
		{//如果参数多于4个,都将其放到栈里
			String t1 = ReadTemp((Temp)Itr.next(),argu, 0);
			OutPut.con(" PASSARG " + j + " " + t1 +  "\n");
		}
		String t1 = SimpleExpCode(n.f1, argu,0);
		OutPut.con(" CALL " + t1 + "\n");
		if(currProc.ParaNum>4)//在call语句之后要恢复a0-a3,如果这个函数的参数数目大于4,那么(参数数目-4+使用的寄存器数目)->(参数数目+使用的寄存器数目+ParaStack)为存放a0->a3的栈单元
		 for(int k=0;k<currProc.ParaStack.size();k++)
		  OutPut.con(" ALOAD " + currProc.ParaStack.get(k) + " SPILLEDARG "+(currProc.ParaNum-4+currProc.TakenRegs().size()+k)+ "\n");
		else //如果这个函数的参数数目小于等于4,那么(使用的寄存器数目)->(使用的寄存器数目+ParaStack)为存放a0->a3的栈单元
		 for(int k=0;k<currProc.ParaStack.size();k++)
		  OutPut.con(" ALOAD " + currProc.ParaStack.get(k) + " SPILLEDARG "+(currProc.TakenRegs().size()+k)+ "\n");
		}*/
	public void visit(Call n, ARGU argu)////////////////////
	{
		int size = n.f3.size();
		int i;
		Proc currProc = (Proc)argu;
		Iterator<Node> Itr = n.f3.nodes.iterator();
		    if(currProc.ParaNum>4)//在call语句之后要恢复a0-a3,如果这个函数的参数数目大于4,那么(参数数目-4+使用的寄存器数目)->(参数数目+使用的寄存器数目+ParaStack)为存放a0->a3的栈单元
			 for(int k=0;k<currProc.ParaStack.size();k++)
			  OutPut.con(" ASTORE  "  + " SPILLEDARG "+(currProc.ParaNum-4+currProc.TakenRegs().size()+k)+" "+ currProc.ParaStack.get(k)+ "\n");
			else //如果这个函数的参数数目小于等于4,那么(使用的寄存器数目)->(使用的寄存器数目+ParaStack)为存放a0->a3的栈单元
			 for(int k=0;k<currProc.ParaStack.size();k++)
			  OutPut.con(" ASTORE  "  + " SPILLEDARG "+(currProc.TakenRegs().size()+k)+" "+ currProc.ParaStack.get(k)+ "\n");
		    
		    for(i=0;i<4&&i<size;i++)
		    {//将参数放在a0-a3里
		    	String t1 = ReadTemp((Temp)Itr.next(), argu, 0);
		    	if (t1.charAt(0)=='a')
		    	{
		    		String s =""+t1.charAt(1);
                    if(currProc.ParaNum>4)
			    	 OutPut.con("ALOAD v0 SPILLEDARG "+(currProc.ParaNum-4+currProc.TakenRegs().size()+ Integer.parseInt(s))+"\n");
                    else 
                     OutPut.con("ALOAD v0 SPILLEDARG "+(currProc.TakenRegs().size()+ Integer.parseInt(s))+"\n");
		    		OutPut.con("MOVE "+"a" +i+" v0\n");
		    	}
		    	else
		    	{
			    	OutPut.con(" MOVE " + "a" + i + " "+t1+"\n");
		    	}
		    }
		int j=1;
		for(;i<size;i++,j++)
		{//如果参数多于4个,都将其放到栈里
	    	String t1 = ReadTemp((Temp)Itr.next(), argu, 0);
	    	if (t1.charAt(0)=='a')
	    	{
	    		String s =""+t1.charAt(1);
                OutPut.con("ALOAD v0 SPILLEDARG "+(currProc.ParaNum-4+currProc.TakenRegs().size()+ Integer.parseInt(s))+"\n");
    			OutPut.con(" PASSARG " + j + " v0 \n");
	    	}
	    	else
	    	{
				OutPut.con(" PASSARG " + j + " " + t1 +  "\n");
	    	}
		//	String t1 = ReadTemp((Temp)Itr.next(),argu, 0);
		//	OutPut.con(" PASSARG " + j + " " + t1 +  "\n");
		}
		String t1 = SimpleExpCode(n.f1, argu,0);
		OutPut.con(" CALL " + t1 + "\n");
		if(currProc.ParaNum>4)//在call语句之后要恢复a0-a3,如果这个函数的参数数目大于4,那么(参数数目-4+使用的寄存器数目)->(参数数目+使用的寄存器数目+ParaStack)为存放a0->a3的栈单元
		 for(int k=0;k<currProc.ParaStack.size();k++)
		  OutPut.con(" ALOAD " + currProc.ParaStack.get(k) + " SPILLEDARG "+(currProc.ParaNum-4+currProc.TakenRegs().size()+k)+ "\n");
		else //如果这个函数的参数数目小于等于4,那么(使用的寄存器数目)->(使用的寄存器数目+ParaStack)为存放a0->a3的栈单元
		 for(int k=0;k<currProc.ParaStack.size();k++)
		  OutPut.con(" ALOAD " + currProc.ParaStack.get(k) + " SPILLEDARG "+(currProc.TakenRegs().size()+k)+ "\n");
		}
Exemple #17
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);
   }
 }
 private static void generateAction(Table table, Proc proc, PrintWriter outData) {
   String dataStruct;
   if (proc.isStd || proc.isStdExtended()) dataStruct = table.useName();
   else dataStruct = table.useName() + proc.upperFirst();
   String parameters = "";
   outData.println("    def " + proc.name + "(self):");
   outData.println("        ''' Action");
   outData.println("        Input:");
   for (int f = 0; f < proc.inputs.size(); f++) {
     Field field = (Field) proc.inputs.elementAt(f);
     outData.println("            " + field.useName());
     parameters += ", " + field.useName() + "=" + defValue(field);
   }
   for (int f = 0; f < proc.dynamics.size(); f++) {
     String field = (String) proc.dynamics.elementAt(f);
     outData.println("            " + field);
     parameters += ", " + field + "=''";
   }
   outData.println("        '''");
   outData.println(
       "        return " + pymodFront + table.useName() + proc.upperFirst() + "(self)");
   generateInput(table.useName(), dataStruct, proc.name, parameters, outData);
 }
	public void FuncBegin(String funcName,ARGU argu,int ParaNum, int MaxStack, int MaxPara)
	{//函数开始,保存所有的寄存器
		Proc currProc = (Proc)argu;
		Vector<String> Registers= currProc.TakenRegs();
		OutPut.con(funcName + " [ " + ParaNum + " ] [ " + MaxStack + " ] [ " +MaxPara+ " ]\n");
		for(int i=4;i<ParaNum;i++)
	      currProc.StackRecorder.add(i);//放父函数传进来的参数
		if(ParaNum-4>0)//如果参数数目大于4,因为大于4的参数都要放到栈里面,所以存放寄存器的栈要接着存放参数的栈单元即为f1-3的位置往下增长,这里f1代表参数数目
		{
		 int i,j;
		 for(i=ParaNum-4,j=0;i<ParaNum-4+Registers.size();i++,j++)
		 {
		   OutPut.con(" ASTORE " + " SPILLEDARG " + i + " " + Registers.get(j) + "\n");
		   currProc.StackRecorder.add(-1);
		 }//存放所有使用的寄存器但除了a0-a3,因为不是temp溢出,所以不用存放temp号,这里用-1代替temp号
		 for(j=0;j<currProc.ParaStack.size();j++,i++)
		 {
		   OutPut.con(" ASTORE " + " SPILLEDARG " + i + " " + currProc.ParaStack.get(j) + "\n");
		   currProc.StackRecorder.add(-1);
		 }//存放a0->a3,因为不是temp溢出,所以不用存放temp号,这里用-1代替temp号
		}
		else
		{
			int i,j; 
		   for(i=0,j=0;i<Registers.size();i++,j++)
		  {
		    OutPut.con(" ASTORE " + " SPILLEDARG " + i + " " + Registers.get(j) + "\n");	
		    currProc.StackRecorder.add(-1);
		  }//如果参数数目小于等于4,因为参数都不放到栈里面,所以存放寄存器的栈从0开始增长即可
		  for(j=0;j<currProc.ParaStack.size();j++,i++)
		  {
			OutPut.con(" ASTORE " + " SPILLEDARG " + i + " " + currProc.ParaStack.get(j) + "\n");
		    currProc.StackRecorder.add(-1);
		  }//存放a0->a3,因为不是temp溢出,所以不用存放temp号,这里用-1代替temp号
		}
	}
 private static void generateBulkAction(Table table, Proc proc, PrintWriter outData) {
   outData.println("    def " + proc.name + "(self, recs):");
   outData.println("        ''' Bulk Action");
   outData.println("        Input:");
   for (int f = 0; f < proc.inputs.size(); f++) {
     Field field = (Field) proc.inputs.elementAt(f);
     outData.println("            " + field.useName());
   }
   for (int f = 0; f < proc.dynamics.size(); f++) {
     String field = (String) proc.dynamics.elementAt(f);
     outData.println("            " + field);
   }
   outData.println("        '''");
   outData.println(
       "        " + pymodFront + table.useName() + proc.upperFirst() + "(len(recs), recs)");
 }
  /** 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));
      }
    }
  }
Exemple #22
0
  @Override
  public byte[] compile() {
    final ByteArrayOutputStream stream;
    final int[] offsets = new int[255];
    int ptr, procNo, procOffsets;

    try {
      // Get the procs from the program and validate the quantity
      final Proc[] procs = getProcs();
      final int procsCount = procs.length;
      if (procs.length > 255)
        throw new CompileException("More than " + 255 + " procs are not allowed");

      // Create the byte array output stream to write the binary to
      stream = new ByteArrayOutputStream();
      ptr = 0;

      // Write number of procs
      stream.write(procsCount);
      ptr++;

      // Write place holders for proc start addresses and wait counters
      procOffsets = ptr;
      for (int i = 0; i < procsCount; i++) {
        stream.write(0);
        stream.write(0);
        stream.write(0);
        stream.write(0);
        stream.write(0);
        stream.write(0);
        ptr += 6;
      }

      // Write number of variables
      final byte[] varStatsCode = this.variables.compileStats();
      stream.write(varStatsCode);
      ptr += varStatsCode.length;

      // Write variables
      final byte[] varCode = this.variables.compileValues();
      stream.write(varCode);
      ptr += varCode.length;

      // Write place holder for code size
      final int codeSizeOffset = ptr;
      int codeSize = 0;
      stream.write(0);
      stream.write(0);
      ptr += 2;

      // Write the procs and update the start addresses
      procNo = 0;
      for (final Proc proc : procs) {
        offsets[procNo] = ptr;
        final byte[] procCode = proc.compile();
        try {
          stream.write(procCode);
        } catch (final IOException e) {
          throw new CompileException(e.toString(), e);
        }
        ptr += procCode.length;
        codeSize += procCode.length;
        procNo++;
      }

      final byte[] progCode = stream.toByteArray();

      // Update the offsets
      for (int i = 0; i < procsCount; i++) {
        final int offset = offsets[i];

        progCode[procOffsets + i * 6] = (byte) (offset & 0xff);
        progCode[procOffsets + i * 6 + 1] = (byte) (offset >> 8);

        progCode[procOffsets + i * 6 + 2] = (byte) (offset & 0xff);
        progCode[procOffsets + i * 6 + 3] = (byte) (offset >> 8);
      }

      // Update code size
      progCode[codeSizeOffset] = (byte) (codeSize & 0xff);
      progCode[codeSizeOffset + 1] = (byte) (codeSize >> 8);

      return progCode;
    } catch (final IOException e) {
      throw new CompileException("IO error occured during compiling: " + e, e);
    }
  }
Exemple #23
0
 @Override
 public void init() throws ServletException {
   super.init();
   proc = new Proc();
   System.out.println("proc is connected: " + proc.isConnected());
 }
Exemple #24
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");
     }
   }
 }
Exemple #25
0
 private static void generateImplementationStructPairs(
     Proc proc, String mainName, PrintWriter outData) {
   if (proc.outputs.size() > 0) {
     outData.println("@implementation O" + mainName + "Rec");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       if (field.type == Field.BLOB) {
         outData.println("@synthesize " + useLowerName(field) + "_len;");
         outData.println("@synthesize " + useLowerName(field) + "_data;");
       } else outData.println("@synthesize " + useLowerName(field) + ";");
       if (isNull(field) == true)
         outData.println("@synthesize " + useLowerName(field) + "IsNull;");
     }
     outData.println("- (id)init");
     outData.println("  {");
     outData.println("    self = [super init];");
     outData.println("    return self;");
     outData.println("  }");
     outData.println("- (void)clear");
     outData.println("  {");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       clearCall(field, outData);
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println("    self." + useLowerName(field) + "IsNull = NO;");
     }
     outData.println("  }");
     outData.println("- (void)write:(Writer*)writer");
     outData.println("  {");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       writeCall(field, outData);
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println(
             "    [writer putBoolean:self." + useLowerName(field) + "IsNull];[writer filler:6];");
     }
     outData.println("  }");
     outData.println("- (void)read:(Reader*)reader");
     outData.println("  {");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       readCall(field, outData);
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println(
             "    self." + useLowerName(field) + "IsNull = [reader getBoolean];[reader skip:6];");
     }
     outData.println("  }");
     outData.println("- (void)dealloc");
     outData.println("  {");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       freeCall(field, outData);
     }
     outData.println("    [super dealloc];");
     outData.println("  }");
     outData.println("@end");
     outData.println();
   }
   if (proc.inputs.size() + proc.dynamics.size() > 0) {
     outData.println("@implementation D" + mainName + "Rec");
     for (int i = 0; i < proc.inputs.size(); i++) {
       Field field = (Field) proc.inputs.elementAt(i);
       if (proc.hasOutput(field.name)) continue;
       if (field.type == Field.BLOB) {
         outData.println("@synthesize " + useLowerName(field) + "_len;");
         outData.println("@synthesize " + useLowerName(field) + "_data;");
       } else outData.println("@synthesize " + useLowerName(field) + ";");
       if (isNull(field) == true)
         outData.println("@synthesize " + useLowerName(field) + "IsNull;");
     }
     for (int i = 0; i < proc.dynamics.size(); i++) {
       String name = (String) proc.dynamics.elementAt(i);
       Field field = new Field();
       field.name = name;
       outData.println("@synthesize " + useLowerName(field) + ";");
     }
     outData.println("- (id)init");
     outData.println("  {");
     outData.println("    self = [super init];");
     outData.println("    return self;");
     outData.println("  }");
     outData.println("- (void)clear");
     outData.println("  {");
     if (proc.outputs.size() > 0) outData.println("    [super clear];");
     for (int i = 0; i < proc.inputs.size(); i++) {
       Field field = (Field) proc.inputs.elementAt(i);
       clearCall(field, outData);
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println("    self." + useLowerName(field) + "IsNull = NO;");
     }
     for (int i = 0; i < proc.dynamics.size(); i++) {
       Field field = new Field();
       field.name = (String) proc.dynamics.elementAt(i);
       field.length = ((Integer) proc.dynamicSizes.elementAt(i)).intValue();
       field.type = Field.CHAR;
       clearCall(field, outData);
     }
     outData.println("  }");
     outData.println("- (void)write:(Writer*)writer");
     outData.println("  {");
     if (proc.outputs.size() > 0) outData.println("    [super write:writer];");
     for (int i = 0; i < proc.inputs.size(); i++) {
       Field field = (Field) proc.inputs.elementAt(i);
       writeCall(field, outData);
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println(
             "    [writer putBoolean:self." + useLowerName(field) + "IsNull];[writer filler:6];");
     }
     for (int i = 0; i < proc.dynamics.size(); i++) {
       Field field = new Field();
       field.name = (String) proc.dynamics.elementAt(i);
       field.length = ((Integer) proc.dynamicSizes.elementAt(i)).intValue();
       field.type = Field.CHAR;
       writeCall(field, outData);
     }
     outData.println("  }");
     outData.println("- (void)read:(Reader*)reader");
     outData.println("  {");
     if (proc.outputs.size() > 0) outData.println("    [super read:reader];");
     for (int i = 0; i < proc.inputs.size(); i++) {
       Field field = (Field) proc.inputs.elementAt(i);
       readCall(field, outData);
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println(
             "    self." + useLowerName(field) + "IsNull = [reader getBoolean];[reader skip:6];");
     }
     for (int i = 0; i < proc.dynamics.size(); i++) {
       Field field = new Field();
       field.name = (String) proc.dynamics.elementAt(i);
       field.length = ((Integer) proc.dynamicSizes.elementAt(i)).intValue();
       field.type = Field.CHAR;
       readCall(field, outData);
     }
     outData.println("  }");
     outData.println("- (void)dealloc");
     outData.println("  {");
     for (int i = 0; i < proc.dynamics.size(); i++) {
       Field field = new Field();
       field.name = (String) proc.dynamics.elementAt(i);
       outData.println("    [" + useLowerName(field) + " release];");
     }
     outData.println("    [super dealloc];");
     outData.println("  }");
     outData.println("@end");
     outData.println();
   }
 }
Exemple #26
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);
   }
 }
 /** Prints a child proc to standard out. */
 private void print(String prefix) {
   System.out.println(prefix + "id=" + id + ", name=" + name);
   for (Proc child : children) {
     child.print(prefix + "    ");
   }
 }
Exemple #28
0
 /** Emits functions for processing the database activity */
 static void emitCode(
     Proc proc, PrintWriter outData, String tableName, String optIndex, String optUseIndex) {
   if (proc.outputs.size() == 0) {
     outData.println("Public Sub " + proc.upperFirst() + "(Connect as TConnect" + optIndex + ")");
   } else if (proc.isSingle)
     outData.println(
         "Public Function "
             + proc.upperFirst()
             + "(Connect as TConnect"
             + optIndex
             + ") as Boolean");
   else {
     outData.println("Public Sub " + proc.upperFirst() + "(Connect as TConnect)");
     if (optUseIndex != "") optUseIndex = "(0)";
   }
   if (proc.comments.size() > 0) {
     for (int i = 0; i < proc.comments.size(); i++) {
       String comment = (String) proc.comments.elementAt(i);
       outData.println("'" + comment);
     }
   }
   if (proc.outputs.size() == 0) {
     outData.println("' Returns no output.");
   } else if (proc.isSingle) {
     outData.println("  Dim RS as RecordSet");
     outData.println("  " + proc.upperFirst() + " = False");
   } else {
     outData.println("  Set " + proc.upperFirst() + "Cursor = new TCursor");
   }
   outData.println("  Connect.RoutineName = \"" + proc.upperFirst() + "\"");
   outData.println("  Dim QD as QueryDef");
   for (int index = 0; index < proc.inputs.size(); index++) {
     Field field = (Field) proc.inputs.elementAt(index);
     if (proc.isInsert) {
       if (field.isSequence)
         outData.println(
             "  Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + " = getSequence(\""
                 + tableName
                 + "\") ' User supplied Function for Sequences");
     }
     if (field.type == Field.TIMESTAMP)
       outData.println(
           "  Rec"
               + optUseIndex
               + "."
               + field.useName()
               + " = getTimeStamp ' User supplied Function for Time Stamp");
     if (field.type == Field.USERSTAMP)
       outData.println(
           "  Rec"
               + optUseIndex
               + "."
               + field.useName()
               + " = getUserStamp ' User supplied Function for User Stamp");
   }
   outData.print("  Set QD = Connect.DB.CreateQueryDef(\"\", ");
   String vbline = "";
   for (int i = 0; i < proc.lines.size(); i++) {
     String x = "";
     if (i + 1 < proc.lines.size()) x = " & ";
     Line l = (Line) proc.lines.elementAt(i);
     if (l.isVar) vbline = vbline + l.line + x;
     else vbline = vbline + "\"" + l.line + "\"" + x;
   }
   int p;
   while ((p = vbline.indexOf("\" & \"")) > -1)
     vbline = vbline.substring(0, p) + vbline.substring(p + 5);
   if (proc.placeHolders.size() > 0) {
     for (int i = 0; i < proc.placeHolders.size(); i++) {
       String placeHolder = ":" + (String) proc.placeHolders.elementAt(i);
       String work = "";
       int n = vbline.indexOf(placeHolder);
       if (n == -1) {
         outData.println("Error with placeholders " + placeHolder);
         break;
       }
       if (n > 0) work = vbline.substring(0, n);
       work = work + "?";
       n += placeHolder.length();
       if (n < vbline.length()) ;
       work = work + vbline.substring(n);
       vbline = work;
     }
     outData.println(vbline + ")");
     for (int i = 0, pos = 0; i < proc.placeHolders.size(); i++) {
       String placeHolder = (String) proc.placeHolders.elementAt(i);
       int index = proc.indexOf(placeHolder);
       pos = emitInputCode(proc, index, pos, outData, optUseIndex);
     }
   } else {
     outData.println(vbline + ")");
     for (int index = 0, pos = 0; index < proc.inputs.size(); index++)
       pos = emitInputCode(proc, index, pos, outData, optUseIndex);
   }
   if (proc.outputs.size() == 0) {
     outData.println("  QD.execute");
     outData.println("  QD.Close");
   } else if (proc.isSingle) {
     outData.println("  Set RS = QD.OpenRecordSet(dbOpenSnapShot, dbForwardOnly and dbReadOnly)");
     outData.println("  If Not RS.eof Then");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       if (field.isNull && notString(field)) {
         outData.println(
             "    Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + "IsNull = isNull(RS!"
                 + field.name
                 + ")");
         outData.println(
             "    If Not Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + "IsNull Then Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + " = RS!"
                 + field.name);
       } else
         outData.println("    Rec" + optUseIndex + "." + field.useName() + " =  RS!" + field.name);
     }
     outData.println("    " + proc.upperFirst() + " = True");
     outData.println("  End If");
     outData.println("  RS.Close");
     outData.println("  QD.Close");
   } else {
     outData.println("  Set " + proc.upperFirst() + "Cursor.Connect = Connect");
     outData.println("  Set " + proc.upperFirst() + "Cursor.QD = QD");
     outData.println(
         "  Set "
             + proc.upperFirst()
             + "Cursor.RS = "
             + proc.upperFirst()
             + "Cursor.QD.openRecordSet(dbOpenSnapShot, dbForwardOnly and dbReadOnly)");
   }
   if (proc.isSingle) outData.println("End Function");
   else outData.println("End Sub");
   outData.println();
   if (proc.outputs.size() > 0 && !proc.isSingle) {
     outData.println("Public Function next" + proc.upperFirst() + "() as Boolean");
     outData.println(
         "  If "
             + proc.upperFirst()
             + "Cursor Is Nothing Then Err.Raise 1998, \""
             + proc.upperFirst()
             + "\"");
     outData.println(
         "  "
             + proc.upperFirst()
             + "Cursor.Connect.RoutineName = \"next"
             + proc.upperFirst()
             + "\"");
     outData.println("  next" + proc.upperFirst() + " = False");
     outData.println("  If Not " + proc.upperFirst() + "Cursor.RS.eof Then");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       if (field.isNull && notString(field)) {
         outData.println(
             "    Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + "IsNull = isNull("
                 + proc.upperFirst()
                 + "Cursor.RS!"
                 + field.name
                 + ")");
         outData.println(
             "    If Not Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + "IsNull Then Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + " = "
                 + proc.upperFirst()
                 + "Cursor.RS!"
                 + field.name);
       } else
         outData.println(
             "    Rec"
                 + optUseIndex
                 + "."
                 + field.useName()
                 + " = "
                 + proc.upperFirst()
                 + "Cursor.RS!"
                 + field.name);
     }
     outData.println("    next" + proc.upperFirst() + " = True");
     outData.println("    " + proc.upperFirst() + "Cursor.RS.MoveNext");
     outData.println("  Else");
     outData.println("    " + proc.upperFirst() + "Cursor.RS.Close");
     outData.println("  End If");
     outData.println("End Function");
     outData.println();
     outData.println("Public Sub cancel" + proc.upperFirst() + "()");
     outData.println(
         "  if " + proc.upperFirst() + "Cursor.isOpen then " + proc.upperFirst() + "Cursor.Done");
     outData.println("End Sub");
     outData.println();
     outData.println(
         "Public Sub load" + proc.upperFirst() + "(Connect as TConnect, Optional Max As Long)");
     outData.println("  Dim AllocCount As Long");
     outData.println("  AllocCount = 64");
     outData.println("  ReDim Rec(0 to AllocCount)");
     outData.println("  " + proc.upperFirst() + " Connect");
     outData.println("  Do While next" + proc.upperFirst() + "()");
     outData.println("    RecCount = RecCount + 1");
     outData.println("    If RecCount > AllocCount Then");
     outData.println("      AllocCount = AllocCount * 2");
     outData.println("      ReDim Preserve Rec(0 to AllocCount)");
     outData.println("    End If");
     outData.println("    Rec(RecCount) = Rec(0)");
     outData.println("    If RecCount = Max Then");
     outData.println("      cancel" + proc.upperFirst() + "");
     outData.println("      Exit Do");
     outData.println("    End If");
     outData.println("  Loop");
     outData.println("  ReDim Preserve Rec(0 to RecCount)");
     outData.println("End Sub");
     outData.println();
   }
 }
Exemple #29
0
 private static void generateInterfaceStructPairs(
     Proc proc, String mainName, PrintWriter outData) {
   if (proc.outputs.size() > 0) {
     outData.println("@interface O" + mainName + "Rec:NSObject");
     outData.println("{");
     outData.println(" @protected");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       outData.println("  " + fieldDef(field));
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println("  BOOL " + useLowerName(field) + "IsNull;");
     }
     outData.println("}");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       if (field.type == Field.BLOB) {
         outData.println("@property (readwrite) int32 " + useLowerName(field) + "_len;");
         outData.println("@property (retain) NSMutableData* " + useLowerName(field) + "_data;");
       } else outData.println("@property (" + fieldProp(field) + ") " + fieldDef(field));
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println("@property (readwrite) BOOL " + useLowerName(field) + "IsNull;");
     }
     outData.println("- (id)init;");
     outData.println("- (void)clear;");
     outData.println("- (void)write:(Writer*)writer;");
     outData.println("- (void)read:(Reader*)reader;");
     outData.println("- (void)dealloc;");
     outData.println("@end");
     if (proc.inputs.size() + proc.dynamics.size() == 0)
       outData.println("#define D" + mainName + "Rec O" + mainName + "Rec");
     outData.println();
   }
   if (proc.inputs.size() + proc.dynamics.size() > 0) {
     if (proc.outputs.size() > 0)
       outData.println("@interface D" + mainName + "Rec:O" + mainName + "Rec");
     else outData.println("@interface D" + mainName + "Rec:NSObject");
     outData.println("{");
     outData.println(" @protected");
     for (int j = 0; j < proc.inputs.size(); j++) {
       Field field = (Field) proc.inputs.elementAt(j);
       if (proc.hasOutput(field.name)) continue;
       outData.println("  " + fieldDef(field));
       if (isNull(field) == true) outData.println("  BOOL " + useLowerName(field) + "IsNull;");
     }
     for (int j = 0; j < proc.dynamics.size(); j++) {
       String s = (String) proc.dynamics.elementAt(j);
       Integer n = (Integer) proc.dynamicSizes.elementAt(j);
       Field field = new Field();
       field.name = s;
       field.type = Field.CHAR;
       field.length = n.intValue();
       outData.println("  " + fieldDef(field));
     }
     outData.println("}");
     for (int j = 0; j < proc.inputs.size(); j++) {
       Field field = (Field) proc.inputs.elementAt(j);
       if (proc.hasOutput(field.name)) continue;
       if (field.type == Field.BLOB) {
         outData.println("@property (readwrite) int32 " + useLowerName(field) + "_len;");
         outData.println("@property (retain) NSMutableData* " + useLowerName(field) + "_data;");
       } else outData.println("@property (" + fieldProp(field) + ") " + fieldDef(field));
       if (isNull(field) == true)
         outData.println("@property (readwrite) BOOL " + useLowerName(field) + "IsNull;");
     }
     for (int j = 0; j < proc.dynamics.size(); j++) {
       String s = (String) proc.dynamics.elementAt(j);
       Field field = new Field();
       field.name = s;
       outData.println("@property (retain) NSString* " + useLowerName(field) + ";");
     }
     outData.println("- (id)init;");
     outData.println("- (void)clear;");
     outData.println("- (void)write:(Writer*)writer;");
     outData.println("- (void)read:(Reader*)reader;");
     outData.println("- (void)dealloc;");
     outData.println("@end");
     if (proc.outputs.size() == 0)
       outData.println("#define O" + mainName + "Rec D" + mainName + "Rec");
     outData.println();
   }
 }