From 66ffeaf968bd332f1e18cb27aad11b50e4dd0eab Mon Sep 17 00:00:00 2001 From: bd-912 Date: Fri, 19 Apr 2024 19:04:01 -0600 Subject: Switched to use of Logger Module --- vaporize/library/Kettle.java | 52 ++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'vaporize/library/Kettle.java') diff --git a/vaporize/library/Kettle.java b/vaporize/library/Kettle.java index 340d53e..fb9ddc4 100644 --- a/vaporize/library/Kettle.java +++ b/vaporize/library/Kettle.java @@ -1,6 +1,11 @@ package vaporize.library; +import java.util.logging.Logger; +import java.util.logging.ConsoleHandler; + import cs132.vapor.ast.*; +import misc.*; + import java.util.ArrayList; /** @@ -12,9 +17,17 @@ import java.util.ArrayList; */ class Kettle { + private static Logger log = Logger.getLogger(Kettle.class.getName()); + private static ConsoleHandler consoleHandler = new ConsoleHandler(); + static { + consoleHandler.setFormatter(new MinimalSimpleFormatter()); + log.addHandler(consoleHandler); + } + ArrayList vapor; protected Kettle(ArrayList vapor) { + log.info("Pouring program into kettle..."); this.vapor = vapor; } @@ -27,12 +40,31 @@ class Kettle { protected void replaceFunctionDeclare(VFunction prev, int in, int out, int local) { - this.set(prev, - String.format("func %s [in %d, out %d, local %d]", - this.parseFuncName(this.get(prev)), - in, - out, - local)); + /** + * Replaces a function declaraction in the program + * with the vapor equivalent. + */ + String next = String.format("func %s [in %d, out %d, local %d]", + this.parseFuncName(prev), + in, + out, + local); + + log.info(String.format("Replacing function declaraction\n%s\nwith\n%s", + this.get(prev), + next)); + + this.set(prev, next); + } + + protected String parseFuncName(VFunction func) { + /** + * Helper for replaceFunctionDeclare + * "func A_foo(this t.1)" -> "A_foo" + */ + String str = this.get(func); + int openParenIndex = str.indexOf('('); + return str.substring(5, openParenIndex).trim(); } protected String spill() { @@ -59,12 +91,4 @@ class Kettle { this.vapor.set(this.indexOf(n), s); } - private static String parseFuncName(String func) { - /** - * "func A_foo(this t.1)" -> "A_foo" - */ - int openParenIndex = func.indexOf('('); - return func.substring(5, openParenIndex); - } - } -- cgit v1.2.3