From 558796182f5f78acdc46b30c243bcb1cc1d89584 Mon Sep 17 00:00:00 2001 From: stephey Date: Thu, 21 Apr 2011 09:15:39 +0000 Subject: [PATCH] The compiler is BROKEN, but it's NOT MY FAULT. I think Brian forgot to check in something. Anyway, now my code can do single imports and on demand multi-imports. KNOWN PROBLEM: The package declarations can go only 1 level deep.. this means that imports would only work 1 level deep as well (but the logic for it is all correct). I think the problem lies in the .cup file... When I get the name of a package, I only get the last thing in the list of something.something.something.last.class when I ask for the package. I'll check it out later. --- Robust/src/IR/ClassDescriptor.java | 4 +- Robust/src/IR/Tree/BuildIR.java | 120 +++++++++++++++++++------- Robust/src/IR/Tree/SemanticCheck.java | 8 +- Robust/src/IR/TypeUtil.java | 3 +- 4 files changed, 96 insertions(+), 39 deletions(-) diff --git a/Robust/src/IR/ClassDescriptor.java b/Robust/src/IR/ClassDescriptor.java index 46d73e76..c8e1c9d2 100644 --- a/Robust/src/IR/ClassDescriptor.java +++ b/Robust/src/IR/ClassDescriptor.java @@ -19,7 +19,6 @@ public class ClassDescriptor extends Descriptor { SymbolTable methods; Hashtable singleImports; - Vector multiImports; int numstaticblocks = 0; int numstaticfields = 0; @@ -413,9 +412,8 @@ public class ClassDescriptor extends Descriptor { this.sourceFileName=sourceFileName; } - public void setImports(Hashtable singleImports, Vector multiImports) { + public void setImports(Hashtable singleImports) { this.singleImports = singleImports; - this.multiImports = multiImports; } public String getSourceFileName(){ diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 087415d0..29ced9be 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -1,6 +1,8 @@ package IR.Tree; import IR.*; import Util.Lattice; + +import java.io.File; import java.util.*; public class BuildIR { @@ -27,36 +29,66 @@ public class BuildIR { } } - Hashtable singleimports; - Vector multiimports; + //This is all single imports and a subset of the + //multi imports that have been resolved. + Hashtable mandatoryImports; + //maps class names in file to full name + //Note may map a name to an ERROR. + Hashtable multiimports; NameDescriptor packages; /** Parse the classes in this file */ public void parseFile(ParseNode pn, Set toanalyze, String sourcefile) { - singleimports=new Hashtable(); - multiimports=new Vector(); - ParseNode ipn=pn.getChild("imports").getChild("import_decls_list"); - if (ipn!=null) { - ParseNodeVector pnv=ipn.getChildren(); - for(int i=0; i completed; + //This is the class mappings for a particular file based + //on the import names. Maps class to canonical class name. + static Hashtable singleImportMap; public static final int NOCHECK=0; public static final int REFERENCE=1; public static final int INIT=2; @@ -37,7 +40,6 @@ public class SemanticCheck { public ClassDescriptor getClass(ClassDescriptor context, String classname) { return getClass(context, classname, INIT); } - public ClassDescriptor getClass(ClassDescriptor context, String classname, int fullcheck) { if (context!=null) { Hashtable remaptable=context.getSingleImportMappings(); @@ -47,7 +49,7 @@ public class SemanticCheck { checkClass(cd, fullcheck); return cd; } - + public void checkClass(ClassDescriptor cd) { checkClass(cd, INIT); } @@ -121,6 +123,8 @@ public class SemanticCheck { } else { ClassDescriptor cd = (ClassDescriptor) obj; toanalyze.remove(cd); + //set the class mappings based on imports. + singleImportMap = cd.getSingleImportMappings(); // need to initialize typeutil object here...only place we can // get class descriptors without first calling getclass diff --git a/Robust/src/IR/TypeUtil.java b/Robust/src/IR/TypeUtil.java index 35ee680b..05f93f50 100644 --- a/Robust/src/IR/TypeUtil.java +++ b/Robust/src/IR/TypeUtil.java @@ -28,6 +28,7 @@ public class TypeUtil { } public void addNewClass(String cl, Set todo) { + //search through the default locations for the file. for (int i = 0; i < state.classpath.size(); i++) { String path = (String) state.classpath.get(i); //The name has ___________ to separate out packages @@ -41,7 +42,7 @@ public class TypeUtil { throw new Error(e); } } - } + } throw new Error("Couldn't find class " + cl); } -- 2.34.1