diff options
author | Sven Gothel <[email protected]> | 2014-06-17 03:12:28 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-06-17 03:12:28 +0200 |
commit | afb698ac3846713e5000226de9e28a9b06bf6f9a (patch) | |
tree | 83f795d0d9023ac022fe9b7af35f819125b79f17 | |
parent | c3054a01990e55ab35756ea23ab7d7c05f24dd37 (diff) | |
parent | 5d802fb8dd4004039d4597253712d24fffb90a36 (diff) |
Merge remote-tracking branch 'hharrison/antlr-move'
15 files changed, 93 insertions, 104 deletions
diff --git a/make/build.xml b/make/build.xml index 8791d76..1308f18 100644 --- a/make/build.xml +++ b/make/build.xml @@ -58,6 +58,7 @@ <!-- The source and build directories. --> <property name="project.root" value=".." /> <property name="src.java" value="${project.root}/src/java" /> + <property name="src.antlr" value="${project.root}/src/main/antlr" /> <property name="build" location="${project.root}/${rootrel.build}" /> <property name="javadoc.root.path" location="${build}/javadoc" /> <property name="javadoc.gluegen.path" location="${javadoc.root.path}/gluegen/javadoc" /> @@ -116,15 +117,13 @@ </path> <!-- The location of the GlueGen source and the C grammar files. --> - <property name="gluegen" value="${src.java}/com/jogamp/gluegen" /> - <property name="c.grammar" value="${gluegen}/cgram" /> - <property name="j.grammar" value="${gluegen}/jgram" /> + <property name="c.grammar" value="${src.antlr}/com/jogamp/gluegen/cgram" /> + <property name="j.grammar" value="${src.antlr}/com/jogamp/gluegen/jgram" /> <!-- The resulting location of the generated Java files from the - C grammar via ANTLR. --> - <property name="gluegen.build" value="${src.generated.java}/com/jogamp/gluegen" /> - <property name="generated.java.from.c.grammar" value="${gluegen.build}/cgram" /> - <property name="generated.java.from.j.grammar" value="${gluegen.build}/jgram" /> + <property name="c.grammar.out.dir" value="${src.generated.java}/com/jogamp/gluegen/cgram" /> + <property name="j.grammar.out.dir" value="${src.generated.java}/com/jogamp/gluegen/jgram" /> <property name="tools.jar" value="${java.home}/../lib/tools.jar"/> @@ -158,36 +157,6 @@ </target> <target name="init.debug" depends="set.debug, init"/> - <!-- - - Using ANTLR generate the specified Java files. - - - - @param target the grammar file to process - - @param output.dir the directory to write the generated files to. If - - the directory does not exist, it will be created. - --> - <target name="generate.grammar"> - <!-- Generate the Java files --> - <antlr target="${output.dir}/${target}" outputdirectory="${output.dir}"> - <classpath refid="antlr.classpath" /> - </antlr> - </target> - - <!-- - - Using ANTLR generate the specified Java files with an overridden - - grammar file. - - - - @param target the grammar file to process - - @param glib the overridding grammar file - - @param output.dir the directory to write the generated files to. If - - the directory does not exist, it will be created. - --> - <target name="generate.c.grammar.glib"> - <!-- Generate the Java files --> - <antlr target="${output.dir}/${target}" glib="${output.dir}/${glib}" outputdirectory="${output.dir}"> - <classpath refid="antlr.classpath" /> - </antlr> - </target> - <property name="gluegen.root" value="../" /> <!-- Use GlueGen to generate the source code for the ElfHeader @@ -631,15 +600,15 @@ <uptodate property="gluegen.build.skip.java1"> <srcfiles dir= "." includes="*.xml"/> <srcfiles dir= "${src.java}" includes="**"/> - <srcfiles dir= "${c.grammar}" includes="**/*.g"/> - <srcfiles dir= "${j.grammar}" includes="**/*.g"/> + <srcfiles dir= "${c.grammar}" includes="*.g"/> + <srcfiles dir= "${j.grammar}" includes="*.g"/> <mapper type="merge" to="${build}/gluegen.jar"/> </uptodate> <uptodate property="gluegen.build.skip.java2"> <srcfiles dir= "." includes="*.xml"/> <srcfiles dir= "${src.java}" includes="**"/> - <srcfiles dir= "${c.grammar}" includes="**/*.g"/> - <srcfiles dir= "${j.grammar}" includes="**/*.g"/> + <srcfiles dir= "${c.grammar}" includes="*.g"/> + <srcfiles dir= "${j.grammar}" includes="*.g"/> <mapper type="merge" to="${build}/gluegen-rt.jar"/> </uptodate> <condition property="gluegen.build.skip.java" value="true"> @@ -650,52 +619,82 @@ </condition> </target> + <!-- + - Using ANTLR generate the specified Java files. + - + - @param target the grammar file to process + - @param output.dir the directory to write the generated files to. If + - the directory does not exist, it will be created. + --> + <target name="generate.java"> + <!-- Generate the Java files --> + <antlr target="${output.dir}/${target}" outputdirectory="${output.dir}"> + <classpath refid="antlr.classpath" /> + </antlr> + </target> + + <!-- + - Using ANTLR generate the specified Java files with an overridden + - grammar file. + - + - @param target the grammar file to process + - @param override the overridding grammar file + - @param output.dir the directory to write the generated files to. If + - the directory does not exist, it will be created. + --> + <target name="generate.java.override"> + <!-- Generate the Java files --> + <antlr target="${output.dir}/${target}" glib="${output.dir}/${override}" outputdirectory="${output.dir}"> + <classpath refid="antlr.classpath" /> + </antlr> + </target> + <target name="gluegen.build.javase"> <!-- Because ANTLR looks for importVocab files in the current working directory, it likes to have all of its files, including supergrammars, in one place, so copy all of the grammars to the output directory up front so we don't put temporary files into the source tree --> - <mkdir dir="${generated.java.from.c.grammar}" /> - <copy todir="${generated.java.from.c.grammar}"> + <mkdir dir="${c.grammar.out.dir}" /> + <copy todir="${c.grammar.out.dir}"> <fileset dir="${c.grammar}"> <include name="*.g" /> </fileset> </copy> - <mkdir dir="${generated.java.from.j.grammar}" /> - <copy todir="${generated.java.from.j.grammar}"> + <mkdir dir="${j.grammar.out.dir}" /> + <copy todir="${j.grammar.out.dir}"> <fileset dir="${j.grammar}"> <include name="*.g" /> </fileset> </copy> <!-- Generate the Java files from the C grammar using ANTLR. --> - <antcall target="generate.grammar" inheritRefs="true"> - <param name="output.dir" value="${generated.java.from.c.grammar}" /> - <param name="target" value="StdCParser.g" /> + <antcall target="generate.java" inheritRefs="true"> + <param name="output.dir" value="${c.grammar.out.dir}" /> + <param name="target" value="StdCParser.g" /> </antcall> - <antcall target="generate.c.grammar.glib" inheritRefs="true"> - <param name="output.dir" value="${generated.java.from.c.grammar}" /> - <param name="target" value="GnuCParser.g" /> - <param name="glib" value="StdCParser.g" /> + <antcall target="generate.java.override" inheritRefs="true"> + <param name="output.dir" value="${c.grammar.out.dir}" /> + <param name="target" value="GnuCParser.g" /> + <param name="override" value="StdCParser.g" /> </antcall> - <antcall target="generate.grammar" inheritRefs="true"> - <param name="output.dir" value="${generated.java.from.c.grammar}" /> - <param name="target" value="GnuCTreeParser.g" /> + <antcall target="generate.java" inheritRefs="true"> + <param name="output.dir" value="${c.grammar.out.dir}" /> + <param name="target" value="GnuCTreeParser.g" /> </antcall> - <antcall target="generate.c.grammar.glib" inheritRefs="true"> - <param name="output.dir" value="${generated.java.from.c.grammar}" /> - <param name="target" value="GnuCEmitter.g" /> - <param name="glib" value="GnuCTreeParser.g" /> + <antcall target="generate.java.override" inheritRefs="true"> + <param name="output.dir" value="${c.grammar.out.dir}" /> + <param name="target" value="GnuCEmitter.g" /> + <param name="override" value="GnuCTreeParser.g" /> </antcall> - <antcall target="generate.c.grammar.glib" inheritRefs="true"> - <param name="output.dir" value="${generated.java.from.c.grammar}" /> - <param name="target" value="HeaderParser.g" /> - <param name="glib" value="GnuCTreeParser.g" /> + <antcall target="generate.java.override" inheritRefs="true"> + <param name="output.dir" value="${c.grammar.out.dir}" /> + <param name="target" value="HeaderParser.g" /> + <param name="override" value="GnuCTreeParser.g" /> </antcall> - <antcall target="generate.grammar" inheritRefs="true"> - <param name="output.dir" value="${generated.java.from.j.grammar}" /> - <param name="target" value="JavaParser.g" /> + <antcall target="generate.java" inheritRefs="true"> + <param name="output.dir" value="${j.grammar.out.dir}" /> + <param name="target" value="JavaParser.g" /> </antcall> <!-- Build GlueGen using the generated Java files along with the diff --git a/src/java/com/jogamp/gluegen/DebugEmitter.java b/src/java/com/jogamp/gluegen/DebugEmitter.java index 781188e..8773f1b 100644 --- a/src/java/com/jogamp/gluegen/DebugEmitter.java +++ b/src/java/com/jogamp/gluegen/DebugEmitter.java @@ -41,7 +41,6 @@ package com.jogamp.gluegen; import java.util.*; -import com.jogamp.common.os.MachineDescription; import com.jogamp.gluegen.cgram.types.*; /** Debug emitter which prints the parsing results to standard output. */ diff --git a/src/java/com/jogamp/gluegen/FunctionEmitter.java b/src/java/com/jogamp/gluegen/FunctionEmitter.java index 8bb2ca5..01a0e12 100644 --- a/src/java/com/jogamp/gluegen/FunctionEmitter.java +++ b/src/java/com/jogamp/gluegen/FunctionEmitter.java @@ -47,7 +47,7 @@ public abstract class FunctionEmitter { public static final EmissionModifier STATIC = new EmissionModifier("static"); private boolean isInterfaceVal; - private ArrayList<EmissionModifier> modifiers = new ArrayList<EmissionModifier>(); + private final ArrayList<EmissionModifier> modifiers; private CommentEmitter commentEmitter = null; private PrintWriter defaultOutput; @@ -56,6 +56,7 @@ public abstract class FunctionEmitter { */ public FunctionEmitter(PrintWriter defaultOutput, boolean isInterface) { assert(defaultOutput != null); + this.modifiers = new ArrayList<EmissionModifier>(); this.defaultOutput = defaultOutput; this.isInterfaceVal = isInterface; } @@ -63,9 +64,8 @@ public abstract class FunctionEmitter { /** * Makes this FunctionEmitter a copy of the passed one. */ - @SuppressWarnings("unchecked") public FunctionEmitter(FunctionEmitter arg) { - modifiers = (ArrayList<EmissionModifier>)arg.modifiers.clone(); + modifiers = new ArrayList<EmissionModifier>(arg.modifiers); commentEmitter = arg.commentEmitter; defaultOutput = arg.defaultOutput; isInterfaceVal = arg.isInterfaceVal; @@ -169,7 +169,6 @@ public abstract class FunctionEmitter { } protected int emitModifiers(PrintWriter writer) { - PrintWriter w = getDefaultOutput(); int numEmitted = 0; for (Iterator<EmissionModifier> it = getModifiers(); it.hasNext(); ) { writer.print(it.next()); diff --git a/src/java/com/jogamp/gluegen/GlueEmitter.java b/src/java/com/jogamp/gluegen/GlueEmitter.java index bd5a7f3..bb46cf5 100644 --- a/src/java/com/jogamp/gluegen/GlueEmitter.java +++ b/src/java/com/jogamp/gluegen/GlueEmitter.java @@ -41,7 +41,6 @@ package com.jogamp.gluegen; import java.util.*; -import com.jogamp.common.os.MachineDescription; import com.jogamp.gluegen.cgram.types.*; /** Specifies the interface by which GlueGen requests glue code to be diff --git a/src/java/com/jogamp/gluegen/GlueGen.java b/src/java/com/jogamp/gluegen/GlueGen.java index 54e510d..891878b 100644 --- a/src/java/com/jogamp/gluegen/GlueGen.java +++ b/src/java/com/jogamp/gluegen/GlueGen.java @@ -190,8 +190,7 @@ public class GlueGen implements GlueEmitterControls { // Repackage the enum and #define statements from the parser into a common format // so that SymbolFilters can operate upon both identically constants = new ArrayList<ConstantDefinition>(); - for (Object elem : headerParser.getEnums()) { - EnumType enumeration = (EnumType) elem; + for (EnumType enumeration : headerParser.getEnums()) { String enumName = enumeration.getName(); if (enumName.equals("<anonymous>")) { enumName = null; diff --git a/src/java/com/jogamp/gluegen/cgram/CToken.java b/src/java/com/jogamp/gluegen/cgram/CToken.java index cfa88fc..78fc7f7 100644 --- a/src/java/com/jogamp/gluegen/cgram/CToken.java +++ b/src/java/com/jogamp/gluegen/cgram/CToken.java @@ -1,7 +1,5 @@ package com.jogamp.gluegen.cgram; -import antlr.CommonToken; - public class CToken extends antlr.CommonToken { String source = ""; int tokenNumber; diff --git a/src/java/com/jogamp/gluegen/cgram/TNodeFactory.java b/src/java/com/jogamp/gluegen/cgram/TNodeFactory.java index ccbd233..ff2f1b0 100644 --- a/src/java/com/jogamp/gluegen/cgram/TNodeFactory.java +++ b/src/java/com/jogamp/gluegen/cgram/TNodeFactory.java @@ -1,6 +1,5 @@ package com.jogamp.gluegen.cgram; -import antlr.Token; import antlr.ASTFactory; import antlr.collections.AST; diff --git a/src/java/com/jogamp/gluegen/jgram/Test.java b/src/java/com/jogamp/gluegen/jgram/Test.java index 8baff02..19d2110 100644 --- a/src/java/com/jogamp/gluegen/jgram/Test.java +++ b/src/java/com/jogamp/gluegen/jgram/Test.java @@ -1,13 +1,11 @@ package com.jogamp.gluegen.jgram; -import java.util.*; - -import java.io.*; -// import antlr.collections.AST; -import antlr.collections.impl.*; -import antlr.debug.misc.*; -import antlr.*; -// import java.awt.event.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.Reader; +import java.util.Iterator; +import java.util.Set; class Test { @@ -74,16 +72,16 @@ class Test { // start parsing at the compilationUnit rule parser.compilationUnit(); - Set set = parser.getParsedEnumNames(); + Set<String> set = parser.getParsedEnumNames(); System.out.println("Enums"); - for(Iterator iter = set.iterator(); iter.hasNext(); ) { - String s = (String) iter.next(); + for(Iterator<String> iter = set.iterator(); iter.hasNext(); ) { + String s = iter.next(); System.out.println(s); } System.out.println("Functions"); set = parser.getParsedFunctionNames(); - for(Iterator iter = set.iterator(); iter.hasNext(); ) { - String s = (String) iter.next(); + for(Iterator<String> iter = set.iterator(); iter.hasNext(); ) { + String s = iter.next(); System.out.println(s); } diff --git a/src/java/com/jogamp/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java index 236627c..f28c50d 100644 --- a/src/java/com/jogamp/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/procaddress/ProcAddressJavaMethodBindingEmitter.java @@ -42,7 +42,6 @@ import com.jogamp.gluegen.MethodBinding; import com.jogamp.gluegen.FunctionEmitter; import com.jogamp.gluegen.JavaMethodBindingEmitter; import java.io.*; -import com.jogamp.gluegen.*; /** A specialization of JavaMethodBindingEmitter with knowledge of how to call through a function pointer. */ diff --git a/src/java/com/jogamp/gluegen/cgram/GnuCEmitter.g b/src/main/antlr/com/jogamp/gluegen/cgram/GnuCEmitter.g index 38ded36..38ded36 100644 --- a/src/java/com/jogamp/gluegen/cgram/GnuCEmitter.g +++ b/src/main/antlr/com/jogamp/gluegen/cgram/GnuCEmitter.g diff --git a/src/java/com/jogamp/gluegen/cgram/GnuCParser.g b/src/main/antlr/com/jogamp/gluegen/cgram/GnuCParser.g index e8ca8c5..e8ca8c5 100644 --- a/src/java/com/jogamp/gluegen/cgram/GnuCParser.g +++ b/src/main/antlr/com/jogamp/gluegen/cgram/GnuCParser.g diff --git a/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g b/src/main/antlr/com/jogamp/gluegen/cgram/GnuCTreeParser.g index dbe2f98..dbe2f98 100644 --- a/src/java/com/jogamp/gluegen/cgram/GnuCTreeParser.g +++ b/src/main/antlr/com/jogamp/gluegen/cgram/GnuCTreeParser.g diff --git a/src/java/com/jogamp/gluegen/cgram/HeaderParser.g b/src/main/antlr/com/jogamp/gluegen/cgram/HeaderParser.g index 0b4d5ec..75cf413 100644 --- a/src/java/com/jogamp/gluegen/cgram/HeaderParser.g +++ b/src/main/antlr/com/jogamp/gluegen/cgram/HeaderParser.g @@ -100,7 +100,7 @@ options { /** Pre-define the list of EnumTypes for this HeaderParser. Must be done before parsing. */ - public void setEnums(List/*<EnumType>*/ enumTypes) { + public void setEnums(List<EnumType> enumTypes) { // FIXME: Need to take the input set of EnumTypes, extract all // the enumerates from each EnumType, and fill in the enumHash // so that each enumerate maps to the enumType to which it @@ -109,8 +109,8 @@ options { } /** Returns the EnumTypes this HeaderParser processed. */ - public List/*<EnumType>*/ getEnums() { - return new ArrayList(enumHash.values()); + public List<EnumType> getEnums() { + return new ArrayList<EnumType>(enumHash.values()); } /** Clears the list of functions this HeaderParser has parsed. @@ -121,7 +121,7 @@ options { } /** Returns the list of FunctionSymbols this HeaderParser has parsed. */ - public List getParsedFunctions() { + public List<FunctionSymbol> getParsedFunctions() { return functions; } @@ -241,9 +241,9 @@ options { private List parameters; private TypeDictionary typedefDictionary; private TypeDictionary structDictionary; - private List/*<FunctionSymbol>*/ functions = new ArrayList(); + private List<FunctionSymbol> functions = new ArrayList<FunctionSymbol>(); // hash from name of an enumerated value to the EnumType to which it belongs - private HashMap/*<String,EnumType>*/ enumHash = new HashMap(); + private HashMap<String, EnumType> enumHash = new HashMap<String, EnumType>(); // Storage class specifiers private static final int AUTO = 1 << 0; @@ -317,9 +317,9 @@ options { returns an existing one if it has already been created. */ private EnumType getEnumType(String enumTypeName) { EnumType enumType = null; - Iterator it = enumHash.values().iterator(); + Iterator<EnumType> it = enumHash.values().iterator(); while (it.hasNext()) { - EnumType potentialMatch = (EnumType)it.next(); + EnumType potentialMatch = it.next(); if (potentialMatch.getName().equals(enumTypeName)) { enumType = potentialMatch; break; @@ -652,7 +652,7 @@ enumerator[EnumType enumeration, long defaultValue] returns [long newDefaultValu if (eVal != null) { String vTxt = eVal.getAllChildrenText(); if (enumHash.containsKey(vTxt)) { - EnumType oldEnumType = (EnumType) enumHash.get(vTxt); + EnumType oldEnumType = enumHash.get(vTxt); value = oldEnumType.getEnumValue(vTxt); } else { try { @@ -669,7 +669,7 @@ enumerator[EnumType enumeration, long defaultValue] returns [long newDefaultValu newDefaultValue = value+1; String eTxt = eName.getText(); if (enumHash.containsKey(eTxt)) { - EnumType oldEnumType = (EnumType) enumHash.get(eTxt); + EnumType oldEnumType = enumHash.get(eTxt); long oldValue = oldEnumType.getEnumValue(eTxt); System.err.println("WARNING: redefinition of enumerated value '" + eTxt + "';" + " existing definition is in enumeration '" + oldEnumType.getName() + diff --git a/src/java/com/jogamp/gluegen/cgram/StdCParser.g b/src/main/antlr/com/jogamp/gluegen/cgram/StdCParser.g index 7b34656..7b34656 100644 --- a/src/java/com/jogamp/gluegen/cgram/StdCParser.g +++ b/src/main/antlr/com/jogamp/gluegen/cgram/StdCParser.g diff --git a/src/java/com/jogamp/gluegen/jgram/JavaParser.g b/src/main/antlr/com/jogamp/gluegen/jgram/JavaParser.g index 18f2970..f67579e 100644 --- a/src/java/com/jogamp/gluegen/jgram/JavaParser.g +++ b/src/main/antlr/com/jogamp/gluegen/jgram/JavaParser.g @@ -155,7 +155,7 @@ tokens { } /** Returns the EnumTypes this HeaderParser processed. */ - public Set getParsedEnumNames() { + public Set<String> getParsedEnumNames() { return enumNames; } @@ -167,13 +167,13 @@ tokens { } /** Returns the list of FunctionSymbols this HeaderParser has parsed. */ - public Set getParsedFunctionNames() { + public Set<String> getParsedFunctionNames() { return functionNames; } - private Set/*<String>*/ functionNames = new HashSet(); + private Set<String> functionNames = new HashSet<String>(); // hash from name of an enumerated value to the EnumType to which it belongs - private Set/*<String>*/ enumNames = new HashSet(); + private Set<String> enumNames = new HashSet<String>(); private int blockDepth = 0; } |