]> git.saurik.com Git - bison.git/blobdiff - data/lalr1.cc
In Bison 1.875's yacc.c, YYLLOC_DEFAULT was called regardless
[bison.git] / data / lalr1.cc
index 00090e7a02898b383e0b8022608814709e9c72f6..e77e784262a612c4e75bbd9a2c605022372a628b 100644 (file)
@@ -181,13 +181,22 @@ b4_syncline([@oline@], [@ofile@])],
 
 ]/* Line __line__ of lalr1.cc.  */
 b4_syncline([@oline@], [@ofile@])[
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].  */
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+   If N is 0, then set CURRENT to the empty location which ends
+   the previous symbol: RHS[0] (always defined).  */
 
 #ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N)       \
-do {                                           \
-   ((Current).begin = (Rhs)[1].begin);         \
-   ((Current).end   = (Rhs)[N].end);           \
+# define YYLLOC_DEFAULT(Current, Rhs, N)               \
+do {                                                   \
+  if (N)                                               \
+    {                                                  \
+      (Current).begin = (Rhs)[1].begin;                        \
+      (Current).end   = (Rhs)[N].end;                  \
+    }                                                  \
+  else                                                 \
+    {                                                  \
+      (Current).begin = (Current).end = (Rhs)[0].end;  \
+    }                                                  \
 } while (0)
 #endif
 
@@ -195,18 +204,18 @@ namespace yy
 {
   class ]b4_parser_class_name[;
 
-  template < typename P >
+  template <typename P>
   struct Traits
   {
   };
 
-  template < >
-  struct Traits< ]b4_parser_class_name[ >
+  template <>
+  struct Traits<]b4_parser_class_name[>
   {
     typedef ]b4_int_type_for([b4_translate])[ TokenNumberType;
     typedef ]b4_int_type_for([b4_rhs])[       RhsNumberType;
-    typedef int      StateType;
-    typedef yystype  SemanticType;
+    typedef int StateType;
+    typedef yystype SemanticType;
     typedef ]b4_location_type[ LocationType;
   };
 }
@@ -217,15 +226,15 @@ namespace yy
   {
   public:
 
-    typedef Traits< ]b4_parser_class_name[ >::TokenNumberType TokenNumberType;
-    typedef Traits< ]b4_parser_class_name[ >::RhsNumberType   RhsNumberType;
-    typedef Traits< ]b4_parser_class_name[ >::StateType       StateType;
-    typedef Traits< ]b4_parser_class_name[ >::SemanticType    SemanticType;
-    typedef Traits< ]b4_parser_class_name[ >::LocationType    LocationType;
+    typedef Traits<]b4_parser_class_name[>::TokenNumberType TokenNumberType;
+    typedef Traits<]b4_parser_class_name[>::RhsNumberType   RhsNumberType;
+    typedef Traits<]b4_parser_class_name[>::StateType       StateType;
+    typedef Traits<]b4_parser_class_name[>::SemanticType    SemanticType;
+    typedef Traits<]b4_parser_class_name[>::LocationType    LocationType;
 
-    typedef Stack< StateType >    StateStack;
-    typedef Stack< SemanticType > SemanticStack;
-    typedef Stack< LocationType > LocationStack;
+    typedef Stack<StateType>    StateStack;
+    typedef Stack<SemanticType> SemanticStack;
+    typedef Stack<LocationType> LocationStack;
 
     ]b4_parser_class_name[ (bool debug][]b4_param[]b4_parse_param_decl[) :
       ]b4_constructor[][debug_ (debug),
@@ -233,6 +242,17 @@ namespace yy
     {
     }
 
+    ]b4_parser_class_name[ (bool debug,
+           LocationType][]b4_param[]b4_parse_param_decl[) :
+      ]b4_constructor[][debug_ (debug),
+      cdebug_ (std::cerr)]b4_parse_param_cons[
+    {
+      cdebug_ << __FILE__ << ':' << __LINE__
+             << ": this constructor is provided by backward compatibility"
+             << ", but will be removed in the near future."
+             << std::endl;
+    }
+
     virtual ~]b4_parser_class_name[ ()
     {
     }
@@ -247,8 +267,8 @@ namespace yy
     virtual void report_syntax_error_ ();
 #if YYDEBUG
     virtual void symprint_ (int yytype,
-                           const SemanticType *yyvaluep,
-                           const LocationType *yylocationp);
+                           const SemanticTypeyyvaluep,
+                           const LocationTypeyylocationp);
 #endif /* ! YYDEBUG */
 
 
@@ -286,9 +306,9 @@ namespace yy
 
     /* Even more tables.  */
     inline TokenNumberType translate_ (int token);
-    inline void destruct_ (const char *yymsg,
+    inline void destruct_ (const charyymsg,
                            int yytype,
-                           SemanticType *yyvaluep, LocationType *yylocationp);
+                           SemanticType* yyvaluep, LocationType* yylocationp);
 
     /// Pop \a n symbols the three stacks.
     inline void pop (unsigned int n = 1);
@@ -317,7 +337,7 @@ namespace yy
 
     /* Debugging.  */
     int debug_;
-    std::ostream &cdebug_;
+    std::ostreamcdebug_;
 
     /* Look-ahead and look-ahead in internal form.  */
     int looka_;
@@ -398,7 +418,7 @@ do {                                        \
 
 void
 yy::]b4_parser_class_name[::symprint_ (int yytype,
-                         const SemanticType *yyvaluep, const LocationType *yylocationp)
+                         const SemanticType* yyvaluep, const LocationType* yylocationp)
 {
   /* Pacify ``unused variable'' warnings.  */
   (void) yyvaluep;
@@ -418,8 +438,8 @@ yy::]b4_parser_class_name[::symprint_ (int yytype,
 #endif /* ! YYDEBUG */
 
 void
-yy::]b4_parser_class_name[::destruct_ (const char *yymsg,
-                         int yytype, SemanticType *yyvaluep, LocationType *yylocationp)
+yy::]b4_parser_class_name[::destruct_ (const charyymsg,
+                         int yytype, SemanticType* yyvaluep, LocationType* yylocationp)
 {
   /* Pacify ``unused variable'' warnings.  */
   (void) yyvaluep;
@@ -572,21 +592,14 @@ yyreduce:
      This behavior is undocumented and Bison
      users should not rely upon it.  */
   if (len_)
-    {
-      yyval = semantic_stack_[len_ - 1];
-      yyloc = location_stack_[len_ - 1];
-    }
+    yyval = semantic_stack_[len_ - 1];
   else
-    {
-      yyval = semantic_stack_[0];
-      yyloc = location_stack_[0];
-    }
+    yyval = semantic_stack_[0];
 
-  if (len_)
-    {
-      Slice< LocationType, LocationStack > slice (location_stack_, len_);
-      YYLLOC_DEFAULT (yyloc, slice, len_);
-    }
+  {
+    Slice<LocationType, LocationStack> slice (location_stack_, len_);
+    YYLLOC_DEFAULT (yyloc, slice, len_);
+  }
   YY_REDUCE_PRINT (n_);
   switch (n_)
     {
@@ -916,7 +929,8 @@ yy::]b4_parser_class_name[::reduce_print_ (int yyrule)
 {
   unsigned int yylno = rline_[yyrule];
   /* Print the symbols being reduced, and their result.  */
-  cdebug_ << "Reducing stack by rule " << n_ - 1 << " (line " << yylno << "), ";
+  cdebug_ << "Reducing stack by rule " << n_ - 1
+          << " (line " << yylno << "), ";
   for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_];
        0 <= rhs_[i]; ++i)
     cdebug_ << name_[rhs_[i]] << ' ';
@@ -964,7 +978,7 @@ b4_copyright([Stack handling for Bison C++ parsers], [2002, 2003, 2004])[
 
 namespace yy
 {
-  template < class T, class S = std::deque< T > >
+  template <class T, class S = std::deque<T> >
   class Stack
   {
   public:
@@ -1025,7 +1039,7 @@ namespace yy
     S seq_;
   };
 
-  template < class T, class S = Stack< T > >
+  template <class T, class S = Stack<T> >
   class Slice
   {
   public:
@@ -1245,7 +1259,7 @@ namespace yy
   }
 
   /** \brief Add and assign a Location */
-  inline Location &operator+= (Location& res, unsigned int width)
+  inline Locationoperator+= (Location& res, unsigned int width)
   {
     res.columns (width);
     return res;