View Javadoc

1   /*
2    * Copyright (c) 2001, Zoltan Farkas All Rights Reserved.
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this program; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17   */
18  package net.sf.zel.vm;
19  
20  import net.sf.zel.math.ExtendedMathContext;
21  
22  class TmpParsingContext implements ParsingContext
23  {
24  
25      /**
26       * Construct A TmpExprContext with the relay context
27       * @param ectx ExprContext
28       */
29      public TmpParsingContext(ParsingContext ectx)
30      {
31          this.ectx = ectx;
32      }
33      /**
34       * The relay context
35       */
36      final ParsingContext ectx;
37      /**
38       * The generated code
39       */
40      final ProgramBuilder code = new ProgramBuilder();
41  
42      /**
43       * generate instruction code with argument
44       *
45       * @param instr Instruction
46       * @param arg Object
47       */
48  
49      @Override
50      public final void generateCode(Object... args)
51      {          
52          if (args == null)
53              code.add(null);
54          else
55              code.addAll(args);
56  
57      }
58  
59      /**
60       * return the current code address
61       * @return
62       */
63      @Override
64      public int getAddress()
65      {
66          throw new UnsupportedOperationException("Not supported yet.");
67      }
68  
69      /**
70       * Relay processing to the relay context
71       * @param obj Object
72       */
73      @Override
74      public void process(Object obj)
75      {
76          ectx.process(obj);
77      }
78  
79      /**
80       * return code generated in this context
81       * @return Object[]
82       */
83      @Override
84      public ProgramBuilder getProgramBuilder()
85      {
86          return code;
87      }
88  
89      /**
90       * Emty implement don't need it now
91       * @param code Object[]
92       */
93      @Override
94      public void generateCodeAll(ParsingContext parsingContext)
95      {
96          this.code.addAll( parsingContext.getProgramBuilder() );
97      }
98  
99      @Override
100     public TmpParsingContext createSubContext()
101     {
102         return this;
103     }
104 
105     @Override
106     public ExtendedMathContext getMathContext()
107     {
108         return null;
109     }
110 
111     @Override
112     public void generateCodeAt(int address, Object... args)
113     {
114        if (args == null)
115             code.set(address, null);
116         else
117             code.setAll(address, args);
118     }
119 }