Skip to content
Snippets Groups Projects
Commit 30e55c67 authored by dgelessus's avatar dgelessus
Browse files

Begin using generics in generated parser

parent 3e837b13
No related branches found
No related tags found
No related merge requests found
Source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -2,15 +2,14 @@ ...@@ -2,15 +2,14 @@
package org.sablecc.sablecc.parser; package org.sablecc.sablecc.parser;
import java.util.ArrayList; import java.util.List;
@SuppressWarnings("rawtypes")
final class State final class State
{ {
int state; int state;
ArrayList nodes; List<Object> nodes; // elements are of type Node or List<Node>
State(int state, ArrayList nodes) State(int state, List<Object> nodes)
{ {
this.state = state; this.state = state;
this.nodes = nodes; this.nodes = nodes;
......
...@@ -24,10 +24,10 @@ import java.io.IOException; ...@@ -24,10 +24,10 @@ import java.io.IOException;
@SuppressWarnings({"rawtypes","unchecked","unused"}) @SuppressWarnings({"rawtypes","unchecked","unused"})
public class Parser implements IParser public class Parser implements IParser
{ {
protected ArrayList nodeList; protected List<Object> nodeList;
private final Lexer lexer; private final Lexer lexer;
private final ListIterator stack = new LinkedList().listIterator(); private final ListIterator<State> stack = new LinkedList<State>().listIterator();
private int last_pos; private int last_pos;
private int last_line; private int last_line;
private Token last_token; private Token last_token;
...@@ -39,8 +39,8 @@ public class Parser implements IParser ...@@ -39,8 +39,8 @@ public class Parser implements IParser
private final static int ACCEPT = 2; private final static int ACCEPT = 2;
private final static int ERROR = 3; private final static int ERROR = 3;
protected ArrayList firstPopped = null; protected List<Object> firstPopped = null;
protected ArrayList lastPopped = null; protected List<Object> lastPopped = null;
public Parser(Lexer lexer) public Parser(Lexer lexer)
{ {
...@@ -63,13 +63,13 @@ public class Parser implements IParser ...@@ -63,13 +63,13 @@ public class Parser implements IParser
return; return;
} }
if (elementToCheck instanceof LinkedList) { if (elementToCheck instanceof List<?>) {
/* /*
* special case: this is a list of nodes, for example an identifier * special case: this is a list of nodes, for example an identifier
* list, so we don't want to check the list but the last element * list, so we don't want to check the list but the last element
* added to it * added to it
*/ */
final LinkedList nodeList = (LinkedList) elementToCheck; final List<?> nodeList = (List<?>) elementToCheck;
if (nodeList.size() > 0) { if (nodeList.size() > 0) {
elementToCheck = nodeList.get(nodeList.size() - 1); elementToCheck = nodeList.get(nodeList.size() - 1);
...@@ -100,11 +100,11 @@ public class Parser implements IParser ...@@ -100,11 +100,11 @@ public class Parser implements IParser
} }
protected int findBeginPos(final ArrayList list, protected int findBeginPos(final List<Object> list,
PositionedNode n) { PositionedNode n) {
Object first = list.get(0); Object first = list.get(0);
if (!(first instanceof PositionedNode) && !(first instanceof IToken)) { if (!(first instanceof PositionedNode) && !(first instanceof IToken)) {
List list2 = (List) first; List<?> list2 = (List<?>) first;
if (list2.size() > 0) { if (list2.size() > 0) {
first = list2.get(0); first = list2.get(0);
...@@ -131,10 +131,10 @@ public class Parser implements IParser ...@@ -131,10 +131,10 @@ public class Parser implements IParser
} }
protected int findEndPos(final ArrayList list) { protected int findEndPos(final List<Object> list) {
Object last = list.get(list.size() - 1); Object last = list.get(list.size() - 1);
if (!(last instanceof PositionedNode) && !(last instanceof IToken)) { if (!(last instanceof PositionedNode) && !(last instanceof IToken)) {
final List list2 = (List) last; final List<?> list2 = (List<?>) last;
last = list2.get(list2.size() - 1); last = list2.get(list2.size() - 1);
} }
...@@ -182,7 +182,7 @@ $ ...@@ -182,7 +182,7 @@ $
Macro:ParserInliningPushHeader Macro:ParserInliningPushHeader
private void push(int numstate, ArrayList listNode) throws ParserException, LexerException, IOException private void push(int numstate, List<Object> listNode) throws ParserException, LexerException, IOException
{ {
this.nodeList = listNode; this.nodeList = listNode;
...@@ -195,7 +195,7 @@ Macro:ParserNoInliningPushHeader ...@@ -195,7 +195,7 @@ Macro:ParserNoInliningPushHeader
// Empty body // Empty body
} }
private void push(int numstate, ArrayList listNode, boolean hidden) throws ParserException, LexerException, IOException private void push(int numstate, List<Object> listNode, boolean hidden) throws ParserException, LexerException, IOException
{ {
this.nodeList = listNode; this.nodeList = listNode;
...@@ -214,7 +214,7 @@ Macro:ParserCommon ...@@ -214,7 +214,7 @@ Macro:ParserCommon
return; return;
} }
State s = (State) this.stack.next(); State s = this.stack.next();
s.state = numstate; s.state = numstate;
s.nodes = this.nodeList; s.nodes = this.nodeList;
} }
...@@ -250,14 +250,14 @@ Macro:ParserCommon ...@@ -250,14 +250,14 @@ Macro:ParserCommon
private int state() private int state()
{ {
State s = (State) this.stack.previous(); State s = this.stack.previous();
this.stack.next(); this.stack.next();
return s.state; return s.state;
} }
protected ArrayList pop() protected List<Object> pop()
{ {
ArrayList list = ((State) this.stack.previous()).nodes; List<Object> list = this.stack.previous().nodes;
if (this.firstPopped == null) { if (this.firstPopped == null) {
this.firstPopped = list; this.firstPopped = list;
} else { } else {
...@@ -322,7 +322,7 @@ Macro:ParserCommon ...@@ -322,7 +322,7 @@ Macro:ParserCommon
{ {
case SHIFT: case SHIFT:
{ {
ArrayList list = new ArrayList(); List<Object> list = new ArrayList<Object>();
list.add(this.lexer.next()); list.add(this.lexer.next());
push(this.action[1], list$1$); push(this.action[1], list$1$);
} }
...@@ -336,7 +336,7 @@ $ ...@@ -336,7 +336,7 @@ $
Macro:ParserInliningReduce Macro:ParserInliningReduce
case $0$: /* reduce $2$ */ case $0$: /* reduce $2$ */
{ {
ArrayList list = new$0$(); List<Object> list = new$0$();
push(goTo($1$), list); push(goTo($1$), list);
} }
break; break;
...@@ -346,7 +346,7 @@ $ ...@@ -346,7 +346,7 @@ $
Macro:ParserNoInliningReduce Macro:ParserNoInliningReduce
case $0$: /* reduce $3$ */ case $0$: /* reduce $3$ */
{ {
ArrayList list = new$0$(); List<Object> list = new$0$();
push(goTo($1$), list, $2$); push(goTo($1$), list, $2$);
} }
break; break;
...@@ -378,23 +378,23 @@ Macro:ParserNewHeader ...@@ -378,23 +378,23 @@ Macro:ParserNewHeader
protected ArrayList new$0$() /* reduce $1$ */ protected List<Object> new$0$() /* reduce $1$ */
{ {
this.firstPopped = null; this.firstPopped = null;
this.lastPopped = null; this.lastPopped = null;
final boolean addElementsToNewList = addElementsFromListToNewList("$1$"); final boolean addElementsToNewList = addElementsFromListToNewList("$1$");
ArrayList nodeList = new ArrayList(); List<Object> nodeList = new ArrayList<>();
$ $
Macro:ParserNewBodyDecl Macro:ParserNewBodyDecl
ArrayList nodeArrayList$0$ = pop(); List<Object> nodeArrayList$0$ = pop();
$ $
Macro:ParserNewBodyDeclNull Macro:ParserNewBodyDeclNull
ArrayList nodeArrayList$0$ = null; List<Object> nodeArrayList$0$ = null;
$ $
...@@ -684,15 +684,14 @@ Macro:State ...@@ -684,15 +684,14 @@ Macro:State
package $0$; package $0$;
import java.util.ArrayList; import java.util.List;
@SuppressWarnings("rawtypes")
final class State final class State
{ {
int state; int state;
ArrayList nodes; List<Object> nodes; // elements are of type Node or List<Node>
State(int state, ArrayList nodes) State(int state, List<Object> nodes)
{ {
this.state = state; this.state = state;
this.nodes = nodes; this.nodes = nodes;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment