From 1851f5e76018ec1df3b55dce6cc9a64c9497bf7a Mon Sep 17 00:00:00 2001 From: bd-912 Date: Fri, 26 Apr 2024 15:50:38 -0600 Subject: Rearrange directory structure --- vaporize/library/Kettle.java | 116 ------------------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 vaporize/library/Kettle.java (limited to 'vaporize/library/Kettle.java') diff --git a/vaporize/library/Kettle.java b/vaporize/library/Kettle.java deleted file mode 100644 index ffbf2dd..0000000 --- a/vaporize/library/Kettle.java +++ /dev/null @@ -1,116 +0,0 @@ -package vaporize.library; - -import cs132.vapor.ast.*; -import misc.*; - -import java.util.ArrayList; - -/** - * This class contains various generic methods for - * assembling common-use vaporm strings and managing - * the original input program. - * - * Robert Martin cries - */ -class Kettle { - - ArrayList vapor; - ArrayList vaporm; - - protected Kettle(ArrayList vapor) { - MinimalLogger.info("Pouring program into kettle..."); - this.vapor = vapor; - this.vaporm = new ArrayList(); - } - - protected String get(Node n) { - /** - * Given the source position of a Node, returns the original line. - */ - return this.vapor.get(this.indexOf(n)); - } - - protected void replaceFunctionDeclare(VFunction prev, int in, - int out, int 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); - - MinimalLogger.info(String.format("Replacing function declaraction %s with %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() { - return null; - } - - protected String backup() { - return null; - } - - protected String dump() { - return String.join("\n", this.vapor); - } - - private void set(Node n, String s) { - /** - * Sets the position of Node n in the original - * file to String s. - */ - this.vapor.set(this.indexOf(n), s); - } - - protected int indexOf(Node n) { - return n.sourcePos.line-1; - } - - // METHODS INTENDED TO BE USED WITH CFG - - /** - * Needed because VBranch doesn't seem to - * keep track of this... - */ - protected int findLabelIndex(String str) { - int index = -3; - // is this guarenteed? - String search = str.substring(1); - String comp; - for (int i = 0; i < this.vapor.size(); ++i) { - if (!this.vapor.get(i).isEmpty()) { - comp = this.vapor.get(i).trim(); - if (comp.substring(0, comp.length()-1) - .equals(search)) { - index = i; - break; - } - } - } - - if (index == -3) { - MinimalLogger.severe(String.format("findLabelIndex could not compute label for %s!", - str.trim())); - } - // go to the section AFTER the label, and account for starting at zero - return index+2; - } - -} -- cgit v1.2.3