torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
generic/edif/location.hh
Go to the documentation of this file.
1 
2 /* A Bison parser, made by GNU Bison 2.4. */
3 
4 /* Locations for Bison parsers in C++
5 
6  Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 
21 /* As a special exception, you may create a larger work that contains
22  part or all of the Bison parser skeleton and distribute that work
23  under terms of your choice, so long as that work isn't itself a
24  parser generator using the skeleton or a modified version thereof
25  as a parser skeleton. Alternatively, if you modify or redistribute
26  the parser skeleton itself, you may (at your option) remove this
27  special exception, which will cause the skeleton and the resulting
28  Bison output files to be licensed under the GNU General Public
29  License without this special exception.
30 
31  This special exception was added by the Free Software Foundation in
32  version 2.2 of Bison. */
33 
34 /**
35  ** \file location.hh
36  ** Define the torc::generic::location class.
37  */
38 
39 #ifndef BISON_LOCATION_HH
40 # define BISON_LOCATION_HH
41 
42 # include <iostream>
43 # include <string>
44 # include "position.hh"
45 
46 
47 /* Line 162 of location.cc */
48 #line 44 "parser.yy"
49 namespace torc { namespace generic {
50 
51 /* Line 162 of location.cc */
52 #line 53 "location.hh"
53 
54  /// Abstract a location.
55  class location
56  {
57  public:
58 
59  /// Construct a location.
61  : begin (), end ()
62  {
63  }
64 
65 
66  /// Initialization.
67  inline void initialize (std::string* fn)
68  {
69  begin.initialize (fn);
70  end = begin;
71  }
72 
73  /** \name Line and Column related manipulators
74  ** \{ */
75  public:
76  /// Reset initial location to final location.
77  inline void step ()
78  {
79  begin = end;
80  }
81 
82  /// Extend the current location to the COUNT next columns.
83  inline void columns (unsigned int count = 1)
84  {
85  end += count;
86  }
87 
88  /// Extend the current location to the COUNT next lines.
89  inline void lines (unsigned int count = 1)
90  {
91  end.lines (count);
92  }
93  /** \} */
94 
95 
96  public:
97  /// Beginning of the located region.
99  /// End of the located region.
101  };
102 
103  /// Join two location objects to create a location.
104  inline const location operator+ (const location& begin, const location& end)
105  {
106  location res = begin;
107  res.end = end.end;
108  return res;
109  }
110 
111  /// Add two location objects.
112  inline const location operator+ (const location& begin, unsigned int width)
113  {
114  location res = begin;
115  res.columns (width);
116  return res;
117  }
118 
119  /// Add and assign a location.
120  inline location& operator+= (location& res, unsigned int width)
121  {
122  res.columns (width);
123  return res;
124  }
125 
126  /// Compare two location objects.
127  inline bool
128  operator== (const location& loc1, const location& loc2)
129  {
130  return loc1.begin == loc2.begin && loc1.end == loc2.end;
131  }
132 
133  /// Compare two location objects.
134  inline bool
135  operator!= (const location& loc1, const location& loc2)
136  {
137  return !(loc1 == loc2);
138  }
139 
140  /** \brief Intercept output stream redirection.
141  ** \param ostr the destination output stream
142  ** \param loc a reference to the location to redirect
143  **
144  ** Avoid duplicate information.
145  */
146  inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
147  {
148  position last = loc.end - 1;
149  ostr << loc.begin;
150  if (last.filename
151  && (!loc.begin.filename
152  || *loc.begin.filename != *last.filename))
153  ostr << '-' << last;
154  else if (loc.begin.line != last.line)
155  ostr << '-' << last.line << '.' << last.column;
156  else if (loc.begin.column != last.column)
157  ostr << '-' << last.column;
158  return ostr;
159  }
160 
161 
162 /* Line 271 of location.cc */
163 #line 44 "parser.yy"
164 } } // torc::generic
165 
166 /* Line 271 of location.cc */
167 #line 168 "location.hh"
168 
169 #endif // not BISON_LOCATION_HH
position begin
Beginning of the located region.
location()
Construct a location.
position begin
Beginning of the located region.
void initialize(std::string *fn)
Initialization.
position end
End of the located region.
void step()
Reset initial location to final location.
unsigned int line
Current line number.
location & operator+=(location &res, unsigned int width)
Add and assign a location.
void columns(unsigned int count=1)
Extend the current location to the COUNT next columns.
const location operator+(const location &begin, const location &end)
Join two location objects to create a location.
std::string string
bool operator!=(const location &loc1, const location &loc2)
Compare two location objects.
std::ostream & operator<<(std::ostream &ostr, const location &loc)
Intercept output stream redirection.
std::string * filename
File name to which this position refers.
void lines(unsigned int count=1)
Extend the current location to the COUNT next lines.
bool operator==(const location &loc1, const location &loc2)
Compare two location objects.
void columns(unsigned int count=1)
Extend the current location to the COUNT next columns.
unsigned int column
Current column number.
position end
End of the located region.
void lines(int count=1)
(line related) Advance to the COUNT next lines.
void initialize(std::string *fn)
Initialization.