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

Remove TypedTreeMap in favor of TreeMap and real generics

parent d84843d8
No related branches found
No related tags found
No related merge requests found
Showing
with 77 additions and 430 deletions
......@@ -17,7 +17,7 @@ public class AltTransformAdapter extends DepthFirstAdapter
ResolveAltIds altIds;
String currentNewAltName;
private Map isElementIsAlist;
private Map<String, String> isElementIsAlist;
private LinkedList listSimpleTermTransform;
private Map<Node, String> simpleTermTransform;
......@@ -26,7 +26,7 @@ public class AltTransformAdapter extends DepthFirstAdapter
AltTransformAdapter(Map<Node, String> simpleTermTransform,
LinkedList listSimpleTermTransform,
String currentNewAltName,
ResolveAltIds altIds, Map isElementIsAlist,
ResolveAltIds altIds, Map<String, String> isElementIsAlist,
Map<Node, String> simpleTermOrsimpleListTermTypes)
{
this.currentNewAltName = currentNewAltName;
......@@ -41,8 +41,8 @@ public class AltTransformAdapter extends DepthFirstAdapter
{
String name = node.getId().getText();
if( !((LinkedList)altIds.alts_elems.get(currentNewAltName)).contains(name) &&
!((LinkedList)altIds.alts_elems.get(currentNewAltName)).contains("$"+name) )
if( !altIds.alts_elems.get(currentNewAltName).contains(name) &&
!altIds.alts_elems.get(currentNewAltName).contains("$"+name) )
{
node.replaceBy( new ANullTerm() );
}
......@@ -56,7 +56,7 @@ public class AltTransformAdapter extends DepthFirstAdapter
}
else
{
simpleTermTail = new TId( (String)isElementIsAlist.get(currentNewAltName+name) );
simpleTermTail = new TId(isElementIsAlist.get(currentNewAltName+name));
}
ASimpleTerm asimpleTerm = new ASimpleTerm( node.getSpecifier(), node.getId(), simpleTermTail);
......@@ -67,7 +67,7 @@ public class AltTransformAdapter extends DepthFirstAdapter
}
node.replaceBy(asimpleTerm);
simpleTermTransform.put(asimpleTerm, "L"+ResolveIds.name((String)isElementIsAlist.get(currentNewAltName+name)) );
simpleTermTransform.put(asimpleTerm, "L"+ResolveIds.name(isElementIsAlist.get(currentNewAltName+name)) );
//Terms are added here only if they were implicitely transformed
listSimpleTermTransform.add( asimpleTerm );
......@@ -78,8 +78,8 @@ public class AltTransformAdapter extends DepthFirstAdapter
{
String name = node.getId().getText();
if( !((LinkedList)altIds.alts_elems.get(currentNewAltName)).contains(name) &&
!((LinkedList)altIds.alts_elems.get(currentNewAltName)).contains("$"+name) )
if( !altIds.alts_elems.get(currentNewAltName).contains(name) &&
!altIds.alts_elems.get(currentNewAltName).contains("$"+name) )
{
node.replaceBy( null );
}
......@@ -93,11 +93,11 @@ public class AltTransformAdapter extends DepthFirstAdapter
}
else
{
simpleTermTail = new TId((String)isElementIsAlist.get(currentNewAltName+name));
simpleTermTail = new TId(isElementIsAlist.get(currentNewAltName+name));
}
TId tid;
tid = ( ((LinkedList)altIds.alts_elems_list_elemName.get(currentNewAltName)).contains(name) ?
tid = ( altIds.alts_elems_list_elemName.get(currentNewAltName).contains(name) ?
node.getId() : new TId( "$" + node.getId().getText() ) );
ASimpleListTerm asimpleListTerm = new ASimpleListTerm( node.getSpecifier(), tid, simpleTermTail);
......@@ -108,7 +108,7 @@ public class AltTransformAdapter extends DepthFirstAdapter
}
node.replaceBy(asimpleListTerm);
simpleTermTransform.put(asimpleListTerm, "L"+ResolveIds.name((String)isElementIsAlist.get(currentNewAltName+name) ));
simpleTermTransform.put(asimpleListTerm, "L"+ResolveIds.name(isElementIsAlist.get(currentNewAltName+name)));
//Terms are added here only if they were implicitely transformed
listSimpleTermTransform.add( asimpleListTerm );
......
......@@ -31,12 +31,12 @@ public class ComputeInlining
private Set setOfProdToBeInline;
//Map of all productions in the grammar
private Map productionsMap;
private Map<String, AProd> productionsMap;
private Start tree;
public ComputeInlining(Set set
,
Map productionsMap,
Map<String, AProd> productionsMap,
Start tree)
{
this.setOfProdToBeInline = set
......@@ -59,7 +59,7 @@ public class ComputeInlining
for(int i=0; i<nameOfProds.length; i++)
{
final AProd prod = (AProd)productionsMap.get(nameOfProds[i]);
final AProd prod = productionsMap.get(nameOfProds[i]);
//We proceed inlining only if the production to inline is not recursive
//and if it doesn't have more than SableCC.inliningMaxAlts alternatives.
......
......@@ -277,7 +277,7 @@ public class ConstructNFA extends DepthFirstAdapter
public void outAIdBasic(AIdBasic node)
{
Object o = getOut((Node) ids.helpers.get(node.getId().getText()));
Object o = getOut(ids.helpers.get(node.getId().getText()));
if(o instanceof NFA)
{
......
......@@ -68,8 +68,7 @@ public class ConstructParserGenerationDatas extends DepthFirstAdapter
}
else
{
Object token = ids.tokens.get("T" + name);
Object production = ids.prods.get("P" + name);
ATokenDef token = ids.tokens.get("T" + name);
if(token != null)
{
......
......@@ -13,9 +13,7 @@ import org.sablecc.sablecc.node.*;
public class ConstructProdsMap extends DepthFirstAdapter
{
public Map productionsMap =
new TypedTreeMap(StringCast.instance,
NodeCast.instance);
public Map<String, AProd> productionsMap = new TreeMap<>();
private String currentProd;
......
......@@ -162,7 +162,7 @@ public class GenLexer extends AnalysisAdapter
for(ListIterator i = ids.tokenList.listIterator(); i.hasNext();)
{
String name = (String) i.next();
Node node = (Node) ids.tokens.get(name);
ATokenDef node = ids.tokens.get(name);
boolean fixed = ids.fixedTokens.get(node);
if(fixed)
......@@ -176,18 +176,15 @@ public class GenLexer extends AnalysisAdapter
new String[] {"" + i.previousIndex(), name});
}
Map map = transitions.tokenStates.get(node);
Map<String, String> map = transitions.tokenStates.get(node);
if(map.size() > 0)
{
macros.apply(file, "TokenSwitchHeader", null);
for(Iterator j = map.entrySet().iterator(); j.hasNext();)
for(Map.Entry<String, String> entry : map.entrySet())
{
Map.Entry entry = (Map.Entry) j.next();
macros.apply(file, "TokenCase",
new String[] {ids.stateList.indexOf((String) entry.getKey()) + "",
(String) entry.getValue()});
new String[] {ids.stateList.indexOf(entry.getKey()) + "", entry.getValue()});
}
macros.apply(file, "TokenSwitchTail", null);
......@@ -201,7 +198,7 @@ public class GenLexer extends AnalysisAdapter
for(ListIterator i = ids.tokenList.listIterator(); i.hasNext();)
{
String name = (String) i.next();
Node node = (Node) ids.tokens.get(name);
ATokenDef node = ids.tokens.get(name);
boolean fixed = ids.fixedTokens.get(node);
if(fixed)
......
......@@ -630,10 +630,7 @@ public class GenParser extends DepthFirstAdapter
StringBuffer index = new StringBuffer();
int nextIndex = 0;
Map errorIndex = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
IntegerCast.instance);
Map<String, Integer> errorIndex = new TreeMap<>();
outerArray = new Vector();
Vector indexArray = new Vector();
......
......@@ -18,10 +18,6 @@ public class GenProds extends DepthFirstAdapter
private ResolveAstIds ast_ids;
private File pkgDir;
private String pkgName;
private Map hiddenProds = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
NodeCast.instance);
public GenProds(ResolveAstIds ast_ids)
{
......
......@@ -206,7 +206,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
if( !listSimpleTermTransform.contains(node.getId().getText() ) )
{
String type = CTP.positionsMap.get( realcurrentAlt+"."+node.getId().getText() );
LinkedList list = (LinkedList)transformIds.getProdTransformIds().prod_transforms.get(type);
LinkedList list = transformIds.getProdTransformIds().prod_transforms.get(type);
if( list.indexOf( node.getSimpleTermTail().getText() ) >= 0 )
{
positionMap = list.indexOf( node.getSimpleTermTail().getText() );
......@@ -216,7 +216,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
if(simpleTermOrsimpleListTermTypes.get(node) != null)
{
String type = simpleTermOrsimpleListTermTypes.get(node);
LinkedList list = (LinkedList)transformIds.getProdTransformIds().prod_transforms.get(type);
LinkedList list = transformIds.getProdTransformIds().prod_transforms.get(type);
if( list.indexOf( node.getSimpleTermTail().getText() ) >= 0 )
{
positionMap = list.indexOf( node.getSimpleTermTail().getText() );
......@@ -280,7 +280,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
if( !listSimpleTermTransform.contains(node.getId().getText()) )
{
String type = CTP.positionsMap.get( realcurrentAlt+"."+node.getId().getText() );
LinkedList list = (LinkedList)transformIds.getProdTransformIds().prod_transforms.get(type);
LinkedList list = transformIds.getProdTransformIds().prod_transforms.get(type);
if( list.indexOf( node.getSimpleTermTail().getText() ) >= 0 )
{
positionMap = list.indexOf( node.getSimpleTermTail().getText() );
......@@ -290,7 +290,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
if(simpleTermOrsimpleListTermTypes.get(node) != null)
{
String type = simpleTermOrsimpleListTermTypes.get(node);
LinkedList list = (LinkedList)transformIds.getProdTransformIds().prod_transforms.get(type);
LinkedList list = transformIds.getProdTransformIds().prod_transforms.get(type);
if( list.indexOf( node.getSimpleTermTail().getText() ) >= 0 )
{
positionMap = list.indexOf( node.getSimpleTermTail().getText() );
......
......@@ -46,10 +46,7 @@ public class InternalTransformationsToGrammar extends DepthFirstAdapter
Map<String, LinkedList> mapProductionTransformations;
Map<Node, String> simpleTermOrsimpleListTermTypes;
private Map isElementIsAlist = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
StringCast.instance);
private Map<String, String> isElementIsAlist = new TreeMap<>();
private LinkedList listProd;
......
......@@ -15,10 +15,7 @@ public class MacroExpander
private static final String MACRO = "Macro:";
private static final String lineSeparator = System.getProperty("line.separator");
private Map macros = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
ListCast.instance);
private Map<String, List> macros = new TreeMap<>();
public MacroExpander(Reader in) throws IOException
{
......@@ -69,7 +66,7 @@ public class MacroExpander
public void apply(BufferedWriter out, String macroName, String[] arguments) throws IOException
{
List macro = (List) macros.get(macroName);
List macro = macros.get(macroName);
for(ListIterator li = macro.listIterator(); li.hasNext();)
{
......
......@@ -36,31 +36,19 @@ public class ResolveAltIds extends DepthFirstAdapter
//Map of alternatives elements which are not list :
// ie not followed by * or + operator.
public Map alts_elems = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
ListCast.instance);
public Map<String, LinkedList> alts_elems = new TreeMap<>();
//Map of only alternatives elements which are list :
//followed by * or + operator.
public Map alts_elems_list = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
ListCast.instance);
public Map<String, LinkedList> alts_elems_list = new TreeMap<>();
//Map of all alternatives elements. Elements name are stored
//if it is specified otherwise, it is its id.
//(elem = elem_name? specifier? id un_op?)
public Map alts_elemsGlobal = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
ListCast.instance);
public Map<String, LinkedList> alts_elemsGlobal = new TreeMap<>();
//Map of all alternatives elements which have explicit name.
public Map alts_elems_list_elemName = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
ListCast.instance);
public Map<String, List> alts_elems_list_elemName = new TreeMap<>();
private LinkedList listElemsGlobal;
private LinkedList listElems;
......
......@@ -38,20 +38,11 @@ public class ResolveAstIds extends DepthFirstAdapter
//by giving the name of this production
// Example :: PAstProd is the name of the declared the following productions
// ast_prod = id equal [alts]:ast_alt* semicolon;
public final Map ast_prods = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
NodeCast.instance);
public final Map<String, AAstProd> ast_prods = new TreeMap<>();
//Same thing that above for AST alternatives.
public final Map ast_alts = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
NodeCast.instance);
public final Map<String, AAstAlt> ast_alts = new TreeMap<>();
//Same thing that above for AST alternatives elements.
public final Map ast_elems = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
NodeCast.instance);
public final Map<String, AElem> ast_elems = new TreeMap<>();
//Map of all names of AST productions.
//They are essentially used to generate AST node classes.
public final Map<Node, String> ast_names = new HashMap<>();
......@@ -179,7 +170,7 @@ public class ResolveAstIds extends DepthFirstAdapter
}
else
{
Object token = astIds.tokens.get("T" + name);
ATokenDef token = astIds.tokens.get("T" + name);
if(token != null)
{
......@@ -230,10 +221,10 @@ public class ResolveAstIds extends DepthFirstAdapter
}
else
{
Object token = astIds.tokens.get("T" + name);
Object ignToken = astIds.ignTokens.get("T" + name);
ATokenDef token = astIds.tokens.get("T" + name);
Node ignToken = astIds.ignTokens.get("T" + name);
//Object production = astIds.prods.get("P" + name);
Object ast_production = ast_prods.get("P" + name);
AAstProd ast_production = ast_prods.get("P" + name);
//if()
if((token == null) && (ast_production == null))
{
......
......@@ -14,26 +14,11 @@ import java.io.*;
public class ResolveIds extends DepthFirstAdapter
{
public final Map helpers = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
NodeCast.instance);
public final Map states = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
NodeCast.instance);
public final Map tokens = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
NodeCast.instance);
public final Map ignTokens = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
NodeCast.instance);
public final Map prods = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
NodeCast.instance);
public final Map<String, AHelperDef> helpers = new TreeMap<>();
public final Map<String, Node> states = new TreeMap<>();
public final Map<String, ATokenDef> tokens = new TreeMap<>();
public final Map<String, Node> ignTokens = new TreeMap<>();
public final Map<String, AProd> prods = new TreeMap<>();
public final Map<String, AAlt> alts = new HashMap<>();
......@@ -50,7 +35,7 @@ public class ResolveIds extends DepthFirstAdapter
// Inside an altTransform, one would look at this map to know its type. (P... or T...)
public final Map<String, String> altsElemTypes = new HashMap<>();
public final Map<Node, Boolean> fixedTokens = new HashMap<>();
public final Map<ATokenDef, Boolean> fixedTokens = new HashMap<>();
public final List tokenList = new TypedLinkedList(StringCast.instance);
public final LinkedList stateList = new TypedLinkedList(StringCast.instance);
......@@ -173,7 +158,7 @@ public class ResolveIds extends DepthFirstAdapter
{
name = ((TId)list_id[i]).getText().toUpperCase();
if(states.put(name, list_id[i]) != null)
if(states.put(name, (Node)list_id[i]) != null)
{
error((TId)list_id[i], name);
}
......@@ -197,7 +182,7 @@ public class ResolveIds extends DepthFirstAdapter
error2((TId)list_id[i], name);
}
if(ignTokens.put(name, list_id[i]) != null)
if(ignTokens.put(name, (Node)list_id[i]) != null)
{
error((TId)list_id[i], name);
}
......@@ -205,14 +190,11 @@ public class ResolveIds extends DepthFirstAdapter
}
}
private Map stateMap;
private Map<String, Node> stateMap;
public void inAStateList(AStateList node)
{
stateMap = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
NodeCast.instance);
stateMap = new TreeMap<>();
String name = node.getId().getText().toUpperCase();
......@@ -445,9 +427,9 @@ public class ResolveIds extends DepthFirstAdapter
}
else
{
Object token = tokens.get("T" + name);
Object ignToken = ignTokens.get("T" + name);
Object production = prods.get("P" + name);
ATokenDef token = tokens.get("T" + name);
Node ignToken = ignTokens.get("T" + name);
AProd production = prods.get("P" + name);
if((token == null) && (production == null))
{
......
......@@ -41,16 +41,10 @@ public class ResolveProdTransformIds extends DepthFirstAdapter
public final Map<String, String> prodTransformElemTypesString = new HashMap<>();
//Map of Productions which transformations contains list elements.
public Map mapProdTransformContainsList = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
ListCast.instance);
public Map<String, LinkedList> mapProdTransformContainsList = new TreeMap<>();
//Map of all Production transformations elements.
public final Map prod_transforms = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
NoCast.instance);
public final Map<String, LinkedList> prod_transforms = new TreeMap<>();
public ResolveProdTransformIds(ResolveAstIds ids)
{
......@@ -211,10 +205,9 @@ public class ResolveProdTransformIds extends DepthFirstAdapter
}
else
{
Object token = transformIds.astIds.tokens.get("T" + name);
Object ignToken = transformIds.astIds.ignTokens.get("T" + name);
Object production = transformIds.astIds.prods.get("P" + name);
Object ast_production = transformIds.ast_prods.get("P" + name);
ATokenDef token = transformIds.astIds.tokens.get("T" + name);
AProd production = transformIds.astIds.prods.get("P" + name);
AAstProd ast_production = transformIds.ast_prods.get("P" + name);
if((token == null) && (ast_production == null) && (production == null))
{
......
......@@ -79,9 +79,9 @@ public class ResolveTransformIds extends DepthFirstAdapter
nbTransformAlt = 0;
currentAlt = altIds.ids.names.get(nodeAlt);
listCurrentAltGlobal = (LinkedList)((LinkedList)altIds.alts_elemsGlobal.get(currentAlt)).clone();
listCurrentAlt = (LinkedList)((LinkedList)altIds.alts_elems.get(currentAlt)).clone();
listOfListCurrentAlt = (LinkedList)((LinkedList)altIds.alts_elems_list.get(currentAlt)).clone();
listCurrentAltGlobal = (LinkedList)altIds.alts_elemsGlobal.get(currentAlt).clone();
listCurrentAlt = (LinkedList)altIds.alts_elems.get(currentAlt).clone();
listOfListCurrentAlt = (LinkedList)altIds.alts_elems_list.get(currentAlt).clone();
}
public void inAAltTransform(AAltTransform node)
......@@ -116,7 +116,6 @@ public class ResolveTransformIds extends DepthFirstAdapter
public void outANewTerm(ANewTerm node)
{
LinkedList list = (LinkedList)prodTransformIds.prod_transforms.get(currentProd);
AProdName prodNameNode = (AProdName)node.getProdName();
currentAstProd = "P" + ResolveIds.name(prodNameNode.getId().getText());
......@@ -159,9 +158,9 @@ public class ResolveTransformIds extends DepthFirstAdapter
}
int sizeAstAlt = 0;
if( ((AAstAlt)transformIds.ast_alts.get(currentAstAlt) ).getElems() != null)
if( transformIds.ast_alts.get(currentAstAlt).getElems() != null)
{
sizeAstAlt = ( (LinkedList)((AAstAlt)transformIds.ast_alts.get(currentAstAlt) ).getElems()).size();
sizeAstAlt = transformIds.ast_alts.get(currentAstAlt).getElems().size();
}
if(sizeNewTerm != sizeAstAlt)
......@@ -175,7 +174,7 @@ public class ResolveTransformIds extends DepthFirstAdapter
altTransformElemTypes.put(node, type);
AAstAlt astAlt = (AAstAlt)transformIds.ast_alts.get(currentAstAlt);
AAstAlt astAlt = transformIds.ast_alts.get(currentAstAlt);
if(node.getParams().size() > 0 && astAlt.getElems().size() > 0)
{
......@@ -206,7 +205,6 @@ public class ResolveTransformIds extends DepthFirstAdapter
public void outANewListTerm(ANewListTerm node)
{
LinkedList list = (LinkedList)prodTransformIds.prod_transforms.get(currentProd);
AProdName prodNameNode = (AProdName)node.getProdName();
currentAstProdName = prodNameNode.getId().getText();
......@@ -249,9 +247,9 @@ public class ResolveTransformIds extends DepthFirstAdapter
}
int sizeAstAlt = 0;
if( ((AAstAlt)transformIds.ast_alts.get(currentAstAlt) ).getElems() != null)
if( transformIds.ast_alts.get(currentAstAlt).getElems() != null)
{
sizeAstAlt = ( (LinkedList)((AAstAlt)transformIds.ast_alts.get(currentAstAlt) ).getElems()).size();
sizeAstAlt = transformIds.ast_alts.get(currentAstAlt).getElems().size();
}
if(sizeNewTerm != sizeAstAlt)
......@@ -265,7 +263,7 @@ public class ResolveTransformIds extends DepthFirstAdapter
altTransformElemTypes.put(node, type);
AAstAlt astAlt = (AAstAlt)transformIds.ast_alts.get(currentAstAlt);
AAstAlt astAlt = transformIds.ast_alts.get(currentAstAlt);
if(node.getParams().size() > 0 && astAlt.getElems().size() > 0)
{
......@@ -420,7 +418,7 @@ public class ResolveTransformIds extends DepthFirstAdapter
{
if(prodTransformIds.prod_transforms.get(typeOfExplicitElemName) != null)
{
listL = (LinkedList)((LinkedList)prodTransformIds.prod_transforms.get(typeOfExplicitElemName)).clone();
listL = (LinkedList)prodTransformIds.prod_transforms.get(typeOfExplicitElemName).clone();
mapSimpleTermProdTransformation.put(currentAlt+"."+tmpName, listL);
}
}
......@@ -431,10 +429,10 @@ public class ResolveTransformIds extends DepthFirstAdapter
}
if( mapSimpleTermProdTransformation.get(currentAlt+".P"+tmpName) == null )
{
listP = (LinkedList)prodTransformIds.prod_transforms.get(name);
listP = prodTransformIds.prod_transforms.get(name);
if(prodTransformIds.prod_transforms.get(name) != null)
{
listP = (LinkedList)((LinkedList)prodTransformIds.prod_transforms.get(name)).clone();
listP = (LinkedList)prodTransformIds.prod_transforms.get(name).clone();
mapSimpleTermProdTransformation.put(currentAlt+".P"+tmpName, listP);
}
}
......@@ -518,19 +516,6 @@ public class ResolveTransformIds extends DepthFirstAdapter
}
}
if(node.getSimpleTermTail() != null)
{
String termtail = node.getSimpleTermTail().getText();
LinkedList listProdContains = null;
if(typeOfExplicitElemName != null)
{
listProdContains = (LinkedList)prodTransformIds.mapProdTransformContainsList.get(typeOfExplicitElemName);
}
else
{
listProdContains = (LinkedList)prodTransformIds.mapProdTransformContainsList.get("P" + ResolveIds.name(node.getId().getText()));
}
}
//The Type of the element without his eventual termtail (term.termtail :: (type of term))
if(typeOfExplicitElemName != null)
{
......@@ -663,7 +648,7 @@ public class ResolveTransformIds extends DepthFirstAdapter
{
if(prodTransformIds.prod_transforms.get(typeOfExplicitElemName) != null)
{
listL = (LinkedList)((LinkedList)prodTransformIds.prod_transforms.get(typeOfExplicitElemName)).clone();
listL = (LinkedList)prodTransformIds.prod_transforms.get(typeOfExplicitElemName).clone();
mapSimpleTermProdTransformation.put(currentAlt+"."+tmpName, listL);
}
}
......@@ -674,10 +659,10 @@ public class ResolveTransformIds extends DepthFirstAdapter
}
if( mapSimpleTermProdTransformation.get(currentAlt+".P"+tmpName) == null )
{
listP = (LinkedList)prodTransformIds.prod_transforms.get(name);
listP = prodTransformIds.prod_transforms.get(name);
if(prodTransformIds.prod_transforms.get(name) != null)
{
listP = (LinkedList)((LinkedList)prodTransformIds.prod_transforms.get(name)).clone();
listP = (LinkedList)prodTransformIds.prod_transforms.get(name).clone();
mapSimpleTermProdTransformation.put(currentAlt+".P"+tmpName, listP);
}
}
......@@ -759,25 +744,6 @@ public class ResolveTransformIds extends DepthFirstAdapter
}
}
if(node.getSimpleTermTail() != null)
{
String termtail = node.getSimpleTermTail().getText();
LinkedList listProdContains = null;
LinkedList prodContains = null;
if(typeOfExplicitElemName != null)
{
listProdContains = (LinkedList)prodTransformIds.mapProdTransformContainsList.get(typeOfExplicitElemName);
prodContains = (LinkedList)prodTransformIds.prod_transforms.get(typeOfExplicitElemName);
}
else
{
listProdContains = (LinkedList)prodTransformIds.mapProdTransformContainsList.get("P" + ResolveIds.name(node.getId().getText()));
prodContains = (LinkedList)prodTransformIds.prod_transforms.get("P" + ResolveIds.name(node.getId().getText()));
}
LinkedList lst = (LinkedList)altIds.alts_elems_list.get(currentAlt);
}
//The Type of the element without his eventual termtail (term.termtail :: (type of term))
if(typeOfExplicitElemName != null)
......
......@@ -13,11 +13,11 @@ import java.util.*;
public class Transitions extends DepthFirstAdapter
{
public final Map<Node, Map> tokenStates = new HashMap<>();
public final Map<ATokenDef, Map<String, String>> tokenStates = new HashMap<>();
private String state;
private String transition;
private Map map;
private Map<String, String> map;
public void caseAStateList(AStateList node)
{
......@@ -44,10 +44,7 @@ public class Transitions extends DepthFirstAdapter
public void inATokenDef(ATokenDef node)
{
map = new TypedTreeMap(
StringComparator.instance,
StringCast.instance,
StringCast.instance);
map = new TreeMap<>();
}
public void inAStateList(AStateList node)
......
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file is part of SableCC. *
* See the file "LICENSE" for copyright information and the *
* terms and conditions for copying, distribution and *
* modification of SableCC. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package org.sablecc.sablecc;
import java.util.*;
public class TypedTreeMap extends TreeMap
{
private Cast keyCast;
private Cast valueCast;
private Set entries;
public TypedTreeMap()
{
super();
keyCast = NoCast.instance;
valueCast = NoCast.instance;
}
public TypedTreeMap(Comparator comparator)
{
super(comparator);
keyCast = NoCast.instance;
valueCast = NoCast.instance;
}
public TypedTreeMap(Map map)
{
super();
keyCast = NoCast.instance;
valueCast = NoCast.instance;
Map.Entry[] entries = (Map.Entry[])map.entrySet().toArray(new Map.Entry[0]);
for(int i=0; i < entries.length; i++)
{
this.put(entries[i].getKey(),entries[i].getValue());
}
}
/*
public TypedTreeMap(Map map)
{
super(map);
keyCast = NoCast.instance;
valueCast = NoCast.instance;
}
*/
public TypedTreeMap(SortedMap smap)
{
super(smap.comparator());
keyCast = NoCast.instance;
valueCast = NoCast.instance;
Map.Entry[] entries = (Map.Entry[])smap.entrySet().toArray(new Map.Entry[0]);
for(int i=0; i < entries.length; i++)
{
this.put(entries[i].getKey(),entries[i].getValue());
}
}
/*
public TypedTreeMap(SortedMap smap)
{
super(smap);
keyCast = NoCast.instance;
valueCast = NoCast.instance;
}
*/
public TypedTreeMap(Cast keyCast, Cast valueCast)
{
super();
this.keyCast = keyCast;
this.valueCast = valueCast;
}
public TypedTreeMap(Comparator comparator, Cast keyCast, Cast valueCast)
{
super(comparator);
this.keyCast = keyCast;
this.valueCast = valueCast;
}
public Object clone()
{
return new TypedTreeMap(this, keyCast, valueCast);
}
public TypedTreeMap(Map map, Cast keyCast, Cast valueCast)
{
super();
this.keyCast = keyCast;
this.valueCast = valueCast;
Map.Entry[] entries = (Map.Entry[])map.entrySet().toArray(new Map.Entry[0]);
for(int i=0; i < entries.length; i++)
{
this.put(entries[i].getKey(),entries[i].getValue());
}
}
/*
public TypedTreeMap(Map map, Cast keyCast, Cast valueCast)
{
super(map);
this.keyCast = keyCast;
this.valueCast = valueCast;
}
*/
public TypedTreeMap(SortedMap smap, Cast keyCast, Cast valueCast)
{
super(smap.comparator());
this.keyCast = keyCast;
this.valueCast = valueCast;
Map.Entry[] entries = (Map.Entry[])smap.entrySet().toArray(new Map.Entry[0]);
for(int i=0; i < entries.length; i++)
{
this.put(entries[i].getKey(),entries[i].getValue());
}
}
/*
public TypedTreeMap(SortedMap smap, Cast keyCast, Cast valueCast)
{
super(smap);
this.keyCast = keyCast;
this.valueCast = valueCast;
}
*/
public Cast getKeyCast()
{
return keyCast;
}
public Cast getValueCast()
{
return valueCast;
}
public Set entrySet()
{
if(entries == null)
{
entries = new EntrySet(super.entrySet());
}
return entries;
}
public Object put(Object key, Object value)
{
return super.put(keyCast.cast(key), valueCast.cast(value));
}
private class EntrySet extends AbstractSet
{
private Set set
;
EntrySet(Set set
)
{
this.set = set
;
}
public int size()
{
return set.size();
}
public Iterator iterator()
{
return new EntryIterator(set.iterator());
}
}
private class EntryIterator implements Iterator
{
private Iterator iterator;
EntryIterator(Iterator iterator)
{
this.iterator = iterator;
}
public boolean hasNext()
{
return iterator.hasNext();
}
public Object next()
{
return new TypedEntry((Map.Entry) iterator.next());
}
public void remove
()
{
iterator.remove();
}
}
private class TypedEntry implements Map.Entry
{
private Map.Entry entry;
TypedEntry(Map.Entry entry)
{
this.entry = entry;
}
public Object getKey()
{
return entry.getKey();
}
public Object getValue()
{
return entry.getValue();
}
public Object setValue(Object value)
{
return entry.setValue(valueCast.cast(value));
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment