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

Improve exception handling and resource management in non-generated code

parent 0fbd4bb0
Branches
Tags
No related merge requests found
Showing
with 71 additions and 460 deletions
...@@ -305,9 +305,9 @@ public class ConstructNFA extends DepthFirstAdapter ...@@ -305,9 +305,9 @@ public class ConstructNFA extends DepthFirstAdapter
this.nodeValues.put(node, cs1.diff(cs2)); this.nodeValues.put(node, cs1.diff(cs2));
} }
} }
catch(Exception e) catch(RuntimeException e)
{ {
throw new RuntimeException(node + " is invalid."); throw new RuntimeException(node + " is invalid.", e);
} }
// free memory // free memory
......
...@@ -59,9 +59,9 @@ class DisplayLicense ...@@ -59,9 +59,9 @@ class DisplayLicense
in.close(); in.close();
System.out.println("---- END OF FILE: COPYING-LESSER ----"); System.out.println("---- END OF FILE: COPYING-LESSER ----");
} }
catch(Exception e) catch(IOException | RuntimeException e)
{ {
System.out.println(e); e.printStackTrace();
System.exit(1); System.exit(1);
} }
} }
......
...@@ -35,7 +35,7 @@ public class GenAlts extends DepthFirstAdapter ...@@ -35,7 +35,7 @@ public class GenAlts extends DepthFirstAdapter
} }
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("unable to open alternatives.txt."); throw new RuntimeException("unable to open alternatives.txt.", e);
} }
pkgDir = new File(ast_ids.astIds.pkgDir, "node"); pkgDir = new File(ast_ids.astIds.pkgDir, "node");
...@@ -107,20 +107,7 @@ public class GenAlts extends DepthFirstAdapter ...@@ -107,20 +107,7 @@ public class GenAlts extends DepthFirstAdapter
{ {
String name = ast_ids.ast_names.get(node); String name = ast_ids.ast_names.get(node);
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, name + ".java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, name + ".java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, name + ".java").getAbsolutePath());
}
try
{ {
boolean hasOperator = false; boolean hasOperator = false;
boolean hasList = false; boolean hasList = false;
...@@ -363,16 +350,9 @@ public class GenAlts extends DepthFirstAdapter ...@@ -363,16 +350,9 @@ public class GenAlts extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, name + ".java").getAbsolutePath()); new File(pkgDir, name + ".java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
elemList = null; elemList = null;
} }
......
...@@ -37,7 +37,7 @@ public class GenAnalyses extends DepthFirstAdapter ...@@ -37,7 +37,7 @@ public class GenAnalyses extends DepthFirstAdapter
} }
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("unable to open analyses.txt."); throw new RuntimeException("unable to open analyses.txt.", e);
} }
pkgDir = new File(ast_ids.astIds.pkgDir, "analysis"); pkgDir = new File(ast_ids.astIds.pkgDir, "analysis");
...@@ -143,20 +143,7 @@ public class GenAnalyses extends DepthFirstAdapter ...@@ -143,20 +143,7 @@ public class GenAnalyses extends DepthFirstAdapter
public void createAnalysis() public void createAnalysis()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "Analysis.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "Analysis.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "Analysis.java").getAbsolutePath());
}
try
{ {
macros.apply(file, "AnalysisHeader", new String[] {pkgName, macros.apply(file, "AnalysisHeader", new String[] {pkgName,
ast_ids.astIds.pkgName.equals("") ? "node" : ast_ids.astIds.pkgName + ".node"}); ast_ids.astIds.pkgName.equals("") ? "node" : ast_ids.astIds.pkgName + ".node"});
...@@ -185,33 +172,13 @@ public class GenAnalyses extends DepthFirstAdapter ...@@ -185,33 +172,13 @@ public class GenAnalyses extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Analysis.java").getAbsolutePath()); new File(pkgDir, "Analysis.java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
public void createAnalysisAdapter() public void createAnalysisAdapter()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "AnalysisAdapter.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "AnalysisAdapter.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "AnalysisAdapter.java").getAbsolutePath());
}
try
{ {
macros.apply(file, "AnalysisAdapterHeader", new String[] {pkgName, macros.apply(file, "AnalysisAdapterHeader", new String[] {pkgName,
ast_ids.astIds.pkgName.equals("") ? "node" : ast_ids.astIds.pkgName + ".node"}); ast_ids.astIds.pkgName.equals("") ? "node" : ast_ids.astIds.pkgName + ".node"});
...@@ -238,33 +205,13 @@ public class GenAnalyses extends DepthFirstAdapter ...@@ -238,33 +205,13 @@ public class GenAnalyses extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "AnalysisAdapter.java").getAbsolutePath()); new File(pkgDir, "AnalysisAdapter.java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
public void createDepthFirstAdapter() public void createDepthFirstAdapter()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "DepthFirstAdapter.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "DepthFirstAdapter.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "DepthFirstAdapter.java").getAbsolutePath());
}
try
{ {
macros.apply(file, "DepthFirstAdapterHeader", new String[] {pkgName, macros.apply(file, "DepthFirstAdapterHeader", new String[] {pkgName,
ast_ids.astIds.pkgName.equals("") ? "node" : ast_ids.astIds.pkgName + ".node", ast_ids.astIds.pkgName.equals("") ? "node" : ast_ids.astIds.pkgName + ".node",
...@@ -309,33 +256,13 @@ public class GenAnalyses extends DepthFirstAdapter ...@@ -309,33 +256,13 @@ public class GenAnalyses extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "DepthFirstAdapter.java").getAbsolutePath()); new File(pkgDir, "DepthFirstAdapter.java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
public void createReversedDepthFirstAdapter() public void createReversedDepthFirstAdapter()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "ReversedDepthFirstAdapter.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "ReversedDepthFirstAdapter.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "ReversedDepthFirstAdapter.java").getAbsolutePath());
}
try
{ {
macros.apply(file, "ReversedDepthFirstAdapterHeader", new String[] {pkgName, macros.apply(file, "ReversedDepthFirstAdapterHeader", new String[] {pkgName,
ast_ids.astIds.pkgName.equals("") ? "node" : ast_ids.astIds.pkgName + ".node", ast_ids.astIds.pkgName.equals("") ? "node" : ast_ids.astIds.pkgName + ".node",
...@@ -382,15 +309,8 @@ public class GenAnalyses extends DepthFirstAdapter ...@@ -382,15 +309,8 @@ public class GenAnalyses extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "ReversedDepthFirstAdapter.java").getAbsolutePath()); new File(pkgDir, "ReversedDepthFirstAdapter.java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
private static class ElemInfo private static class ElemInfo
......
...@@ -35,7 +35,7 @@ public class GenLexer extends AnalysisAdapter ...@@ -35,7 +35,7 @@ public class GenLexer extends AnalysisAdapter
} }
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("unable to open lexer.txt."); throw new RuntimeException("unable to open lexer.txt.", e);
} }
pkgDir = new File(ids.pkgDir, "lexer"); pkgDir = new File(ids.pkgDir, "lexer");
...@@ -102,53 +102,20 @@ public class GenLexer extends AnalysisAdapter ...@@ -102,53 +102,20 @@ public class GenLexer extends AnalysisAdapter
private void createLexerException() private void createLexerException()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "LexerException.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "LexerException.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "LexerException.java").getAbsolutePath());
}
try
{ {
macros.apply(file, "LexerException", new String[] {pkgName}); macros.apply(file, "LexerException", new String[] {pkgName});
} }
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "LexerException.java").getAbsolutePath()); new File(pkgDir, "LexerException.java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
private void createLexer() private void createLexer()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "Lexer.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "Lexer.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "Lexer.java").getAbsolutePath());
}
try
{ {
String startState = "INITIAL"; String startState = "INITIAL";
if(ids.stateList.size() > 0) if(ids.stateList.size() > 0)
...@@ -332,14 +299,7 @@ public class GenLexer extends AnalysisAdapter ...@@ -332,14 +299,7 @@ public class GenLexer extends AnalysisAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Lexer.java").getAbsolutePath()); new File(pkgDir, "Lexer.java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
} }
...@@ -101,7 +101,7 @@ public class GenParser extends DepthFirstAdapter ...@@ -101,7 +101,7 @@ public class GenParser extends DepthFirstAdapter
} }
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("unable to open parser.txt."); throw new RuntimeException("unable to open parser.txt.", e);
} }
pkgDir = new File(ids.pkgDir, "parser"); pkgDir = new File(ids.pkgDir, "parser");
...@@ -237,7 +237,7 @@ public class GenParser extends DepthFirstAdapter ...@@ -237,7 +237,7 @@ public class GenParser extends DepthFirstAdapter
{ {
System.out.println("\nA previous conflict that we've tried to solve by inline some productions inside the grammars cannot be solved that way. The transformed grammar is : "); System.out.println("\nA previous conflict that we've tried to solve by inline some productions inside the grammars cannot be solved that way. The transformed grammar is : ");
tree.apply(new PrettyPrinter()); tree.apply(new PrettyPrinter());
throw new RuntimeException(ce.getMessage()); throw new RuntimeException(ce.getMessage(), ce);
} }
System.out.println(); System.out.println();
...@@ -245,7 +245,7 @@ public class GenParser extends DepthFirstAdapter ...@@ -245,7 +245,7 @@ public class GenParser extends DepthFirstAdapter
} }
else else
{ {
throw new RuntimeException(ce.getMessage()); throw new RuntimeException(ce.getMessage(), ce);
} }
} }
} }
...@@ -357,20 +357,7 @@ public class GenParser extends DepthFirstAdapter ...@@ -357,20 +357,7 @@ public class GenParser extends DepthFirstAdapter
//Parser.java Generation //Parser.java Generation
private void createParser() private void createParser()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "Parser.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "Parser.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "Parser.java").getAbsolutePath());
}
try
{ {
Symbol[] terminals = Symbol.terminals(); Symbol[] terminals = Symbol.terminals();
Symbol[] nonterminals = Symbol.nonterminals(); Symbol[] nonterminals = Symbol.nonterminals();
...@@ -443,18 +430,10 @@ public class GenParser extends DepthFirstAdapter ...@@ -443,18 +430,10 @@ public class GenParser extends DepthFirstAdapter
} }
); );
try
{
for(Element e : stack) for(Element e : stack)
{ {
macros.apply(file, e.macro, e.arguments); macros.apply(file, e.macro, e.arguments);
} }
}
catch(IOException e)
{
throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Parser.java").getAbsolutePath());
}
String nodeName = ids.names.get(node); String nodeName = ids.names.get(node);
String realnodeName = ids.names.get(node); String realnodeName = ids.names.get(node);
...@@ -710,33 +689,13 @@ public class GenParser extends DepthFirstAdapter ...@@ -710,33 +689,13 @@ public class GenParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Parser.java").getAbsolutePath()); new File(pkgDir, "Parser.java").getAbsolutePath(), e);
}
try
{
file.close();
} }
catch(IOException e)
{}
} }
private void createTokenIndex() private void createTokenIndex()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "TokenIndex.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "TokenIndex.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "TokenIndex.java").getAbsolutePath());
}
try
{ {
Symbol[] terminals = Symbol.terminals(); Symbol[] terminals = Symbol.terminals();
...@@ -754,33 +713,13 @@ public class GenParser extends DepthFirstAdapter ...@@ -754,33 +713,13 @@ public class GenParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "TokenIndex.java").getAbsolutePath()); new File(pkgDir, "TokenIndex.java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
private void createParserException() private void createParserException()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "ParserException.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "ParserException.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "ParserException.java").getAbsolutePath());
}
try
{ {
macros.apply(file, "ParserException", new String[] {pkgName, macros.apply(file, "ParserException", new String[] {pkgName,
ids.pkgName.equals("") ? "node" : ids.pkgName + ".node"}); ids.pkgName.equals("") ? "node" : ids.pkgName + ".node"});
...@@ -788,48 +727,21 @@ public class GenParser extends DepthFirstAdapter ...@@ -788,48 +727,21 @@ public class GenParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "ParserException.java").getAbsolutePath()); new File(pkgDir, "ParserException.java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
private void createState() private void createState()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "State.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "State.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "State.java").getAbsolutePath());
}
try
{ {
macros.apply(file, "State", new String[] {pkgName}); macros.apply(file, "State", new String[] {pkgName});
} }
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "State.java").getAbsolutePath()); new File(pkgDir, "State.java").getAbsolutePath(), e);
}
try
{
file.close();
} }
catch(IOException e)
{}
} }
private int count(String name) private int count(String name)
......
...@@ -31,7 +31,7 @@ public class GenProds extends DepthFirstAdapter ...@@ -31,7 +31,7 @@ public class GenProds extends DepthFirstAdapter
} }
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("unable to open productions.txt."); throw new RuntimeException("unable to open productions.txt.", e);
} }
pkgDir = new File(ast_ids.astIds.pkgDir, "node"); pkgDir = new File(ast_ids.astIds.pkgDir, "node");
...@@ -56,67 +56,27 @@ public class GenProds extends DepthFirstAdapter ...@@ -56,67 +56,27 @@ public class GenProds extends DepthFirstAdapter
private void createProduction(String name) private void createProduction(String name)
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, name + ".java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, name + ".java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, name + ".java").getAbsolutePath());
}
try
{ {
macros.apply(file, "Production", new String[] {pkgName, name}); macros.apply(file, "Production", new String[] {pkgName, name});
} }
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, name + ".java").getAbsolutePath()); new File(pkgDir, name + ".java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
private void createAlternative(String name, String macro, String[] arg) private void createAlternative(String name, String macro, String[] arg)
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, name + ".java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, name + ".java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, name + ".java").getAbsolutePath());
}
try
{ {
macros.apply(file, macro, arg); macros.apply(file, macro, arg);
} }
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, name + ".java").getAbsolutePath()); new File(pkgDir, name + ".java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
} }
...@@ -34,7 +34,7 @@ public class GenTokens extends DepthFirstAdapter ...@@ -34,7 +34,7 @@ public class GenTokens extends DepthFirstAdapter
} }
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("unable to open tokens.txt."); throw new RuntimeException("unable to open tokens.txt.", e);
} }
pkgDir = new File(ids.pkgDir, "node"); pkgDir = new File(ids.pkgDir, "node");
...@@ -53,20 +53,6 @@ public class GenTokens extends DepthFirstAdapter ...@@ -53,20 +53,6 @@ public class GenTokens extends DepthFirstAdapter
public void inATokenDef(ATokenDef node) public void inATokenDef(ATokenDef node)
{ {
String name = ids.names.get(node); String name = ids.names.get(node);
BufferedWriter file;
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, name + ".java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, name + ".java").getAbsolutePath());
}
text = null; text = null;
ARegExp regExp = (ARegExp) node.getRegExp(); ARegExp regExp = (ARegExp) node.getRegExp();
...@@ -104,7 +90,7 @@ public class GenTokens extends DepthFirstAdapter ...@@ -104,7 +90,7 @@ public class GenTokens extends DepthFirstAdapter
} }
} }
try try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, name + ".java"))))
{ {
if(text == null) if(text == null)
{ {
...@@ -128,15 +114,8 @@ public class GenTokens extends DepthFirstAdapter ...@@ -128,15 +114,8 @@ public class GenTokens extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, name + ".java").getAbsolutePath()); new File(pkgDir, name + ".java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
private String processText(String s) private String processText(String s)
......
...@@ -32,7 +32,7 @@ public class GenUtils extends DepthFirstAdapter ...@@ -32,7 +32,7 @@ public class GenUtils extends DepthFirstAdapter
} }
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("unable to open utils.txt."); throw new RuntimeException("unable to open utils.txt.", e);
} }
pkgDir = new File(ast_ids.astIds.pkgDir, "node"); pkgDir = new File(ast_ids.astIds.pkgDir, "node");
...@@ -85,20 +85,7 @@ public class GenUtils extends DepthFirstAdapter ...@@ -85,20 +85,7 @@ public class GenUtils extends DepthFirstAdapter
public void createStart() public void createStart()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "Start.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "Start.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "Start.java").getAbsolutePath());
}
try
{ {
macros.apply(file, "Start", new String[] {pkgName, macros.apply(file, "Start", new String[] {pkgName,
ast_ids.astIds.pkgName.equals("") ? "analysis" : ast_ids.astIds.pkgName + ".analysis", ast_ids.astIds.pkgName.equals("") ? "analysis" : ast_ids.astIds.pkgName + ".analysis",
...@@ -107,33 +94,13 @@ public class GenUtils extends DepthFirstAdapter ...@@ -107,33 +94,13 @@ public class GenUtils extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Start.java").getAbsolutePath()); new File(pkgDir, "Start.java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
public void createEOF() public void createEOF()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "EOF.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "EOF.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "EOF.java").getAbsolutePath());
}
try
{ {
macros.apply(file, "EOF", new String[] {pkgName, macros.apply(file, "EOF", new String[] {pkgName,
ast_ids.astIds.pkgName.equals("") ? "analysis" : ast_ids.astIds.pkgName + ".analysis"}); ast_ids.astIds.pkgName.equals("") ? "analysis" : ast_ids.astIds.pkgName + ".analysis"});
...@@ -141,33 +108,13 @@ public class GenUtils extends DepthFirstAdapter ...@@ -141,33 +108,13 @@ public class GenUtils extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "EOF.java").getAbsolutePath()); new File(pkgDir, "EOF.java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
public void createNode() public void createNode()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "Node.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "Node.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "Node.java").getAbsolutePath());
}
try
{ {
macros.apply(file, "Node", new String[] {pkgName, macros.apply(file, "Node", new String[] {pkgName,
ast_ids.astIds.pkgName.equals("") ? "analysis" : ast_ids.astIds.pkgName + ".analysis"}); ast_ids.astIds.pkgName.equals("") ? "analysis" : ast_ids.astIds.pkgName + ".analysis"});
...@@ -175,80 +122,33 @@ public class GenUtils extends DepthFirstAdapter ...@@ -175,80 +122,33 @@ public class GenUtils extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Node.java").getAbsolutePath()); new File(pkgDir, "Node.java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
public void createToken() public void createToken()
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, "Token.java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, "Token.java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, "Token.java").getAbsolutePath());
}
try
{ {
macros.apply(file, "Token", new String[] {pkgName}); macros.apply(file, "Token", new String[] {pkgName});
} }
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Token.java").getAbsolutePath()); new File(pkgDir, "Token.java").getAbsolutePath(), e);
} }
try
{
file.close();
}
catch(IOException e)
{}
} }
public void create(String cls) public void create(String cls)
{ {
BufferedWriter file; try(BufferedWriter file = new BufferedWriter(new FileWriter(new File(pkgDir, cls + ".java"))))
try
{
file = new BufferedWriter(
new FileWriter(
new File(pkgDir, cls + ".java")));
}
catch(IOException e)
{
throw new RuntimeException("Unable to create " + new File(pkgDir, cls + ".java").getAbsolutePath());
}
try
{ {
macros.apply(file, cls, new String[] {pkgName}); macros.apply(file, cls, new String[] {pkgName});
} }
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, cls + ".java").getAbsolutePath()); new File(pkgDir, cls + ".java").getAbsolutePath(), e);
}
try
{
file.close();
} }
catch(IOException e)
{}
} }
} }
...@@ -100,7 +100,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter ...@@ -100,7 +100,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Parser.java").getAbsolutePath()); new File(pkgDir, "Parser.java").getAbsolutePath(), e);
} }
} }
} }
...@@ -150,7 +150,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter ...@@ -150,7 +150,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Parser.java").getAbsolutePath()); new File(pkgDir, "Parser.java").getAbsolutePath(), e);
} }
} }
...@@ -189,7 +189,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter ...@@ -189,7 +189,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Parser.java").getAbsolutePath()); new File(pkgDir, "Parser.java").getAbsolutePath(), e);
} }
} }
} }
...@@ -263,7 +263,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter ...@@ -263,7 +263,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Parser.java").getAbsolutePath()); new File(pkgDir, "Parser.java").getAbsolutePath(), e);
} }
} }
...@@ -339,7 +339,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter ...@@ -339,7 +339,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Parser.java").getAbsolutePath()); new File(pkgDir, "Parser.java").getAbsolutePath(), e);
} }
} }
...@@ -353,7 +353,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter ...@@ -353,7 +353,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Parser.java").getAbsolutePath()); new File(pkgDir, "Parser.java").getAbsolutePath(), e);
} }
inAParams(node.getParams()); inAParams(node.getParams());
} }
...@@ -368,7 +368,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter ...@@ -368,7 +368,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Parser.java").getAbsolutePath()); new File(pkgDir, "Parser.java").getAbsolutePath(), e);
} }
inAParams(node.getParams()); inAParams(node.getParams());
} }
...@@ -409,7 +409,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter ...@@ -409,7 +409,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Parser.java").getAbsolutePath()); new File(pkgDir, "Parser.java").getAbsolutePath(), e);
} }
} }
...@@ -450,7 +450,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter ...@@ -450,7 +450,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "Parser.java").getAbsolutePath()); new File(pkgDir, "Parser.java").getAbsolutePath(), e);
} }
} }
...@@ -523,7 +523,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter ...@@ -523,7 +523,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "TokenIndex.java").getAbsolutePath()); new File(pkgDir, "TokenIndex.java").getAbsolutePath(), e);
} }
} }
...@@ -595,7 +595,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter ...@@ -595,7 +595,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
catch(IOException e) catch(IOException e)
{ {
throw new RuntimeException("An error occured while writing to " + throw new RuntimeException("An error occured while writing to " +
new File(pkgDir, "TokenIndex.java").getAbsolutePath()); new File(pkgDir, "TokenIndex.java").getAbsolutePath(), e);
} }
} }
......
...@@ -144,7 +144,7 @@ public final class Grammar ...@@ -144,7 +144,7 @@ public final class Grammar
{ {
production.rightside(items[k].lr0Item.position); production.rightside(items[k].lr0Item.position);
} }
catch(Exception e) catch(RuntimeException e)
{ {
if(production.leftside != startSymbol) if(production.leftside != startSymbol)
{ {
......
...@@ -90,7 +90,7 @@ public class SableCC { ...@@ -90,7 +90,7 @@ public class SableCC {
else if (arguments[arg].equals(OPT_INLINE_MAX_ALTS)) { else if (arguments[arg].equals(OPT_INLINE_MAX_ALTS)) {
try { try {
inliningMaxAlts = Integer.parseInt(arguments[++arg]); inliningMaxAlts = Integer.parseInt(arguments[++arg]);
} catch (Exception e) { } catch (RuntimeException e) {
displayUsage(); displayUsage();
System.exit(1); System.exit(1);
} }
...@@ -117,7 +117,7 @@ public class SableCC { ...@@ -117,7 +117,7 @@ public class SableCC {
for (int i = 0; i < filename.size(); i++) { for (int i = 0; i < filename.size(); i++) {
processGrammar(filename.elementAt(i), d_option); processGrammar(filename.elementAt(i), d_option);
} }
} catch (Exception e) { } catch (IOException | LexerException | ParserException | RuntimeException e) {
e.printStackTrace(); e.printStackTrace();
System.exit(1); System.exit(1);
} }
...@@ -134,7 +134,7 @@ public class SableCC { ...@@ -134,7 +134,7 @@ public class SableCC {
* output directory name * output directory name
*/ */
public static void processGrammar(String grammar, String destDir) public static void processGrammar(String grammar, String destDir)
throws Exception { throws IOException, LexerException, ParserException {
File in; File in;
File dir; File dir;
...@@ -160,7 +160,7 @@ public class SableCC { ...@@ -160,7 +160,7 @@ public class SableCC {
* @param dir * @param dir
* output directory * output directory
*/ */
public static void processGrammar(File in, File dir) throws Exception { public static void processGrammar(File in, File dir) throws IOException, LexerException, ParserException {
if (!in.exists()) { if (!in.exists()) {
System.out.println("ERROR: grammar file " + in.getName() System.out.println("ERROR: grammar file " + in.getName()
+ " does not exist."); + " does not exist.");
...@@ -253,7 +253,7 @@ public class SableCC { ...@@ -253,7 +253,7 @@ public class SableCC {
try { try {
System.out.println("Generating the lexer."); System.out.println("Generating the lexer.");
tree.apply(new GenLexer(ids)); tree.apply(new GenLexer(ids));
} catch (Exception e) { } catch (RuntimeException e) {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
throw e; throw e;
} }
...@@ -263,7 +263,7 @@ public class SableCC { ...@@ -263,7 +263,7 @@ public class SableCC {
tree.apply(new GenParser(ids, alt_ids, transform_ids, ast_ids tree.apply(new GenParser(ids, alt_ids, transform_ids, ast_ids
.getFirstAstProduction(), processInlining, prettyPrinting, .getFirstAstProduction(), processInlining, prettyPrinting,
hasTransformations)); hasTransformations));
} catch (Exception e) { } catch (RuntimeException e) {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
throw e; throw e;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment