Hello Gabriel,

gch...@google.com (Gabriel Charette) a écrit:

[...]

> Do we want to apply the changes to libcpp to trunk now or wait??

[...]


> 2011-08-04  Gabriel Charette  <gch...@google.com>

[...]

>       * include/line-map.h (LC_REASON_BIT): Define as CHAR_BIT.
>       (COLUMN_BITS_BIT): Define as 8.
>       (struct line_map): Use LC_REASON_BIT and COLUMN_BITS_BIT to represent
>       field specific bit requirements.
>       * line-map.c (linemap_ensure_extra_space_available): New.
>       (linemap_add): Call linemap_ensure_extra_space_available.
>       (linemap_line_start): Fixed missing space.

[...]

> diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
> index 3234423..657e47f 100644
> --- a/libcpp/include/line-map.h
> +++ b/libcpp/include/line-map.h
> @@ -44,6 +44,9 @@ typedef unsigned int source_location;
>  /* Memory allocation function typedef.  Works like xrealloc.  */
>  typedef void *(*line_map_realloc) (void *, size_t);
>  
> +#define LC_REASON_BIT CHAR_BIT

This is a nit, but I would keep this hunk ... 

>  /* Physical source file TO_FILE at line TO_LINE at column 0 is represented
>     by the logical START_LOCATION.  TO_LINE+L at column C is represented by
>     START_LOCATION+(L*(1<<column_bits))+C, as long as C<(1<<column_bits),
> @@ -61,11 +64,11 @@ struct GTY(()) line_map {
>    linenum_type to_line;
>    source_location start_location;
>    int included_from;
> -  ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
> +  ENUM_BITFIELD (lc_reason) reason : LC_REASON_BIT;

... and this one into your private branch for now and apply it to trunk
(provided the maintainers agree) with the rest of this patch.
Otherwise, in isolation, this new define could look like a gratuitous
change.

[...]

>  /* A set of chronological line_map structures.  */
> @@ -190,4 +193,24 @@ extern const struct line_map *linemap_lookup
>  extern source_location
>  linemap_position_for_column (struct line_maps *set, unsigned int to_column);
>  
> +/* Makes sure SET has at least one more unused line_map allocated.
> +   If it doesn't, this function allocates more room in SET.  */
> +
> +static inline void
> +linemap_ensure_extra_space_available (struct line_maps *set)
> +{
> +  if (set->used == set->allocated)
> +    {
> +      line_map_realloc reallocator;
> +      reallocator  = set->reallocator ? set->reallocator : xrealloc;
> +
> +      set->allocated = 2 * set->allocated + 256;
> +      set->maps = (struct line_map *) (*reallocator) (set->maps,
> +                               set->allocated * sizeof (struct line_map));
> +
> +      memset (&set->maps[set->used], 0,
> +              (set->allocated - set->used) * sizeof (struct line_map));
> +    }
> +}
> +
>  #endif /* !LIBCPP_LINE_MAP_H  */
> diff --git a/libcpp/line-map.c b/libcpp/line-map.c
> index 86e2484..01ed7b5 100644
> --- a/libcpp/line-map.c
> +++ b/libcpp/line-map.c
> @@ -94,18 +94,7 @@ linemap_add (struct line_maps *set, enum lc_reason reason,
>    if (set->used && start_location < set->maps[set->used - 1].start_location)
>      abort ();
>  
> -  if (set->used == set->allocated)
> -    {
> -      line_map_realloc reallocator
> -     = set->reallocator ? set->reallocator : xrealloc;
> -      set->allocated = 2 * set->allocated + 256;
> -      set->maps
> -     = (struct line_map *) (*reallocator) (set->maps,
> -                                           set->allocated
> -                                           * sizeof (struct line_map));
> -      memset (&set->maps[set->used], 0, ((set->allocated - set->used)
> -                                      * sizeof (struct line_map)));
> -    }
> +  linemap_ensure_extra_space_available (set);

Just FYI, in my macro location tracking patch set (that is also that is
being reviewed "at the moment") I have added a similar function named
new_linemap, that allocates a new line map and adds it to the set of
line maps.  The relevant patch is at [1].

I am CC-ing Tom, as I cannot approve or reject this patch.

Thanks.

[1]: http://tinyurl.com/3jkaeh2

-- 
                Dodji

Reply via email to