libutap  0.93
Uppaal Timed Automata Parser
position.cpp
Go to the documentation of this file.
1 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 
3 /* libutap - Uppaal Timed Automata Parser.
4  Copyright (C) 2006 Uppsala University and Aalborg University.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public License
8  as published by the Free Software Foundation; either version 2.1 of
9  the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  USA
20 */
21 
22 #include <stdexcept>
23 #include "utap/position.h"
24 
25 using std::string;
26 using std::vector;
27 
28 using namespace UTAP;
29 
30 void Positions::add(uint32_t position, uint32_t offset, uint32_t line, const string& path)
31 {
32  if (!elements.empty() && position < elements.back().position)
33  {
34  throw std::logic_error("Positions must be monotonically increasing");
35  }
36  elements.push_back(line_t(position, offset, line, path));
37 }
38 
39 const Positions::line_t &Positions::find(
40  uint32_t position, uint32_t first, uint32_t last) const
41 {
42  while (first + 1 < last)
43  {
44  uint32_t i = (first + last) / 2;
45  if (position < elements[i].position)
46  {
47  last = i;
48  }
49  else
50  {
51  first = i;
52  }
53  }
54  return elements[first];
55 }
56 
57 const Positions::line_t &Positions::find(uint32_t position) const
58 {
59  if (elements.size() == 0)
60  {
61  throw std::logic_error("No positions have been added");
62  }
63  return find(position, 0, elements.size());
64 }
65 
68 {
69  for (size_t i = 0; i < elements.size(); i++)
70  {
71  std::cout << elements[i].position << " "
72  << elements[i].offset << " "
73  << elements[i].line << " "
74  << elements[i].path << std::endl;
75  }
76 }
77 
78 std::ostream &operator <<(std::ostream &out, const UTAP::error_t &e)
79 {
80  if (e.start.path.empty())
81  {
82  out << e.message << " at line "
83  << e.start.line << " column " << (e.position.start - e.start.position)
84  << " to line "
85  << e.end.line << " column " << (e.position.end - e.end.position);
86  }
87  else
88  {
89  out << e.message << " in " << e.start.path << " at line "
90  << e.start.line << " column " << (e.position.start - e.start.position)
91  << " to line "
92  << e.end.line << " column " << (e.position.end - e.end.position);
93  }
94  return out;
95 }
Positions::line_t end
Definition: position.h:97
void dump()
Dump table to stdout.
Definition: position.cpp:67
std::ostream & operator<<(std::ostream &os, const SignalFlow::strs_t &s)
Definition: signalflow.h:189
position_t position
Definition: position.h:98
const std::string message
Definition: position.h:99
uint32_t end
Definition: position.h:36
void add(uint32_t position, uint32_t offset, uint32_t line, const std::string &path)
Add information about a line to the container.
Definition: position.cpp:30
std::string path
Definition: position.h:69
uint32_t start
Definition: position.h:36
Definition: lexer.cc:817
Positions::line_t start
Definition: position.h:96