Skip to content
Snippets Groups Projects
Commit 65b8ec23 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

initial sketch of typedefs as samples

parent f2be82a5
No related branches found
No related tags found
No related merge requests found
aspect TypeDefGen {
public void Specification.generateTypedefs(PrintStream out, int ver) {
for(Decl d : getDecls()) {
d.generateTypedefs(out);
}
}
public void Decl.generateTypedefs(PrintStream out) {
}
public void Decl.generateDepTypedefs(PrintStream out){
Iterator<Decl> it = type_dependencies().iterator();
while(it.hasNext()) {
Decl d = it.next();
d.generateDepTypedefs(out);
}
pp(out);
}
public void SampleDecl.generateTypedefs(PrintStream out){
if(hasDependencies()) {
out.println("sample "+getName()+"_def {");
out.println(" sample sample;");
out.println(" string typedef = <<EOL");
for(Decl d : type_dependencies()) {
d.generateDepTypedefs(out);
}
pp(out);
out.println("EOL;");
}
}
}
......@@ -36,6 +36,7 @@ public class LabComm {
println("[ Misc options ]");
println(" --pretty=PFILE Pretty prints to PFILE");
println(" --typeinfo=TIFILE Generates typeinfo in TIFILE");
println(" --typedefs=TIFILE Generates typedefs in TIFILE");
}
/** To be cleaned up.
......@@ -139,6 +140,7 @@ public class LabComm {
String pythonFile = null;
String prettyFile = null;
String typeinfoFile = null;
String typedefsFile = null;
String rapidFile = null;
String fileName = null;
......@@ -223,6 +225,8 @@ public class LabComm {
prettyFile = args[i].substring(9);
} else if (args[i].startsWith("--typeinfo=")) {
typeinfoFile = args[i].substring(11);
} else if (args[i].startsWith("--typedefs=")) {
typedefsFile = args[i].substring(11);
} else if (args[i].equals("--rapid")) {
rapidFile = coreName + ".sys";
} else if (i == args.length - 1) {
......@@ -361,6 +365,22 @@ public class LabComm {
return wroteFile;
}
boolean generateTypedefs(Specification ast) {
boolean wroteFile = false;
if (typedefsFile != null) {
printStatus("Typedefs: " , typedefsFile);
try {
FileOutputStream f = new FileOutputStream(typedefsFile);
PrintStream out = new PrintStream(f);
ast.generateTypedefs(out, ver);
wroteFile = true;
} catch (IOException e) {
System.err.println("IOException: " + typedefsFile + " " + e);
}
}
return wroteFile;
}
private void printStatus(String kind, String filename){
if (verbose) {
System.err.println("Generating "+kind+": " + filename);
......@@ -389,6 +409,7 @@ public class LabComm {
fileWritten |= opts.generateRAPID(ast);
fileWritten |= opts.generatePrettyPrint(ast);
fileWritten |= opts.generateTypeinfo(ast);
fileWritten |= opts.generateTypedefs(ast);
// if no output to files, prettyprint on stdout
if (!fileWritten) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment