source: proiecte/HadoopJUnit/hadoop-0.20.1/src/core/org/apache/hadoop/record/compiler/generated/Rcc.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 14.7 KB
Line 
1/* Generated By:JavaCC: Do not edit this line. Rcc.java */
2/**
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20package org.apache.hadoop.record.compiler.generated;
21
22import org.apache.hadoop.record.compiler.*;
23import java.util.ArrayList;
24import java.util.Hashtable;
25import java.util.Iterator;
26import java.io.File;
27import java.io.FileReader;
28import java.io.FileNotFoundException;
29import java.io.IOException;
30
31public class Rcc implements RccConstants {
32  private static String language = "java";
33  private static String destDir = ".";
34  private static ArrayList<String> recFiles = new ArrayList<String>();
35  private static ArrayList<String> cmdargs = new ArrayList<String>();
36  private static JFile curFile;
37  private static Hashtable<String,JRecord> recTab;
38  private static String curDir = ".";
39  private static String curFileName;
40  private static String curModuleName;
41
42  public static void main(String[] args) {
43    System.exit(driver(args));
44  }
45
46  public static void usage() {
47    System.err.println("Usage: rcc --language [java|c++] ddl-files");
48  }
49
50  public static int driver(String[] args) {
51    for (int i=0; i<args.length; i++) {
52      if ("-l".equalsIgnoreCase(args[i]) ||
53          "--language".equalsIgnoreCase(args[i])) {
54        language = args[i+1].toLowerCase();
55        i++;
56      } else if ("-d".equalsIgnoreCase(args[i]) ||
57                 "--destdir".equalsIgnoreCase(args[i])) {
58        destDir = args[i+1];
59        i++;
60      } else if (args[i].startsWith("-")) {
61        String arg = args[i].substring(1);
62        if (arg.startsWith("-")) {
63          arg = arg.substring(1);
64        }
65        cmdargs.add(arg.toLowerCase());
66      } else {
67        recFiles.add(args[i]);
68      }
69    }
70    if (recFiles.size() == 0) {
71      usage();
72      return 1;
73    }
74    for (int i=0; i<recFiles.size(); i++) {
75      curFileName = recFiles.get(i);
76      File file = new File(curFileName);
77      try {
78        FileReader reader = new FileReader(file);
79        Rcc parser = new Rcc(reader);
80        try {
81          recTab = new Hashtable<String,JRecord>();
82          curFile = parser.Input();
83        } catch (ParseException e) {
84          System.err.println(e.toString());
85          return 1;
86        }
87        try {
88          reader.close();
89        } catch (IOException e) {
90        }
91      } catch (FileNotFoundException e) {
92        System.err.println("File " + recFiles.get(i) +
93                           " Not found.");
94        return 1;
95      }
96      try {
97        int retCode = curFile.genCode(language, destDir, cmdargs);
98        if (retCode != 0) { return retCode; }
99      } catch (IOException e) {
100        System.err.println(e.toString());
101        return 1;
102      }
103    }
104    return 0;
105  }
106
107  final public JFile Input() throws ParseException {
108    ArrayList<JFile> ilist = new ArrayList<JFile>();
109    ArrayList<JRecord> rlist = new ArrayList<JRecord>();
110    JFile i;
111    ArrayList<JRecord> l;
112    label_1:
113    while (true) {
114      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
115      case INCLUDE_TKN:
116        i = Include();
117        ilist.add(i);
118        break;
119      case MODULE_TKN:
120        l = Module();
121        rlist.addAll(l);
122        break;
123      default:
124        jj_la1[0] = jj_gen;
125        jj_consume_token(-1);
126        throw new ParseException();
127      }
128      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
129      case MODULE_TKN:
130      case INCLUDE_TKN:
131        ;
132        break;
133      default:
134        jj_la1[1] = jj_gen;
135        break label_1;
136      }
137    }
138    jj_consume_token(0);
139    {if (true) return new JFile(curFileName, ilist, rlist);}
140    throw new Error("Missing return statement in function");
141  }
142
143  final public JFile Include() throws ParseException {
144    String fname;
145    Token t;
146    jj_consume_token(INCLUDE_TKN);
147    t = jj_consume_token(CSTRING_TKN);
148    JFile ret = null;
149    fname = t.image.replaceAll("^\"", "").replaceAll("\"$","");
150    File file = new File(curDir, fname);
151    String tmpDir = curDir;
152    String tmpFile = curFileName;
153    curDir = file.getParent();
154    curFileName = file.getName();
155    try {
156      FileReader reader = new FileReader(file);
157      Rcc parser = new Rcc(reader);
158      try {
159        ret = parser.Input();
160        System.out.println(fname + " Parsed Successfully");
161      } catch (ParseException e) {
162        System.out.println(e.toString());
163        System.exit(1);
164      }
165      try {
166        reader.close();
167      } catch (IOException e) {
168      }
169    } catch (FileNotFoundException e) {
170      System.out.println("File " + fname +
171                         " Not found.");
172      System.exit(1);
173    }
174    curDir = tmpDir;
175    curFileName = tmpFile;
176    {if (true) return ret;}
177    throw new Error("Missing return statement in function");
178  }
179
180  final public ArrayList<JRecord> Module() throws ParseException {
181    String mName;
182    ArrayList<JRecord> rlist;
183    jj_consume_token(MODULE_TKN);
184    mName = ModuleName();
185    curModuleName = mName;
186    jj_consume_token(LBRACE_TKN);
187    rlist = RecordList();
188    jj_consume_token(RBRACE_TKN);
189    {if (true) return rlist;}
190    throw new Error("Missing return statement in function");
191  }
192
193  final public String ModuleName() throws ParseException {
194    String name = "";
195    Token t;
196    t = jj_consume_token(IDENT_TKN);
197    name += t.image;
198    label_2:
199    while (true) {
200      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
201      case DOT_TKN:
202        ;
203        break;
204      default:
205        jj_la1[2] = jj_gen;
206        break label_2;
207      }
208      jj_consume_token(DOT_TKN);
209      t = jj_consume_token(IDENT_TKN);
210      name += "." + t.image;
211    }
212    {if (true) return name;}
213    throw new Error("Missing return statement in function");
214  }
215
216  final public ArrayList<JRecord> RecordList() throws ParseException {
217    ArrayList<JRecord> rlist = new ArrayList<JRecord>();
218    JRecord r;
219    label_3:
220    while (true) {
221      r = Record();
222      rlist.add(r);
223      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
224      case RECORD_TKN:
225        ;
226        break;
227      default:
228        jj_la1[3] = jj_gen;
229        break label_3;
230      }
231    }
232    {if (true) return rlist;}
233    throw new Error("Missing return statement in function");
234  }
235
236  final public JRecord Record() throws ParseException {
237    String rname;
238    ArrayList<JField<JType>> flist = new ArrayList<JField<JType>>();
239    Token t;
240    JField<JType> f;
241    jj_consume_token(RECORD_TKN);
242    t = jj_consume_token(IDENT_TKN);
243    rname = t.image;
244    jj_consume_token(LBRACE_TKN);
245    label_4:
246    while (true) {
247      f = Field();
248      flist.add(f);
249      jj_consume_token(SEMICOLON_TKN);
250      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
251      case BYTE_TKN:
252      case BOOLEAN_TKN:
253      case INT_TKN:
254      case LONG_TKN:
255      case FLOAT_TKN:
256      case DOUBLE_TKN:
257      case USTRING_TKN:
258      case BUFFER_TKN:
259      case VECTOR_TKN:
260      case MAP_TKN:
261      case IDENT_TKN:
262        ;
263        break;
264      default:
265        jj_la1[4] = jj_gen;
266        break label_4;
267      }
268    }
269    jj_consume_token(RBRACE_TKN);
270    String fqn = curModuleName + "." + rname;
271    JRecord r = new JRecord(fqn, flist);
272    recTab.put(fqn, r);
273    {if (true) return r;}
274    throw new Error("Missing return statement in function");
275  }
276
277  final public JField<JType> Field() throws ParseException {
278    JType jt;
279    Token t;
280    jt = Type();
281    t = jj_consume_token(IDENT_TKN);
282    {if (true) return new JField<JType>(t.image, jt);}
283    throw new Error("Missing return statement in function");
284  }
285
286  final public JType Type() throws ParseException {
287    JType jt;
288    Token t;
289    String rname;
290    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
291    case MAP_TKN:
292      jt = Map();
293      {if (true) return jt;}
294      break;
295    case VECTOR_TKN:
296      jt = Vector();
297      {if (true) return jt;}
298      break;
299    case BYTE_TKN:
300      jj_consume_token(BYTE_TKN);
301      {if (true) return new JByte();}
302      break;
303    case BOOLEAN_TKN:
304      jj_consume_token(BOOLEAN_TKN);
305      {if (true) return new JBoolean();}
306      break;
307    case INT_TKN:
308      jj_consume_token(INT_TKN);
309      {if (true) return new JInt();}
310      break;
311    case LONG_TKN:
312      jj_consume_token(LONG_TKN);
313      {if (true) return new JLong();}
314      break;
315    case FLOAT_TKN:
316      jj_consume_token(FLOAT_TKN);
317      {if (true) return new JFloat();}
318      break;
319    case DOUBLE_TKN:
320      jj_consume_token(DOUBLE_TKN);
321      {if (true) return new JDouble();}
322      break;
323    case USTRING_TKN:
324      jj_consume_token(USTRING_TKN);
325      {if (true) return new JString();}
326      break;
327    case BUFFER_TKN:
328      jj_consume_token(BUFFER_TKN);
329      {if (true) return new JBuffer();}
330      break;
331    case IDENT_TKN:
332      rname = ModuleName();
333      if (rname.indexOf('.', 0) < 0) {
334        rname = curModuleName + "." + rname;
335      }
336      JRecord r = recTab.get(rname);
337      if (r == null) {
338        System.out.println("Type " + rname + " not known. Exiting.");
339        System.exit(1);
340      }
341      {if (true) return r;}
342      break;
343    default:
344      jj_la1[5] = jj_gen;
345      jj_consume_token(-1);
346      throw new ParseException();
347    }
348    throw new Error("Missing return statement in function");
349  }
350
351  final public JMap Map() throws ParseException {
352    JType jt1;
353    JType jt2;
354    jj_consume_token(MAP_TKN);
355    jj_consume_token(LT_TKN);
356    jt1 = Type();
357    jj_consume_token(COMMA_TKN);
358    jt2 = Type();
359    jj_consume_token(GT_TKN);
360    {if (true) return new JMap(jt1, jt2);}
361    throw new Error("Missing return statement in function");
362  }
363
364  final public JVector Vector() throws ParseException {
365    JType jt;
366    jj_consume_token(VECTOR_TKN);
367    jj_consume_token(LT_TKN);
368    jt = Type();
369    jj_consume_token(GT_TKN);
370    {if (true) return new JVector(jt);}
371    throw new Error("Missing return statement in function");
372  }
373
374  public RccTokenManager token_source;
375  SimpleCharStream jj_input_stream;
376  public Token token, jj_nt;
377  private int jj_ntk;
378  private int jj_gen;
379  final private int[] jj_la1 = new int[6];
380  static private int[] jj_la1_0;
381  static private int[] jj_la1_1;
382  static {
383    jj_la1_0();
384    jj_la1_1();
385  }
386  private static void jj_la1_0() {
387    jj_la1_0 = new int[] {0x2800, 0x2800, 0x40000000, 0x1000, 0xffc000, 0xffc000,};
388  }
389  private static void jj_la1_1() {
390    jj_la1_1 = new int[] {0x0, 0x0, 0x0, 0x0, 0x1, 0x1,};
391  }
392
393  public Rcc(java.io.InputStream stream) {
394    this(stream, null);
395  }
396  public Rcc(java.io.InputStream stream, String encoding) {
397    try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
398    token_source = new RccTokenManager(jj_input_stream);
399    token = new Token();
400    jj_ntk = -1;
401    jj_gen = 0;
402    for (int i = 0; i < 6; i++) jj_la1[i] = -1;
403  }
404
405  public void ReInit(java.io.InputStream stream) {
406    ReInit(stream, null);
407  }
408  public void ReInit(java.io.InputStream stream, String encoding) {
409    try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
410    token_source.ReInit(jj_input_stream);
411    token = new Token();
412    jj_ntk = -1;
413    jj_gen = 0;
414    for (int i = 0; i < 6; i++) jj_la1[i] = -1;
415  }
416
417  public Rcc(java.io.Reader stream) {
418    jj_input_stream = new SimpleCharStream(stream, 1, 1);
419    token_source = new RccTokenManager(jj_input_stream);
420    token = new Token();
421    jj_ntk = -1;
422    jj_gen = 0;
423    for (int i = 0; i < 6; i++) jj_la1[i] = -1;
424  }
425
426  public void ReInit(java.io.Reader stream) {
427    jj_input_stream.ReInit(stream, 1, 1);
428    token_source.ReInit(jj_input_stream);
429    token = new Token();
430    jj_ntk = -1;
431    jj_gen = 0;
432    for (int i = 0; i < 6; i++) jj_la1[i] = -1;
433  }
434
435  public Rcc(RccTokenManager tm) {
436    token_source = tm;
437    token = new Token();
438    jj_ntk = -1;
439    jj_gen = 0;
440    for (int i = 0; i < 6; i++) jj_la1[i] = -1;
441  }
442
443  public void ReInit(RccTokenManager tm) {
444    token_source = tm;
445    token = new Token();
446    jj_ntk = -1;
447    jj_gen = 0;
448    for (int i = 0; i < 6; i++) jj_la1[i] = -1;
449  }
450
451  final private Token jj_consume_token(int kind) throws ParseException {
452    Token oldToken;
453    if ((oldToken = token).next != null) token = token.next;
454    else token = token.next = token_source.getNextToken();
455    jj_ntk = -1;
456    if (token.kind == kind) {
457      jj_gen++;
458      return token;
459    }
460    token = oldToken;
461    jj_kind = kind;
462    throw generateParseException();
463  }
464
465  final public Token getNextToken() {
466    if (token.next != null) token = token.next;
467    else token = token.next = token_source.getNextToken();
468    jj_ntk = -1;
469    jj_gen++;
470    return token;
471  }
472
473  final public Token getToken(int index) {
474    Token t = token;
475    for (int i = 0; i < index; i++) {
476      if (t.next != null) t = t.next;
477      else t = t.next = token_source.getNextToken();
478    }
479    return t;
480  }
481
482  final private int jj_ntk() {
483    if ((jj_nt=token.next) == null)
484      return (jj_ntk = (token.next=token_source.getNextToken()).kind);
485    else
486      return (jj_ntk = jj_nt.kind);
487  }
488
489  private java.util.Vector<int[]> jj_expentries = new java.util.Vector<int[]>();
490  private int[] jj_expentry;
491  private int jj_kind = -1;
492
493  public ParseException generateParseException() {
494    jj_expentries.removeAllElements();
495    boolean[] la1tokens = new boolean[33];
496    for (int i = 0; i < 33; i++) {
497      la1tokens[i] = false;
498    }
499    if (jj_kind >= 0) {
500      la1tokens[jj_kind] = true;
501      jj_kind = -1;
502    }
503    for (int i = 0; i < 6; i++) {
504      if (jj_la1[i] == jj_gen) {
505        for (int j = 0; j < 32; j++) {
506          if ((jj_la1_0[i] & (1<<j)) != 0) {
507            la1tokens[j] = true;
508          }
509          if ((jj_la1_1[i] & (1<<j)) != 0) {
510            la1tokens[32+j] = true;
511          }
512        }
513      }
514    }
515    for (int i = 0; i < 33; i++) {
516      if (la1tokens[i]) {
517        jj_expentry = new int[1];
518        jj_expentry[0] = i;
519        jj_expentries.addElement(jj_expentry);
520      }
521    }
522    int[][] exptokseq = new int[jj_expentries.size()][];
523    for (int i = 0; i < jj_expentries.size(); i++) {
524      exptokseq[i] = jj_expentries.elementAt(i);
525    }
526    return new ParseException(token, exptokseq, tokenImage);
527  }
528
529  final public void enable_tracing() {
530  }
531
532  final public void disable_tracing() {
533  }
534
535}
Note: See TracBrowser for help on using the repository browser.