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

Refactor generating variable declarations in alternative codegen

parent c0911fb8
Branches
Tags
No related merge requests found
......@@ -64,40 +64,41 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
popCount++;
}
@Override
public void inAAltTransform(AAltTransform node)
{
String type_name;
int position;
for(PTerm term : node.getTerms())
{
private void generateVariableDeclaration(Node term) throws IOException {
String typeName;
if(simpleTermTransformMap.get(term) != null)
{
type_name = simpleTermTransformMap.get(term);
typeName = simpleTermTransformMap.get(term);
}
else
{
type_name = CG.getAltTransformElemTypes().get(term);
typeName = CG.getAltTransformElemTypes().get(term);
}
int position = CG.getTermNumbers().get(term);
position = CG.getTermNumbers().get(term);
try
{
if(type_name.startsWith("L"))
if(typeName.startsWith("L"))
{
macros.apply(file, "ParserListVariableDeclaration", new String[] {"" + position});
}
else if(type_name.equals("null"))
else if(typeName.equals("null"))
{
// No intermediate variable needed for null arguments
}
else
{
macros.apply(file, "ParserSimpleVariableDeclaration", new String[] {type_name, type_name.toLowerCase(), "" + position});
macros.apply(file, "ParserSimpleVariableDeclaration", new String[] {typeName, typeName.toLowerCase(), "" + position});
}
}
@Override
public void inAAltTransform(AAltTransform node)
{
for(PTerm term : node.getTerms())
{
try
{
generateVariableDeclaration(term);
}
catch(IOException e)
{
throw new RuntimeException("An error occured while writing to " +
......@@ -157,35 +158,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
public void inAParams(List<PTerm> list_param)
{
String type_name;
int position;
for(PTerm term : list_param)
{
if(simpleTermTransformMap.get(term) != null)
{
type_name = simpleTermTransformMap.get(term);
}
else
{
type_name = CG.getAltTransformElemTypes().get(term);
}
position = CG.getTermNumbers().get(term);
try
{
if(type_name.startsWith("L"))
{
macros.apply(file, "ParserListVariableDeclaration", new String[] {"" + position});
}
else if(type_name.equals("null"))
{
// No intermediate variable needed for null arguments
}
else
{
macros.apply(file, "ParserSimpleVariableDeclaration", new String[] {type_name, type_name.toLowerCase(), "" + position});
}
generateVariableDeclaration(term);
}
catch(IOException e)
{
......@@ -380,31 +357,9 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
try
{
macros.apply(file, "ParserBraceOpening");
for(PListTerm listTerm : node.getListTerms())
{
String type_name;
if(simpleTermTransformMap.get(listTerm) != null)
{
type_name = simpleTermTransformMap.get(listTerm);
}
else
{
type_name = CG.getAltTransformElemTypes().get(listTerm);
}
int position = CG.getTermNumbers().get(listTerm);
if(type_name.startsWith("L"))
for(Node term : node.getListTerms())
{
macros.apply(file, "ParserListVariableDeclaration", new String[] {"" + position});
}
else if(type_name.equals("null"))
{
// No intermediate variable needed for null arguments
}
else
{
macros.apply(file, "ParserSimpleVariableDeclaration", new String[] {type_name, type_name.toLowerCase(), "" + position});
}
generateVariableDeclaration(term);
}
}
catch(IOException e)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment