This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH column number support
On Tue, Dec 02, 2003 at 12:17:48AM -0800, Per Bothner wrote:
> In both this case (an "unreasonably" high line number) or in the
> case of "running low" we might want to have an option for disabling
> column numbers. "Running low" might be defined as after handing
> out 0x8000000.
Certainly an idea.
> However, this might complicate the API. I was thinking of:
>
> /* Get location for start of LINE and up to MAX_COL columns.
> The client gets a source_location L such that L stands for
> "column 0" of LINE, and L+C is column C of LINE, upto C<=MAX_COL. */
> #define LINEMAP_NEW_LINE(MAPS, LINE, MAX_COL) ...
>
> to be used thus:
>
> /* current_line_width has been calculated by _cpp_clean_line */
> pfile->line_start_loc
> = LINEMAP_NEW_LINE(&pfile->line_maps, current_line_number,
> current_line_width);
>
> token->src_loc
> = pfile->line_start_loc + CPP_BUF_COLUMN (buffer, buffer->cur)
>
> It gets a little uglier if we have to check for "running low".
Your API still falls into the trap of exposing the low bits as the
column number. Use an API wherein you must use a function to set
the column number and you don't have that problem:
source_location
linemap_set_column (line_maps *maps, source_location loc, unsigned int col)
{
if (loc is in running low state)
return loc;
if (col is too large)
return a new map;
return (loc stripped of column data) + col;
}
Use inline functions for trivial stuff and stuff shown to be performance
critical; I'm not real hot on macros unless absolutely necessary.
Providing the known line width when creating the line in the first
place is a good idea though.
r~