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

Continue refactoring type handling in alternative code generation

parent 97a6e956
No related branches found
No related tags found
No related merge requests found
......@@ -76,7 +76,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
}
}
private static String variablePrefixFromInternalType(String typeName)
private static String getVariableName(String typeName, int position)
{
if("null".equals(typeName))
{
......@@ -84,11 +84,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
}
else if(typeName.startsWith("L"))
{
return "list";
return "listNode" + position;
}
else
{
return typeName.toLowerCase();
return typeName.toLowerCase() + "Node" + position;
}
}
......@@ -114,7 +114,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
if(typeName.startsWith("L"))
{
macros.apply(file, "ParserListVariableDeclaration", new String[] {"" + position});
macros.apply(file, "ParserListVariableDeclaration", new String[] {getVariableName(typeName, position)});
}
else if(typeName.equals("null"))
{
......@@ -122,7 +122,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
}
else
{
macros.apply(file, "ParserSimpleVariableDeclaration", new String[] {typeName, variablePrefixFromInternalType(typeName), "" + position});
macros.apply(file, "ParserSimpleVariableDeclaration", new String[] {typeName, getVariableName(typeName, position)});
}
}
......@@ -162,7 +162,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
}
else
{
macros.apply(file, "ParserNewBodyListAdd", new String[] {variablePrefixFromInternalType(type_name), "" + position});
macros.apply(file, "ParserNewBodyListAdd", new String[] {getVariableName(type_name, position)});
}
}
......@@ -237,7 +237,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
macros.apply(file, "ParserSimpleTerm", new String[]
{
variablePrefixFromInternalType(type_name), ""+position,
getVariableName(type_name, position),
variableTypeFromInternalType(type_name), ""+elemPosition, ""+positionMap
}
);
......@@ -296,6 +296,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
{
try
{
String listTypeName = lookupInternalTypeName(node);
int listPosition = CG.getTermNumbers().get(node);
for(PListTerm listTerm : node.getListTerms())
......@@ -307,11 +308,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
{
if(type_name.startsWith("L"))
{
macros.apply(file, "ParserTypedLinkedListAddAll", new String[] {"list", ""+listPosition, "list", ""+ position});
macros.apply(file, "ParserTypedLinkedListAddAll", new String[] {getVariableName(listTypeName, listPosition), getVariableName(type_name, position)});
}
else
{
macros.apply(file, "ParserTypedLinkedListAdd", new String[] {"list", ""+listPosition, variablePrefixFromInternalType(type_name), ""+ position});
macros.apply(file, "ParserTypedLinkedListAdd", new String[] {getVariableName(listTypeName, listPosition), getVariableName(type_name, position)});
}
}
}
......@@ -332,7 +333,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
try
{
macros.apply(file, "ParserNewBodyNew", new String[] {variablePrefixFromInternalType(type_name), ""+position, newAltName});
macros.apply(file, "ParserNewBodyNew", new String[] {getVariableName(type_name, position), newAltName});
if(!params.isEmpty())
{
......@@ -345,11 +346,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
if(type_name.equals("null"))
{
macros.apply(file, "ParserNew&ListBodyParamsNull", new String[] {isNotTheFirstParam+"null"});
macros.apply(file, "ParserNewBodyParam", new String[] {isNotTheFirstParam+"null"});
}
else
{
macros.apply(file, "ParserNew&ListBodyParams", new String[] {isNotTheFirstParam + variablePrefixFromInternalType(type_name), ""+position});
macros.apply(file, "ParserNewBodyParam", new String[] {isNotTheFirstParam + getVariableName(type_name, position)});
}
isNotTheFirstParam = ", ";
......
......@@ -333,30 +333,26 @@ Macro:ParserBraceClosing
$
Macro:ParserSimpleVariableDeclaration
$0$ $1$Node$2$;
$0$ $1$;
$
Macro:ParserListVariableDeclaration
LinkedList listNode$0$ = new LinkedList();
LinkedList $0$ = new LinkedList();
$
Macro:ParserSimpleTerm
$0$Node$1$ = ($2$)nodeArrayList$3$.get($4$);
$0$ = ($1$)nodeArrayList$2$.get($3$);
$
Macro:ParserNewBodyNew
$0$Node$1$ = new $2$(
$0$ = new $1$(
$
Macro:ParserNew&ListBodyParams
$0$Node$1$
$
Macro:ParserNew&ListBodyParamsNull
Macro:ParserNewBodyParam
$0$
$
......@@ -366,27 +362,27 @@ Macro:ParserNewBodyNewTail
$
Macro:ParserTypedLinkedListAdd
if($2$Node$3$ != null)
if($1$ != null)
{
$0$Node$1$.add($2$Node$3$);
$0$.add($1$);
}
$
Macro:ParserTypedLinkedListAddAll
if($2$Node$3$ != null)
if($1$ != null)
{
if(!$0$Node$1$.isEmpty()){
$0$Node$1$.addAll($2$Node$3$);
if(!$0$.isEmpty()){
$0$.addAll($1$);
}else{
$0$Node$1$ = $2$Node$3$;
$0$ = $1$;
}
}
$
Macro:ParserNewBodyListAdd
nodeList.add($0$Node$1$);
nodeList.add($0$);
$
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment