001/* Generated By:JavaCC: Do not edit this line. Rcc.java */
002/**
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020package org.apache.hadoop.record.compiler.generated;
021
022import org.apache.hadoop.classification.InterfaceAudience;
023import org.apache.hadoop.classification.InterfaceStability;
024import org.apache.hadoop.record.compiler.*;
025import java.util.ArrayList;
026import java.util.Hashtable;
027import java.io.File;
028import java.io.FileReader;
029import java.io.FileNotFoundException;
030import java.io.IOException;
031import org.apache.hadoop.util.StringUtils;
032
033/**
034 * @deprecated Replaced by <a href="https://hadoop.apache.org/avro/">Avro</a>.
035 */
036@Deprecated
037@InterfaceAudience.Public
038@InterfaceStability.Stable
039public class Rcc implements RccConstants {
040  private static String language = "java";
041  private static String destDir = ".";
042  private static ArrayList<String> recFiles = new ArrayList<String>();
043  private static ArrayList<String> cmdargs = new ArrayList<String>();
044  private static JFile curFile;
045  private static Hashtable<String,JRecord> recTab;
046  private static String curDir = ".";
047  private static String curFileName;
048  private static String curModuleName;
049
050  public static void main(String[] args) {
051    System.exit(driver(args));
052  }
053
054  public static void usage() {
055    System.err.println("Usage: rcc --language [java|c++] ddl-files");
056  }
057
058  public static int driver(String[] args) {
059    for (int i=0; i<args.length; i++) {
060      if ("-l".equalsIgnoreCase(args[i]) ||
061          "--language".equalsIgnoreCase(args[i])) {
062        language = StringUtils.toLowerCase(args[i+1]);
063        i++;
064      } else if ("-d".equalsIgnoreCase(args[i]) ||
065                 "--destdir".equalsIgnoreCase(args[i])) {
066        destDir = args[i+1];
067        i++;
068      } else if (args[i].startsWith("-")) {
069        String arg = args[i].substring(1);
070        if (arg.startsWith("-")) {
071          arg = arg.substring(1);
072        }
073        cmdargs.add(StringUtils.toLowerCase(arg));
074      } else {
075        recFiles.add(args[i]);
076      }
077    }
078    if (recFiles.size() == 0) {
079      usage();
080      return 1;
081    }
082    for (int i=0; i<recFiles.size(); i++) {
083      curFileName = recFiles.get(i);
084      File file = new File(curFileName);
085      try {
086        FileReader reader = new FileReader(file);
087        Rcc parser = new Rcc(reader);
088        try {
089          recTab = new Hashtable<String,JRecord>();
090          curFile = parser.Input();
091        } catch (ParseException e) {
092          System.err.println(e.toString());
093          return 1;
094        }
095        try {
096          reader.close();
097        } catch (IOException e) {
098        }
099      } catch (FileNotFoundException e) {
100        System.err.println("File " + recFiles.get(i) +
101                           " Not found.");
102        return 1;
103      }
104      try {
105        int retCode = curFile.genCode(language, destDir, cmdargs);
106        if (retCode != 0) { return retCode; }
107      } catch (IOException e) {
108        System.err.println(e.toString());
109        return 1;
110      }
111    }
112    return 0;
113  }
114
115  final public JFile Input() throws ParseException {
116    ArrayList<JFile> ilist = new ArrayList<JFile>();
117    ArrayList<JRecord> rlist = new ArrayList<JRecord>();
118    JFile i;
119    ArrayList<JRecord> l;
120    label_1:
121    while (true) {
122      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
123      case INCLUDE_TKN:
124        i = Include();
125        ilist.add(i);
126        break;
127      case MODULE_TKN:
128        l = Module();
129        rlist.addAll(l);
130        break;
131      default:
132        jj_la1[0] = jj_gen;
133        jj_consume_token(-1);
134        throw new ParseException();
135      }
136      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
137      case MODULE_TKN:
138      case INCLUDE_TKN:
139        ;
140        break;
141      default:
142        jj_la1[1] = jj_gen;
143        break label_1;
144      }
145    }
146    jj_consume_token(0);
147    {if (true) return new JFile(curFileName, ilist, rlist);}
148    throw new Error("Missing return statement in function");
149  }
150
151  final public JFile Include() throws ParseException {
152    String fname;
153    Token t;
154    jj_consume_token(INCLUDE_TKN);
155    t = jj_consume_token(CSTRING_TKN);
156    JFile ret = null;
157    fname = t.image.replaceAll("^\"", "").replaceAll("\"$","");
158    File file = new File(curDir, fname);
159    String tmpDir = curDir;
160    String tmpFile = curFileName;
161    curDir = file.getParent();
162    curFileName = file.getName();
163    try {
164      FileReader reader = new FileReader(file);
165      Rcc parser = new Rcc(reader);
166      try {
167        ret = parser.Input();
168        System.out.println(fname + " Parsed Successfully");
169      } catch (ParseException e) {
170        System.out.println(e.toString());
171        System.exit(1);
172      }
173      try {
174        reader.close();
175      } catch (IOException e) {
176      }
177    } catch (FileNotFoundException e) {
178      System.out.println("File " + fname +
179                         " Not found.");
180      System.exit(1);
181    }
182    curDir = tmpDir;
183    curFileName = tmpFile;
184    {if (true) return ret;}
185    throw new Error("Missing return statement in function");
186  }
187
188  final public ArrayList<JRecord> Module() throws ParseException {
189    String mName;
190    ArrayList<JRecord> rlist;
191    jj_consume_token(MODULE_TKN);
192    mName = ModuleName();
193    curModuleName = mName;
194    jj_consume_token(LBRACE_TKN);
195    rlist = RecordList();
196    jj_consume_token(RBRACE_TKN);
197    {if (true) return rlist;}
198    throw new Error("Missing return statement in function");
199  }
200
201  final public String ModuleName() throws ParseException {
202    String name = "";
203    Token t;
204    t = jj_consume_token(IDENT_TKN);
205    name += t.image;
206    label_2:
207    while (true) {
208      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
209      case DOT_TKN:
210        ;
211        break;
212      default:
213        jj_la1[2] = jj_gen;
214        break label_2;
215      }
216      jj_consume_token(DOT_TKN);
217      t = jj_consume_token(IDENT_TKN);
218      name += "." + t.image;
219    }
220    {if (true) return name;}
221    throw new Error("Missing return statement in function");
222  }
223
224  final public ArrayList<JRecord> RecordList() throws ParseException {
225    ArrayList<JRecord> rlist = new ArrayList<JRecord>();
226    JRecord r;
227    label_3:
228    while (true) {
229      r = Record();
230      rlist.add(r);
231      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
232      case RECORD_TKN:
233        ;
234        break;
235      default:
236        jj_la1[3] = jj_gen;
237        break label_3;
238      }
239    }
240    {if (true) return rlist;}
241    throw new Error("Missing return statement in function");
242  }
243
244  final public JRecord Record() throws ParseException {
245    String rname;
246    ArrayList<JField<JType>> flist = new ArrayList<JField<JType>>();
247    Token t;
248    JField<JType> f;
249    jj_consume_token(RECORD_TKN);
250    t = jj_consume_token(IDENT_TKN);
251    rname = t.image;
252    jj_consume_token(LBRACE_TKN);
253    label_4:
254    while (true) {
255      f = Field();
256      flist.add(f);
257      jj_consume_token(SEMICOLON_TKN);
258      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
259      case BYTE_TKN:
260      case BOOLEAN_TKN:
261      case INT_TKN:
262      case LONG_TKN:
263      case FLOAT_TKN:
264      case DOUBLE_TKN:
265      case USTRING_TKN:
266      case BUFFER_TKN:
267      case VECTOR_TKN:
268      case MAP_TKN:
269      case IDENT_TKN:
270        ;
271        break;
272      default:
273        jj_la1[4] = jj_gen;
274        break label_4;
275      }
276    }
277    jj_consume_token(RBRACE_TKN);
278    String fqn = curModuleName + "." + rname;
279    JRecord r = new JRecord(fqn, flist);
280    recTab.put(fqn, r);
281    {if (true) return r;}
282    throw new Error("Missing return statement in function");
283  }
284
285  final public JField<JType> Field() throws ParseException {
286    JType jt;
287    Token t;
288    jt = Type();
289    t = jj_consume_token(IDENT_TKN);
290    {if (true) return new JField<JType>(t.image, jt);}
291    throw new Error("Missing return statement in function");
292  }
293
294  final public JType Type() throws ParseException {
295    JType jt;
296    Token t;
297    String rname;
298    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
299    case MAP_TKN:
300      jt = Map();
301      {if (true) return jt;}
302      break;
303    case VECTOR_TKN:
304      jt = Vector();
305      {if (true) return jt;}
306      break;
307    case BYTE_TKN:
308      jj_consume_token(BYTE_TKN);
309      {if (true) return new JByte();}
310      break;
311    case BOOLEAN_TKN:
312      jj_consume_token(BOOLEAN_TKN);
313      {if (true) return new JBoolean();}
314      break;
315    case INT_TKN:
316      jj_consume_token(INT_TKN);
317      {if (true) return new JInt();}
318      break;
319    case LONG_TKN:
320      jj_consume_token(LONG_TKN);
321      {if (true) return new JLong();}
322      break;
323    case FLOAT_TKN:
324      jj_consume_token(FLOAT_TKN);
325      {if (true) return new JFloat();}
326      break;
327    case DOUBLE_TKN:
328      jj_consume_token(DOUBLE_TKN);
329      {if (true) return new JDouble();}
330      break;
331    case USTRING_TKN:
332      jj_consume_token(USTRING_TKN);
333      {if (true) return new JString();}
334      break;
335    case BUFFER_TKN:
336      jj_consume_token(BUFFER_TKN);
337      {if (true) return new JBuffer();}
338      break;
339    case IDENT_TKN:
340      rname = ModuleName();
341      if (rname.indexOf('.', 0) < 0) {
342        rname = curModuleName + "." + rname;
343      }
344      JRecord r = recTab.get(rname);
345      if (r == null) {
346        System.out.println("Type " + rname + " not known. Exiting.");
347        System.exit(1);
348      }
349      {if (true) return r;}
350      break;
351    default:
352      jj_la1[5] = jj_gen;
353      jj_consume_token(-1);
354      throw new ParseException();
355    }
356    throw new Error("Missing return statement in function");
357  }
358
359  final public JMap Map() throws ParseException {
360    JType jt1;
361    JType jt2;
362    jj_consume_token(MAP_TKN);
363    jj_consume_token(LT_TKN);
364    jt1 = Type();
365    jj_consume_token(COMMA_TKN);
366    jt2 = Type();
367    jj_consume_token(GT_TKN);
368    {if (true) return new JMap(jt1, jt2);}
369    throw new Error("Missing return statement in function");
370  }
371
372  final public JVector Vector() throws ParseException {
373    JType jt;
374    jj_consume_token(VECTOR_TKN);
375    jj_consume_token(LT_TKN);
376    jt = Type();
377    jj_consume_token(GT_TKN);
378    {if (true) return new JVector(jt);}
379    throw new Error("Missing return statement in function");
380  }
381
382  public RccTokenManager token_source;
383  SimpleCharStream jj_input_stream;
384  public Token token, jj_nt;
385  private int jj_ntk;
386  private int jj_gen;
387  final private int[] jj_la1 = new int[6];
388  static private int[] jj_la1_0;
389  static private int[] jj_la1_1;
390  static {
391    jj_la1_0();
392    jj_la1_1();
393  }
394  private static void jj_la1_0() {
395    jj_la1_0 = new int[] {0x2800, 0x2800, 0x40000000, 0x1000, 0xffc000, 0xffc000,};
396  }
397  private static void jj_la1_1() {
398    jj_la1_1 = new int[] {0x0, 0x0, 0x0, 0x0, 0x1, 0x1,};
399  }
400
401  public Rcc(java.io.InputStream stream) {
402    this(stream, null);
403  }
404  public Rcc(java.io.InputStream stream, String encoding) {
405    try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
406    token_source = new RccTokenManager(jj_input_stream);
407    token = new Token();
408    jj_ntk = -1;
409    jj_gen = 0;
410    for (int i = 0; i < 6; i++) jj_la1[i] = -1;
411  }
412
413  public void ReInit(java.io.InputStream stream) {
414    ReInit(stream, null);
415  }
416  public void ReInit(java.io.InputStream stream, String encoding) {
417    try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
418    token_source.ReInit(jj_input_stream);
419    token = new Token();
420    jj_ntk = -1;
421    jj_gen = 0;
422    for (int i = 0; i < 6; i++) jj_la1[i] = -1;
423  }
424
425  public Rcc(java.io.Reader stream) {
426    jj_input_stream = new SimpleCharStream(stream, 1, 1);
427    token_source = new RccTokenManager(jj_input_stream);
428    token = new Token();
429    jj_ntk = -1;
430    jj_gen = 0;
431    for (int i = 0; i < 6; i++) jj_la1[i] = -1;
432  }
433
434  public void ReInit(java.io.Reader stream) {
435    jj_input_stream.ReInit(stream, 1, 1);
436    token_source.ReInit(jj_input_stream);
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 Rcc(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  public void ReInit(RccTokenManager tm) {
452    token_source = tm;
453    token = new Token();
454    jj_ntk = -1;
455    jj_gen = 0;
456    for (int i = 0; i < 6; i++) jj_la1[i] = -1;
457  }
458
459  final private Token jj_consume_token(int kind) throws ParseException {
460    Token oldToken;
461    if ((oldToken = token).next != null) token = token.next;
462    else token = token.next = token_source.getNextToken();
463    jj_ntk = -1;
464    if (token.kind == kind) {
465      jj_gen++;
466      return token;
467    }
468    token = oldToken;
469    jj_kind = kind;
470    throw generateParseException();
471  }
472
473  final public Token getNextToken() {
474    if (token.next != null) token = token.next;
475    else token = token.next = token_source.getNextToken();
476    jj_ntk = -1;
477    jj_gen++;
478    return token;
479  }
480
481  final public Token getToken(int index) {
482    Token t = token;
483    for (int i = 0; i < index; i++) {
484      if (t.next != null) t = t.next;
485      else t = t.next = token_source.getNextToken();
486    }
487    return t;
488  }
489
490  final private int jj_ntk() {
491    if ((jj_nt=token.next) == null)
492      return (jj_ntk = (token.next=token_source.getNextToken()).kind);
493    else
494      return (jj_ntk = jj_nt.kind);
495  }
496
497  private java.util.Vector<int[]> jj_expentries = new java.util.Vector<int[]>();
498  private int[] jj_expentry;
499  private int jj_kind = -1;
500
501  public ParseException generateParseException() {
502    jj_expentries.removeAllElements();
503    boolean[] la1tokens = new boolean[33];
504    for (int i = 0; i < 33; i++) {
505      la1tokens[i] = false;
506    }
507    if (jj_kind >= 0) {
508      la1tokens[jj_kind] = true;
509      jj_kind = -1;
510    }
511    for (int i = 0; i < 6; i++) {
512      if (jj_la1[i] == jj_gen) {
513        for (int j = 0; j < 32; j++) {
514          if ((jj_la1_0[i] & (1<<j)) != 0) {
515            la1tokens[j] = true;
516          }
517          if ((jj_la1_1[i] & (1<<j)) != 0) {
518            la1tokens[32+j] = true;
519          }
520        }
521      }
522    }
523    for (int i = 0; i < 33; i++) {
524      if (la1tokens[i]) {
525        jj_expentry = new int[1];
526        jj_expentry[0] = i;
527        jj_expentries.addElement(jj_expentry);
528      }
529    }
530    int[][] exptokseq = new int[jj_expentries.size()][];
531    for (int i = 0; i < jj_expentries.size(); i++) {
532      exptokseq[i] = jj_expentries.elementAt(i);
533    }
534    return new ParseException(token, exptokseq, tokenImage);
535  }
536
537  final public void enable_tracing() {
538  }
539
540  final public void disable_tracing() {
541  }
542
543}