001: package mlsub.typing.lowlevel;
002:
003: import java.util.Properties;
004: import java.io.*;
005:
006: /**
007: * Repository of useful global variables and methods
008: *
009: * @version $Revision: 1.4 $, $Date: 2002/08/22 16:58:17 $
010: * @author Alexandre Frey
011: **/
012: public class S {
013: private S() {
014: }
015:
016: final static boolean ALLOW_RC = false;
017:
018: final public static Properties props = new Properties();
019: static {
020: try {
021: FileInputStream in = new FileInputStream(new File(System
022: .getProperty("user.home"), ".jazzrc"));
023: props.load(new BufferedInputStream(in));
024: in.close();
025: } catch (Exception e) {
026: }
027: }
028:
029: public static boolean getBoolean(boolean defaultValue, String name) {
030: if (ALLOW_RC) {
031: String value = props.getProperty(name);
032: if (value == null) {
033: return defaultValue;
034: } else {
035: return value.equals("true");
036: }
037: } else {
038: return defaultValue;
039: }
040: }
041:
042: final public static boolean debug = getBoolean(false, "debug");
043:
044: final public static boolean debugK0 = getBoolean(false, "debug.K0");
045:
046: final public static boolean debugBlock = getBoolean(false,
047: "debug.block");
048: final public static boolean contextSimpl = getBoolean(true,
049: "context.simplify");
050:
051: final public static boolean debugSimpl = getBoolean(false,
052: "debug.simplify");
053: final public static boolean trace = getBoolean(false, "trace");
054: final public static boolean trace2 = getBoolean(false, "trace2");
055: final public static boolean debugScope = getBoolean(false,
056: "debug.scope");
057: final public static boolean debugDepend = getBoolean(false,
058: "debug.depend");
059:
060: final public static boolean simplifyBlock = getBoolean(true,
061: "simplify.block");
062: final public static boolean prettyPrint = getBoolean(false,
063: "pretty.print");
064: final public static boolean debugPrint = getBoolean(false,
065: "debug.print");
066: final public static boolean debugType = getBoolean(false,
067: "debug.type");
068: final public static boolean debugPoly = getBoolean(false,
069: "debug.poly");
070:
071: final public static boolean traceDispatch = getBoolean(false,
072: "trace.dispatch");
073: final public static boolean traceDepth = getBoolean(false,
074: "trace.depth");
075: final public static boolean debugMeth = getBoolean(false,
076: "debug.meth");
077: final public static boolean debug1 = getBoolean(false, "debug.1");
078: final public static boolean debug3 = getBoolean(false, "debug.3");
079: final public static boolean debug2 = getBoolean(false, "debug.2");
080: final public static boolean debugInterf = getBoolean(false,
081: "debug.interf");
082: final public static boolean allowOverloading = getBoolean(false,
083: "allow.overloading");
084: final public static boolean debugNative = getBoolean(false,
085: "debug.native");
086: final public static boolean debugBinders = getBoolean(false,
087: "debug.binders");
088: final public static boolean debugNullTypeArgs = getBoolean(false,
089: "debug.nullTypeArgs");
090: final public static boolean debugModule = getBoolean(false,
091: "debug.module");
092:
093: final public static PrintWriter dbg = new PrintWriter(System.err,
094: true);
095:
096: public static Error panic() {
097: return panic("");
098: }
099:
100: public static Error panic(String msg) {
101: bossa.util.Internal.error("panic: " + msg);
102: return null;
103:
104: }
105:
106: public static void printStack() {
107: try {
108: throw new Throwable();
109: } catch (Throwable e) {
110: e.printStackTrace(S.dbg);
111: }
112: }
113:
114: public static String address(Object x) {
115: // return (x == null ? "null" : Integer.toHexString(x.hashCode()));
116: return (x == null ? "null" : Integer
117: .toString(x.hashCode() % 10000));
118: }
119:
120: public static void assume(boolean cond) {
121: assume(cond, "");
122: }
123:
124: public static void assume(boolean cond, Object message) {
125: if (allowAssert && !cond) {
126: S.panic("assertion failed: " + message);
127: }
128: }
129:
130: final private static boolean allowAssert = true;
131: final public static boolean a = allowAssert;
132:
133: public final static int VERBOSE_MUTE = 0;
134: public final static int VERBOSE_DEFAULT = 1;
135: public final static int VERBOSE_DEVEL = 2;
136:
137: /**
138: * verbose = 0: mute
139: * verbose = 1: reasonable
140: * verbose = 2: developer
141: **/
142: private static int verboseLevel = 1;
143:
144: static void setVerboseLevel(int verboseLevel) {
145: S.verboseLevel = verboseLevel;
146: }
147:
148: public static void verbosePrintln(int level, String msg) {
149: if (level <= verboseLevel) {
150: S.dbg.println(msg);
151: }
152: }
153:
154: public static void verbosePrint(int level, String msg) {
155: if (level <= verboseLevel) {
156: S.dbg.print(msg);
157: S.dbg.flush();
158: }
159: }
160: }
|