change the location_t type, DECL_SOURCE_LINE etc

Per Bothner per@bothner.com
Wed Dec 4 19:44:00 GMT 2002


Neil Booth wrote:

> line-maps compress file/line into 32 bits.

I've looked at the code.  I *think* I understand the idea, but
as they don't seem to be used much, even in cpplib, I may be
confused.

One problem is that it isn't obvious what lines numbers are logical,
and which are physical.  I can figure it by tracing calls in
cpplib, but a simple typedef would help.  For example:

typedef unsigned int file_line_t;

The goal of course would be for file_line_t to replace location_t,
so perhaps we could just use location_t.  However, file_line_t is
perhaps less ambiguous.

extern const struct line_map *lookup_line
   PARAMS ((struct line_maps *, file_line_t));

 > They don't hold column info; since when I suggested it before it
 > wasn't popular.

I really would like column numbers.  I also think it is very awkward
when cpplib takes a (file_line_t, column)-pair.  It is much cleaner
to fold the column number into the file_line_t.

Suggestion:  To struct line_map add:

   /* Number of column in a file_line_t which are column numbers. */
   int column_bits;

Then SOURCE_LINE becomes:
#define SOURCE_LINE(MAP, LINE) \
   (((LINE) + (MAP)->to_line - (MAP)->from_line) >> (MAP)->column_bits)
and we get:
#define SOURCE_COLUMN(MAP, LINE) \
   (((LINE) + (MAP)->to_line - (MAP)->from_line)
     & ((1 << (MAP)->column_bits) - 1))

Of course add_line_map would have to take a column_bits parameter,
which leads to the issue of what to set it to.  I suggest a default
of 8, for front-ends that generate column-numbers, and 0 for
front-ends that don't, or when the line-number gets too high.

If a file_line_t is needed in a situation where the current
physical column number is more than 255, we have the option of
making another call to add_line_map with a higher column_bits,
or ignoring the column numbers (set it to 0).  If the current
line numbes starts getting really high, we might similarly want
to reset column_bits to 0, so we don't "use up" the file_line_t
values too quickly.

Another problem:  Currently, the struct line_maps is local to a
cpp_reader.  If it is going to replace location_t, then of course
it needs to be global.  Perhaps cpp_create_reader could take an
extra parameter, which is the line_maps set to use?

-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/



More information about the Gcc mailing list