java-cup/java-cup-java8.patch

398 lines
15 KiB
Diff

--- a/build.xml
+++ b/build.xml
@@ -56,7 +56,7 @@
</target>
<target name="compile" depends="jflex">
- <javac srcdir="${java}" destdir="${classes}" verbose="off" listfiles="off" debug="on" source="10" target="10">
+ <javac srcdir="${java}" destdir="${classes}" verbose="off" listfiles="off" debug="on" source="1.8" target="1.8">
<classpath refid="libraries"/>
<compilerarg value="-Xlint:unchecked" />
<compilerarg value="-Xdiags:verbose" />
--- a/src/java/java_cup/Main.java
+++ b/src/java/java_cup/Main.java
@@ -527,7 +527,7 @@ public class Main {
protected static void check_unused() {
/* check for unused terminals */
- for (var term : terminal.all()) {
+ for (terminal term : terminal.all()) {
/* don't issue a message for EOF */
if (term == terminal.EOF)
continue;
@@ -547,7 +547,7 @@ public class Main {
}
/* check for unused non terminals */
- for (var nt:non_terminal.all()){
+ for (non_terminal nt:non_terminal.all()){
/* is this one unused */
if (nt.use_count() == 0) {
/* count and warn if we are doing warnings */
@@ -613,7 +613,7 @@ public class Main {
System.err.println(" Filling in tables...");
action_table = new parse_action_table();
reduce_table = new parse_reduce_table();
- for (var lst:lalr_state.all_states()){
+ for (lalr_state lst:lalr_state.all_states()){
lst.build_table_entries(action_table, reduce_table);
}
@@ -846,7 +846,7 @@ public class Main {
lalr_state ordered[] = new lalr_state[lalr_state.number()];
/* put the states in sorted order for a nicer display */
- for (var st : lalr_state.all_states()){
+ for (lalr_state st : lalr_state.all_states()){
ordered[st.index()] = st;
}
--- a/src/java/java_cup/emit.java
+++ b/src/java/java_cup/emit.java
@@ -624,14 +624,14 @@ public class emit {
/* collect up the productions in order */
all_prods = new production[production.number()];
- for (var prod:production.all()){
+ for (production prod:production.all()){
all_prods[prod.index()] = prod;
}
// make short[][]
short[][] prod_table = new short[production.number()][2];
for (int i = 0; i < production.number(); i++) {
- var prod = all_prods[i];
+ production prod = all_prods[i];
// { lhs symbol , rhs size }
prod_table[i][0] = (short) prod.lhs().the_symbol().index();
prod_table[i][1] = (short) prod.rhs_length();
@@ -818,12 +818,12 @@ public class emit {
nchar = do_newline(out, nchar, nbytes);
nbytes += do_escaped(out, (char) (sa.length & 0xFFFF));
nchar = do_newline(out, nchar, nbytes);
- for (var element:sa) {
+ for (short[] element:sa) {
nbytes += do_escaped(out, (char) (element.length >> 16));
nchar = do_newline(out, nchar, nbytes);
nbytes += do_escaped(out, (char) (element.length & 0xFFFF));
nchar = do_newline(out, nchar, nbytes);
- for (var element2 : element) {
+ for (short element2 : element) {
// contents of string are (value+2) to allow for common -1, 0 cases
// (UTF-8 encoding is most efficient for 0<c<0x80)
nbytes += do_escaped(out, (char) (2 + element2));
--- a/src/java/java_cup/lalr_item_set.java
+++ b/src/java/java_cup/lalr_item_set.java
@@ -206,7 +206,7 @@ public class lalr_item_set implements Iterable<lalr_item> {
public lalr_item get_one() throws internal_error {
if (_all.values().size() == 0)
return null;
- var result = iterator().next();
+ lalr_item result = iterator().next();
remove(result);
return result;
}
@@ -255,30 +255,30 @@ public class lalr_item_set implements Iterable<lalr_item> {
hashcode_cache = null;
/* each current element needs to be considered */
- var consider = new lalr_item_set(this);
+ lalr_item_set consider = new lalr_item_set(this);
/* repeat this until there is nothing else to consider */
while (consider.size() > 0) {
/* get one item to consider */
- var itm = consider.get_one();
+ lalr_item itm = consider.get_one();
/* do we have a dot before a non terminal */
- var nt = itm.dot_before_nt();
+ non_terminal nt = itm.dot_before_nt();
if (nt != null) {
/* create the lookahead set based on first after dot */
- var new_lookaheads = itm.calc_lookahead(itm.lookahead());
+ terminal_set new_lookaheads = itm.calc_lookahead(itm.lookahead());
/* are we going to need to propagate our lookahead to new item */
- var need_prop = itm.lookahead_visible();
+ boolean need_prop = itm.lookahead_visible();
/* create items for each production of that non term */
- for (var prod : nt.productions()) {
+ for (production prod : nt.productions()) {
/* create new item with dot at start and that lookahead */
- var new_itm = new lalr_item(prod, new terminal_set(new_lookaheads));
+ lalr_item new_itm = new lalr_item(prod, new terminal_set(new_lookaheads));
/* add/merge item into the set */
- var add_itm = add(new_itm);
+ lalr_item add_itm = add(new_itm);
/* if propagation is needed link to that item */
if (need_prop)
itm.add_propagate(add_itm);
@@ -335,7 +335,7 @@ public class lalr_item_set implements Iterable<lalr_item> {
// CSA fix! we'd *like* to hash just a few elements, but
// that means equal sets will have inequal hashcodes, which
// we're not allowed (by contract) to do. So hash them all.
- for (var e : this)
+ for (lalr_item e : this)
result ^= e.hashCode();
hashcode_cache = Integer.valueOf(result);
@@ -352,7 +352,7 @@ public class lalr_item_set implements Iterable<lalr_item> {
StringBuilder result = new StringBuilder();
result.append("{\n");
- for (var e : this)
+ for (lalr_item e : this)
result.append(" " + e + "\n");
result.append("}");
--- a/src/java/java_cup/lalr_state.java
+++ b/src/java/java_cup/lalr_state.java
@@ -187,14 +187,14 @@ public class lalr_state {
}
System.out.println("lalr_state [" + st.index() + "] {");
- for (var itm : st.items()) {
+ for (lalr_item itm : st.items()) {
System.out.print(" [");
System.out.print(itm.the_production().lhs().the_symbol().name());
System.out.print(" ::= ");
for (int i = 0; i < itm.the_production().rhs_length(); i++) {
if (i == itm.dot_pos())
System.out.print("\u00B7 ");
- var part = itm.the_production().rhs(i);
+ production_part part = itm.the_production().rhs(i);
if (part.is_action())
System.out.print("{action} ");
else
@@ -219,7 +219,7 @@ public class lalr_state {
*/
protected static void propagate_all_lookaheads() throws internal_error {
/* iterate across all states */
- for (var st : all_states())
+ for (lalr_state st : all_states())
st.propagate_lookaheads();
}
@@ -298,7 +298,7 @@ public class lalr_state {
/* build item with dot at front of start production and EOF lookahead */
start_items = new lalr_item_set();
- var start_itm = new lalr_item(start_prod);
+ lalr_item start_itm = new lalr_item(start_prod);
start_itm.lookahead().add(terminal.EOF);
start_items.add(start_itm);
@@ -319,29 +319,29 @@ public class lalr_state {
/* continue looking at new states until we have no more work to do */
while (!work_stack.empty()) {
/* remove a state from the work set */
- var st = work_stack.pop();
+ lalr_state st = work_stack.pop();
/* gather up all the symbols that appear before dots */
- var outgoing = new symbol_set();
- for (var itm : st.items()) {
+ symbol_set outgoing = new symbol_set();
+ for (lalr_item itm : st.items()) {
/* add the symbol before the dot (if any) to our collection */
- var sym = itm.symbol_after_dot();
+ symbol sym = itm.symbol_after_dot();
if (sym != null)
outgoing.add(sym);
}
/* now create a transition out for each individual symbol */
- for (var sym : outgoing) {
+ for (symbol sym : outgoing) {
/* will be keeping the set of items with propagate links */
- var linked_items = new lalr_item_set();
+ lalr_item_set linked_items = new lalr_item_set();
// gather up shifted versions of all the items that have this symbol before the
// dot
- var new_items = new lalr_item_set();
- for (var itm : st.items()) {
+ lalr_item_set new_items = new lalr_item_set();
+ for (lalr_item itm : st.items()) {
/* if this is the symbol we are working on now, add to set */
- var sym2 = itm.symbol_after_dot();
+ symbol sym2 = itm.symbol_after_dot();
if (sym.equals(sym2)) {
/* add to the kernel of the new state */
new_items.add(itm.shift());
@@ -353,7 +353,7 @@ public class lalr_state {
/* use new items as state kernel */
kernel = new lalr_item_set(new_items);
/* have we seen this one already? */
- var new_st = _all_kernels.get(kernel);
+ lalr_state new_st = _all_kernels.get(kernel);
/* if we haven't, build a new state out of the item set */
if (new_st == null) {
@@ -372,7 +372,7 @@ public class lalr_state {
/* otherwise relink propagation to items in existing state */
else {
/* walk through the items that have links to the new state */
- for (var fix_itm : linked_items) {
+ for (lalr_item fix_itm : linked_items) {
/* look at each propagate link out of that item */
for (int l = 0; l < fix_itm.propagate_items().size(); l++) {
@@ -410,7 +410,7 @@ public class lalr_state {
*/
protected void propagate_lookaheads() throws internal_error {
/* recursively propagate out from each item in the state */
- for (var itm : items())
+ for (lalr_item itm : items())
itm.propagate_lookaheads(null);
}
@@ -439,17 +439,17 @@ public class lalr_state {
* @param reduce_table the reduce-goto table to put entries in.
*/
public void build_table_entries(parse_action_table act_table, parse_reduce_table reduce_table) throws internal_error {
- var conflict_set = new terminal_set();
+ terminal_set conflict_set = new terminal_set();
/* pull out our rows from the tables */
- var our_act_row = act_table.under_state[index()];
- var our_red_row = reduce_table.under_state[index()];
+ parse_action_row our_act_row = act_table.under_state[index()];
+ parse_reduce_row our_red_row = reduce_table.under_state[index()];
/* consider each item in our state */
- for (var itm : items()) {
+ for (lalr_item itm : items()) {
/* if its completed (dot at end) then reduce under the lookahead */
if (itm.dot_at_end()) {
- var act = new reduce_action(itm.the_production());
+ reduce_action act = new reduce_action(itm.the_production());
/* consider each lookahead symbol */
for (int t = 0; t < terminal.number(); t++) {
@@ -463,7 +463,7 @@ public class lalr_state {
} else {
/* we now have at least one conflict */
terminal term = terminal.find(t);
- var other_act = our_act_row.under_term[t];
+ parse_action other_act = our_act_row.under_term[t];
/* if the other act was not a shift */
if ((other_act.kind() != parse_action.SHIFT) && (other_act.kind() != parse_action.NONASSOC)) {
@@ -490,9 +490,9 @@ public class lalr_state {
/* consider each outgoing transition */
for (lalr_transition trans = transitions(); trans != null; trans = trans.next()) {
/* if its on an terminal add a shift entry */
- var sym = trans.on_symbol();
+ symbol sym = trans.on_symbol();
if (!sym.is_non_term()) {
- var act = new shift_action(trans.to_state());
+ shift_action act = new shift_action(trans.to_state());
/* if we don't already have an action put this one in */
if (our_act_row.under_term[sym.index()].kind() == parse_action.ERROR) {
@@ -641,7 +641,7 @@ public class lalr_state {
boolean after_itm;
/* consider each element */
- for (var itm : items()) {
+ for (lalr_item itm : items()) {
/* clear the S/R conflict set for this item */
/* if it results in a reduce, it could be a conflict */
@@ -650,7 +650,7 @@ public class lalr_state {
after_itm = false;
/* compare this item against all others looking for conflicts */
- for (var compare : items()) {
+ for (lalr_item compare : items()) {
/* if this is the item, next one is after it */
if (itm == compare)
after_itm = true;
@@ -727,7 +727,7 @@ public class lalr_state {
int relevancecounter = 0;
/* find and report on all items that shift under our conflict symbol */
- for (var itm : items()) {
+ for (lalr_item itm : items()) {
/* only look if its not the same item and not a reduce */
if (itm != red_itm && !itm.dot_at_end()) {
--- a/src/java/java_cup/parse_action_table.java
+++ b/src/java/java_cup/parse_action_table.java
@@ -73,7 +73,7 @@ public class parse_action_table {
}
/* now go across every production and make sure we hit it */
- for (var prod : production.all()){
+ for (production prod : production.all()){
/* if we didn't hit it give a warning */
if (prod.num_reductions() == 0) {
/*
--- a/src/java/java_cup/symbol_set.java
+++ b/src/java/java_cup/symbol_set.java
@@ -90,8 +90,8 @@ public class symbol_set implements Iterable<symbol> {
not_null(other);
/* walk down our set and make sure every element is in the other */
- for (var e : this)
- if (!other.contains(e))
+ for (Iterator<symbol> e = iterator(); e.hasNext();)
+ if (!other.contains(e.next()))
return false;
/* they were all there */
return true;
@@ -155,8 +155,8 @@ public class symbol_set implements Iterable<symbol> {
not_null(other);
/* walk down the other set and do the adds individually */
- for (var e : other)
- result = add(e) || result;
+ for (Iterator<symbol> e = other.iterator(); e.hasNext();)
+ result = add(e.next()) || result;
return result;
}
@@ -172,8 +172,8 @@ public class symbol_set implements Iterable<symbol> {
not_null(other);
/* walk down the other set and do the removes individually */
- for (var s : other)
- remove(s);
+ for (Iterator<symbol> s = other.iterator(); s.hasNext();)
+ remove(s.next());
}
/* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
@@ -212,8 +212,8 @@ public class symbol_set implements Iterable<symbol> {
int result = 0;
/* hash together codes from at most first 5 elements */
- for (var s : this)
- result ^= s.hashCode();
+ for (Iterator<symbol> s = iterator(); s.hasNext(); )
+ result ^= s.next().hashCode();
return result;
}
@@ -228,12 +228,12 @@ public class symbol_set implements Iterable<symbol> {
result = "{";
comma_flag = false;
- for (var s : this) {
+ for (Iterator<symbol> s = iterator(); s.hasNext();) {
if (comma_flag)
result += ", ";
else
comma_flag = true;
- result += s.name();
+ result += s.next().name();
}
result += "}";