Loading...
Searching...
No Matches
blast-parser-location.h
Go to the documentation of this file.
// A Bison parser, made by GNU Bison 3.8.2.
// Locations for Bison parsers in C++
// Copyright (C) 2002-2015, 2018-2021 Free Software Foundation, Inc.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// As a special exception, you may create a larger work that contains
// part or all of the Bison parser skeleton and distribute that work
// under terms of your choice, so long as that work isn't itself a
// parser generator using the skeleton or a modified version thereof
// as a parser skeleton. Alternatively, if you modify or redistribute
// the parser skeleton itself, you may (at your option) remove this
// special exception, which will cause the skeleton and the resulting
// Bison output files to be licensed under the GNU General Public
// License without this special exception.
// This special exception was added by the Free Software Foundation in
// version 2.2 of Bison.
#ifndef YY_YY_ROSTLAB_BLAST_PARSER_LOCATION_H_INCLUDED
# define YY_YY_ROSTLAB_BLAST_PARSER_LOCATION_H_INCLUDED
# include <iostream>
# include <string>
# ifndef YY_NULLPTR
# if defined __cplusplus
# if 201103L <= __cplusplus
# define YY_NULLPTR nullptr
# else
# define YY_NULLPTR 0
# endif
# else
# define YY_NULLPTR ((void*)0)
# endif
# endif
#line 22 "blast-parser-parser.ypp"
namespace rostlab { namespace blast {
#line 59 "rostlab/blast-parser-location.h"
class position
{
public:
typedef const std::string filename_type;
typedef int counter_type;
explicit position (filename_type* f = YY_NULLPTR,
counter_type l = 1,
counter_type c = 1)
: filename (f)
, line (l)
, column (c)
{}
void initialize (filename_type* fn = YY_NULLPTR,
counter_type l = 1,
counter_type c = 1)
{
filename = fn;
line = l;
column = c;
}
void lines (counter_type count = 1)
{
if (count)
{
column = 1;
line = add_ (line, count, 1);
}
}
void columns (counter_type count = 1)
{
column = add_ (column, count, 1);
}
filename_type* filename;
counter_type line;
counter_type column;
private:
static counter_type add_ (counter_type lhs, counter_type rhs, counter_type min)
{
return lhs + rhs < min ? min : lhs + rhs;
}
};
inline position&
operator+= (position& res, position::counter_type width)
{
res.columns (width);
return res;
}
inline position
operator+ (position res, position::counter_type width)
{
return res += width;
}
inline position&
operator-= (position& res, position::counter_type width)
{
return res += -width;
}
inline position
operator- (position res, position::counter_type width)
{
return res -= width;
}
template <typename YYChar>
std::basic_ostream<YYChar>&
operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
{
if (pos.filename)
ostr << *pos.filename << ':';
return ostr << pos.line << '.' << pos.column;
}
class location
{
public:
typedef position::filename_type filename_type;
typedef position::counter_type counter_type;
location (const position& b, const position& e)
: begin (b)
, end (e)
{}
explicit location (const position& p = position ())
: begin (p)
, end (p)
{}
explicit location (filename_type* f,
counter_type l = 1,
counter_type c = 1)
: begin (f, l, c)
, end (f, l, c)
{}
void initialize (filename_type* f = YY_NULLPTR,
counter_type l = 1,
counter_type c = 1)
{
begin.initialize (f, l, c);
end = begin;
}
public:
void step ()
{
begin = end;
}
void columns (counter_type count = 1)
{
end += count;
}
void lines (counter_type count = 1)
{
end.lines (count);
}
public:
position begin;
position end;
};
inline location&
operator+= (location& res, const location& end)
{
res.end = end.end;
return res;
}
inline location
operator+ (location res, const location& end)
{
return res += end;
}
inline location&
operator+= (location& res, location::counter_type width)
{
res.columns (width);
return res;
}
inline location
operator+ (location res, location::counter_type width)
{
return res += width;
}
inline location&
operator-= (location& res, location::counter_type width)
{
return res += -width;
}
inline location
operator- (location res, location::counter_type width)
{
return res -= width;
}
template <typename YYChar>
std::basic_ostream<YYChar>&
operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
{
location::counter_type end_col
= 0 < loc.end.column ? loc.end.column - 1 : 0;
ostr << loc.begin;
if (loc.end.filename
&& (!loc.begin.filename
|| *loc.begin.filename != *loc.end.filename))
ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
else if (loc.begin.line < loc.end.line)
ostr << '-' << loc.end.line << '.' << end_col;
else if (loc.begin.column < end_col)
ostr << '-' << end_col;
return ostr;
}
#line 22 "blast-parser-parser.ypp"
} } // rostlab::blast
#line 305 "rostlab/blast-parser-location.h"
#endif // !YY_YY_ROSTLAB_BLAST_PARSER_LOCATION_H_INCLUDED
YY_NULLPTR
#define YY_NULLPTR
Definition blast-parser-location.h:52
rostlab::blast::location
Two points in a source file.
Definition blast-parser-location.h:167
rostlab::blast::location::begin
position begin
Beginning of the located region.
Definition blast-parser-location.h:229
rostlab::blast::location::filename_type
position::filename_type filename_type
Type for file name.
Definition blast-parser-location.h:170
rostlab::blast::location::counter_type
position::counter_type counter_type
Type for line and column numbers.
Definition blast-parser-location.h:172
rostlab::blast::location::lines
void lines(counter_type count=1)
Extend the current location to the COUNT next lines.
Definition blast-parser-location.h:220
rostlab::blast::location::location
location(const position &p=position())
Construct a 0-width location in p.
Definition blast-parser-location.h:181
rostlab::blast::location::initialize
void initialize(filename_type *f=YY_NULLPTR, counter_type l=1, counter_type c=1)
Initialization.
Definition blast-parser-location.h:196
rostlab::blast::location::step
void step()
Reset initial location to final location.
Definition blast-parser-location.h:208
rostlab::blast::location::end
position end
End of the located region.
Definition blast-parser-location.h:231
rostlab::blast::location::columns
void columns(counter_type count=1)
Extend the current location to the COUNT next columns.
Definition blast-parser-location.h:214
rostlab::blast::location::location
location(filename_type *f, counter_type l=1, counter_type c=1)
Construct a 0-width location in f, l, c.
Definition blast-parser-location.h:187
rostlab::blast::location::location
location(const position &b, const position &e)
Construct a location from b to e.
Definition blast-parser-location.h:175
rostlab::blast::position
A point in a source file.
Definition blast-parser-location.h:62
rostlab::blast::position::filename_type
const std::string filename_type
Type for file name.
Definition blast-parser-location.h:65
rostlab::blast::position::line
counter_type line
Current line number.
Definition blast-parser-location.h:111
rostlab::blast::position::lines
void lines(counter_type count=1)
(line related) Advance to the COUNT next lines.
Definition blast-parser-location.h:92
rostlab::blast::position::column
counter_type column
Current column number.
Definition blast-parser-location.h:113
rostlab::blast::position::initialize
void initialize(filename_type *fn=YY_NULLPTR, counter_type l=1, counter_type c=1)
Initialization.
Definition blast-parser-location.h:80
rostlab::blast::position::filename
filename_type * filename
File name to which this position refers.
Definition blast-parser-location.h:109
rostlab::blast::position::counter_type
int counter_type
Type for line and column numbers.
Definition blast-parser-location.h:67
rostlab::blast::position::position
position(filename_type *f=YY_NULLPTR, counter_type l=1, counter_type c=1)
Construct a position.
Definition blast-parser-location.h:70
rostlab::blast::position::columns
void columns(counter_type count=1)
(column related) Advance to the COUNT next columns.
Definition blast-parser-location.h:102
rostlab::blast::operator+=
position & operator+=(position &res, position::counter_type width)
Add width columns, in place.
Definition blast-parser-location.h:125
rostlab::blast::operator+
position operator+(position res, position::counter_type width)
Add width columns.
Definition blast-parser-location.h:133
rostlab::blast::operator-
position operator-(position res, position::counter_type width)
Subtract width columns.
Definition blast-parser-location.h:147
rostlab::blast::operator-=
position & operator-=(position &res, position::counter_type width)
Subtract width columns, in place.
Definition blast-parser-location.h:140
rostlab::blast::operator<<
std::basic_ostream< YYChar > & operator<<(std::basic_ostream< YYChar > &ostr, const position &pos)
Intercept output stream redirection.
Definition blast-parser-location.h:158
rostlab
Definition blast-parser-driver.h:45