X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/75ae8299840bbd854fa2474d38402bbb933c6511..edb2e90531197dfd3250bd3ca2e5993376002182:/data/location.cc diff --git a/data/location.cc b/data/location.cc index 309b9c0f..e80742a5 100644 --- a/data/location.cc +++ b/data/location.cc @@ -27,7 +27,7 @@ m4_define([b4_position_define], { public:]m4_ifdef([b4_location_constructors], [[ /// Construct a position. - explicit position (]b4_percent_define_get([[filename_type]])[* f = YY_NULL, + explicit position (]b4_percent_define_get([[filename_type]])[* f = YY_NULLPTR, unsigned int l = ]b4_location_initial_line[u, unsigned int c = ]b4_location_initial_column[u) : filename (f) @@ -38,7 +38,7 @@ m4_define([b4_position_define], ]])[ /// Initialization. - void initialize (]b4_percent_define_get([[filename_type]])[* fn = YY_NULL, + void initialize (]b4_percent_define_get([[filename_type]])[* fn = YY_NULLPTR, unsigned int l = ]b4_location_initial_line[u, unsigned int c = ]b4_location_initial_column[u) { @@ -55,20 +55,14 @@ m4_define([b4_position_define], if (count) { column = ]b4_location_initial_column[u; - line = - 0 < count || -count < line - ? line + count - : ]b4_location_initial_line[; + line = add_ (line, count, ]b4_location_initial_line[); } } /// (column related) Advance to the COUNT next columns. void columns (int count = 1) { - column = - 0 < count || -count < column - ? column + count - : ]b4_location_initial_column[; + column = add_ (column, count, ]b4_location_initial_column[); } /** \} */ @@ -78,6 +72,15 @@ m4_define([b4_position_define], unsigned int line; /// Current column number. unsigned int column; + + private: + /// Compute max(min, lhs+rhs) (provided min <= lhs). + static unsigned int add_ (unsigned int lhs, int rhs, unsigned int min) + { + return (0 < rhs || -static_cast(rhs) < lhs + ? rhs + lhs + : min); + } }; /// Add and assign a position. @@ -175,7 +178,7 @@ m4_define([b4_location_define], ])[ /// Initialization. - void initialize (]b4_percent_define_get([[filename_type]])[* f = YY_NULL, + void initialize (]b4_percent_define_get([[filename_type]])[* f = YY_NULLPTR, unsigned int l = ]b4_location_initial_line[u, unsigned int c = ]b4_location_initial_column[u) {