souffle  2.0.2-371-g6315b36
SrcLocation.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file SrcLocation.h
12  *
13  * Structures to describe a location within input code.
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include <ostream>
20 #include <string>
21 #include <vector>
22 
23 namespace souffle {
24 
25 /** A class describing a range in an input file */
26 class SrcLocation {
27 public:
28  /** A class locating a single point in an input file */
29  struct Point {
30  /** The line in the source file */
31  int line;
32 
33  /** The column in the source file */
34  int column;
35 
36  /** A comparison for points */
37  bool operator<(const Point& other) const {
38  return line < other.line || (line == other.line && column < other.column);
39  }
40 
41  bool operator>(const Point& other) const {
42  return other < *this;
43  }
44 
45  void print(std::ostream& out) const {
46  out << line << ":" << column;
47  }
48 
49  /** Enables locations to be printed */
50  friend std::ostream& operator<<(std::ostream& out, const Point& loc) {
51  loc.print(out);
52  return out;
53  }
54  };
55 
56  /** The file referred to */
57  std::vector<std::string> filenames;
58 
59  /** The start location */
60  Point start = {};
61 
62  /** The End location */
63  Point end = {};
64 
65  /** A comparison for source locations */
66  bool operator<(const SrcLocation& other) const;
67 
68  void setFilename(std::string filename);
69 
70  /** An extended string describing this location in a end-user friendly way */
71  std::string extloc() const;
72 
73  void print(std::ostream& out) const;
74 
75  /** Enables ranges to be printed */
76  friend std::ostream& operator<<(std::ostream& out, const SrcLocation& range) {
77  range.print(out);
78  return out;
79  }
80 };
81 
82 } // end of namespace souffle
souffle::range
A utility class enabling representation of ranges by pairing two iterator instances marking lower and...
Definition: ContainerUtil.h:313
souffle::SrcLocation::start
Point start
The start location.
Definition: SrcLocation.h:72
souffle::SrcLocation::Point::operator<
bool operator<(const Point &other) const
A comparison for points.
Definition: SrcLocation.h:55
souffle::SrcLocation::Point::print
void print(std::ostream &out) const
Definition: SrcLocation.h:63
souffle::SrcLocation::operator<<
friend std::ostream & operator<<(std::ostream &out, const SrcLocation &range)
Enables ranges to be printed.
Definition: SrcLocation.h:88
souffle::SrcLocation::end
Point end
The End location.
Definition: SrcLocation.h:75
souffle::SrcLocation::operator<
bool operator<(const SrcLocation &other) const
A comparison for source locations.
Definition: SrcLocation.cpp:54
souffle::SrcLocation::Point::column
int column
The column in the source file.
Definition: SrcLocation.h:52
souffle::SrcLocation::Point::operator<<
friend std::ostream & operator<<(std::ostream &out, const Point &loc)
Enables locations to be printed.
Definition: SrcLocation.h:68
souffle::SrcLocation::Point::operator>
bool operator>(const Point &other) const
Definition: SrcLocation.h:59
souffle::SrcLocation::filenames
std::vector< std::string > filenames
The file referred to.
Definition: SrcLocation.h:69
souffle::SrcLocation::print
void print(std::ostream &out) const
Definition: SrcLocation.cpp:137
souffle::SrcLocation::setFilename
void setFilename(std::string filename)
Definition: SrcLocation.cpp:78
souffle::SrcLocation::Point
A class locating a single point in an input file.
Definition: SrcLocation.h:41
souffle::SrcLocation::Point::line
int line
The line in the source file.
Definition: SrcLocation.h:49
souffle::SrcLocation
A class describing a range in an input file.
Definition: SrcLocation.h:32
souffle
Definition: AggregateOp.h:25
souffle::SrcLocation::extloc
std::string extloc() const
An extended string describing this location in a end-user friendly way.
Definition: SrcLocation.cpp:93