01: /**************************************************************************/
02: /* B O S S A */
03: /* A simple imperative object-oriented research language */
04: /* (c) Daniel Bonniot 1999 */
05: /* */
06: /* This program is free software; you can redistribute it and/or modify */
07: /* it under the terms of the GNU General Public License as published by */
08: /* the Free Software Foundation; either version 2 of the License, or */
09: /* (at your option) any later version. */
10: /* */
11: /**************************************************************************/package bossa.util;
12:
13: /**
14: Internal messages are sent through this static class
15: */
16:
17: public final class Internal {
18: public static void printStackTrace() {
19: try {
20: throw new Exception();
21: } catch (Exception e) {
22: bossa.syntax.dispatch._printStackTraceWithSourceInfo(e);
23: }
24: }
25:
26: public static void warning(Located loc, String message) {
27: Location l = loc.location();
28: if (l == null)
29: warning(message);
30: else
31: warning(l + ":\n" + message);
32: }
33:
34: public static void warning(String message) {
35: if (Debug.powerUser) {
36: if (Debug.alwaysDumpStack)
37: printStackTrace();
38: if (bossa.modules.Package.currentCompilation != null)
39: bossa.modules.Package.currentCompilation.warning(null,
40: "[Internal warning] " + message);
41: else
42: System.err.println("[Internal warning] " + message);
43: }
44: }
45:
46: public static Error error(Located loc, String message, String dbgMsg) {
47: if (Debug.powerUser)
48: return error(loc, message + dbgMsg);
49: else
50: return error(loc, message);
51: }
52:
53: public static Error error(Located loc, String message) {
54: Location l = loc.location();
55: if (l == null)
56: return error(message);
57: else
58: return error(l + ":\n" + message);
59: }
60:
61: public static Error error(String message, String dbgMsg) {
62: if (Debug.powerUser)
63: return error(message + dbgMsg);
64: else
65: return error(message);
66: }
67:
68: public static Error error(String message) {
69: throw new InternalError(message);
70: }
71:
72: public static Error error(Throwable e) {
73: if (e instanceof ExceptionInInitializerError) {
74: System.out.println("Exception in initializer");
75: e.printStackTrace();
76: e = ((ExceptionInInitializerError) e).getException();
77: }
78:
79: String msg = e.getMessage();
80: if (msg == null)
81: msg = "";
82:
83: System.out.println("[Internal error]\n" + msg);
84: System.out.println("Upstream error:\n");
85: e.printStackTrace();
86: System.out.println("Internal error:\n");
87: printStackTrace();
88: System.exit(1);
89: return null;
90: }
91:
92: }
93:
94: class InternalError extends Error {
95: InternalError(String message) {
96: super(message);
97: }
98: }
|