From f3c29c50aa7dfb5240574bdc2e4d2121bdc9e6b8 Mon Sep 17 00:00:00 2001 From: stephey Date: Thu, 21 Apr 2011 23:40:14 +0000 Subject: [PATCH] Fixes so that our unit tests now pass. Single and multi imports currently only work on .java file classes (i.e. no internal classes). Packages work more than 1 layer deep now. TODO: Add support for importing subclasses Add support for implicit imports (i.e. dir1.dir2.obj o = new dir1.dir2.obj(); calls). P.S. Jin told me to put in the .goal file --- Robust/src/IR/NameDescriptor.java | 4 ++++ Robust/src/IR/Tree/BuildIR.java | 6 ++++-- Robust/src/Tests/output/StaticInnerClassTest.output.goal | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 Robust/src/Tests/output/StaticInnerClassTest.output.goal diff --git a/Robust/src/IR/NameDescriptor.java b/Robust/src/IR/NameDescriptor.java index 3814320e..fb4f5344 100644 --- a/Robust/src/IR/NameDescriptor.java +++ b/Robust/src/IR/NameDescriptor.java @@ -30,6 +30,10 @@ public class NameDescriptor extends Descriptor { return nd.getRoot(); } + public String getPathFromRootToHere() { + return getPathFromRootToHere(identifier); + } + public String getPathFromRootToHere(String id) { String path = id; NameDescriptor temp = this.nd; diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 29ced9be..943f52c5 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -50,7 +50,7 @@ public class BuildIR { if (isNode(pnimport, "import_single")) if (!mandatoryImports.containsKey(nd.getIdentifier())) { // map name to full name (includes package/directory - mandatoryImports.put(nd.getIdentifier(), nd.getPathFromRootToHere(nd.getIdentifier())); + mandatoryImports.put(nd.getIdentifier(), nd.getPathFromRootToHere()); } else { throw new Error("An ambiguous class "+ nd.getIdentifier() +" has been found. It is included for " + ((String)mandatoryImports.get(nd.getIdentifier())).replace("___________", ".") + " and " + @@ -92,8 +92,10 @@ public class BuildIR { ParseNode ppn=pn.getChild("packages").getChild("package"); String packageName = null; if (ppn!=null) { - packageName = ppn.getChild("name").getChild("identifier").getTerminal(); + NameDescriptor nd = parseName(ppn.getChild("name")); + packageName = nd.getPathFromRootToHere(); } + ParseNode tpn=pn.getChild("type_declaration_list"); if (tpn != null) { ParseNodeVector pnv = tpn.getChildren(); diff --git a/Robust/src/Tests/output/StaticInnerClassTest.output.goal b/Robust/src/Tests/output/StaticInnerClassTest.output.goal new file mode 100644 index 00000000..4ff18917 --- /dev/null +++ b/Robust/src/Tests/output/StaticInnerClassTest.output.goal @@ -0,0 +1 @@ +Tasmania -- 2.34.1