This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Brace-balancing warning patch for C++ (vs. egcs-970917).
- To: egcs at cygnus dot com
- Subject: Brace-balancing warning patch for C++ (vs. egcs-970917).
- From: "Paul Rusty Russell" <Paul dot Russell at rustcorp dot com dot au>
- Date: Sat, 27 Sep 1997 20:16:10 +1000
- cc: g++ at cygnus dot com
Hi all,
Tallies { vs } on a per file basis and warns if they are uneven. This
is done right at the bottom level; I found trying to do it in
real_yylex caused missed braces... Please tell me if this is the
Wrong Way.
This depends on the "Brace-balancing warning patch (vs. egcs-970917)."
patch I submitted previously.
Enjoy.
---------------------------------------------------------------- Changelog
Fri Sep 26 15:53:40 1997 Paul Russell <Paul.Russell@RustCorp.com.au>
* lex.c (check_newline): Per-file {}-count & imbalance warning.
(real_yylex): Count { or } produced from digraphs.
* input.c (getch): keep {}-count.
(put_back): keep {}-count.
---------------------------------------------------------------- Patch
*** gcc/cp/lex.c.~1~ Mon Sep 8 19:28:46 1997
--- gcc/cp/lex.c Sat Sep 27 11:35:08 1997
*************** linenum:
*** 2518,2523 ****
--- 2518,2524 ----
input_file_stack->line = old_lineno;
p->next = input_file_stack;
p->name = input_filename;
+ p->indent_level = indent_level;
input_file_stack = p;
input_file_stack_tick++;
debug_start_source_file (input_filename);
*************** linenum:
*** 2546,2551 ****
--- 2547,2560 ----
in_system_header = entering_system_header;
p = input_file_stack;
+ if (indent_level != p->indent_level)
+ {
+ warning_with_file_and_line
+ (p->name, old_lineno,
+ "This file contains more `%c's than `%c's.",
+ indent_level > p->indent_level ? '{' : '}',
+ indent_level > p->indent_level ? '}' : '{');
+ }
input_file_stack = p->next;
free (p);
input_file_stack_tick++;
*************** real_yylex ()
*** 4191,4201 ****
}
/* digraphs */
else if (c == '<' && c1 == '%')
! { value = '{'; goto done; }
else if (c == '<' && c1 == ':')
{ value = '['; goto done; }
else if (c == '%' && c1 == '>')
! { value = '}'; goto done; }
else if (c == '%' && c1 == ':')
{ value = '#'; goto done; }
--- 4200,4210 ----
}
/* digraphs */
else if (c == '<' && c1 == '%')
! { value = '{'; indent_level++; goto done; }
else if (c == '<' && c1 == ':')
{ value = '['; goto done; }
else if (c == '%' && c1 == '>')
! { value = '}'; indent_level--; goto done; }
else if (c == '%' && c1 == ':')
{ value = '#'; goto done; }
*** gcc/cp/input.c.~1~ Tue Aug 26 11:34:48 1997
--- gcc/cp/input.c Sat Sep 27 11:28:18 1997
*************** struct input_source {
*** 50,55 ****
--- 50,58 ----
static struct input_source *input, *free_inputs;
+ /* Number of { minus number of }. */
+ static int indent_level = 0;
+
extern char *input_filename;
extern int lineno;
*************** put_back (ch)
*** 179,184 ****
--- 182,189 ----
if (ch != EOF)
{
my_friendly_assert (putback_char == -1, 224);
+ if (ch == '{') indent_level--;
+ else if (ch == '}') indent_level++;
putback_char = ch;
}
}
*************** getch ()
*** 194,199 ****
--- 199,207 ----
put_back (ch);
ch = EOF;
}
+
+ if (ch == '{') indent_level++;
+ else if (ch == '}') indent_level--;
return ch;
}
---------------------------------------------------------------- End Patch
Rusty.
--
.sig lost in the mail.