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