Return-Path: Delivered-To: apmail-lucene-hadoop-commits-archive@locus.apache.org Received: (qmail 4242 invoked from network); 4 May 2006 02:04:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 4 May 2006 02:04:46 -0000 Received: (qmail 65326 invoked by uid 500); 4 May 2006 02:04:46 -0000 Delivered-To: apmail-lucene-hadoop-commits-archive@lucene.apache.org Received: (qmail 65269 invoked by uid 500); 4 May 2006 02:04:45 -0000 Mailing-List: contact hadoop-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hadoop-dev@lucene.apache.org Delivered-To: mailing list hadoop-commits@lucene.apache.org Received: (qmail 65225 invoked by uid 99); 4 May 2006 02:04:45 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 May 2006 19:04:45 -0700 Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 03 May 2006 19:04:44 -0700 Received: (qmail 4153 invoked by uid 65534); 4 May 2006 02:04:23 -0000 Message-ID: <20060504020423.4151.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r399509 [3/5] - in /lucene/hadoop/trunk: ./ bin/ src/c++/ src/c++/librecordio/ src/c++/librecordio/test/ src/java/org/apache/hadoop/record/ src/java/org/apache/hadoop/record/compiler/ src/java/org/apache/hadoop/record/compiler/generated/ sr... Date: Thu, 04 May 2006 02:04:07 -0000 To: hadoop-commits@lucene.apache.org From: cutting@apache.org X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JFile.java URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JFile.java?rev=399509&view=auto ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JFile.java (added) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JFile.java Wed May 3 19:04:01 2006 @@ -0,0 +1,56 @@ +/** + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.record.compiler; + +import java.io.IOException; +import java.util.ArrayList; + +/** + * + * @author milindb@yahoo-inc.com + */ +public class JFile { + + private String mName; + private ArrayList mInclFiles; + private ArrayList mRecords; + + /** Creates a new instance of JFile */ + public JFile(String name, ArrayList inclFiles, ArrayList recList) { + mName = name; + mInclFiles = inclFiles; + mRecords = recList; + } + + String getName() { + int idx = mName.lastIndexOf('/'); + return (idx > 0) ? mName.substring(idx) : mName; + } + + public void genCode(String language) throws IOException { + if ("c++".equals(language)) { + CppGenerator gen = new CppGenerator(mName, mInclFiles, mRecords); + gen.genCode(); + } else if ("java".equals(language)) { + JavaGenerator gen = new JavaGenerator(mName, mInclFiles, mRecords); + gen.genCode(); + } else { + System.out.println("Cannnot recognize language:"+language); + System.exit(1); + } + } +} Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JFloat.java URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JFloat.java?rev=399509&view=auto ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JFloat.java (added) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JFloat.java Wed May 3 19:04:01 2006 @@ -0,0 +1,37 @@ +/** + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.record.compiler; + +/** + * + * @author milindb + */ +public class JFloat extends JType { + + /** Creates a new instance of JFloat */ + public JFloat() { + super("float", "float", "Float", "Float", "toFloat"); + } + + public String getSignature() { + return "f"; + } + + public String genJavaHashCode(String fname) { + return " ret = Float.floatToIntBits("+fname+");\n"; + } +} Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JInt.java URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JInt.java?rev=399509&view=auto ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JInt.java (added) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JInt.java Wed May 3 19:04:01 2006 @@ -0,0 +1,33 @@ +/** + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.record.compiler; + +/** + * + * @author milindb + */ +public class JInt extends JType { + + /** Creates a new instance of JInt */ + public JInt() { + super("int32_t", "int", "Int", "Integer", "toInt"); + } + + public String getSignature() { + return "i"; + } +} Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JLong.java URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JLong.java?rev=399509&view=auto ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JLong.java (added) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JLong.java Wed May 3 19:04:01 2006 @@ -0,0 +1,37 @@ +/** + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.record.compiler; + +/** + * + * @author milindb + */ +public class JLong extends JType { + + /** Creates a new instance of JLong */ + public JLong() { + super("int64_t", "long", "Long", "Long", "toLong"); + } + + public String getSignature() { + return "l"; + } + + public String genJavaHashCode(String fname) { + return " ret = (int) ("+fname+"^("+fname+">>>32));\n"; + } +} Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JMap.java URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JMap.java?rev=399509&view=auto ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JMap.java (added) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JMap.java Wed May 3 19:04:01 2006 @@ -0,0 +1,99 @@ +/** + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.record.compiler; + +/** + * + * @author milindb + */ +public class JMap extends JCompType { + + static private int level = 0; + + static private String getLevel() { return Integer.toString(level); } + + static private void incrLevel() { level++; } + + static private void decrLevel() { level--; } + + static private String getId(String id) { return id+getLevel(); } + + private JType mKey; + private JType mValue; + + /** Creates a new instance of JMap */ + public JMap(JType t1, JType t2) { + super(" ::std::map<"+t1.getCppType()+","+t2.getCppType()+">", + "java.util.TreeMap", "Map", "java.util.TreeMap"); + mKey = t1; + mValue = t2; + } + + public String getSignature() { + return "{" + mKey.getSignature() + mValue.getSignature() +"}"; + } + + public String genJavaCompareTo(String fname) { + return ""; + } + + public String genJavaReadWrapper(String fname, String tag, boolean decl) { + StringBuffer ret = new StringBuffer(""); + if (decl) { + ret.append(" java.util.TreeMap "+fname+";\n"); + } + ret.append(" {\n"); + incrLevel(); + ret.append(" org.apache.hadoop.record.Index "+getId("midx")+" = a_.startMap(\""+tag+"\");\n"); + ret.append(" "+fname+"=new java.util.TreeMap();\n"); + ret.append(" for (; !"+getId("midx")+".done(); "+getId("midx")+".incr()) {\n"); + ret.append(mKey.genJavaReadWrapper(getId("k"),getId("k"),true)); + ret.append(mValue.genJavaReadWrapper(getId("v"),getId("v"),true)); + ret.append(" "+fname+".put("+getId("k")+","+getId("v")+");\n"); + ret.append(" }\n"); + ret.append(" a_.endMap(\""+tag+"\");\n"); + decrLevel(); + ret.append(" }\n"); + return ret.toString(); + } + + public String genJavaReadMethod(String fname, String tag) { + return genJavaReadWrapper(fname, tag, false); + } + + public String genJavaWriteWrapper(String fname, String tag) { + StringBuffer ret = new StringBuffer(" {\n"); + incrLevel(); + ret.append(" a_.startMap("+fname+",\""+tag+"\");\n"); + ret.append(" java.util.Set "+getId("es")+" = "+fname+".entrySet();\n"); + ret.append(" for(java.util.Iterator "+getId("midx")+" = "+getId("es")+".iterator(); "+getId("midx")+".hasNext(); ) {\n"); + ret.append(" java.util.Map.Entry "+getId("me")+" = (java.util.Map.Entry) "+getId("midx")+".next();\n"); + ret.append(" "+mKey.getJavaWrapperType()+" "+getId("k")+" = ("+mKey.getJavaWrapperType()+") "+getId("me")+".getKey();\n"); + ret.append(" "+mValue.getJavaWrapperType()+" "+getId("v")+" = ("+mValue.getJavaWrapperType()+") "+getId("me")+".getValue();\n"); + ret.append(mKey.genJavaWriteWrapper(getId("k"),getId("k"))); + ret.append(mValue.genJavaWriteWrapper(getId("v"),getId("v"))); + ret.append(" }\n"); + ret.append(" a_.endMap("+fname+",\""+tag+"\");\n"); + ret.append(" }\n"); + decrLevel(); + return ret.toString(); + } + + public String genJavaWriteMethod(String fname, String tag) { + return genJavaWriteWrapper(fname, tag); + } +} Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JRecord.java URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JRecord.java?rev=399509&view=auto ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JRecord.java (added) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JRecord.java Wed May 3 19:04:01 2006 @@ -0,0 +1,384 @@ +/** + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.record.compiler; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; + +/** + * + * @author milindb + */ +public class JRecord extends JCompType { + + private String mFQName; + private String mName; + private String mModule; + private ArrayList mFields; + + /** + * Creates a new instance of JRecord + */ + public JRecord(String name, ArrayList flist) { + super(name.replaceAll("\\.","::"), name, "Record", name); + mFQName = name; + int idx = name.lastIndexOf('.'); + mName = name.substring(idx+1); + mModule = name.substring(0, idx); + mFields = flist; + } + + public String getName() { + return mName; + } + + public String getJavaFQName() { + return mFQName; + } + + public String getCppFQName() { + return mFQName.replaceAll("\\.", "::"); + } + + public String getJavaPackage() { + return mModule; + } + + public String getCppNameSpace() { + return mModule.replaceAll("\\.", "::"); + } + + public ArrayList getFields() { + return mFields; + } + + public String getSignature() { + StringBuffer sb = new StringBuffer(); + sb.append("L").append(mName).append("("); + for (Iterator i = mFields.iterator(); i.hasNext();) { + String s = ((JField) i.next()).getSignature(); + sb.append(s); + } + sb.append(")"); + return sb.toString(); + } + + public String genCppDecl(String fname) { + return " "+mName+" "+fname+";\n"; + } + + public String genJavaDecl (String fname) { + return " private "+mName+" "+fname+";\n"; + } + + public String genJavaReadWrapper(String fname, String tag, boolean decl) { + StringBuffer ret = new StringBuffer(""); + if (decl) { + ret.append(" "+getJavaFQName()+" "+fname+";\n"); + } + ret.append(" "+fname+"= new "+getJavaFQName()+"();\n"); + ret.append(" a_.readRecord("+fname+",\""+tag+"\");\n"); + return ret.toString(); + } + + public String genJavaWriteWrapper(String fname, String tag) { + return " a_.writeRecord("+fname+",\""+tag+"\");\n"; + } + + public void genCppCode(FileWriter hh, FileWriter cc) + throws IOException { + String[] ns = getCppNameSpace().split("::"); + for (int i = 0; i < ns.length; i++) { + hh.write("namespace "+ns[i]+" {\n"); + } + + hh.write("class "+getName()+" : public ::hadoop::Record {\n"); + hh.write("private:\n"); + + for (Iterator i = mFields.iterator(); i.hasNext();) { + JField jf = (JField) i.next(); + hh.write(jf.genCppDecl()); + } + hh.write(" std::bitset<"+mFields.size()+"> bs_;\n"); + hh.write("public:\n"); + hh.write(" virtual void serialize(::hadoop::OArchive& a_, const char* tag);\n"); + hh.write(" virtual void deserialize(::hadoop::IArchive& a_, const char* tag);\n"); + hh.write(" virtual const ::std::string& type() const;\n"); + hh.write(" virtual const ::std::string& signature() const;\n"); + hh.write(" virtual bool validate() const;\n"); + hh.write(" virtual bool operator<(const "+getName()+"& peer_);\n"); + hh.write(" virtual bool operator==(const "+getName()+"& peer_);\n"); + hh.write(" virtual ~"+getName()+"() {};\n"); + int fIdx = 0; + for (Iterator i = mFields.iterator(); i.hasNext(); fIdx++) { + JField jf = (JField) i.next(); + hh.write(jf.genCppGetSet(fIdx)); + } + hh.write("}; // end record "+getName()+"\n"); + for (int i=0; i", "java.util.ArrayList", "Vector", "java.util.ArrayList"); + mElement = t; + } + + public String getSignature() { + return "[" + mElement.getSignature() + "]"; + } + + public String genJavaCompareTo(String fname) { + return ""; + } + + public String genJavaReadWrapper(String fname, String tag, boolean decl) { + StringBuffer ret = new StringBuffer(""); + if (decl) { + ret.append(" java.util.ArrayList "+fname+";\n"); + } + ret.append(" {\n"); + incrLevel(); + ret.append(" org.apache.hadoop.record.Index "+getId("vidx")+" = a_.startVector(\""+tag+"\");\n"); + ret.append(" "+fname+"=new java.util.ArrayList();\n"); + ret.append(" for (; !"+getId("vidx")+".done(); "+getId("vidx")+".incr()) {\n"); + ret.append(mElement.genJavaReadWrapper(getId("e"), getId("e"), true)); + ret.append(" "+fname+".add("+getId("e")+");\n"); + ret.append(" }\n"); + ret.append(" a_.endVector(\""+tag+"\");\n"); + decrLevel(); + ret.append(" }\n"); + return ret.toString(); + } + + public String genJavaReadMethod(String fname, String tag) { + return genJavaReadWrapper(fname, tag, false); + } + + public String genJavaWriteWrapper(String fname, String tag) { + StringBuffer ret = new StringBuffer(" {\n"); + incrLevel(); + ret.append(" a_.startVector("+fname+",\""+tag+"\");\n"); + ret.append(" int "+getId("len")+" = "+fname+".size();\n"); + ret.append(" for(int "+getId("vidx")+" = 0; "+getId("vidx")+"<"+getId("len")+"; "+getId("vidx")+"++) {\n"); + ret.append(" "+mElement.getJavaWrapperType()+" "+getId("e")+" = ("+mElement.getJavaWrapperType()+") "+fname+".get("+getId("vidx")+");\n"); + ret.append(mElement.genJavaWriteWrapper(getId("e"), getId("e"))); + ret.append(" }\n"); + ret.append(" a_.endVector("+fname+",\""+tag+"\");\n"); + ret.append(" }\n"); + decrLevel(); + return ret.toString(); + } + + public String genJavaWriteMethod(String fname, String tag) { + return genJavaWriteWrapper(fname, tag); + } +} Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JavaGenerator.java URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JavaGenerator.java?rev=399509&view=auto ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JavaGenerator.java (added) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/JavaGenerator.java Wed May 3 19:04:01 2006 @@ -0,0 +1,47 @@ +/** + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.record.compiler; + +import java.util.ArrayList; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Iterator; + +/** + * + * @author milindb + */ +class JavaGenerator { + private String mName; + private ArrayList mInclFiles; + private ArrayList mRecList; + + /** Creates a new instance of JavaGenerator */ + JavaGenerator(String name, ArrayList incl, ArrayList records) { + mName = name; + mInclFiles = incl; + mRecList = records; + } + + public void genCode() throws IOException { + for (Iterator i = mRecList.iterator(); i.hasNext(); ) { + JRecord rec = (JRecord) i.next(); + rec.genJavaCode(); + } + } +} Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/generated/ParseException.java URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/generated/ParseException.java?rev=399509&view=auto ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/generated/ParseException.java (added) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/generated/ParseException.java Wed May 3 19:04:01 2006 @@ -0,0 +1,208 @@ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */ +/** + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.record.compiler.generated; + +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. The boolean + * flag "specialConstructor" is also set to true to indicate that + * this constructor was used to create this object. + * This constructor calls its super class with the empty string + * to force the "toString" method of parent class "Throwable" to + * print the error message in the form: + * ParseException: + */ + public ParseException(Token currentTokenVal, + int[][] expectedTokenSequencesVal, + String[] tokenImageVal + ) + { + super(""); + specialConstructor = true; + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + specialConstructor = false; + } + + public ParseException(String message) { + super(message); + specialConstructor = false; + } + + /** + * This variable determines which constructor was used to create + * this object and thereby affects the semantics of the + * "getMessage" method (see below). + */ + protected boolean specialConstructor; + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * This method has the standard behavior when this object has been + * created using the standard constructors. Otherwise, it uses + * "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser), then this method is called during the printing + * of the final stack trace, and hence the correct error message + * gets displayed. + */ + public String getMessage() { + if (!specialConstructor) { + return super.getMessage(); + } + StringBuffer expected = new StringBuffer(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) { + maxSize = expectedTokenSequences[i].length; + } + for (int j = 0; j < expectedTokenSequences[i].length; j++) { + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(" "); + } + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { + expected.append("..."); + } + expected.append(eol).append(" "); + } + String retval = "Encountered \""; + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + if (i != 0) retval += " "; + if (tok.kind == 0) { + retval += tokenImage[0]; + break; + } + retval += add_escapes(tok.image); + tok = tok.next; + } + retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; + retval += "." + eol; + if (expectedTokenSequences.length == 1) { + retval += "Was expecting:" + eol + " "; + } else { + retval += "Was expecting one of:" + eol + " "; + } + retval += expected.toString(); + return retval; + } + + /** + * The end of line string for this machine. + */ + protected String eol = System.getProperty("line.separator", "\n"); + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + protected String add_escapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + +} Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/generated/Rcc.java URL: http://svn.apache.org/viewcvs/lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/generated/Rcc.java?rev=399509&view=auto ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/generated/Rcc.java (added) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/record/compiler/generated/Rcc.java Wed May 3 19:04:01 2006 @@ -0,0 +1,517 @@ +/* Generated By:JavaCC: Do not edit this line. Rcc.java */ +/** + * Copyright 2005 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.record.compiler.generated; + +import org.apache.hadoop.record.compiler.*; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.io.File; +import java.io.FileReader; +import java.io.FileNotFoundException; +import java.io.IOException; + +public class Rcc implements RccConstants { + private static String language = "java"; + private static ArrayList recFiles = new ArrayList(); + private static JFile curFile; + private static Hashtable recTab; + private static String curDir = System.getProperty("user.dir"); + private static String curFileName; + private static String curModuleName; + + public static void main(String args[]) { + for (int i=0; i= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 6; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "\"//\"", + "", + "", + "\"/*\"", + "\"*/\"", + "", + "\"module\"", + "\"class\"", + "\"include\"", + "\"byte\"", + "\"boolean\"", + "\"int\"", + "\"long\"", + "\"float\"", + "\"double\"", + "\"ustring\"", + "\"buffer\"", + "\"vector\"", + "\"map\"", + "\"{\"", + "\"}\"", + "\"<\"", + "\">\"", + "\";\"", + "\",\"", + "\".\"", + "", + "", + }; + +}