1 // $Id: platform.h,v 1.53 2004/08/20 00:21:17 elliott-oss Exp $ -*- c++ -*-
2 //
3 // This software is subject to the terms of the IBM Jikes Compiler
4 // License Agreement available at the following URL:
5 // http://ibm.com/developerworks/opensource/jikes.
6 // Copyright (C) 2000, 2004 IBM Corporation and others. All Rights Reserved.
7 // You must accept the terms of that agreement to use this software.
8 //
9 //
10 // NOTE: The code for accurate conversions between floating point
11 // and decimal strings, in double.h, double.cpp, platform.h, and
12 // platform.cpp, is adapted from dtoa.c. The original code can be
13 // found at http://netlib2.cs.utk.edu/fp/dtoa.c.
14 //
15 // The code in dtoa.c is copyrighted as follows:
16 //****************************************************************
17 //*
18 //* The author of this software is David M. Gay.
19 //*
20 //* Copyright (c) 1991, 2000, 2001 by Lucent Technologies.
21 //*
22 //* Permission to use, copy, modify, and distribute this software for any
23 //* purpose without fee is hereby granted, provided that this entire notice
24 //* is included in all copies of any software which is or includes a copy
25 //* or modification of this software and in all copies of the supporting
26 //* documentation for such software.
27 //*
28 //* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
29 //* WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY
30 //* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
31 //* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
32 //*
33 //***************************************************************/
34 //
35 //
36
37 #ifndef platform_INCLUDED
38 #define platform_INCLUDED
39
40
41 #include <config.h>
42
43 /*
44 undefine any symbols defined by the autotools
45 build process that can conflict with our symbols
46 */
47
48 #undef PACKAGE
49 #undef PACKAGE_NAME
50 #undef VERSION
51
52 // A macro for generating <cname> vs. <name.h> as appropriate.
53 #ifdef HAVE_STD
54 # define STD_LIB_NAME(name) <c ## name>
55 #else
56 # define STD_LIB_NAME(name) <name.h>
57 #endif // ! HAVE_STD
58
59 /* Boilerplate autoconf checking */
60
61 #include <sys/types.h>
62 //FIXME: all stat stuff should be included in the platform.cpp file!
63 #include <sys/stat.h>
64 #ifdef STDC_HEADERS
65 # include STD_LIB_NAME(stdlib)
66 # include STD_LIB_NAME(stddef)
67 #else // ! STDC_HEADERS
68 # ifdef HAVE_STDLIB_H
69 # include <stdlib.h>
70 # endif
71 #endif // ! STDC_HEADERS
72
73 #ifdef HAVE_STRING_H
74 # ifndef STDC_HEADERS
75 # ifdef HAVE_MEMORY_H
76 # include <memory.h>
77 # endif
78 # endif // ! STDC_HEADERS
79 # include STD_LIB_NAME(string)
80 #else // ! HAVE_STRING_H
81 # ifdef HAVE_STRINGS_H
82 # include <strings.h>
83 # endif
84 #endif // ! HAVE_STRING_H
85
86 #ifdef HAVE_SYS_CYGWIN_H
87 #include <sys/cygwin.h>
88 #endif
89
90 #if defined(HAVE_LIBICU_UC)
91 # include <unicode/ucnv.h>
92 #elif defined(HAVE_ICONV_H)
93 # include <iconv.h>
94 # include STD_LIB_NAME(errno)
95 #endif
96
97 #ifdef HAVE_UNISTD_H
98 # include <unistd.h>
99 #endif
100
101 #ifdef HAVE_WINDOWS_H
102 # include <windows.h>
103 #endif
104
105 #ifdef HAVE_DIRECT_H
106 # include <direct.h>
107 #endif
108
109 #ifdef HAVE_DIRENT_H
110 # include <dirent.h>
111 #endif
112
113 #ifdef HAVE_ERRNO_H
114 # include STD_LIB_NAME(errno)
115 #endif
116
117 #ifndef HAVE_WINT_T
118 /* On some systems the type wint_t is not defined in wchar.h */
119 typedef unsigned int wint_t;
120 #endif
121
122 #ifdef HAVE_WCHAR_H
123 # include STD_LIB_NAME(wchar)
124 #endif
125
126 #ifdef HAVE_CTYPE_H
127 # include STD_LIB_NAME(ctype)
128 #endif
129
130 #ifdef HAVE_ASSERT_H
131 # include STD_LIB_NAME(assert)
132 #endif
133
134 #ifdef HAVE_STDIO_H
135 # include STD_LIB_NAME(stdio)
136 #endif
137
138 #ifdef HAVE_LIMITS_H
139 # include STD_LIB_NAME(limits)
140 #endif
141
142 #ifdef HAVE_MATH_H
143 # include STD_LIB_NAME(math)
144 #endif
145
146 #ifdef HAVE_FLOAT_H
147 # include STD_LIB_NAME(float)
148 #endif
149
150 #ifdef HAVE_TIME_H
151 # include STD_LIB_NAME(time)
152 #endif
153
154 // C++ standard support
155
156 #ifdef HAVE_STD
157 # include <iostream>
158 # include <fstream>
159 #else
160 # include <iostream.h>
161 # include <fstream.h>
162 #endif // ! HAVE_STD
163
164 // VC++ pretends to support the C++ standard, but it does not.
165 // The set_new_handler method in <new> is not implemented so
166 // the _set_new_handler method in <new.h> must be used.
167
168 #ifdef HAVE_VCPP_SET_NEW_HANDLER
169 # include <new.h>
170 #else
171 # ifdef HAVE_STD
172 # include <new>
173 # else
174 # include <new.h>
175 # endif // ! HAVE_STD
176 #endif // ! HAVE_VCPP_SET_NEW_HANDLER
177
178 #ifdef HAVE_STD
179 # ifdef HAVE_NAMESPACES
180 using namespace std;
181 # endif
182 #endif
183
184
185 //
186 // In the compiler, we want EXACT control over signed and unsigned values
187 // of certain bit widths. Configure should have already found us what we need.
188 //
189 #if HAVE_INTTYPES_H
190 # include <inttypes.h>
191 #else
192 # if HAVE_STDINT_H
193 # include <stdint.h>
194 # endif
195 #endif // HAVE_INTTYPES_H
196
197 typedef uint8_t u1;
198 typedef int8_t i1;
199 typedef uint16_t u2;
200 typedef int16_t i2;
201 typedef uint32_t u4;
202 typedef int32_t i4;
203 #ifdef HAVE_64BIT_TYPES
204 typedef uint64_t u8;
205 typedef int64_t i8;
206 #endif // HAVE_64BIT_TYPES
207 typedef u4 TokenIndex;
208 static const TokenIndex BAD_TOKEN = (TokenIndex) 0;
209
210 // Rename for readability in double.h.
211 #ifdef TYPE_INT32_T_IS_INT
212 #define TYPE_I4_IS_INT TYPE_INT32_T_IS_INT
213 #endif
214
215 //
216 // Some compilers do not correctly predefine the primitive type "bool"
217 // and its possible values: "false" and "true"
218 //
219 #ifndef HAVE_BOOL
220 // We define the type "bool" and the constants "false" and "true".
221 // The type bool as well as the constants false and true are expected
222 // to become standard C++. When that happens, these declarations should
223 // be removed.
224 typedef unsigned char bool;
225 enum { false = 0, true = 1 };
226 #endif
227
228
229 //
230 // Define a templatized function for dynamic_cast<> operator.
231 // This is slightly scary, but we need to do it so that we
232 // can continue to support older compilers that don't implement
233 // the dynamic_cast<> operator. We also do extra checking
234 // of the result when RTTI is supported. This does add some
235 // overhead, but if we catch a downcast bug as a result it
236 // is worth it. Downcast bugs were to blame for a number of
237 // core dumps in Jikes.
238 //
239 #ifdef HAVE_RTTI
240 # include <typeinfo>
241 #endif
242
243 #ifdef HAVE_JIKES_NAMESPACE
244 namespace Jikes { // Open namespace Jikes block
245 #endif
246
247 template <typename TO, typename FROM>
DYNAMIC_CAST(FROM f)248 inline TO DYNAMIC_CAST(FROM f)
249 {
250 #ifndef HAVE_DYNAMIC_CAST
251 return (TO) f;
252 #else
253 // If NULL, return NULL to support dynamic_cast semantics
254 if (!f)
255 return (TO) NULL;
256 TO ptr = dynamic_cast<TO> (f);
257
258 if (! ptr)
259 {
260 # ifdef HAVE_RTTI
261 const type_info& t = typeid(f);
262 const char* name = t.name();
263 fprintf(stderr, "DYNAMIC_CAST argument type was \"%s\"\n", name);
264 # endif // HAVE_RTTI
265 assert(ptr && "Failed dynamic_cast<> in DYNAMIC_CAST");
266 }
267 return ptr;
268 #endif // HAVE_DYNAMIC_CAST
269 }
270
271 //
272 // The configure scripts check each of these to see if we need our own
273 // implementation
274 //
275
276 #ifndef HAVE_WCSLEN
277 extern size_t wcslen(const wchar_t*);
278 #endif
279
280 #ifndef HAVE_WCSCPY
281 extern wchar_t* wcscpy(wchar_t*, const wchar_t*);
282 #endif
283
284 #ifndef HAVE_WCSNCPY
285 extern wchar_t* wcsncpy(wchar_t*, const wchar_t*, size_t);
286 #endif
287
288 #ifndef HAVE_WCSCAT
289 extern wchar_t* wcscat(wchar_t*, const wchar_t*);
290 #endif
291
292 #ifndef HAVE_WCSCMP
293 extern int wcscmp(const wchar_t*, const wchar_t*);
294 #endif
295
296 #ifndef HAVE_WCSNCMP
297 extern int wcsncmp(const wchar_t*, const wchar_t*, size_t);
298 #endif
299
300
301 //
302 // If the system runs out of memory, this function is invoked.
303 //
304 void SetNewHandler();
305
306 #ifdef HAVE_VCPP_SET_NEW_HANDLER
307 extern int OutOfMemory(size_t);
308 #else
309 extern void OutOfMemory();
310 #endif
311
312 //
313 // When using the ICC compiler on Win95 or OS/2, we need to disable
314 // testing for various floating point exceptions. Default behavior
315 // was causing problems reading some standard class files.
316 //
317 extern void FloatingPointCheck();
318
319
320 //
321 // variants of system functions
322 // are declared here and defined in code.cpp
323 //
324 extern int SystemStat(const char* name, struct stat* stat_struct);
325 extern FILE* SystemFopen(const char* name, const char* mode);
326 extern size_t SystemFread(char* ptr, size_t element_size, size_t count,
327 FILE* stream);
328 extern int SystemIsDirectory(char* name);
329
330 //
331 // The symbol used in this environment for separating argument in a system
332 // string. E.g., in a unix system directories specified in the CLASSPATH
333 // are separated by a ':', whereas in win95 it is ';'.
334 //
335 extern char PathSeparator();
336 extern int SystemMkdir(char*);
337 extern int SystemMkdirhier(char*);
338 extern int SystemMkdirhierForFile(char*);
339
340 extern char* strcat3(const char*, const char*, const char*);
341 extern char* wstring2string(wchar_t* in);
342
343
344 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
345 //
346 // End of platform specific defines in this file, the rest of the code
347 // in this file should work on any system
348 //
349 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
350
351
352 // The following comment was part of the original config.h, it explains why
353 // some parts of the guts of the compiler are written the way they are. This
354 // comment was removed when the ifdef'd EBCDIC code was initially removed.
355 // I've added it back for its "why do they do it that way" value, hopefully
356 // its presence will help prevent people from making assumptions and breaking
357 // the code for non-ascii platforms. At some point we'll want to be able to
358 // compile on EBCDIC systems again, using the API and iconv/ICU instead of
359 // ifdefs scattered all over creation, if the core code hasn't been
360 // compromised this should be easier. For those that have no idea what EBCDIC
361 // is... it is like ASCII in that it is an encoding system, but it predates
362 // ASCII by a number of years (think punchcards). It is still the default
363 // encoding on some mainframes and minicomputers such as the IBM zSeries and
364 // iSeries (aka the 390 and the 400). To see what the old EBCDIC code looked
365 // like, pull a cvs tree with the tag v1-06.
366 //
367 //
368 // Jikes can be compiled on systems using the EBCDIC character set, for which
369 // character and string literals are translated by the compiler to EBCDIC and
370 // not ASCII, and so cannot be used to represent ASCII/UNICODE values. Such
371 // values are constructed using the U_ values defined below. Thus 'a' is
372 // represented using U_a, and ".java" is represented by an explicit literal:
373 // {U_DOT, U_j, U_a, U_v, U_a, U_NULL}
374 // Variables associated with such literals have names beginning with US_ if
375 // the value are 16-bits or U8S_ for 8 bits. The initial underscore is
376 // followed by the characters being represented, with letters and digits
377 // representing themselves, and other values, all of which have a two
378 // character code, surrounded by underscore. Thus the name used for the
379 // literal above is US_DO_java.
380 //
381 // All string-related values are represented internally in ASCII/UNICODE
382 // using the U_ values defined below. EBCDIC systems also require that
383 // arguments to system functions representing file names be converted from
384 // the internal form used by Jikes to EBCDIC, and such functions are referred
385 // to using their usual name prefixed with "system_"; for example, a call to
386 // "fopen(..." is written "system_fopen(..." The "system_" procedures are
387 // define in the file code.cpp.
388 //
389
390 enum U_chars
391 {
392 U_NULL = 0, U_NU = U_NULL, // L'\0'
393 U_BACKSPACE = 8, U_BS = U_BACKSPACE, // L'\b'
394 U_HORIZONTAL_TAB = 9, U_HT = U_HORIZONTAL_TAB, // L'\t'
395 U_LINE_FEED = 10, U_LF = U_LINE_FEED, // L'\n'
396 U_FORM_FEED = 12, U_FF = U_FORM_FEED, // L'\f'
397 U_CARRIAGE_RETURN = 13, U_CR = U_CARRIAGE_RETURN, // L'\r'
398
399 U_CTL_Z = 26,
400 U_ESCAPE = 27,
401
402 U_SPACE = 32, U_SP = U_SPACE, // L' '
403 U_EXCLAMATION = 33, U_EX = U_EXCLAMATION, // L'!'
404 U_DOUBLE_QUOTE = 34, U_DQ = U_DOUBLE_QUOTE, // L'"'
405 U_POUND = 35, U_SH = U_POUND, // L'#'
406 U_DOLLAR = 36, U_DS = U_DOLLAR, // L'$'
407 U_PERCENT = 37, U_PE = U_PERCENT, // L'%'
408 U_AMPERSAND = 38, U_AM = U_AMPERSAND, // L'&'
409 U_SINGLE_QUOTE = 39, U_SQ = U_SINGLE_QUOTE, // L'\''
410 U_LEFT_PARENTHESIS = 40, U_LP = U_LEFT_PARENTHESIS, // L'('
411 U_RIGHT_PARENTHESIS = 41, U_RP = U_RIGHT_PARENTHESIS, // L')'
412 U_STAR = 42, U_ST = U_STAR, // L'*'
413 U_PLUS = 43, U_PL = U_PLUS, // L'+'
414 U_MINUS = 45, U_MI = U_MINUS, // L'-'
415 U_COMMA = 44, U_CM = U_COMMA, // L','
416 U_DOT = 46, U_DO = U_DOT, // L'.'
417 U_SLASH = 47, U_SL = U_SLASH, // L'/'
418
419 U_0 = 48, // L'0'
420 U_1 = 49, // L'1'
421 U_2 = 50, // L'2'
422 U_3 = 51, // L'3'
423 U_4 = 52, // L'4'
424 U_5 = 53, // L'5'
425 U_6 = 54, // L'6'
426 U_7 = 55, // L'7'
427 U_8 = 56, // L'8'
428 U_9 = 57, // L'9'
429
430 U_COLON = 58, U_CO = U_COLON, // L':'
431 U_SEMICOLON = 59, U_SC = U_SEMICOLON, // L';'
432 U_LESS = 60, U_LT = U_LESS, // L'<'
433 U_EQUAL = 61, U_EQ = U_EQUAL, // L'='
434 U_GREATER = 62, U_GT = U_GREATER, // L'>'
435 U_QUESTION = 63, U_QU = U_QUESTION, // L'?'
436 U_AT = 64, // L'@'
437
438 U_A = 65, // L'A'
439 U_B = 66, // L'B'
440 U_C = 67, // L'C'
441 U_D = 68, // L'D'
442 U_E = 69, // L'E'
443 U_F = 70, // L'F'
444 U_G = 71, // L'G'
445 U_H = 72, // L'H'
446 U_I = 73, // L'I'
447 U_J = 74, // L'J'
448 U_K = 75, // L'K'
449 U_L = 76, // L'L'
450 U_M = 77, // L'M'
451 U_N = 78, // L'N'
452 U_O = 79, // L'O'
453 U_P = 80, // L'P'
454 U_Q = 81, // L'Q'
455 U_R = 82, // L'R'
456 U_S = 83, // L'S'
457 U_T = 84, // L'T'
458 U_U = 85, // L'U'
459 U_V = 86, // L'V'
460 U_W = 87, // L'W'
461 U_X = 88, // L'X'
462 U_Y = 89, // L'Y'
463 U_Z = 90, // L'Z'
464
465 U_LEFT_BRACKET = 91, U_LB = U_LEFT_BRACKET, // L'['
466 U_BACKSLASH = 92, U_RS = U_BACKSLASH, // L'\\'
467 U_RIGHT_BRACKET = 93, U_RB = U_RIGHT_BRACKET, // L']'
468 U_CARET = 94, U_CA = U_CARET, // L'^'
469 U_UNDERSCORE = 95, U_UN = U_UNDERSCORE, // L'_'
470
471 U_a = 97, // L'a'
472 U_b = 98, // L'b'
473 U_c = 99, // L'c'
474 U_d = 100, // L'd'
475 U_e = 101, // L'e'
476 U_f = 102, // L'f'
477 U_g = 103, // L'g'
478 U_h = 104, // L'h'
479 U_i = 105, // L'i'
480 U_j = 106, // L'j'
481 U_k = 107, // L'k'
482 U_l = 108, // L'l'
483 U_m = 109, // L'm'
484 U_n = 110, // L'n',
485 U_o = 111, // L'o'
486 U_p = 112, // L'p'
487 U_q = 113, // L'q'
488 U_r = 114, // L'r'
489 U_s = 115, // L's'
490 U_t = 116, // L't'
491 U_u = 117, // L'u'
492 U_v = 118, // L'v'
493 U_w = 119, // L'w'
494 U_x = 120, // L'x'
495 U_y = 121, // L'y'
496 U_z = 122, // L'z'
497
498 U_LEFT_BRACE = 123, U_OS = U_LEFT_BRACE, // L'{'
499 U_BAR = 124, U_BA = U_BAR, // L'|'
500 U_RIGHT_BRACE = 125, U_CS = U_RIGHT_BRACE, // L'}'
501 U_TILDE = 126, U_TI = U_TILDE, // L'~'
502
503 U_BOM = 0xfeff,
504 U_REVERSE_BOM = 0xfffe
505 };
506
507
508 //
509 // Constant strings used in the program. Those prefixed with US_ are
510 // Unicode strings in wchar_t, and those with U8S are UTF8 strings in char.
511 //
512 class StringConstant
513 {
514 public:
515 //
516 // Symbols and operators.
517 //
518 static const wchar_t US_AND[]; // L"&"
519 static const wchar_t US_AND_AND[]; // L"&&"
520 static const wchar_t US_AND_EQUAL[]; // L"&="
521 static const wchar_t US_AT[]; // L"@"
522 static const wchar_t US_COLON[]; // L":"
523 static const wchar_t US_COMMA[]; // L";"
524 static const wchar_t US_DIVIDE[]; // L"/"
525 static const wchar_t US_DIVIDE_EQUAL[]; // L"/="
526 static const wchar_t US_DOT[]; // L"."
527 static const wchar_t US_DOT_DOT_DOT[]; // L"..."
528 static const wchar_t US_EMPTY[]; // L""
529 static const wchar_t US_EOF[]; // L"EOF"
530 static const wchar_t US_EQUAL[]; // L"="
531 static const wchar_t US_EQUAL_EQUAL[]; // L"=="
532 static const wchar_t US_GREATER[]; // L">"
533 static const wchar_t US_GREATER_EQUAL[]; // L">="
534 static const wchar_t US_LBRACE[]; // L"{"
535 static const wchar_t US_LBRACKET[]; // L"["
536 static const wchar_t US_LEFT_SHIFT[]; // L"<<"
537 static const wchar_t US_LEFT_SHIFT_EQUAL[]; // L"<<="
538 static const wchar_t US_LESS[]; // L"<"
539 static const wchar_t US_LESS_EQUAL[]; // L"<="
540 static const wchar_t US_LPAREN[]; // L"("
541 static const wchar_t US_MINUS[]; // L"-"
542 static const wchar_t US_MINUS_EQUAL[]; // L"-="
543 static const wchar_t US_MINUS_MINUS[]; // L"--"
544 static const wchar_t US_MULTIPLY[]; // L"*"
545 static const wchar_t US_MULTIPLY_EQUAL[]; // L"*="
546 static const wchar_t US_NOT[]; // L"!"
547 static const wchar_t US_NOT_EQUAL[]; // L"!="
548 static const wchar_t US_OR[]; // L"|"
549 static const wchar_t US_OR_EQUAL[]; // L"|="
550 static const wchar_t US_OR_OR[]; // L"||"
551 static const wchar_t US_PLUS[]; // L"+"
552 static const wchar_t US_PLUS_EQUAL[]; // L"+="
553 static const wchar_t US_PLUS_PLUS[]; // L"++"
554 static const wchar_t US_QUESTION[]; // L"?"
555 static const wchar_t US_RBRACE[]; // L"}"
556 static const wchar_t US_RBRACKET[]; // L"]"
557 static const wchar_t US_REMAINDER[]; // L"%"
558 static const wchar_t US_REMAINDER_EQUAL[]; // L"%="
559 static const wchar_t US_RIGHT_SHIFT[]; // L">>"
560 static const wchar_t US_RIGHT_SHIFT_EQUAL[]; // L">>="
561 static const wchar_t US_RPAREN[]; // L")"
562 static const wchar_t US_SEMICOLON[]; // L";"
563 static const wchar_t US_TWIDDLE[]; // L"~"
564 static const wchar_t US_UNSIGNED_RIGHT_SHIFT[]; // L">>>"
565 static const wchar_t US_UNSIGNED_RIGHT_SHIFT_EQUAL[]; // L">>>="
566 static const wchar_t US_XOR[]; // L"^"
567 static const wchar_t US_XOR_EQUAL[]; // L"^="
568
569
570 //
571 // Unicode strings for files and packages.
572 //
573 static const wchar_t US_DS[]; // L"$"
574 static const wchar_t US_LB_RB[]; // L"[]"
575 static const wchar_t US_MI[]; // L"-"
576 static const wchar_t US_SC[]; // L";"
577 static const wchar_t US_SL[]; // L"/"
578 static const wchar_t US_jar[]; // L"jar"
579 static const wchar_t US_java_SL_io[]; // L"java/io"
580 static const wchar_t US_java_SL_lang[]; // L"java/lang"
581 // L"java/lang/annotation"
582 static const wchar_t US_java_SL_lang_SL_annotation[];
583 static const wchar_t US_java_SL_util[]; // L"java/util"
584 static const wchar_t US_zip[]; // L"zip"
585
586 //
587 // Java keywords.
588 //
589 static const wchar_t US_abstract[]; // L"abstract"
590 static const wchar_t US_assert[]; // L"assert"
591 static const wchar_t US_boolean[]; // L"boolean"
592 static const wchar_t US_break[]; // L"break"
593 static const wchar_t US_byte[]; // L"byte"
594 static const wchar_t US_case[]; // L"case"
595 static const wchar_t US_catch[]; // L"catch"
596 static const wchar_t US_char[]; // L"char"
597 static const wchar_t US_class[]; // L"class"
598 static const wchar_t US_const[]; // L"const"
599 static const wchar_t US_continue[]; // L"continue"
600 static const wchar_t US_default[]; // L"default"
601 static const wchar_t US_do[]; // L"do"
602 static const wchar_t US_double[]; // L"double"
603 static const wchar_t US_else[]; // L"else"
604 static const wchar_t US_enum[]; // L"enum"
605 static const wchar_t US_extends[]; // L"extends"
606 static const wchar_t US_false[]; // L"false"
607 static const wchar_t US_final[]; // L"final"
608 static const wchar_t US_finally[]; // L"finally"
609 static const wchar_t US_float[]; // L"float"
610 static const wchar_t US_for[]; // L"for"
611 static const wchar_t US_goto[]; // L"goto"
612 static const wchar_t US_if[]; // L"if"
613 static const wchar_t US_implements[]; // L"implements"
614 static const wchar_t US_import[]; // L"import"
615 static const wchar_t US_instanceof[]; // L"instanceof"
616 static const wchar_t US_int[]; // L"int"
617 static const wchar_t US_interface[]; // L"interface"
618 static const wchar_t US_long[]; // L"long"
619 static const wchar_t US_native[]; // L"native"
620 static const wchar_t US_new[]; // L"new"
621 static const wchar_t US_null[]; // L"null"
622 static const wchar_t US_package[]; // L"package"
623 static const wchar_t US_private[]; // L"private"
624 static const wchar_t US_protected[]; // L"protected"
625 static const wchar_t US_public[]; // L"public"
626 static const wchar_t US_return[]; // L"return"
627 static const wchar_t US_short[]; // L"short"
628 static const wchar_t US_static[]; // L"static"
629 static const wchar_t US_strictfp[]; // L"strictfp"
630 static const wchar_t US_super[]; // L"super"
631 static const wchar_t US_switch[]; // L"switch"
632 static const wchar_t US_synchronized[]; // L"synchronized"
633 static const wchar_t US_this[]; // L"this"
634 static const wchar_t US_throw[]; // L"throw"
635 static const wchar_t US_throws[]; // L"throws"
636 static const wchar_t US_transient[]; // L"transient"
637 static const wchar_t US_true[]; // L"true"
638 static const wchar_t US_try[]; // L"try"
639 static const wchar_t US_void[]; // L"void"
640 static const wchar_t US_volatile[]; // L"volatile"
641 static const wchar_t US_while[]; // L"while"
642
643 //
644 // Miscellaneous strings.
645 //
646 static const char U8S_help_header[];
647 static const char U8S_command_format[];
648
649 //
650 // Constant pool entries.
651 //
652 static const char U8S_AnnotationDefault[]; // "AnnotationDefault"
653 static const char U8S_Code[]; // "Code"
654 static const char U8S_ConstantValue[]; // "ConstantValue"
655 static const char U8S_Deprecated[]; // "Deprecated"
656 static const char U8S_EnclosingMethod[]; // "EnclosingMethod"
657 static const char U8S_Exceptions[]; // "Exceptions"
658 static const char U8S_InnerClasses[]; // "InnerClasses"
659 static const char U8S_LineNumberTable[]; // "LineNumberTable"
660 static const char U8S_LocalVariableTable[]; // "LocalVariableTable"
661 static const char U8S_LocalVariableTypeTable[]; // "LocalVariableTypeTable"
662 // "RuntimeInvisibleAnnotations"
663 static const char U8S_RuntimeInvisibleAnnotations[];
664 // "RuntimeInvisibleParameterAnnotations"
665 static const char U8S_RuntimeInvisibleParameterAnnotations[];
666 // "RuntimeVisibleAnnotations"
667 static const char U8S_RuntimeVisibleAnnotations[];
668 // "RuntimeVisibleParameterAnnotations"
669 static const char U8S_RuntimeVisibleParameterAnnotations[];
670 static const char U8S_Signature[]; // "Signature"
671 static const char U8S_SourceFile[]; // "SourceFile"
672 static const char U8S_StackMap[]; // "StackMap"
673 static const char U8S_Synthetic[]; // "Synthetic"
674
675 //
676 // ASCII file names.
677 //
678 static const char U8S_DO_class[]; // ".class"
679 static const char U8S_DO_java[]; // ".java"
680 static const char U8S_DO_tok[]; // ".tok"
681 static const char U8S_DO_u[]; // ".u"
682 static const char U8S_LP[]; // "("
683 static const char U8S_RP[]; // ")"
684 static const char U8S_SL[]; // "/"
685
686 //
687 // Convert number to string.
688 //
689 static const char U8S_NaN[]; // "NaN"
690 static const char U8S_pos_Infinity[]; // "Infinity"
691 static const char U8S_neg_Infinity[]; // "-Infinity"
692 static const char U8S_pos_Zero[]; // "0.0"
693 static const char U8S_neg_Zero[]; // "-0.0"
694 };
695
696
697 //
698 // Convert an integer to its character string representation.
699 //
700 class IntToString
701 {
702 public:
703 IntToString(i4); // Signed decimal conversion.
704 IntToString(u4, int width); // Unsigned zero-padded hexadecimal.
705
String()706 const char* String() { return str; }
Length()707 int Length() { return (&info[TAIL_INDEX]) - str; }
708
709 private:
710 enum { TAIL_INDEX = 1 + 10 }; // 1 for sign, +10 significant digits
711
712 char info[TAIL_INDEX + 1]; // +1 for '\0'
713 char* str;
714 };
715
716
717 //
718 // Same as IntToString for wide strings.
719 //
720 class IntToWstring
721 {
722 public:
723 IntToWstring(i4);
724
String()725 const wchar_t* String() { return wstr; }
Length()726 int Length() { return (&winfo[TAIL_INDEX]) - wstr; }
727
728 private:
729 enum { TAIL_INDEX = 1 + 10 }; // 1 for sign, +10 significant digits
730
731 wchar_t winfo[TAIL_INDEX + 1]; // 1 for sign, +10 significant digits + '\0'
732 wchar_t* wstr;
733 };
734
735
736 //
737 // Convert a Long integer to its character string representation.
738 //
739 class BaseLong;
740 class ULongInt;
741 class LongInt;
742 class LongToString
743 {
744 public:
745 LongToString(const LongInt&); // Signed decimal conversion.
746 LongToString(const ULongInt&); // Unsigned decimal conversion.
747 // Unsigned hexadecimal or octal, with optional base designator.
748 LongToString(const BaseLong&, bool octal = false);
749
String()750 const char* String() { return str; }
StringWithBase()751 const char* StringWithBase() { return base; }
Length()752 int Length() { return (&info[TAIL_INDEX]) - str; }
753
754 private:
755 enum { TAIL_INDEX = 23 }; // 22 octal digits + base designator
756
757 char info[TAIL_INDEX + 1]; // +1 for '\0'
758 char* str;
759 char* base;
760 };
761
762
763 //
764 // Convert an double to its character string representation.
765 //
766 class IEEEdouble;
767 class DoubleToString
768 {
769 public:
770 DoubleToString(const IEEEdouble&);
771
String()772 const char* String() const { return str; }
Length()773 int Length() const { return length; }
774
775 private:
776 void Format(char*, int, bool);
777
778 enum
779 {
780 MAXIMUM_PRECISION = 17,
781 // +1 for sign, +17 significant digits +1 for ".", +5 for exponent
782 MAXIMUM_STR_LENGTH = 1 + MAXIMUM_PRECISION + 1 + 5
783 };
784
785 char str[MAXIMUM_STR_LENGTH + 1]; // +1 for '\0'
786 int length;
787 };
788
789 //
790 // Convert an float to its character string representation.
791 //
792 class IEEEfloat;
793 class FloatToString
794 {
795 public:
796 FloatToString(const IEEEfloat&);
797
String()798 const char* String() const { return str; }
Length()799 int Length() const { return length; }
800
801 private:
802 void Format(char*, int, bool);
803
804 enum
805 {
806 MAXIMUM_PRECISION = 9,
807 // +1 for sign, +9 significant digits +1 for ".", +4 for exponent
808 MAXIMUM_STR_LENGTH = 1 + MAXIMUM_PRECISION + 1 + 4
809 };
810
811 char str[MAXIMUM_STR_LENGTH + 1]; // +1 for '\0'
812 int length;
813 };
814
815
816 class LongInt;
817 class ULongInt;
818 //
819 //
820 //
821 class Ostream
822 {
823 ostream* os;
824
825 bool expand_wchar;
826
827 public:
828
Ostream()829 Ostream() : os(&cerr),
830 expand_wchar(false)
831 {}
832
Ostream(ostream * _os)833 Ostream(ostream* _os)
834 : os(_os)
835 , expand_wchar(false)
836 {}
837
StandardOutput()838 void StandardOutput() { os = &cout; }
StandardError()839 void StandardError() { os = &cerr; }
840 void SetExpandWchar(bool val = true) { expand_wchar = val; }
ExpandWchar()841 bool ExpandWchar() { return expand_wchar; }
842
843 Ostream& operator<<(wchar_t ch)
844 {
845 // output only printable characters directly
846 if (ch == U_CARRIAGE_RETURN || ch == U_LINE_FEED)
847 *os << (char) U_LINE_FEED;
848 else if (ch >= U_SPACE && ch < 0x0ff)
849 *os << (char) ch;
850 else
851 {
852 if (expand_wchar == 0)
853 *os << (char) U_QUESTION;
854 else
855 {
856 *os << (char) U_BACKSLASH
857 << (char) U_u;
858 char str[4];
859 for (int i = 3; i >= 0; i--)
860 {
861 int d = ch & 0x0f;
862 switch (d)
863 {
864 case 10: case 11: case 12: case 13: case 14: case 15:
865 str[i] = U_A - 10 + d;
866 break;
867 default:
868 str[i] = U_0 + d;
869 break;
870 }
871 ch >>= 4;
872 }
873 *os << str[0] << str[1] << str[2] << str[3];
874 }
875 }
876
877 return *this;
878 }
879
880 Ostream& operator<<(const wchar_t* str)
881 {
882 for ( ; *str; str++)
883 (*this) << *str;
884 return *this;
885 }
886
887
888 Ostream& operator<<(char c)
889 {
890 *os << c;
891 return *this;
892 }
893
894 Ostream& operator<<(signed char c)
895 {
896 *os << c;
897 return *this;
898 }
899
900 Ostream& operator<<(unsigned char c)
901 {
902 *os << c;
903 return *this;
904 }
905
906 Ostream& operator<<(const char* c)
907 {
908 *os << c;
909 return *this;
910 }
911
912 Ostream& operator<<(const signed char* c)
913 {
914 *os << c;
915 return *this;
916 }
917
918 Ostream& operator<<(const unsigned char* c)
919 {
920 #ifndef HAVE_OSTREAM_CONST_UNSIGNED_CHAR_PTR
921 # ifdef HAVE_CONST_CAST
922 *os << const_cast<unsigned char*> (c);
923 # else
924 *os << (unsigned char*) c;
925 # endif
926 #else
927 *os << c;
928 #endif
929 return *this;
930 }
931
932 Ostream& operator<<(int a)
933 {
934 *os << a;
935 return *this;
936 }
937
938 Ostream& operator<<(unsigned int a)
939 {
940 *os << a;
941 return *this;
942 }
943
944 Ostream& operator<<(long a)
945 {
946 *os << a;
947 return *this;
948 }
949
950 Ostream& operator<<(unsigned long a)
951 {
952 *os << a;
953 return *this;
954 }
955
956 Ostream& operator<<(LongInt);
957 Ostream& operator<<(ULongInt);
958
959 Ostream& operator<<(float f)
960 {
961 *os << f;
962 return *this;
963 }
964
965 Ostream& operator<<(double d)
966 {
967 *os << d;
968 return *this;
969 }
970
fill(char c)971 char fill(char c) { return os -> fill(c); }
972
flush()973 Ostream& flush()
974 {
975 os -> flush();
976 return *this;
977 }
978
width(int w)979 int width(int w)
980 {
981 return os -> width(w);
982 }
983
984 Ostream& operator<<(ios& (*f)(ios&))
985 {
986 (*f)(*os);
987 return *this;
988 }
989
990 Ostream& operator<<(ostream& (*f)(ostream&))
991 {
992 (*f)(*os);
993 return *this;
994 }
995 };
996
997 extern Ostream Coutput;
998
999 //
1000 // From now on, DO NOT USE cout or cerr !
1001 // Instead, use Coutput, which wraps either cout or cerr as determined by
1002 // command line flags, and translates unicode output properly.
1003 // If you try to use cerr or cout this define will
1004 // create an undefined symbol and give you a linker error.
1005 //
1006 #define cout Please_Do_Not_Use_cout_Directly_But_use_an_instance_of_Ostream_with_cout_as_argument
1007 #define cerr Please_Do_Not_Use_cerr_Directly_But_use_an_instance_of_Ostream_with_cerr_as_argument
1008
1009 #ifdef HAVE_JIKES_NAMESPACE
1010 } // Close namespace Jikes block
1011 #endif
1012
1013 #endif // platform_INCLUDED
1014
1015