libutap  0.93
Uppaal Timed Automata Parser
position.h
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 #ifndef UTAP_POSITION
23 #define UTAP_POSITION
24 
25 #include <cinttypes>
26 #include <climits>
27 
28 #include <vector>
29 #include <string>
30 #include <iostream>
31 
32 namespace UTAP
33 {
34  struct position_t
35  {
36  uint32_t start, end;
37  // Do NOT use UINT_MAX but INT_MAX instead because Java Integer
38  // will not parse UINT_MAX.
39  position_t() : start{0}, end{INT_MAX} {}
40  position_t(uint32_t s, uint32_t e) : start{s}, end{e} {}
41  };
42 
61  class Positions
62  {
63  public:
64  struct line_t
65  {
66  uint32_t position;
67  uint32_t offset;
68  uint32_t line;
69  std::string path;
70  line_t(uint32_t pos, uint32_t offs, uint32_t l, std::string p)
71  : position{pos}, offset{offs}, line{l}, path{std::move(p)} {}
72  };
73 
74  private:
75  std::vector<line_t> elements;
76  const line_t &find(uint32_t, uint32_t, uint32_t) const;
77  public:
79  void add(uint32_t position, uint32_t offset, uint32_t line,
80  const std::string& path);
81 
87  const line_t &find(uint32_t position) const;
88 
90  void dump();
91  };
92 
93 
94  struct error_t
95  {
99  const std::string message;
100  const std::string context;
101 
103  position_t pos, std::string msg, std::string ctx="")
104  : start{s}, end{e}, position{pos},
105  message{std::move(msg)}, context{std::move(ctx)} {}
106  };
107 }
108 
109 std::ostream &operator <<(std::ostream &out, const UTAP::error_t &);
110 
111 #endif
Positions::line_t end
Definition: position.h:97
A container for information about lines and positions in the input file.
Definition: position.h:61
position_t(uint32_t s, uint32_t e)
Definition: position.h:40
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
const std::string context
Definition: position.h:100
std::string path
Definition: position.h:69
line_t(uint32_t pos, uint32_t offs, uint32_t l, std::string p)
Definition: position.h:70
uint32_t start
Definition: position.h:36
error_t(Positions::line_t s, Positions::line_t e, position_t pos, std::string msg, std::string ctx="")
Definition: position.h:102
Definition: lexer.cc:817
Positions::line_t start
Definition: position.h:96