Source code: mlsub/typing/lowlevel/S.java
1 package mlsub.typing.lowlevel;
2
3 import java.util.Properties;
4 import java.io.*;
5
6 /**
7 * Repository of useful global variables and methods
8 *
9 * @version $Revision: 1.4 $, $Date: 2002/08/22 16:58:17 $
10 * @author Alexandre Frey
11 **/
12 public class S {
13 private S() {}
14
15 final static boolean ALLOW_RC = false;
16
17 final public static Properties props = new Properties();
18 static {
19 try {
20 FileInputStream in =
21 new FileInputStream(new File(System.getProperty("user.home"),
22 ".jazzrc"));
23 props.load(new BufferedInputStream(in));
24 in.close();
25 } catch (Exception e) {}
26 }
27
28 public static boolean getBoolean(boolean defaultValue, String name) {
29 if (ALLOW_RC) {
30 String value = props.getProperty(name);
31 if (value == null) {
32 return defaultValue;
33 } else {
34 return value.equals("true");
35 }
36 } else {
37 return defaultValue;
38 }
39 }
40
41 final public static boolean debug = getBoolean(false, "debug");
42
43 final public static boolean debugK0 = getBoolean(false, "debug.K0");
44
45 final public static boolean debugBlock = getBoolean(false, "debug.block");
46 final public static boolean contextSimpl = getBoolean(true, "context.simplify");
47
48 final public static boolean debugSimpl = getBoolean(false, "debug.simplify");
49 final public static boolean trace = getBoolean(false, "trace");
50 final public static boolean trace2 = getBoolean(false, "trace2");
51 final public static boolean debugScope = getBoolean(false, "debug.scope");
52 final public static boolean debugDepend = getBoolean(false, "debug.depend");
53
54 final public static boolean simplifyBlock = getBoolean(true, "simplify.block");
55 final public static boolean prettyPrint = getBoolean(false, "pretty.print");
56 final public static boolean debugPrint = getBoolean(false, "debug.print");
57 final public static boolean debugType = getBoolean(false, "debug.type");
58 final public static boolean debugPoly = getBoolean(false, "debug.poly");
59
60 final public static boolean traceDispatch = getBoolean(false, "trace.dispatch");
61 final public static boolean traceDepth = getBoolean(false, "trace.depth");
62 final public static boolean debugMeth = getBoolean(false, "debug.meth");
63 final public static boolean debug1 = getBoolean(false, "debug.1");
64 final public static boolean debug3 = getBoolean(false, "debug.3");
65 final public static boolean debug2 = getBoolean(false, "debug.2");
66 final public static boolean debugInterf = getBoolean(false, "debug.interf");
67 final public static boolean allowOverloading = getBoolean(false, "allow.overloading");
68 final public static boolean debugNative = getBoolean(false, "debug.native");
69 final public static boolean debugBinders = getBoolean(false, "debug.binders");
70 final public static boolean debugNullTypeArgs = getBoolean(false, "debug.nullTypeArgs");
71 final public static boolean debugModule = getBoolean(false, "debug.module");
72
73 final public static PrintWriter dbg = new PrintWriter(System.err, true);
74
75 public static Error panic() {
76 return panic("");
77 }
78 public static Error panic(String msg) {
79 bossa.util.Internal.error("panic: " + msg);
80 return null;
81
82 }
83
84 public static void printStack() {
85 try {
86 throw new Throwable();
87 } catch (Throwable e) {
88 e.printStackTrace(S.dbg);
89 }
90 }
91 public static String address(Object x) {
92 // return (x == null ? "null" : Integer.toHexString(x.hashCode()));
93 return (x == null ? "null" : Integer.toString(x.hashCode() % 10000));
94 }
95
96 public static void assume(boolean cond) {
97 assume(cond, "");
98 }
99 public static void assume(boolean cond, Object message) {
100 if (allowAssert && !cond) {
101 S.panic("assertion failed: " + message);
102 }
103 }
104 final private static boolean allowAssert = true;
105 final public static boolean a = allowAssert;
106
107
108 public final static int VERBOSE_MUTE = 0;
109 public final static int VERBOSE_DEFAULT = 1;
110 public final static int VERBOSE_DEVEL = 2;
111
112 /**
113 * verbose = 0: mute
114 * verbose = 1: reasonable
115 * verbose = 2: developer
116 **/
117 private static int verboseLevel = 1;
118 static void setVerboseLevel(int verboseLevel) {
119 S.verboseLevel = verboseLevel;
120 }
121 public static void verbosePrintln(int level, String msg) {
122 if (level <= verboseLevel) {
123 S.dbg.println(msg);
124 }
125 }
126 public static void verbosePrint(int level, String msg) {
127 if (level <= verboseLevel) {
128 S.dbg.print(msg);
129 S.dbg.flush();
130 }
131 }
132 }