diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-19 19:36:03 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-19 19:36:03 -0600 |
commit | e188aa3f962df621fc49097418959c7d00ce9969 (patch) | |
tree | c575bd207e9715b6acdc1e655c93209453efffa1 | |
parent | 7b93ef1ec7cb51f3494d7f18cc39dd9d26a24be8 (diff) |
Global PrintFilter -> MinimalLogger
-rw-r--r-- | J2V.java | 2 | ||||
-rw-r--r-- | Typecheck.java | 4 | ||||
-rw-r--r-- | boil/library/BoilSimp.java | 4 | ||||
-rw-r--r-- | misc/PPrinter.java | 18 | ||||
-rw-r--r-- | misc/PrintFilter.java | 15 | ||||
-rw-r--r-- | st/SymTableBottomUp.java | 20 | ||||
-rw-r--r-- | typecheck/library/TypeCheckSimp.java | 25 |
7 files changed, 41 insertions, 47 deletions
@@ -27,7 +27,7 @@ public class J2V { BoilSimp vp = new BoilSimp(symt); root.accept(vp, null); - PrintFilter.print("===================================================", true); + MinimalLogger.info("==================================================="); System.out.println(vp.getVapor()); diff --git a/Typecheck.java b/Typecheck.java index 4c43709..755ce36 100644 --- a/Typecheck.java +++ b/Typecheck.java @@ -17,14 +17,14 @@ public class Typecheck { // GJDepthFirst<R,A>. R=Void, A=String. PPrinter<Void,String> pp = new PPrinter<Void,String>(); root.accept(pp, ""); - PrintFilter.print("===================================================", true); + MinimalLogger.info("==================================================="); // Build the symbol table. Top-down visitor, inherits from // GJDepthFirst<R,A>. R=Void, A=Integer. SymbolTable symt = new SymbolTable(); root.accept(new SymTableBottomUp<Void>(), symt); root.accept(new SymTableTopDown<Void>(), symt); - PrintFilter.print("===================================================", true); + MinimalLogger.info("==================================================="); TypeCheckSimp ts = new TypeCheckSimp(); TypeInstance res = root.accept(ts, symt); diff --git a/boil/library/BoilSimp.java b/boil/library/BoilSimp.java index febaa20..25b27e0 100644 --- a/boil/library/BoilSimp.java +++ b/boil/library/BoilSimp.java @@ -768,8 +768,8 @@ public class BoilSimp extends GJDepthFirst<String,String> { String tp1 = Integer.toString(this.id++); // TypeFactory likes to know who it's renting to String tp2 = Integer.toString(this.id++); - // System.out.println("id " + id); - // System.out.println("cur " + cur); + MinimalLogger.warning("id " + id); + MinimalLogger.warning("cur " + cur); int mtdIndex = cur.getClassInstance().getMethods() .indexOf(this.symt.getMethod(id2)) * 4; diff --git a/misc/PPrinter.java b/misc/PPrinter.java index eff2357..ad2842a 100644 --- a/misc/PPrinter.java +++ b/misc/PPrinter.java @@ -13,12 +13,16 @@ public class PPrinter<R,A> extends GJDepthFirst<R,A> { private int offset; private void printNode(Node n, A argu) { + String str = ""; for (int i=0; i < this.offset; ++i) - PrintFilter.print(".", false); - PrintFilter.print(n.getClass().getSimpleName(), true); + str += "."; + MinimalLogger.info(String.format("%s%s", + str, + n.getClass().getSimpleName())); ++this.offset; } + // // User-generated visitor methods below // @@ -725,11 +729,13 @@ public class PPrinter<R,A> extends GJDepthFirst<R,A> { } public R visit(NodeToken n, A argu) { + String str = ""; for (int i=0; i < this.offset; ++i) - PrintFilter.print(".", false); - PrintFilter.print(n.getClass().getSimpleName() + - " => " + - n.toString(), true); + str += "."; + MinimalLogger.info(String.format("%s%s => %s", + str, + n.getClass().getSimpleName(), + n.toString())); R _ret=null; return _ret; } diff --git a/misc/PrintFilter.java b/misc/PrintFilter.java deleted file mode 100644 index 971ef04..0000000 --- a/misc/PrintFilter.java +++ /dev/null @@ -1,15 +0,0 @@ -package misc; - - -public class PrintFilter { - - public static void print(String message, boolean newline) { - boolean debug = true; - if (debug) { - System.out.print(message); - if (newline) - System.out.println(); - } - } - -} diff --git a/st/SymTableBottomUp.java b/st/SymTableBottomUp.java index 9f60b91..b0772fc 100644 --- a/st/SymTableBottomUp.java +++ b/st/SymTableBottomUp.java @@ -54,12 +54,12 @@ public class SymTableBottomUp<R> extends GJDepthFirst<R,SymbolTable> { String id = n.f1.f0.tokenImage; ClassInstance instance = new ClassInstance(id); - PrintFilter.print("Inserting " + id + " => " + instance.getType(), true); + MinimalLogger.info("Inserting " + id + " => " + instance.getType()); symt.put(id, instance); id = "main"; MethodInstance main = new MethodInstance(id, TypeEnum.ERROR); - PrintFilter.print("Inserting " + id + " => " + main.getType(), true); + MinimalLogger.info("Inserting " + id + " => " + main.getType()); symt.put(id, main); @@ -85,7 +85,7 @@ public class SymTableBottomUp<R> extends GJDepthFirst<R,SymbolTable> { String id = n.f1.f0.tokenImage; ClassInstance instance = new ClassInstance(id); - PrintFilter.print("Inserting " + id + " => " + instance.getType(), true); + MinimalLogger.info("Inserting " + id + " => " + instance.getType()); symt.put(id, instance); @@ -115,7 +115,7 @@ public class SymTableBottomUp<R> extends GJDepthFirst<R,SymbolTable> { String id = n.f1.f0.tokenImage; ClassInstance instance = new ClassInstance(id); - PrintFilter.print("Inserting " + id + " => " + instance.getType(), true); + MinimalLogger.info("Inserting " + id + " => " + instance.getType()); symt.put(id, instance); @@ -144,11 +144,11 @@ public class SymTableBottomUp<R> extends GJDepthFirst<R,SymbolTable> { case 3: rtrn = TypeEnum.classname; break; default: - PrintFilter.print("Unsupported case", true); + MinimalLogger.severe("Unsupported case"); } TypeInstance instance = new TypeInstance(id, rtrn); - PrintFilter.print("Inserting " + id + "=> " + instance.getType(), true); + MinimalLogger.info("Inserting " + id + " => " + instance.getType()); symt.put(id, instance); @@ -198,11 +198,11 @@ public class SymTableBottomUp<R> extends GJDepthFirst<R,SymbolTable> { case 3: rtrn = TypeEnum.classname; break; default: - PrintFilter.print("Unsupported case", true); + MinimalLogger.severe("Unsupported case"); } MethodInstance instance = new MethodInstance(id, rtrn); - PrintFilter.print("Inserting " + id + " => " + instance.getType(), true); + MinimalLogger.info("Inserting " + id + " => " + instance.getType()); symt.put(id, instance); @@ -230,11 +230,11 @@ public class SymTableBottomUp<R> extends GJDepthFirst<R,SymbolTable> { case 3: rtrn = TypeEnum.classname; break; default: - PrintFilter.print("Unsupported case", true); + MinimalLogger.severe("Unsupported case"); } TypeInstance instance = new TypeInstance(id, rtrn); - PrintFilter.print("Inserting " + id + " => " + instance.getType(), true); + MinimalLogger.info("Inserting " + id + " => " + instance.getType()); symt.put(id, instance); diff --git a/typecheck/library/TypeCheckSimp.java b/typecheck/library/TypeCheckSimp.java index b50fa53..b330c65 100644 --- a/typecheck/library/TypeCheckSimp.java +++ b/typecheck/library/TypeCheckSimp.java @@ -15,20 +15,21 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,SymbolTable> { private int offset; private void printNode(Node n, SymbolTable symt, boolean enter, TypeEnum consensus) { + String str = ""; for (int i=0; i < this.offset; ++i) - PrintFilter.print(".", false); + str += "."; if (enter) - PrintFilter.print("Visiting ", false); + str += "Visiting "; else - PrintFilter.print("Leaving ", false); - PrintFilter.print(n.getClass().getSimpleName(), false); + str += "Leaving "; + str += "n.getClass().getSimpleName()"; if (!enter) { if (consensus == TypeEnum.ERROR) - PrintFilter.print(" did not type check.", false); + str += " did not type check."; else - PrintFilter.print(" found type " + consensus, false); + str += String.format(" found type %s", consensus); } - PrintFilter.print("", true); + MinimalLogger.info(str); } public TypeInstance visit(NodeList n, SymbolTable symt) { @@ -110,11 +111,13 @@ public class TypeCheckSimp extends GJDepthFirst<TypeInstance,SymbolTable> { public TypeInstance visit(NodeToken n, SymbolTable symt) { // A fixed string token. '⌣' + String str = ""; for (int i=0; i < this.offset; ++i) - PrintFilter.print(".", false); - PrintFilter.print("Leaving " + n.getClass().getSimpleName() + - " => " + - n.toString(), true); + str += "."; + MinimalLogger.info(String.format("%sLeaving %s => %s", + str, + n.getClass().getSimpleName(), + n.toString())); return null; } |