diff mbox

cleanups in line-map

Message ID CAESRpQDatbjs7nihn=hzYByAMQHzRRepiOSBLum3OAv2Qfy0DA@mail.gmail.com
State New
Headers show

Commit Message

Manuel López-Ibáñez Oct. 11, 2014, 11:07 p.m. UTC
A few cleanups in line-map code. Bootstrapped and regression tested on
x86_64-linux-gnu.

OK?

libcpp/ChangeLog:

2014-10-12  Manuel López-Ibáñez  <manu@gcc.gnu.org>

    * include/line-map.h (linemap_location_from_macro_expansion_p):
    const struct line_maps * argument.
    (linemap_position_for_line_and_column): const struct line_map *
    argument.
    * line-map.c (linemap_macro_map_loc_to_def_point): Delete
    redundant declaration.
    (linemap_add_macro_token): Use correct argument name in comment.
    (linemap_position_for_line_and_column): const struct line_map *
    argument.
    (linemap_macro_map_loc_to_def_point): Fix comment. Make static.
    (linemap_location_from_macro_expansion_p): const struct line_maps *
    argument.
    (linemap_resolve_location): Fix argument names in comment.

Comments

Dodji Seketeli Oct. 13, 2014, 8:52 a.m. UTC | #1
Manuel López-Ibáñez <lopezibanez@gmail.com> writes:

> A few cleanups in line-map code. Bootstrapped and regression tested on
> x86_64-linux-gnu.

Thanks for doing this.

> OK?

Yes, barring this little nit:

[...]

> Index: libcpp/line-map.c
> ===================================================================
> --- libcpp/line-map.c	(revision 216098)
> +++ libcpp/line-map.c	(working copy)
> @@ -29,12 +29,10 @@ along with this program; see the file CO
>  static void trace_include (const struct line_maps *, const struct line_map *);
>  static const struct line_map * linemap_ordinary_map_lookup (struct line_maps *,
>  							    source_location);
>  static const struct line_map* linemap_macro_map_lookup (struct line_maps *,
>  							source_location);
> -static source_location linemap_macro_map_loc_to_def_point
> -(const struct line_map*, source_location);

This is not redundant per se, is it?  It's just a forward declaration of
the function that is defined later.  Just like for
linemap_macro_map_loc_unwind_toward_spelling() below.  Or what am I
missing?  I'd prefer to see this forward declaration stay, FWIW.

Otherwise, this cleanup patch looks good to me.  If it was my call, I'd
say "OK with that change".

Thank you for tackling this.
Manuel López-Ibáñez Oct. 13, 2014, 9:06 a.m. UTC | #2
On 13 October 2014 10:52, Dodji Seketeli <dodji@redhat.com> wrote:
> Manuel López-Ibáñez <lopezibanez@gmail.com> writes:
>
>> Index: libcpp/line-map.c
>> ===================================================================
>> --- libcpp/line-map.c (revision 216098)
>> +++ libcpp/line-map.c (working copy)
>> @@ -29,12 +29,10 @@ along with this program; see the file CO
>>  static void trace_include (const struct line_maps *, const struct line_map *);
>>  static const struct line_map * linemap_ordinary_map_lookup (struct line_maps *,
>>                                                           source_location);
>>  static const struct line_map* linemap_macro_map_lookup (struct line_maps *,
>>                                                       source_location);
>> -static source_location linemap_macro_map_loc_to_def_point
>> -(const struct line_map*, source_location);
>
> This is not redundant per se, is it?  It's just a forward declaration of
> the function that is defined later.  Just like for
> linemap_macro_map_loc_unwind_toward_spelling() below.  Or what am I
> missing?  I'd prefer to see this forward declaration stay, FWIW.

Oh, well, I guess it is a matter of taste. I was annoyed by having to
update two different places (I added "const" to the first argument of
this definition function, so I will have to also add it here).
Moreover, as the patch shows, the two declarations might be different
(one was static, the other not), and then which one is the "correct
one" requires some expert knowledge of C++. I understand using forward
declarations when otherwise it would be a mess to re-order the
functions, but in this case, it is not really necessary. But I can
leave it and just update the argument type.

> Otherwise, this cleanup patch looks good to me.  If it was my call, I'd
> say "OK with that change".
>
> Thank you for tackling this.

Thanks for the review.

Cheers,

Manuel.
diff mbox

Patch

Index: libcpp/include/line-map.h
===================================================================
--- libcpp/include/line-map.h	(revision 216098)
+++ libcpp/include/line-map.h	(working copy)
@@ -521,11 +521,11 @@  int linemap_location_in_system_header_p
 					 source_location);
 
 /* Return TRUE if LOCATION is a source code location of a token coming
    from a macro replacement-list at a macro expansion point, FALSE
    otherwise.  */
-bool linemap_location_from_macro_expansion_p (struct line_maps *,
+bool linemap_location_from_macro_expansion_p (const struct line_maps *,
 					      source_location);
 
 /* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will
    be reserved for libcpp user as special values, no token from libcpp
    will contain any of those locations.  */
@@ -597,13 +597,14 @@  bool linemap_location_from_macro_expansi
 extern source_location
 linemap_position_for_column (struct line_maps *, unsigned int);
 
 /* Encode and return a source location from a given line and
    column.  */
-source_location linemap_position_for_line_and_column (struct line_map *,
-						      linenum_type,
-						      unsigned int);
+source_location
+linemap_position_for_line_and_column (const struct line_map *,
+				      linenum_type, unsigned int);
+
 /* Return the file this map is for.  */
 #define LINEMAP_FILE(MAP)					\
   (linemap_check_ordinary (MAP)->d.ordinary.to_file)
 
 /* Return the line number this map started encoding location from.  */
Index: libcpp/line-map.c
===================================================================
--- libcpp/line-map.c	(revision 216098)
+++ libcpp/line-map.c	(working copy)
@@ -29,12 +29,10 @@  along with this program; see the file CO
 static void trace_include (const struct line_maps *, const struct line_map *);
 static const struct line_map * linemap_ordinary_map_lookup (struct line_maps *,
 							    source_location);
 static const struct line_map* linemap_macro_map_lookup (struct line_maps *,
 							source_location);
-static source_location linemap_macro_map_loc_to_def_point
-(const struct line_map*, source_location);
 static source_location linemap_macro_map_loc_unwind_toward_spelling
 (const struct line_map*, source_location);
 static source_location linemap_macro_map_loc_to_exp_point
 (const struct line_map*, source_location);
 static source_location linemap_macro_loc_to_spelling_point
@@ -482,11 +480,11 @@  linemap_enter_macro (struct line_maps *s
    definition, it is the locus in the macro definition; otherwise it
    is a location in the context of the caller of this macro expansion
    (which is a virtual location or a source location if the caller is
    itself a macro expansion or not).
 
-   MACRO_DEFINITION_LOC is the location in the macro definition,
+   ORIG_PARM_REPLACEMENT_LOC is the location in the macro definition,
    either of the token itself or of a macro parameter that it
    replaces.  */
 
 source_location
 linemap_add_macro_token (const struct line_map *map,
@@ -619,11 +617,11 @@  linemap_position_for_column (struct line
 
 /* Encode and return a source location from a given line and
    column.  */
 
 source_location
-linemap_position_for_line_and_column (struct line_map *map,
+linemap_position_for_line_and_column (const struct line_map *map,
 				      linenum_type line,
 				      unsigned column)
 {
   linemap_assert (ORDINARY_MAP_STARTING_LINE_NUMBER (map) <= line);
 
@@ -770,19 +768,17 @@  linemap_macro_map_loc_to_exp_point (cons
 		  <  MACRO_MAP_NUM_MACRO_TOKENS (map));
 
   return MACRO_MAP_EXPANSION_POINT_LOCATION (map);
 }
 
-/* If LOCATION is the source location of a token that belongs to a
-   macro replacement-list -- as part of a macro expansion -- then
-   return the location of the token at the definition point of the
-   macro.  Otherwise, return LOCATION.  SET is the set of maps
-   location come from.  ORIGINAL_MAP is an output parm. If non NULL,
-   the function sets *ORIGINAL_MAP to the ordinary (non-macro) map the
-   returned location comes from.  */
+/* LOCATION is the source location of a token that belongs to a macro
+   replacement-list as part of the macro expansion denoted by MAP.
 
-source_location
+   Return the location of the token at the definition point of the
+   macro.  */
+
+static source_location
 linemap_macro_map_loc_to_def_point (const struct line_map *map,
 				    source_location location)
 {
   unsigned token_no;
 
@@ -938,11 +934,11 @@  linemap_location_in_system_header_p (str
 /* Return TRUE if LOCATION is a source code location of a token coming
    from a macro replacement-list at a macro expansion point, FALSE
    otherwise.  */
 
 bool
-linemap_location_from_macro_expansion_p (struct line_maps *set,
+linemap_location_from_macro_expansion_p (const struct line_maps *set,
 					 source_location location)
 {
   if (IS_ADHOC_LOC (location))
     location = set->location_adhoc_data_map.data[location
 						 & MAX_SOURCE_LOCATION].locus;
@@ -1231,13 +1227,13 @@  linemap_macro_loc_to_exp_point (struct l
 
    If LOC is the locus of a token that is not an argument of a
    function-like macro, then the function behaves as if LRK was set to
    LRK_SPELLING_LOCATION.
 
-   If LOC_MAP is not NULL, *LOC_MAP is set to the map encoding the
+   If MAP is not NULL, *MAP is set to the map encoding the
    returned location.  Note that if the returned location wasn't originally
-   encoded by a map, the *MAP is set to NULL.  This can happen if LOC
+   encoded by a map, then *MAP is set to NULL.  This can happen if LOC
    resolves to a location reserved for the client code, like
    UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC.  */
 
 source_location
 linemap_resolve_location (struct line_maps *set,