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

Use generics in ResolveAltIds and related code

parent 342e2728
No related branches found
No related tags found
No related merge requests found
...@@ -92,8 +92,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -92,8 +92,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
currentProd = ids.names.get(node); currentProd = ids.names.get(node);
listOfAlts = new LinkedList<>(); listOfAlts = new LinkedList<>();
PAlt[] list_alt = node.getAlts().toArray(new PAlt[0]); for(PAlt alt : node.getAlts())
for(PAlt alt : list_alt)
{ {
alt.apply(this); alt.apply(this);
} }
...@@ -103,12 +102,12 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -103,12 +102,12 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
private List<PElem> listElems; private List<PElem> listElems;
private AAlt aParsedAlt; private AAlt aParsedAlt;
private LinkedList listElemsAltTransform; private List<String> listElemsAltTransform;
private String currentNewAltName; private String currentNewAltName;
boolean countElementNecessary; boolean countElementNecessary;
LinkedList listOfAlternativeElemsWHaveName; List<String> listOfAlternativeElemsWHaveName;
private final Map<AElem, Integer> elemOperators = new HashMap<>(); private final Map<AElem, Integer> elemOperators = new HashMap<>();
...@@ -120,7 +119,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -120,7 +119,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
AAltTransform currentAltTransform = (AAltTransform)node.getAltTransform(); AAltTransform currentAltTransform = (AAltTransform)node.getAltTransform();
listOfAlternativeElemsWHaveName = new LinkedList(); listOfAlternativeElemsWHaveName = new LinkedList<>();
node.apply(new DepthFirstAdapter() node.apply(new DepthFirstAdapter()
{ {
...@@ -155,18 +154,17 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -155,18 +154,17 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
if(count == 1) if(count == 1)
{ {
listElems = new LinkedList<>(); listElems = new LinkedList<>();
listElemsAltTransform = new LinkedList(); listElemsAltTransform = new LinkedList<>();
countElementNecessary = false; countElementNecessary = false;
Object temp[] = node.getElems().toArray(); for(PElem pElem : node.getElems())
for(int i = 0; i < temp.length; i++)
{ {
Object obj = temp[i]; final PUnOp unOp = ((AElem)pElem).getUnOp();
if( ((AElem)obj).getUnOp() != null && if( unOp != null &&
( ((AElem)obj).getUnOp() instanceof AQMarkUnOp || ( unOp instanceof AQMarkUnOp ||
((AElem)obj).getUnOp() instanceof AStarUnOp ) unOp instanceof AStarUnOp )
) )
{ {
if(!countElementNecessary) if(!countElementNecessary)
...@@ -176,9 +174,9 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -176,9 +174,9 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
} }
} }
for(int i = 0; i < temp.length; i++) for(PElem pElem : node.getElems())
{ {
((PElem)temp[i]).apply(this); pElem.apply(this);
} }
TId nameOfAlt = null; TId nameOfAlt = null;
...@@ -216,7 +214,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -216,7 +214,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
for(count = 0; count < max; count++) for(count = 0; count < max; count++)
{ {
listElems = new LinkedList<>(); listElems = new LinkedList<>();
listElemsAltTransform = new LinkedList(); listElemsAltTransform = new LinkedList<>();
elem = 0; elem = 0;
...@@ -224,14 +222,13 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -224,14 +222,13 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
countElementNecessary = false; countElementNecessary = false;
Object temp[] = node.getElems().toArray(); for(PElem pElem : node.getElems())
for(int i = 0; i < temp.length; i++)
{ {
Object obj = temp[i]; final PUnOp unOp = ((AElem)pElem).getUnOp();
if( ((AElem)obj).getUnOp() != null && if( unOp != null &&
( ((AElem)obj).getUnOp() instanceof AQMarkUnOp || ( unOp instanceof AQMarkUnOp ||
((AElem)obj).getUnOp() instanceof AStarUnOp ) unOp instanceof AStarUnOp )
) )
{ {
if(!countElementNecessary) if(!countElementNecessary)
...@@ -241,9 +238,9 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter ...@@ -241,9 +238,9 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
} }
} }
for(int i = 0; i < temp.length; i++) for(PElem pElem : node.getElems())
{ {
((PElem)temp[i]).apply(this); pElem.apply(this);
} }
altIds.alts_elems.put(currentNewAltName, listElemsAltTransform); altIds.alts_elems.put(currentNewAltName, listElemsAltTransform);
......
...@@ -33,23 +33,23 @@ public class ResolveAltIds extends DepthFirstAdapter ...@@ -33,23 +33,23 @@ public class ResolveAltIds extends DepthFirstAdapter
//Map of alternatives elements which are not list : //Map of alternatives elements which are not list :
// ie not followed by * or + operator. // ie not followed by * or + operator.
public Map<String, LinkedList> alts_elems = new TreeMap<>(); public Map<String, List<String>> alts_elems = new TreeMap<>();
//Map of only alternatives elements which are list : //Map of only alternatives elements which are list :
//followed by * or + operator. //followed by * or + operator.
public Map<String, LinkedList> alts_elems_list = new TreeMap<>(); public Map<String, List<String>> alts_elems_list = new TreeMap<>();
//Map of all alternatives elements. Elements name are stored //Map of all alternatives elements. Elements name are stored
//if it is specified otherwise, it is its id. //if it is specified otherwise, it is its id.
//(elem = elem_name? specifier? id un_op?) //(elem = elem_name? specifier? id un_op?)
public Map<String, LinkedList> alts_elemsGlobal = new TreeMap<>(); public Map<String, List<String>> alts_elemsGlobal = new TreeMap<>();
//Map of all alternatives elements which have explicit name. //Map of all alternatives elements which have explicit name.
public Map<String, List> alts_elems_list_elemName = new TreeMap<>(); public Map<String, List<String>> alts_elems_list_elemName = new TreeMap<>();
private LinkedList listElemsGlobal; private List<String> listElemsGlobal;
private LinkedList listElems; private List<String> listElems;
private LinkedList listElemslist; private List<String> listElemslist;
String currentAlt; String currentAlt;
...@@ -69,8 +69,7 @@ public class ResolveAltIds extends DepthFirstAdapter ...@@ -69,8 +69,7 @@ public class ResolveAltIds extends DepthFirstAdapter
@Override @Override
public void caseAProd(AProd node) public void caseAProd(AProd node)
{ {
PAlt[] list_alts = node.getAlts().toArray(new PAlt[0]); for(PAlt alt : node.getAlts())
for(PAlt alt : list_alts)
{ {
alt.apply(this); alt.apply(this);
} }
...@@ -84,18 +83,17 @@ public class ResolveAltIds extends DepthFirstAdapter ...@@ -84,18 +83,17 @@ public class ResolveAltIds extends DepthFirstAdapter
public void caseAAlt(AAlt alt) public void caseAAlt(AAlt alt)
{ {
//contains all the elements in the alternative, no matter if they are list or not //contains all the elements in the alternative, no matter if they are list or not
listElemsGlobal = new LinkedList(); listElemsGlobal = new LinkedList<>();
//contains only single (without operator * or +) element of the alternative. //contains only single (without operator * or +) element of the alternative.
listElems = new LinkedList(); listElems = new LinkedList<>();
//contains only element of the alternative which are list(operator * or +). //contains only element of the alternative which are list(operator * or +).
listElemslist = new LinkedList(); listElemslist = new LinkedList<>();
currentAlt = ids.names.get(alt); currentAlt = ids.names.get(alt);
PElem[] list_elems = alt.getElems().toArray(new PElem[0]); for(PElem elem : alt.getElems())
for(PElem elem : list_elems)
{ {
elem.apply(this); elem.apply(this);
} }
......
...@@ -71,9 +71,9 @@ public class ResolveTransformIds extends DepthFirstAdapter ...@@ -71,9 +71,9 @@ public class ResolveTransformIds extends DepthFirstAdapter
} }
} }
private LinkedList listCurrentAltGlobal; private List<String> listCurrentAltGlobal;
private LinkedList listCurrentAlt; private List<String> listCurrentAlt;
private LinkedList listOfListCurrentAlt; private List<String> listOfListCurrentAlt;
@Override @Override
public void inAAlt(AAlt nodeAlt) public void inAAlt(AAlt nodeAlt)
...@@ -81,9 +81,9 @@ public class ResolveTransformIds extends DepthFirstAdapter ...@@ -81,9 +81,9 @@ public class ResolveTransformIds extends DepthFirstAdapter
nbTransformAlt = 0; nbTransformAlt = 0;
currentAlt = altIds.ids.names.get(nodeAlt); currentAlt = altIds.ids.names.get(nodeAlt);
listCurrentAltGlobal = (LinkedList)altIds.alts_elemsGlobal.get(currentAlt).clone(); listCurrentAltGlobal = new LinkedList<>(altIds.alts_elemsGlobal.get(currentAlt));
listCurrentAlt = (LinkedList)altIds.alts_elems.get(currentAlt).clone(); listCurrentAlt = new LinkedList<>(altIds.alts_elems.get(currentAlt));
listOfListCurrentAlt = (LinkedList)altIds.alts_elems_list.get(currentAlt).clone(); listOfListCurrentAlt = new LinkedList<>(altIds.alts_elems_list.get(currentAlt));
} }
@Override @Override
...@@ -360,12 +360,9 @@ public class ResolveTransformIds extends DepthFirstAdapter ...@@ -360,12 +360,9 @@ public class ResolveTransformIds extends DepthFirstAdapter
} }
else else
{ {
ListIterator iter = null; for(Iterator<String> iter = listCurrentAltGlobal.iterator(); iter.hasNext();)
iter = listCurrentAltGlobal.listIterator();
while(iter.hasNext())
{ {
if( name.equals((String)iter.next()) ) if( name.equals(iter.next()) )
{ {
if( node.getSimpleTermTail() == null ) if( node.getSimpleTermTail() == null )
{ {
...@@ -382,12 +379,9 @@ public class ResolveTransformIds extends DepthFirstAdapter ...@@ -382,12 +379,9 @@ public class ResolveTransformIds extends DepthFirstAdapter
} }
else else
{ {
ListIterator iter = null; for(Iterator<String> iter = listCurrentAlt.iterator(); iter.hasNext();)
iter = listCurrentAlt.listIterator();
while(iter.hasNext())
{ {
if( name.equals((String)iter.next()) ) if( name.equals(iter.next()) )
{ {
if( node.getSimpleTermTail() == null ) if( node.getSimpleTermTail() == null )
{ {
...@@ -587,12 +581,9 @@ public class ResolveTransformIds extends DepthFirstAdapter ...@@ -587,12 +581,9 @@ public class ResolveTransformIds extends DepthFirstAdapter
} }
else else
{ {
ListIterator iter = null; for(Iterator<String> iter = listCurrentAltGlobal.iterator(); iter.hasNext();)
iter = listCurrentAltGlobal.listIterator();
while(iter.hasNext())
{ {
if( name.equals((String)iter.next()) ) if( name.equals(iter.next()) )
{ {
if( node.getSimpleTermTail() == null ) if( node.getSimpleTermTail() == null )
{ {
...@@ -609,19 +600,19 @@ public class ResolveTransformIds extends DepthFirstAdapter ...@@ -609,19 +600,19 @@ public class ResolveTransformIds extends DepthFirstAdapter
} }
else else
{ {
ListIterator iter = null; Iterator<String> iter = null;
if( (listCurrentAlt != null) && listCurrentAlt.contains(name) ) if( (listCurrentAlt != null) && listCurrentAlt.contains(name) )
{ {
iter = listCurrentAlt.listIterator(); iter = listCurrentAlt.iterator();
} }
else if( (listOfListCurrentAlt != null) && listOfListCurrentAlt.contains(name) ) else if( (listOfListCurrentAlt != null) && listOfListCurrentAlt.contains(name) )
{ {
iter = listOfListCurrentAlt.listIterator(); iter = listOfListCurrentAlt.iterator();
} }
while(iter.hasNext()) while(iter.hasNext())
{ {
if( name.equals((String)iter.next()) ) if( name.equals(iter.next()) )
{ {
if( node.getSimpleTermTail() == null ) if( node.getSimpleTermTail() == null )
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment