Blame d4_function/location.hh

Packit a4aae4
// A Bison parser, made by GNU Bison 3.0.4.
Packit a4aae4
Packit a4aae4
// Locations for Bison parsers in C++
Packit a4aae4
Packit a4aae4
// Copyright (C) 2002-2015 Free Software Foundation, Inc.
Packit a4aae4
Packit a4aae4
// This program is free software: you can redistribute it and/or modify
Packit a4aae4
// it under the terms of the GNU General Public License as published by
Packit a4aae4
// the Free Software Foundation, either version 3 of the License, or
Packit a4aae4
// (at your option) any later version.
Packit a4aae4
Packit a4aae4
// This program is distributed in the hope that it will be useful,
Packit a4aae4
// but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4aae4
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit a4aae4
// GNU General Public License for more details.
Packit a4aae4
Packit a4aae4
// You should have received a copy of the GNU General Public License
Packit a4aae4
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit a4aae4
Packit a4aae4
// As a special exception, you may create a larger work that contains
Packit a4aae4
// part or all of the Bison parser skeleton and distribute that work
Packit a4aae4
// under terms of your choice, so long as that work isn't itself a
Packit a4aae4
// parser generator using the skeleton or a modified version thereof
Packit a4aae4
// as a parser skeleton.  Alternatively, if you modify or redistribute
Packit a4aae4
// the parser skeleton itself, you may (at your option) remove this
Packit a4aae4
// special exception, which will cause the skeleton and the resulting
Packit a4aae4
// Bison output files to be licensed under the GNU General Public
Packit a4aae4
// License without this special exception.
Packit a4aae4
Packit a4aae4
// This special exception was added by the Free Software Foundation in
Packit a4aae4
// version 2.2 of Bison.
Packit a4aae4
Packit a4aae4
/**
Packit a4aae4
 ** \file location.hh
Packit a4aae4
 ** Define the libdap::location class.
Packit a4aae4
 */
Packit a4aae4
Packit a4aae4
#ifndef YY_YY_LOCATION_HH_INCLUDED
Packit a4aae4
# define YY_YY_LOCATION_HH_INCLUDED
Packit a4aae4
Packit a4aae4
# include "position.hh"
Packit a4aae4
Packit a4aae4
#line 34 "d4_function_parser.yy" // location.cc:337
Packit a4aae4
namespace libdap {
Packit a4aae4
#line 46 "location.hh" // location.cc:337
Packit a4aae4
  /// Abstract a location.
Packit a4aae4
  class location
Packit a4aae4
  {
Packit a4aae4
  public:
Packit a4aae4
Packit a4aae4
    /// Construct a location from \a b to \a e.
Packit a4aae4
    location (const position& b, const position& e)
Packit a4aae4
      : begin (b)
Packit a4aae4
      , end (e)
Packit a4aae4
    {
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    /// Construct a 0-width location in \a p.
Packit a4aae4
    explicit location (const position& p = position ())
Packit a4aae4
      : begin (p)
Packit a4aae4
      , end (p)
Packit a4aae4
    {
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    /// Construct a 0-width location in \a f, \a l, \a c.
Packit a4aae4
    explicit location (std::string* f,
Packit a4aae4
                       unsigned int l = 1u,
Packit a4aae4
                       unsigned int c = 1u)
Packit a4aae4
      : begin (f, l, c)
Packit a4aae4
      , end (f, l, c)
Packit a4aae4
    {
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
Packit a4aae4
    /// Initialization.
Packit a4aae4
    void initialize (std::string* f = YY_NULLPTR,
Packit a4aae4
                     unsigned int l = 1u,
Packit a4aae4
                     unsigned int c = 1u)
Packit a4aae4
    {
Packit a4aae4
      begin.initialize (f, l, c);
Packit a4aae4
      end = begin;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    /** \name Line and Column related manipulators
Packit a4aae4
     ** \{ */
Packit a4aae4
  public:
Packit a4aae4
    /// Reset initial location to final location.
Packit a4aae4
    void step ()
Packit a4aae4
    {
Packit a4aae4
      begin = end;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    /// Extend the current location to the COUNT next columns.
Packit a4aae4
    void columns (int count = 1)
Packit a4aae4
    {
Packit a4aae4
      end += count;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    /// Extend the current location to the COUNT next lines.
Packit a4aae4
    void lines (int count = 1)
Packit a4aae4
    {
Packit a4aae4
      end.lines (count);
Packit a4aae4
    }
Packit a4aae4
    /** \} */
Packit a4aae4
Packit a4aae4
Packit a4aae4
  public:
Packit a4aae4
    /// Beginning of the located region.
Packit a4aae4
    position begin;
Packit a4aae4
    /// End of the located region.
Packit a4aae4
    position end;
Packit a4aae4
  };
Packit a4aae4
Packit a4aae4
  /// Join two locations, in place.
Packit a4aae4
  inline location& operator+= (location& res, const location& end)
Packit a4aae4
  {
Packit a4aae4
    res.end = end.end;
Packit a4aae4
    return res;
Packit a4aae4
  }
Packit a4aae4
Packit a4aae4
  /// Join two locations.
Packit a4aae4
  inline location operator+ (location res, const location& end)
Packit a4aae4
  {
Packit a4aae4
    return res += end;
Packit a4aae4
  }
Packit a4aae4
Packit a4aae4
  /// Add \a width columns to the end position, in place.
Packit a4aae4
  inline location& operator+= (location& res, int width)
Packit a4aae4
  {
Packit a4aae4
    res.columns (width);
Packit a4aae4
    return res;
Packit a4aae4
  }
Packit a4aae4
Packit a4aae4
  /// Add \a width columns to the end position.
Packit a4aae4
  inline location operator+ (location res, int width)
Packit a4aae4
  {
Packit a4aae4
    return res += width;
Packit a4aae4
  }
Packit a4aae4
Packit a4aae4
  /// Subtract \a width columns to the end position, in place.
Packit a4aae4
  inline location& operator-= (location& res, int width)
Packit a4aae4
  {
Packit a4aae4
    return res += -width;
Packit a4aae4
  }
Packit a4aae4
Packit a4aae4
  /// Subtract \a width columns to the end position.
Packit a4aae4
  inline location operator- (location res, int width)
Packit a4aae4
  {
Packit a4aae4
    return res -= width;
Packit a4aae4
  }
Packit a4aae4
Packit a4aae4
  /// Compare two location objects.
Packit a4aae4
  inline bool
Packit a4aae4
  operator== (const location& loc1, const location& loc2)
Packit a4aae4
  {
Packit a4aae4
    return loc1.begin == loc2.begin && loc1.end == loc2.end;
Packit a4aae4
  }
Packit a4aae4
Packit a4aae4
  /// Compare two location objects.
Packit a4aae4
  inline bool
Packit a4aae4
  operator!= (const location& loc1, const location& loc2)
Packit a4aae4
  {
Packit a4aae4
    return !(loc1 == loc2);
Packit a4aae4
  }
Packit a4aae4
Packit a4aae4
  /** \brief Intercept output stream redirection.
Packit a4aae4
   ** \param ostr the destination output stream
Packit a4aae4
   ** \param loc a reference to the location to redirect
Packit a4aae4
   **
Packit a4aae4
   ** Avoid duplicate information.
Packit a4aae4
   */
Packit a4aae4
  template <typename YYChar>
Packit a4aae4
  inline std::basic_ostream<YYChar>&
Packit a4aae4
  operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
Packit a4aae4
  {
Packit a4aae4
    unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
Packit a4aae4
    ostr << loc.begin;
Packit a4aae4
    if (loc.end.filename
Packit a4aae4
        && (!loc.begin.filename
Packit a4aae4
            || *loc.begin.filename != *loc.end.filename))
Packit a4aae4
      ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
Packit a4aae4
    else if (loc.begin.line < loc.end.line)
Packit a4aae4
      ostr << '-' << loc.end.line << '.' << end_col;
Packit a4aae4
    else if (loc.begin.column < end_col)
Packit a4aae4
      ostr << '-' << end_col;
Packit a4aae4
    return ostr;
Packit a4aae4
  }
Packit a4aae4
Packit a4aae4
#line 34 "d4_function_parser.yy" // location.cc:337
Packit a4aae4
} // libdap
Packit a4aae4
#line 192 "location.hh" // location.cc:337
Packit a4aae4
#endif // !YY_YY_LOCATION_HH_INCLUDED