This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: adding support for column numbers


Mike S suggested it would be better to use a struct for linecol.
I thought about it some, and realized we can still keep partial backwards
compatibility if we make lineno a macro.  So since a struct is a cleaner
long-term solution, and the initial work seems no harder, and with errors
more likely to be caught at compiler build time, I think that might be
better.

So here is another concept patch (i.e. it is incomplete and untested).

One question:  In a couple of functions, the code does:
	#ifndef ANSI_PROTOTYPES 
	  line = va_arg (ap, linecol);
	  ...
	#endif
However, I'm not sure if va_arg is guaranteed to work for structs.
If not, we'll have to do some kludge, such as passing the line number
only in those cases.  (Since this is only for boot-strapping,
that is good enough.)
	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner

Index: machmode.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/machmode.h,v
retrieving revision 1.8
diff -u -p -r1.8 machmode.h
--- machmode.h	1998/11/07 13:00:33	1.8
+++ machmode.h	1999/01/14 18:53:29
@@ -236,4 +236,14 @@ extern enum machine_mode byte_mode;
 extern enum machine_mode word_mode;
 extern enum machine_mode ptr_mode;
 
+/* Line and column values for a source location.
+   Values of zero mean unknown or missing, or (for a zero column number)
+   the entire line. */
+
+typedef struct
+{
+  int line : 22;
+  unsigned int column : 10;
+} linecol;
+
 #endif /* not HAVE_MACHINE_MODES */
Index: tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/tree.h,v
retrieving revision 1.59
diff -u -p -r1.59 tree.h
--- tree.h	1998/11/27 10:09:15	1.59
+++ tree.h	1999/01/14 18:53:29
@@ -682,7 +682,7 @@ struct tree_vec
 
 /* In ordinary expression nodes.  */
 #define TREE_OPERAND(NODE, I) (EXPR_CHECK (NODE)->exp.operands[I])
-#define TREE_COMPLEXITY(NODE) (EXPR_CHECK (NODE)->exp.complexity)
+#define TREE_COMPLEXITY(NODE) (EXPR_CHECK (NODE)->exp.u.complexity)
 
 /* In a LABELED_BLOCK_EXPR node.  */
 #define LABELED_BLOCK_LABEL(NODE) TREE_OPERAND (NODE, 0)
@@ -699,17 +699,20 @@ struct tree_vec
 #define EXPR_WFL_NODE(NODE) TREE_OPERAND((NODE), 0)
 #define EXPR_WFL_FILENAME(NODE) (IDENTIFIER_POINTER ((NODE)->common.chain))
 #define EXPR_WFL_FILENAME_NODE(NODE) ((NODE)->common.chain)
-#define EXPR_WFL_LINENO(NODE) (EXPR_CHECK (NODE)->exp.complexity >> 12)
-#define EXPR_WFL_COLNO(NODE) (EXPR_CHECK (NODE)->exp.complexity & 0xfff)
-#define EXPR_WFL_LINECOL(NODE) (EXPR_CHECK (NODE)->exp.complexity)
+#define EXPR_WFL_LINENO(NODE) (EXPR_CHECK (NODE)->exp.u.linecolno.line)
+#define EXPR_WFL_COLNO(NODE) (EXPR_CHECK (NODE)->exp.u.linecolno.column)
+#define EXPR_WFL_LINECOL(NODE) (EXPR_CHECK (NODE)->exp.u.linecolno)
 #define EXPR_WFL_SET_LINECOL(NODE, LINE, COL) \
-  (EXPR_WFL_LINECOL(NODE) = ((LINE) << 12) | ((COL) & 0xfff))
+  (EXPR_WFL_LINENO (NODE) = (LINE), EXPR_WFL_COLNO (NODE) = (COL))
 #define EXPR_WFL_EMIT_LINE_NOTE(NODE) ((NODE)->common.public_flag)
 
 struct tree_exp
 {
   char common[sizeof (struct tree_common)];
-  int complexity;
+  union {
+    int complexity;
+    linecol linecolno;
+  } u;
   union tree_node *operands[1];
 };
 
@@ -1065,7 +1068,9 @@ struct tree_type
 #define DECL_QUALIFIER(NODE) (DECL_CHECK (NODE)->decl.initial)
 /* These two fields describe where in the source code the declaration was.  */
 #define DECL_SOURCE_FILE(NODE) (DECL_CHECK (NODE)->decl.filename)
-#define DECL_SOURCE_LINE(NODE) (DECL_CHECK (NODE)->decl.linenum)
+#define DECL_SOURCE_LINECOL(NODE) (DECL_CHECK (NODE)->decl.linecolnum)
+#define DECL_SOURCE_LINE(NODE) (DECL_CHECK (NODE)->decl.linecolnum.line)
+#define DECL_SOURCE_COLUMN(NODE) (DECL_CHECK (NODE)->decl.linecolnum.column)
 /* Holds the size of the datum, as a tree expression.
    Need not be constant.  */
 #define DECL_SIZE(NODE) (DECL_CHECK (NODE)->decl.size)
@@ -1279,7 +1284,7 @@ struct tree_decl
 {
   char common[sizeof (struct tree_common)];
   char *filename;
-  int linenum;
+  linecol linecolnum;
   unsigned int uid;
   union tree_node *size;
 #ifdef ONLY_INT_FIELDS
@@ -1843,8 +1848,14 @@ extern tree char_type_node;
    being parsed originally came (before it went into cpp).  */
 extern char *input_filename;
 
+/* Current line and column in input file.  */
+extern linecol linecolno;
+
 /* Current line number in input file.  */
-extern int lineno;
+#define lineno linecolno.line
+
+/* Current column number in input file.  */
+#define columnno linecolno.column
 
 /* Nonzero for -pedantic switch: warn about anything
    that standard C forbids.  */
Index: rtl.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/rtl.h,v
retrieving revision 1.70
diff -u -p -r1.70 rtl.h
--- rtl.h	1998/12/03 01:32:21	1.70
+++ rtl.h	1999/01/14 18:53:29
@@ -91,6 +91,7 @@ typedef union rtunion_def
   addr_diff_vec_flags rt_addr_diff_vec_flags;
   struct bitmap_head_def *rtbit;
   union tree_node *rttree;
+  linecol rtlinecol;
 } rtunion;
 
 /* RTL expression ("rtx").  */
@@ -224,6 +225,8 @@ typedef struct rtvec_def{
 
 #define XEXP(RTX, N)	((RTX)->fld[N].rtx)
 #define XINT(RTX, N)	((RTX)->fld[N].rtint)
+#define XLINECOL(RTX, N)((RTX)->fld[N].rtlinecol)
+#define XLINE(RTX, N)	((RTX)->fld[N].rtlinecol.line)
 #define XWINT(RTX, N)	((RTX)->fld[N].rtwint)
 #define XSTR(RTX, N)	((RTX)->fld[N].rtstr)
 #define XVEC(RTX, N)	((RTX)->fld[N].rtvec)
@@ -400,7 +403,8 @@ extern char *reg_note_name[];
 
 /* In a NOTE that is a line number, this is the line number.
    Other kinds of NOTEs are identified by negative numbers here.  */
-#define NOTE_LINE_NUMBER(INSN) ((INSN)->fld[4].rtint)
+#define NOTE_LINE_NUMBER(INSN) ((INSN)->fld[4].rtlinecol.line)
+#define NOTE_LINE_LINECOL(INSN) ((INSN)->fld[4].rtlinecol)
 
 /* Codes that appear in the NOTE_LINE_NUMBER field
    for kinds of notes that are not line numbers.
@@ -554,7 +558,8 @@ extern char *note_insn_name[];
 #define ASM_OPERANDS_INPUT_CONSTRAINT(RTX, N) XSTR (XVECEXP ((RTX), 4, (N)), 0)
 #define ASM_OPERANDS_INPUT_MODE(RTX, N) GET_MODE (XVECEXP ((RTX), 4, (N)))
 #define ASM_OPERANDS_SOURCE_FILE(RTX) XSTR ((RTX), 5)
-#define ASM_OPERANDS_SOURCE_LINE(RTX) XINT ((RTX), 6)
+#define ASM_OPERANDS_SOURCE_LINECOL(RTX) XLINECOL ((RTX), 6)
+#define ASM_OPERANDS_SOURCE_LINE(RTX) XLINE ((RTX), 6)
 
 /* For a MEM rtx, 1 if it's a volatile reference.
    Also in an ASM_OPERANDS rtx.  */
Index: toplev.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/toplev.c,v
retrieving revision 1.134
diff -u -p -r1.134 toplev.c
--- toplev.c	1998/12/06 03:02:47	1.134
+++ toplev.c	1999/01/14 18:53:30
@@ -163,7 +163,8 @@ extern void print_rtl ();
 extern void print_rtl_with_bb ();
 
 void rest_of_decl_compilation ();
-void error_with_file_and_line PVPROTO((char *file, int line, char *s, ...));
+void error_with_file_and_line PVPROTO((char *file, linecol line,
+				       char *s, ...));
 void error_with_decl PVPROTO((tree decl, char *s, ...));
 void error PVPROTO((char *s, ...));
 void fatal PVPROTO((char *s, ...));
@@ -177,11 +178,12 @@ void sorry PVPROTO((char *s, ...));
 static void set_target_switch PROTO((char *));
 static char *decl_name PROTO((tree, int));
 static void vmessage PROTO((char *, char *, va_list));
-static void v_message_with_file_and_line PROTO((char *, int, char *,
+static void v_message_with_file_and_line PROTO((char *, linecol, char *,
 						char *, va_list));
 static void v_message_with_decl PROTO((tree, char *, char *, va_list));
-static void file_and_line_for_asm PROTO((rtx, char **, int *));
-static void v_error_with_file_and_line PROTO((char *, int, char *, va_list));
+static void file_and_line_for_asm PROTO((rtx, char **, linecol *));
+static void v_error_with_file_and_line PROTO((char *, linecol,
+					      char *, va_list));
 static void v_error_with_decl PROTO((tree, char *, va_list));
 static void v_error_for_asm PROTO((rtx, char *, va_list));
 static void verror PROTO((char *, va_list));
@@ -192,7 +194,8 @@ static void v_warning_for_asm PROTO((rtx
 static void vwarning PROTO((char *, va_list));
 static void vpedwarn PROTO((char *, va_list));
 static void v_pedwarn_with_decl PROTO((tree, char *, va_list));
-static void v_pedwarn_with_file_and_line PROTO((char *, int, char *, va_list));
+static void v_pedwarn_with_file_and_line PROTO((char *, linecol,
+						char *, va_list));
 static void vsorry PROTO((char *, va_list));
 static void v_really_sorry PROTO((char *, va_list)) ATTRIBUTE_NORETURN;
 static void float_signal PROTO((int)) ATTRIBUTE_NORETURN;
@@ -238,9 +241,9 @@ char *input_filename;
 
 char *main_input_filename;
 
-/* Current line number in real source file.  */
+/* Current line and column numbers in real source file.  */
 
-int lineno;
+linecol linecolno;
 
 /* Nonzero if it is unsafe to create any new pseudo registers.  */
 int no_new_pseudos;
@@ -1517,6 +1520,16 @@ report_error_function (file)
       last_error_tick = input_file_stack_tick;
     }
 }
+
+static void
+print_lineno (file, linecolno)
+     char *file;
+     linecol linecolno;
+{
+  fprintf (stderr, "%s:%d: ", file, linecolno.line);
+  if (linecolno.column != 0)
+    fprintf (stderr, ":%d", linecolno.column);
+}
 
 /* Print a message.  */
 
@@ -1537,13 +1550,13 @@ vmessage (prefix, s, ap)
 static void
 v_message_with_file_and_line (file, line, prefix, s, ap)
      char *file;
-     int line;
+     linecol line;
      char *prefix;
      char *s;
      va_list ap;
 {
   if (file)
-    fprintf (stderr, "%s:%d: ", file, line);
+    print_lineno (file, line);
   else
     fprintf (stderr, "%s: ", progname);
 
@@ -1562,8 +1575,7 @@ v_message_with_decl (decl, prefix, s, ap
 {
   char *p;
 
-  fprintf (stderr, "%s:%d: ",
-	   DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
+  print_lineno (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINECOL (decl));
 
   if (prefix)
     fprintf (stderr, "%s: ", prefix);
@@ -1619,7 +1631,7 @@ static void
 file_and_line_for_asm (insn, pfile, pline)
      rtx insn;
      char **pfile;
-     int *pline;
+     linecol *pline;
 {
   rtx body = PATTERN (insn);
   rtx asmop;
@@ -1641,7 +1653,8 @@ file_and_line_for_asm (insn, pfile, plin
   if (asmop)
     {
       *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
-      *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
+      pline->line = ASM_OPERANDS_SOURCE_LINE (asmop);
+      pline->column = 0;  /* For now */
     }
   else
     {
@@ -1655,7 +1668,7 @@ file_and_line_for_asm (insn, pfile, plin
 static void
 v_error_with_file_and_line (file, line, s, ap)
      char *file;
-     int line;
+     linecol line;
      char *s;
      va_list ap;
 {
@@ -1665,11 +1678,11 @@ v_error_with_file_and_line (file, line, 
 }
 
 void
-error_with_file_and_line VPROTO((char *file, int line, char *s, ...))
+error_with_file_and_line VPROTO((char *file, linecol line, char *s, ...))
 {
 #ifndef ANSI_PROTOTYPES
   char *file;
-  int line;
+  linecol line;
   char *s;
 #endif
   va_list ap;
@@ -1732,7 +1745,7 @@ v_error_for_asm (insn, s, ap)
      va_list ap;
 {
   char *file;
-  int line;
+  linecol line;
 
   count_error (0);
   file_and_line_for_asm (insn, &file, &line);
@@ -1767,7 +1780,7 @@ verror (s, ap)
      char *s;
      va_list ap;
 {
-  v_error_with_file_and_line (input_filename, lineno, s, ap);
+  v_error_with_file_and_line (input_filename, linecolno, s, ap);
 }
 
 void
@@ -1822,7 +1835,7 @@ fatal VPROTO((char *s, ...))
 static void
 v_warning_with_file_and_line (file, line, s, ap)
      char *file;
-     int line;
+     linecol line;
      char *s;
      va_list ap;
 {
@@ -1834,11 +1847,11 @@ v_warning_with_file_and_line (file, line
 }
 
 void
-warning_with_file_and_line VPROTO((char *file, int line, char *s, ...))
+warning_with_file_and_line VPROTO((char *file, linecol line, char *s, ...))
 {
 #ifndef ANSI_PROTOTYPES
   char *file;
-  int line;
+  linecol line;
   char *s;
 #endif
   va_list ap;
@@ -1847,7 +1860,7 @@ warning_with_file_and_line VPROTO((char 
 
 #ifndef ANSI_PROTOTYPES
   file = va_arg (ap, char *);
-  line = va_arg (ap, int);
+  line = va_arg (ap, linecol);
   s = va_arg (ap, char *);
 #endif
 
@@ -1905,7 +1918,7 @@ v_warning_for_asm (insn, s, ap)
   if (count_error (1))
     {
       char *file;
-      int line;
+      linecol line;
 
       file_and_line_for_asm (insn, &file, &line);
       report_error_function (file);
@@ -1940,7 +1953,7 @@ vwarning (s, ap)
      char *s;
      va_list ap;
 {
-  v_warning_with_file_and_line (input_filename, lineno, s, ap);
+  v_warning_with_file_and_line (input_filename, linecolno, s, ap);
 }
 
 void
@@ -2038,7 +2051,7 @@ pedwarn_with_decl VPROTO((tree decl, cha
 static void
 v_pedwarn_with_file_and_line (file, line, s, ap)
      char *file;
-     int line;
+     linecol line;
      char *s;
      va_list ap;
 {
@@ -2049,11 +2062,11 @@ v_pedwarn_with_file_and_line (file, line
 }
 
 void
-pedwarn_with_file_and_line VPROTO((char *file, int line, char *s, ...))
+pedwarn_with_file_and_line VPROTO((char *file, linecol line, char *s, ...))
 {
 #ifndef ANSI_PROTOTYPES
   char *file;
-  int line;
+  linecol line;
   char *s;
 #endif
   va_list ap;
@@ -2062,7 +2075,7 @@ pedwarn_with_file_and_line VPROTO((char 
 
 #ifndef ANSI_PROTOTYPES
   file = va_arg (ap, char *);
-  line = va_arg (ap, int);
+  line = va_arg (ap, linecol);
   s = va_arg (ap, char *);
 #endif
 
@@ -2079,7 +2092,7 @@ vsorry (s, ap)
 {
   sorrycount++;
   if (input_filename)
-    fprintf (stderr, "%s:%d: ", input_filename, lineno);
+    print_lineno (input_filename, linecolno);
   else
     fprintf (stderr, "%s: ", progname);
   vmessage ("sorry, not implemented", s, ap);
@@ -2113,7 +2126,7 @@ v_really_sorry (s, ap)
 {
   sorrycount++;
   if (input_filename)
-    fprintf (stderr, "%s:%d: ", input_filename, lineno);
+    print_lineno (input_filename, linecolno);
   else
     fprintf (stderr, "%s: ", progname);
   vmessage ("sorry, not implemented", s, ap);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]