libutap
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 "config.h"
26 
27 #ifdef HAVE_INTTYPES_H
28 #include <inttypes.h>
29 #elif defined(HAVE_STDINT_H)
30 #include <stdint.h>
31 #else
32 #error "No inttypes.h or stdint.h"
33 #endif
34 
35 #include <vector>
36 #include <string>
37 #include <iostream>
38 #include <climits>
39 
40 namespace UTAP
41 {
42  struct position_t
43  {
44  uint32_t start, end;
45  // Do NOT use UINT_MAX but INT_MAX instead because Java Integer
46  // will not parse UINT_MAX.
47  position_t() : start(0), end(INT_MAX) {}
48  position_t(uint32_t start, uint32_t end) : start(start), end(end) {}
49  };
50 
69  class Positions
70  {
71  public:
72  struct line_t
73  {
74  uint32_t position;
75  uint32_t offset;
76  uint32_t line;
77  std::string path;
78  line_t(uint32_t position, uint32_t offset, uint32_t line, std::string path)
79  : position(position), offset(offset), line(line), path(path) {}
80  };
81 
82  private:
83  std::vector<line_t> elements;
84  const line_t &find(uint32_t, uint32_t, uint32_t) const;
85  public:
87  void add(uint32_t position, uint32_t offset, uint32_t line, std::string path);
88 
94  const line_t &find(uint32_t position) const;
95 
97  void dump();
98  };
99 
100 
101  struct error_t
102  {
106  std::string msg;
107  std::string context;
108 
110  position_t position, std::string msg, std::string context="")
111  : start(start), end(end), position(position), msg(msg), context(context){}
112  };
113 }
114 
115 std::ostream &operator <<(std::ostream &out, const UTAP::error_t &);
116 
117 #endif
std::string path
Definition: position.h:77
uint32_t position
Definition: position.h:74
Positions::line_t start
Definition: position.h:103
uint32_t line
Definition: position.h:76
error_t(Positions::line_t start, Positions::line_t end, position_t position, std::string msg, std::string context="")
Definition: position.h:109
void dump()
Dump table to stdout.
Definition: position.cpp:67
position_t position
Definition: position.h:105
Definition: position.h:72
Definition: lexer.cc:585
position_t()
Definition: position.h:47
std::string msg
Definition: position.h:106
void add(uint32_t position, uint32_t offset, uint32_t line, std::string path)
Add information about a line to the container.
Definition: position.cpp:30
uint32_t offset
Definition: position.h:75
std::string context
Definition: position.h:107
std::ostream & operator<<(std::ostream &out, const UTAP::error_t &)
Definition: position.cpp:78
Positions::line_t end
Definition: position.h:104
Definition: position.h:42
uint32_t end
Definition: position.h:44
line_t(uint32_t position, uint32_t offset, uint32_t line, std::string path)
Definition: position.h:78
Definition: position.h:101
position_t(uint32_t start, uint32_t end)
Definition: position.h:48
A container for information about lines and positions in the input file.
Definition: position.h:69
uint32_t start
Definition: position.h:44