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

Begin using generics in generated parser

parent 3e837b13
Branches
Tags
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 @@
package org.sablecc.sablecc.parser;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("rawtypes")
final class 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.nodes = nodes;
......
......@@ -24,10 +24,10 @@ import java.io.IOException;
@SuppressWarnings({"rawtypes","unchecked","unused"})
public class Parser implements IParser
{
protected ArrayList nodeList;
protected List<Object> nodeList;
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_line;
private Token last_token;
......@@ -39,8 +39,8 @@ public class Parser implements IParser
private final static int ACCEPT = 2;
private final static int ERROR = 3;
protected ArrayList firstPopped = null;
protected ArrayList lastPopped = null;
protected List<Object> firstPopped = null;
protected List<Object> lastPopped = null;
public Parser(Lexer lexer)
{
......@@ -63,13 +63,13 @@ public class Parser implements IParser
return;
}
if (elementToCheck instanceof LinkedList) {
if (elementToCheck instanceof List<?>) {
/*
* 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
* added to it
*/
final LinkedList nodeList = (LinkedList) elementToCheck;
final List<?> nodeList = (List<?>) elementToCheck;
if (nodeList.size() > 0) {
elementToCheck = nodeList.get(nodeList.size() - 1);
......@@ -100,11 +100,11 @@ public class Parser implements IParser
}
protected int findBeginPos(final ArrayList list,
protected int findBeginPos(final List<Object> list,
PositionedNode n) {
Object first = list.get(0);
if (!(first instanceof PositionedNode) && !(first instanceof IToken)) {
List list2 = (List) first;
List<?> list2 = (List<?>) first;
if (list2.size() > 0) {
first = list2.get(0);
......@@ -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);
if (!(last instanceof PositionedNode) && !(last instanceof IToken)) {
final List list2 = (List) last;
final List<?> list2 = (List<?>) last;
last = list2.get(list2.size() - 1);
}
......@@ -182,7 +182,7 @@ $
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;
......@@ -195,7 +195,7 @@ Macro:ParserNoInliningPushHeader
// 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;
......@@ -214,7 +214,7 @@ Macro:ParserCommon
return;
}
State s = (State) this.stack.next();
State s = this.stack.next();
s.state = numstate;
s.nodes = this.nodeList;
}
......@@ -250,14 +250,14 @@ Macro:ParserCommon
private int state()
{
State s = (State) this.stack.previous();
State s = this.stack.previous();
this.stack.next();
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) {
this.firstPopped = list;
} else {
......@@ -322,7 +322,7 @@ Macro:ParserCommon
{
case SHIFT:
{
ArrayList list = new ArrayList();
List<Object> list = new ArrayList<Object>();
list.add(this.lexer.next());
push(this.action[1], list$1$);
}
......@@ -336,7 +336,7 @@ $
Macro:ParserInliningReduce
case $0$: /* reduce $2$ */
{
ArrayList list = new$0$();
List<Object> list = new$0$();
push(goTo($1$), list);
}
break;
......@@ -346,7 +346,7 @@ $
Macro:ParserNoInliningReduce
case $0$: /* reduce $3$ */
{
ArrayList list = new$0$();
List<Object> list = new$0$();
push(goTo($1$), list, $2$);
}
break;
......@@ -378,23 +378,23 @@ Macro:ParserNewHeader
protected ArrayList new$0$() /* reduce $1$ */
protected List<Object> new$0$() /* reduce $1$ */
{
this.firstPopped = null;
this.lastPopped = null;
final boolean addElementsToNewList = addElementsFromListToNewList("$1$");
ArrayList nodeList = new ArrayList();
List<Object> nodeList = new ArrayList<>();
$
Macro:ParserNewBodyDecl
ArrayList nodeArrayList$0$ = pop();
List<Object> nodeArrayList$0$ = pop();
$
Macro:ParserNewBodyDeclNull
ArrayList nodeArrayList$0$ = null;
List<Object> nodeArrayList$0$ = null;
$
......@@ -684,15 +684,14 @@ Macro:State
package $0$;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("rawtypes")
final class 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.nodes = nodes;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment