This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Re: [PATCH 2/3] Remove is_first_nonwhitespace_on_line(), instead improve get_visual_column()


On 06/09/2015 11:31 AM, Patrick Palka wrote:
This patch removes the function is_first_nonwhitespace_on_line() in
favor of augmenting the function get_visual_column() to optionally
return the visual column corresponding to the first non-whitespace character
on the line.  Existing usage of is_first_nonwhitespace_on_line() can
be trivially replaced by calling get_visual_column() and comparing *out
with *first_nws.

The rationale for this change is that in many cases it is better to use
the visual column of the first non-whitespace character rather than the
visual column of the token.  Consider:

   if (p) {
     foo (1);
   } else       // GUARD
     if (q)     // BODY
       foo (2);
     foo (3);   // NEXT

Here, with current heuristics, we do not emit a warning because we
notice that the visual columns of each token line up ("suggesting"
autogenerated code).  Yet it is obvious that we should warn here because
it misleadingly looks like the foo (3); statement is guarded by the
else.

If we instead consider the visual column of the first non-whitespace
character on the guard line, the columns will not line up thus we will
emit the warning.  This will be done in the next patch.

gcc/c-family/ChangeLog:

	* c-indentation.c (get_visual_column): Add parameter first_nws,
	use it.  Update comment documenting the function.
	(is_first_nonwhitespace_on_line): Remove.
	(should_warn_for_misleading_indentation): Replace usage of
	of is_first_nonwhitespace_on_line with get_visual_column.
Same comment/question WRT testing as the prior patch.

OK once you've confirmed bootstrap & regression testing was completed successfully.

jeff


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