Set up so we compile link all of the files in the test directory. Does not run the binary afterwards, but that's because there's still a print being generated somewhere (and I have no idea where it's coming from).

This commit is contained in:
David Sisson 2016-05-24 01:44:17 -07:00
parent 7d69f24201
commit b3a17b00a2
5 changed files with 44 additions and 34 deletions

View File

@ -157,9 +157,9 @@ string(text) ::= <<
writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>"
writeln(s) ::= <<print(<s>)>>
writeln(s) ::= "cout << <s> << \"\\n\";"
write(s) ::= <<print(<s>,end='')>>
write(s) ::= "cout << <s>;"
False() ::= "False"
@ -303,7 +303,7 @@ else:
class LeafListener(TListener):
def visitTerminal(self, node):
print(node.symbol.text)
cout << node.symbol.text;
>>
@ -333,10 +333,11 @@ else:
class LeafListener(TListener):
def exitA(self, ctx):
if ctx.getChildCount()==2:
print(ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + str_list(ctx.INT()))
else:
print(str(ctx.ID().symbol))
if (ctx.getChildCount()==2) {
cout << ctx.INT(0).symbol.text << ' ' << ctx.INT(1).symbol.text << ' ' << str_list(ctx.INT());
} else {
cout << str(ctx.ID().symbol);
}
>>
@ -348,10 +349,11 @@ else:
class LeafListener(TListener):
def exitA(self, ctx):
if ctx.getChildCount()==2:
print(ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text)
else:
print(ctx.b(0).start.text)
if (ctx.getChildCount()==2) {
cout << ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
} else {
cout << ctx.b(0).start.text;
}
>>
@ -365,9 +367,9 @@ else:
class LeafListener(TListener):
def exitE(self, ctx):
if ctx.getChildCount()==3:
print(ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text)
cout << ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
else:
print(ctx.INT().symbol.text)
cout << ctx.INT().symbol.text;
>>
@ -379,9 +381,9 @@ else:
class LeafListener(TListener):
def exitCall(self, ctx):
print(ctx.e().start.text + ' ' + str(ctx.eList()))
cout << ctx.e().start.text << ' ' << str(ctx.eList());
def exitInt(self, ctx):
print(ctx.INT().symbol.text)
cout << ctx.INT().symbol.text;
>>
@ -393,13 +395,13 @@ def foo():
>>
Declare_foo() ::= <<def foo(self):
print('foo')
cout << 'foo';
>>
Invoke_foo() ::= "self.foo()"
Declare_pred() ::= <<def pred(self, v):
print('eval=' + str(v).lower())
cout << "eval=" << str(v).lower();
return v
>>

View File

@ -527,15 +527,34 @@ public abstract class BaseCppTest {
return execModule("Test.cpp");
}
public List<String> allCppFiles(String path) {
ArrayList<String> files = new ArrayList<String>();
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
String file = listOfFiles[i].getAbsolutePath();
if (file.endsWith(".cpp")) {
files.add(file);
}
}
return files;
}
public String execModule(String fileName) {
String compilerPath = locateCompiler();
String linkerPath = locateLinker();
String runtimePath = locateRuntime();
String modulePath = new File(new File(tmpdir), fileName).getAbsolutePath();
String inputPath = new File(new File(tmpdir), "input").getAbsolutePath();
try {
ProcessBuilder builder = new ProcessBuilder(
compilerPath, "-I", runtimePath, "-std=c++11", "-c", modulePath);
ArrayList<String> args = new ArrayList<String>();
args.add(compilerPath);
args.add("-std=c++11");
args.add("-I");
args.add(runtimePath);
args.add("-L");
args.add(runtimePath);
args.add("-lantlrcpp_static");
args.addAll(allCppFiles(tmpdir));
ProcessBuilder builder = new ProcessBuilder(args.toArray(new String[0]));
builder.directory(new File(tmpdir));
Process process = builder.start();
StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream());
@ -585,17 +604,6 @@ public abstract class BaseCppTest {
return file.getAbsolutePath();
}
protected String locateLinker() {
String propName = getPropertyPrefix() + "-linker";
String prop = System.getProperty(propName);
if(prop==null || prop.length()==0)
prop = locateTool("ld");
File file = new File(prop);
if(!file.exists())
throw new RuntimeException("Missing system property:" + propName);
return file.getAbsolutePath();
}
protected String locateRuntime() {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final URL runtimeSrc = loader.getResource("Cpp/runtime/src");

Binary file not shown.

View File

@ -1008,7 +1008,7 @@ ListenerDispatchMethodHeader(method) ::= <<
virtual void <if (method.isEnter)>enter<else>exit<endif>Rule(Ref\<tree::ParseTreeListener> listener) override;
>>
ListenerDispatchMethod(method) ::= <<
void <method.factory.grammar.name>::<struct.name>::<if (method.isEnter)>enter<else>exit<endif>Rule(Ref\<tree::ParseTreeListener> listener) {
void <parser.grammarName>Parser::<struct.name>::<if (method.isEnter)>enter<else>exit<endif>Rule(Ref\<tree::ParseTreeListener> listener) {
auto parserListener = std::dynamic_pointer_cast\<<parser.grammarName>Listener>(listener);
if (parserListener)
parserListener-><if(method.isEnter)>enter<else>exit<endif><struct.derivedFromName; format="cap">(this);

View File

@ -131,7 +131,7 @@ ParserFile(file, parser, namedActions, contextSuperClass) ::= <<
#include "atn/ATNDeserializer.h"
#include "tree/ParseTreeListener.h"
<if (file.genListener)>#include "<file.parser.name>Listener.h"<endif>
<if (file.genListener)>#include "<file.grammarName>BaseListener.h"<endif>
#include "<file.parser.name>.h"