Skip to content
Snippets Groups Projects
Commit 4fd5ee9c authored by Jesper's avatar Jesper
Browse files

Add attribute statistics option

Added a nonstandard option to write attribute statistics to a CSV file.
parent 784210ce
No related branches found
No related tags found
No related merge requests found
2017-02-06 Jesper Öqvist <jesper.oqvist@cs.lth.se>
* Added --statistics=FILE option. If specified, attribute statistics are
written in CSV format to the specified file. The number of synthesized,
inherited, and collection attribute declarations and equations written
for each AST class.
2016-10-24 Jesper Öqvist <jesper.oqvist@cs.lth.se> 2016-10-24 Jesper Öqvist <jesper.oqvist@cs.lth.se>
* Changed default name of the AST state class from ASTNode$State to * Changed default name of the AST state class from ASTNode$State to
......
...@@ -123,6 +123,29 @@ aspect JastAddCodeGen { ...@@ -123,6 +123,29 @@ aspect JastAddCodeGen {
} }
} }
/**
* @param filename filepath to a CSV file to write to
*/
public void Grammar.writeStatistics(String filename) throws IOException {
System.out.println("Writing attribute statistics to " + filename);
File csv = new File(filename);
PrintStream out = new PrintStream(new FileOutputStream(csv));
out.println("node,syndecl,syneq,inhdecl,inheq,colldecl,colleq");
for (int i = 0; i < getNumTypeDecl(); i++) {
getTypeDecl(i).writeStatistics(out);
}
out.close();
}
public void TypeDecl.writeStatistics(PrintStream out) {
}
public void ASTDecl.writeStatistics(PrintStream out) {
out.format("%s,%d,%d,%d,%d,%d,%d%n", name(), getNumSynDecl(), getNumSynEq(),
getNumInhDecl(), inhAttrSet().size(),
getNumCollDecl(), getNumCollEq());
}
public String TypeDecl.modifiers = ""; public String TypeDecl.modifiers = "";
syn String TypeDecl.modifiers() { syn String TypeDecl.modifiers() {
...@@ -307,7 +330,6 @@ aspect JastAddCodeGen { ...@@ -307,7 +330,6 @@ aspect JastAddCodeGen {
} }
} }
public void ASTDecl.jastAddGen(boolean publicModifier) { public void ASTDecl.jastAddGen(boolean publicModifier) {
File file = grammar().targetJavaFile(name()); File file = grammar().targetJavaFile(name());
try { try {
......
...@@ -333,6 +333,11 @@ public class Configuration { ...@@ -333,6 +333,11 @@ public class Configuration {
FlagOption printNonStandardOptionsOption = new FlagOption("X", FlagOption printNonStandardOptionsOption = new FlagOption("X",
"print list of non-standard options and halt"); "print list of non-standard options and halt");
Option<String> statisticsOption = new ValueOption("statistics",
"write attribute statistics to a CSV file")
.acceptAnyValue()
.nonStandard();
ValueOption indentOption = new ValueOption("indent", "indentation used in generated code") ValueOption indentOption = new ValueOption("indent", "indentation used in generated code")
.addDefaultValue("2space", "two spaces") .addDefaultValue("2space", "two spaces")
.addAcceptedValue("4space", "four spaces") .addAcceptedValue("4space", "four spaces")
...@@ -462,6 +467,9 @@ public class Configuration { ...@@ -462,6 +467,9 @@ public class Configuration {
// New since 2.2.1: // New since 2.2.1:
allOptions.add(safeLazyOption); allOptions.add(safeLazyOption);
// New since 2.2.3:
allOptions.add(statisticsOption);
// Deprecated in 2.1.5. // Deprecated in 2.1.5.
allOptions.add(doxygenOption); allOptions.add(doxygenOption);
allOptions.add(cacheAllOption); allOptions.add(cacheAllOption);
...@@ -792,6 +800,17 @@ public class Configuration { ...@@ -792,6 +800,17 @@ public class Configuration {
return printNonStandardOptionsOption.value(); return printNonStandardOptionsOption.value();
} }
/**
* @return <code>true</code> if attribute statistics should be generated
*/
public boolean shouldWriteStatistics() {
return !statisticsOption.value().isEmpty();
}
public String statisticsFile() {
return statisticsOption.value();
}
/** /**
* @return <code>true</code> if the --tracing option is enabled * @return <code>true</code> if the --tracing option is enabled
*/ */
......
...@@ -232,6 +232,10 @@ public class JastAdd { ...@@ -232,6 +232,10 @@ public class JastAdd {
grammar.jastAddGen(config.getPublicModifier()); grammar.jastAddGen(config.getPublicModifier());
if (config.shouldWriteStatistics()) {
grammar.writeStatistics(config.statisticsFile());
}
} catch(NullPointerException e) { } catch(NullPointerException e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
......
...@@ -286,6 +286,10 @@ public class JastAddTask extends Task { ...@@ -286,6 +286,10 @@ public class JastAddTask extends Task {
setOption(config.safeLazyOption, enable); setOption(config.safeLazyOption, enable);
} }
public void setStatistics(String arg) {
setOption(config.statisticsOption, arg);
}
@Override @Override
public void execute() throws BuildException { public void execute() throws BuildException {
System.err.println("generating node types and weaving aspects"); System.err.println("generating node types and weaving aspects");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment