[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Code formatting
From: |
Bryce McKinlay |
Subject: |
Code formatting |
Date: |
Tue, 24 Oct 2000 00:36:19 +1300 |
I've written a brutal hack for GNU indent that makes it produce java
code that is reasonably close to the unofficial libgcj/classpath/GNU
coding style. It doesn't get it 100% right (it produces ugly array
initializers, and synchronized blocks aren't quite right), but it still
works a lot better than the other free code
indenter/formatter/beautifiers that I've found so far.
The patch is attached in case anyone is interested.
I plan to do some bulk reformatting in java.util in preparation for
producing diffs for some enhancements/fixes/merges that I'm working on.
If there's any objections, speak up now ;-)
regards
[ bryce ]
diff -u ../orig/comments.c ./comments.c
--- ../orig/comments.c Tue Oct 26 13:20:56 1999
+++ ./comments.c Mon Oct 23 22:38:56 2000
@@ -123,6 +123,7 @@
stars = 0;
blankline_delims = 0;
}
+#if 0
else if (*buf_ptr == '*' || *buf_ptr == '-'
|| *buf_ptr == '=' || *buf_ptr == '_'
|| (parser_state_tos->col_1 && !format_col1_comments))
@@ -202,6 +203,7 @@
}
}
}
+#endif
else
{
start_delim = "/*";
diff -u ../orig/gperf-cc.c ./gperf-cc.c
--- ../orig/gperf-cc.c Mon Jan 17 04:46:01 2000
+++ ./gperf-cc.c Mon Oct 23 23:30:53 2000
@@ -1,12 +1,12 @@
/* C code produced by gperf version 2.7 */
/* Command-line: gperf -D -c -l -p -t -T -g -j1 -o -K rwd -N is_reserved_cc -H
hash_cc indent-cc.gperf */
-#define TOTAL_KEYWORDS 48
+#define TOTAL_KEYWORDS 51
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 9
#define MIN_HASH_VALUE 4
-#define MAX_HASH_VALUE 63
-/* maximum key range = 60, duplicates = 1 */
+#define MAX_HASH_VALUE 86
+/* maximum key range = 83, duplicates = 2 */
#ifdef __GNUC__
__inline
@@ -18,32 +18,32 @@
{
static unsigned char asso_values[] =
{
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 8, 18,
- 14, 0, 9, 5, 0, 26, 64, 3, 0, 4,
- 1, 5, 64, 64, 18, 4, 33, 11, 45, 1,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 2, 17,
+ 9, 0, 5, 44, 0, 1, 87, 2, 0, 6,
+ 43, 27, 87, 87, 16, 8, 31, 38, 19, 0,
+ 87, 0, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
+ 87, 87, 87, 87, 87, 87
};
return len + asso_values[(unsigned char)str[len - 1]] +
asso_values[(unsigned char)str[0]];
}
@@ -58,72 +58,79 @@
{
static unsigned char lengthtable[] =
{
- 4, 3, 5, 6, 4, 4, 6, 6, 4, 9, 4, 6, 5, 5,
- 5, 6, 6, 6, 2, 4, 5, 6, 6, 5, 6, 6, 3, 8,
- 6, 8, 7, 2, 5, 4, 8, 5, 6, 8, 5, 6, 7, 6,
- 7, 8, 7, 5, 3, 4
+ 4, 5, 4, 6, 2, 5, 4, 6, 7, 6, 6, 6, 9, 5,
+ 6, 6, 4, 5, 5, 6, 3, 6, 7, 8, 7, 5, 6, 4,
+ 3, 3, 5, 4, 2, 8, 8, 5, 6, 7, 5, 6, 3, 7,
+ 4, 6, 6, 8, 5, 8, 6, 4, 5
};
static struct templ wordlist[] =
{
{"else", rw_sp_else,},
- {"new", rw_return,},
{"while", rw_sp_paren,},
- {"extern", rw_decl,},
+ {"bool", rw_decl,},
+ {"inline", rw_decl,},
+ {"if", rw_sp_paren,},
+ {"break", rw_break,},
{"enum", rw_enum,},
- {"long", rw_decl,},
+ {"headof", rw_sizeof,},
+ {"finally", rw_sp_nparen},
{"switch", rw_switch,},
- {"global", rw_decl,},
- {"bool", rw_decl,},
+ {"double", rw_decl,},
+ {"delete", rw_return,},
{"signature", rw_struct_like,},
- {"goto", rw_break,},
- {"headof", rw_sizeof,},
- {"break", rw_break,},
- {"union", rw_struct_like,},
{"sigof", rw_sizeof,},
{"sizeof", rw_sizeof,},
- {"double", rw_decl,},
- {"delete", rw_return,},
- {"do", rw_sp_nparen,},
+ {"friend", rw_decl,},
{"case", rw_case,},
{"catch", rw_sp_paren,},
+ {"catch", rw_sp_paren,},
{"signed", rw_decl,},
- {"return", rw_return,},
- {"class", rw_struct_like,},
- {"static", rw_decl,},
- {"friend", rw_decl,},
{"for", rw_sp_paren,},
- {"operator", rw_operator,},
- {"inline", rw_decl,},
- {"unsigned", rw_decl,},
+ {"va_dcl", rw_decl,},
+ {"virtual", rw_decl,},
+ {"volatile", rw_decl,},
{"classof", rw_sizeof,},
- {"if", rw_sp_paren,},
+ {"class", rw_struct_like,},
+ {"static", rw_decl,},
+ {"void", rw_decl,},
+ {"try", rw_sp_nparen,},
+ {"int", rw_decl,},
{"throw", rw_return,},
{"char", rw_decl,},
+ {"do", rw_sp_nparen,},
{"template", rw_decl,},
- {"short", rw_decl,},
- {"struct", rw_struct_like,},
{"register", rw_decl,},
{"float", rw_decl,},
{"typeof", rw_sizeof,},
{"typedef", rw_decl,},
- {"va_dcl", rw_decl,},
- {"virtual", rw_decl,},
- {"volatile", rw_decl,},
+ {"short", rw_decl,},
+ {"struct", rw_struct_like,},
+ {"new", rw_return,},
{"default", rw_case,},
+ {"long", rw_decl,},
+ {"extern", rw_decl,},
+ {"global", rw_decl,},
+ {"operator", rw_operator,},
{"const", rw_decl,},
- {"int", rw_decl,},
- {"void", rw_decl,}
+ {"unsigned", rw_decl,},
+ {"return", rw_return,},
+ {"goto", rw_break,},
+ {"union", rw_struct_like,}
};
static short lookup[] =
{
- -1, -1, -1, -1, 0, 1, 2, 3, 4, 5,
- 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- -84, 18, 19, 20, 21, 22, -1, 23, 24, 25,
- 26, 27, 28, 29, 30, -32, -2, 31, -1, 32,
- 33, 34, 35, 36, 37, -1, -1, 38, 39, 40,
- -1, 41, 42, 43, 44, -1, 45, -1, -1, -1,
- -1, -1, 46, 47
+ -1, -1, -1, -1, 0, 1, 2, 3,
+ 4, 5, 6, 7, 8, -1, 9, -110,
+ -1, 12, 13, 14, 15, 16, -108, 19,
+ 20, 21, 22, 23, -1, 24, 25, 26,
+ 27, -1, 28, 29, 30, 31, 32, 33,
+ 34, 35, 36, 37, 38, 39, 40, 41,
+ 42, 43, 44, 45, -1, 46, -1, 47,
+ -34, -2, -41, -2, -1, -1, -1, -1,
+ -1, 48, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 49, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, 50
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
diff -u ../orig/gperf.c ./gperf.c
--- ../orig/gperf.c Mon Jan 17 04:46:01 2000
+++ ./gperf.c Mon Oct 23 23:38:39 2000
@@ -1,51 +1,51 @@
/* C code produced by gperf version 2.7 */
/* Command-line: gperf -D -c -l -p -t -T -g -j1 -o -K rwd -N is_reserved
indent.gperf */
-#define TOTAL_KEYWORDS 32
+#define TOTAL_KEYWORDS 50
#define MIN_WORD_LENGTH 2
-#define MAX_WORD_LENGTH 8
-#define MIN_HASH_VALUE 3
-#define MAX_HASH_VALUE 35
-/* maximum key range = 33, duplicates = 0 */
+#define MAX_WORD_LENGTH 9
+#define MIN_HASH_VALUE 4
+#define MAX_HASH_VALUE 92
+/* maximum key range = 89, duplicates = 1 */
#ifdef __GNUC__
__inline
#endif
-static unsigned int
+ static unsigned int
hash (str, len)
register const char *str;
register unsigned int len;
{
- static unsigned char asso_values[] =
- {
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 19, 11,
- 1, 0, 20, 19, 3, 9, 36, 0, 9, 2,
- 11, 0, 36, 36, 3, 4, 0, 19, 14, 0,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
- 36, 36, 36, 36, 36, 36
- };
- return len + asso_values[(unsigned char)str[len - 1]] +
asso_values[(unsigned char)str[0]];
+ static unsigned char asso_values[] = {
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 2, 17,
+ 9, 0, 5, 48, 35, 1, 93, 2, 0, 6,
+ 45, 39, 93, 93, 16, 8, 31, 42, 19, 0,
+ 93, 0, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
+ 93, 93, 93, 93, 93, 93
+ };
+ return len + asso_values[(unsigned char) str[len - 1]] +
+ asso_values[(unsigned char) str[0]];
}
#ifdef __GNUC__
@@ -56,94 +56,122 @@
register const char *str;
register unsigned int len;
{
- static unsigned char lengthtable[] =
- {
- 2, 4, 5, 4, 6, 7, 5, 6, 6, 3, 6, 8, 4, 5,
- 6, 4, 4, 6, 6, 8, 4, 5, 5, 3, 7, 8, 6, 6,
- 2, 4, 6, 5
- };
- static struct templ wordlist[] =
- {
- {"do", rw_sp_nparen,},
- {"else", rw_sp_else,},
- {"while", rw_sp_paren,},
- {"enum", rw_enum,},
- {"double", rw_decl,},
- {"default", rw_case,},
- {"short", rw_decl,},
- {"struct", rw_struct_like,},
- {"signed", rw_decl,},
- {"int", rw_decl,},
- {"switch", rw_switch,},
- {"register", rw_decl,},
- {"case", rw_case,},
- {"const", rw_decl,},
- {"extern", rw_decl,},
- {"char", rw_decl,},
- {"void", rw_decl,},
- {"return", rw_return,},
- {"static", rw_decl,},
- {"volatile", rw_decl,},
- {"goto", rw_break,},
- {"break", rw_break,},
- {"float", rw_decl,},
- {"for", rw_sp_paren,},
- {"typedef", rw_decl,},
- {"unsigned", rw_decl,},
- {"va_dcl", rw_decl,},
- {"sizeof", rw_sizeof,},
- {"if", rw_sp_paren,},
- {"long", rw_decl,},
- {"global", rw_decl,},
- {"union", rw_struct_like,}
- };
-
- static short lookup[] =
- {
- -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
- 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, -1, 30, 31
- };
+ static unsigned char lengthtable[] = {
+ 4, 5, 4, 6, 2, 5, 4, 7, 6, 6, 9, 5, 6, 6,
+ 4, 6, 3, 6, 7, 8, 7, 5, 6, 4, 3, 3, 5, 4,
+ 8, 8, 5, 6, 7, 5, 6, 6, 7, 3, 6, 2, 6, 4,
+ 5, 6, 5, 8, 8, 6, 4, 5
+ };
+ static struct templ wordlist[] = {
+ {"else", rw_sp_else,},
+ {"while", rw_sp_paren,},
+ {"bool", rw_decl,},
+ {"inline", rw_decl,},
+ {"if", rw_sp_paren,},
+ {"break", rw_break,},
+ {"enum", rw_enum,},
+ {"finally", rw_sp_nparen,},
+ {"double", rw_decl,},
+ {"delete", rw_return,},
+ {"signature", rw_struct_like,},
+ {"sigof", rw_sizeof,},
+ {"sizeof", rw_sizeof,},
+ {"friend", rw_decl,},
+ {"case", rw_case,},
+ {"signed", rw_decl,},
+ {"for", rw_sp_paren,},
+ {"va_dcl", rw_decl,},
+ {"virtual", rw_decl,},
+ {"volatile", rw_decl,},
+ {"classof", rw_sizeof,},
+ {"class", rw_struct_like,},
+ {"static", rw_decl,},
+ {"void", rw_decl,},
+ {"try", rw_sp_nparen,},
+ {"int", rw_decl,},
+ {"throw", rw_return,},
+ {"char", rw_decl,},
+ {"template", rw_decl,},
+ {"register", rw_decl,},
+ {"float", rw_decl,},
+ {"typeof", rw_sizeof,},
+ {"typedef", rw_decl,},
+ {"short", rw_decl,},
+ {"struct", rw_struct_like,},
+ {"headof", rw_sizeof,},
+ {"default", rw_case,},
+ {"new", rw_return,},
+ {"switch", rw_switch,},
+ {"do", rw_sp_nparen,},
+ {"extern", rw_decl,},
+ {"long", rw_decl,},
+ {"const", rw_decl,},
+ {"global", rw_decl,},
+ {"catch", rw_sp_paren,},
+ {"unsigned", rw_decl,},
+ {"operator", rw_operator,},
+ {"return", rw_return,},
+ {"goto", rw_break,},
+ {"union", rw_struct_like,}
+ };
+
+ static short lookup[] = {
+ -1, -1, -1, -1, 0, 1, 2, 3,
+ 4, 5, 6, -1, 7, -1, -1, -106,
+ -1, 10, 11, 12, 13, 14, -1, 15,
+ 16, 17, 18, 19, -1, 20, 21, 22,
+ 23, -1, 24, 25, 26, 27, -1, 28,
+ 29, 30, 31, 32, 33, 34, 35, 36,
+ 37, 38, 39, 40, 41, 42, 43, -42,
+ -2, 44, -1, 45, -1, -1, -1, 46,
+ -1, -1, -1, 47, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 48, 49
+ };
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = hash (str, len);
if (key <= MAX_HASH_VALUE && key >= 0)
- {
- register int index = lookup[key];
+ {
+ register int index = lookup[key];
- if (index >= 0)
- {
- if (len == lengthtable[index])
- {
- register const char *s = wordlist[index].rwd;
-
- if (*str == *s && !strncmp (str + 1, s + 1, len - 1))
- return &wordlist[index];
- }
- }
- else if (index < -TOTAL_KEYWORDS)
- {
- register int offset = - 1 - TOTAL_KEYWORDS - index;
- register const unsigned char *lengthptr =
&lengthtable[TOTAL_KEYWORDS + lookup[offset]];
- register struct templ *wordptr = &wordlist[TOTAL_KEYWORDS +
lookup[offset]];
- register struct templ *wordendptr = wordptr + -lookup[offset +
1];
-
- while (wordptr < wordendptr)
- {
- if (len == *lengthptr)
- {
- register const char *s = wordptr->rwd;
-
- if (*str == *s && !strncmp (str + 1, s + 1, len - 1))
- return wordptr;
- }
- lengthptr++;
- wordptr++;
- }
- }
- }
+ if (index >= 0)
+ {
+ if (len == lengthtable[index])
+ {
+ register const char *s = wordlist[index].rwd;
+
+ if (*str == *s && !strncmp (str + 1, s + 1, len - 1))
+ return &wordlist[index];
+ }
+ }
+ else if (index < -TOTAL_KEYWORDS)
+ {
+ register int offset = -1 - TOTAL_KEYWORDS - index;
+ register const unsigned char *lengthptr =
+ &lengthtable[TOTAL_KEYWORDS + lookup[offset]];
+ register struct templ *wordptr =
+ &wordlist[TOTAL_KEYWORDS + lookup[offset]];
+ register struct templ *wordendptr =
+ wordptr + -lookup[offset + 1];
+
+ while (wordptr < wordendptr)
+ {
+ if (len == *lengthptr)
+ {
+ register const char *s = wordptr->rwd;
+
+ if (*str == *s && !strncmp (str + 1, s + 1, len - 1))
+ return wordptr;
+ }
+ lengthptr++;
+ wordptr++;
+ }
+ }
+ }
}
return 0;
}
diff -u ../orig/indent-cc.gperf ./indent-cc.gperf
--- ../orig/indent-cc.gperf Fri Oct 1 07:09:31 1999
+++ ./indent-cc.gperf Mon Oct 23 18:18:06 2000
@@ -48,3 +48,6 @@
sigof, rw_sizeof,
bool, rw_decl,
operator, rw_operator,
+try, rw_sp_nparen,
+catch, rw_sp_paren,
+finally, rw_sp_nparen
diff -u ../orig/indent.c ./indent.c
--- ../orig/indent.c Mon Jan 17 04:15:53 2000
+++ ./indent.c Tue Oct 24 00:12:34 2000
@@ -1060,7 +1060,8 @@
/* if we were in a first level structure declaration,
we aren't any more */
- parser_state_tos->in_decl = (parser_state_tos->dec_nest > 0);
+ /*parser_state_tos->in_decl = (parser_state_tos->dec_nest > 0);*/
+ parser_state_tos->in_decl = 0;
/* If we have a semicolon following an if, while, or for, and the
user wants us to, we should insert a space (to show that there
@@ -1082,11 +1083,13 @@
case lbrace: /* got a '{' */
parser_state_tos->saw_double_colon = false;
- if (!parser_state_tos->block_init)
+ if (!parser_state_tos->block_init
+ || parser_state_tos->maybe_anon_class)
{
force_nl = true; /* force other stuff on same line as '{' onto
new line */
parser_state_tos->in_stmt = false; /* dont indent the '{'
*/
+ parser_state_tos->block_init = false;
}
else
{
@@ -1304,17 +1307,18 @@
parser_state_tos->in_decl = false;
goto copy_id; /* go move the token into buffer */
- case sp_paren: /* token is if, while, for */
+ case sp_paren: /* token is if, while, for, catch */
sp_sw = true; /* the interesting stuff is done after the
expression is scanned */
hd_type = (*token == 'i' ? ifstmt :
- (*token == 'w' ? whilestmt : forstmt));
+ (*token == 'w' ? whilestmt :
+ (*token == 'c' ? catchstmt : forstmt)));
/* remember the type of header for later use by parser */
goto copy_id; /* copy the token into line */
case sp_else: /* got else */
- case sp_nparen: /* got do */
+ case sp_nparen: /* got do, try, or finally */
parser_state_tos->in_stmt = false;
if (*token == 'e')
{
@@ -1343,7 +1347,12 @@
force_nl = true; /* also, following stuff must go onto new
line */
last_else = 0;
- PARSE (dolit);
+ if (*token == 'd')
+ PARSE (dolit);
+ else if (*token == 't')
+ PARSE (trystmt);
+ else if (*token == 'f')
+ PARSE (finallystmt);
}
goto copy_id; /* move the token into line */
@@ -1908,7 +1917,13 @@
&& type_code != cplus_comment
&& type_code != newline
&& type_code != preesc && type_code != form_feed)
- parser_state_tos->last_token = type_code;
+ {
+ parser_state_tos->last_token = type_code;
+ if (token[0] == ')')
+ parser_state_tos->maybe_anon_class = 1;
+ else
+ parser_state_tos->maybe_anon_class = 0;
+ }
/* Now that we've put the token on the line (in most cases),
consider breaking the line because it's too long.
diff -u ../orig/indent.gperf ./indent.gperf
--- ../orig/indent.gperf Fri Oct 1 07:09:31 1999
+++ ./indent.gperf Mon Oct 23 23:30:35 2000
@@ -32,3 +32,21 @@
else, rw_sp_else,
do, rw_sp_nparen,
sizeof, rw_sizeof,
+catch, rw_sp_paren,
+class, rw_struct_like,
+delete, rw_return,
+new, rw_return,
+throw, rw_return,
+friend, rw_decl,
+inline, rw_decl,
+template, rw_decl,
+virtual, rw_decl,
+signature, rw_struct_like,
+typeof, rw_sizeof,
+classof, rw_sizeof,
+headof, rw_sizeof,
+sigof, rw_sizeof,
+bool, rw_decl,
+operator, rw_operator,
+try, rw_sp_nparen,
+finally, rw_sp_nparen,
diff -u ../orig/indent.h ./indent.h
--- ../orig/indent.h Mon Jan 17 04:15:53 2000
+++ ./indent.h Mon Oct 23 17:00:53 2000
@@ -427,6 +427,9 @@
int matching_brace_on_same_line; /* Set to a value >= 0 if the the
current '}' has a matching '{'
on the same input line */
+ int maybe_anon_class; /* True if the last token was a ')'. Used
+ to distinguish between initializer blocks
+ and Java anonymous class declarations */
};
/* All manipulations of the parser state occur at the top of stack (tos). A
diff -u ../orig/lexi.h ./lexi.h
--- ../orig/lexi.h Sun Jul 18 07:16:23 1999
+++ ./lexi.h Tue Oct 24 00:14:57 2000
@@ -43,7 +43,7 @@
newline,
lparen, /* '(' or '['. Also '{' in an
initialization. */
- rparen, /* ')' or ']'. Also '}' in an
+ rparen, /* ')' or ']'. Also '}' in an
initialization. */
start_token,
unary_op,
@@ -79,6 +79,10 @@
ifstmt,
elseifstmt,
whilestmt,
+ trystmt,
+ catchstmt,
+ finallystmt,
+ synchronizedstmt,
forstmt,
stmt,
diff -u ../orig/parse.c ./parse.c
--- ../orig/parse.c Mon Jan 17 04:15:53 2000
+++ ./parse.c Mon Oct 23 23:29:24 2000
@@ -278,6 +278,9 @@
case dolit: /* 'do' */
case forstmt: /* for (...) */
case casestmt: /* case n: */
+ case catchstmt:
+ case trystmt:
+ case finallystmt:
inc_pstack ();
parser_state_tos->p_stack[parser_state_tos->tos] = tk;
parser_state_tos->il[parser_state_tos->tos]
@@ -558,6 +561,9 @@
/* <case n:> <stmt> */
case whilestmt:
/* <while> <stmt> */
+ case catchstmt:
+ case trystmt:
+ case finallystmt:
parser_state_tos->p_stack[--parser_state_tos->tos] = stmt;
parser_state_tos->i_l_follow =
parser_state_tos->il[parser_state_tos->tos];