souffle  2.0.2-371-g6315b36
Data Structures | Public Member Functions | Data Fields | Friends
souffle::SrcLocation Class Reference

A class describing a range in an input file. More...

#include <SrcLocation.h>

Collaboration diagram for souffle::SrcLocation:
Collaboration graph

Data Structures

struct  Point
 A class locating a single point in an input file. More...
 

Public Member Functions

std::string extloc () const
 An extended string describing this location in a end-user friendly way. More...
 
bool operator< (const SrcLocation &other) const
 A comparison for source locations. More...
 
void print (std::ostream &out) const
 
void setFilename (std::string filename)
 

Data Fields

Point end = {}
 The End location. More...
 
std::vector< std::string > filenames
 The file referred to. More...
 
Point start = {}
 The start location. More...
 

Friends

std::ostream & operator<< (std::ostream &out, const SrcLocation &range)
 Enables ranges to be printed. More...
 

Detailed Description

A class describing a range in an input file.

Definition at line 32 of file SrcLocation.h.

Member Function Documentation

◆ extloc()

std::string souffle::SrcLocation::extloc ( ) const

An extended string describing this location in a end-user friendly way.

Definition at line 93 of file SrcLocation.cpp.

93  {
94  in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
95  }
96  int c;
97  int lineLen = 0;
98  int offsetColumn = start.column;
99  bool prevWhitespace = false;
100  bool afterFirstNonSpace = false;
101  while ((c = in.get()) != '\n' && c != EOF) {
102  s << (char)c;
103  lineLen++;
104 
105  // Offset column to account for C preprocessor having reduced
106  // consecutive non-leading whitespace chars to a single space.
107  if (std::isspace(c) != 0) {
108  if (afterFirstNonSpace && prevWhitespace && offsetColumn >= lineLen) {
109  offsetColumn++;
110  }
111  prevWhitespace = true;
112  } else {
113  prevWhitespace = false;
114  afterFirstNonSpace = true;
115  }
116  }
117  lineLen++; // Add new line
118  in.close();
119  s << "\n";
120  for (int i = 1; i <= lineLen; i++) {
121  char ch = (i == offsetColumn) ? '^' : '-';
122  s << ch;
123  }
124  in.close();
125  } else {
126  s << filename << ":" << start.line << ":" << start.column;
127  }
128  return s.str();
129 }
130 
131 void SrcLocation::print(std::ostream& out) const {
132  out << getCurrentFilename(filenames) << " [" << start << "-" << end << "]";
133 }
134 } // end of namespace souffle

◆ operator<()

bool souffle::SrcLocation::operator< ( const SrcLocation other) const

A comparison for source locations.

Definition at line 54 of file SrcLocation.cpp.

57  {
58  return false;
59  }
60  if (start < other.start) {
61  return true;
62  }
63  if (start > other.start) {
64  return false;
65  }
66  if (end < other.end) {
67  return true;
68  }
69  return false;
70 }
71 
72 void SrcLocation::setFilename(std::string filename) {
73  if (filenames.empty()) {
74  filenames.emplace_back(filename);
75  return;
76  }

◆ print()

void souffle::SrcLocation::print ( std::ostream &  out) const

Definition at line 137 of file SrcLocation.cpp.

◆ setFilename()

void souffle::SrcLocation::setFilename ( std::string  filename)

Definition at line 78 of file SrcLocation.cpp.

80  {
81  filenames.pop_back();
82  return;
83  }
84  filenames.emplace_back(filename);
85 }
86 
87 std::string SrcLocation::extloc() const {
88  std::string filename = getCurrentFilename(filenames);
89  std::ifstream in(filename);
90  std::stringstream s;
91  if (in.is_open()) {

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const SrcLocation range 
)
friend

Enables ranges to be printed.

Definition at line 88 of file SrcLocation.h.

Field Documentation

◆ end

Point souffle::SrcLocation::end = {}

The End location.

Definition at line 75 of file SrcLocation.h.

◆ filenames

std::vector<std::string> souffle::SrcLocation::filenames

The file referred to.

Definition at line 69 of file SrcLocation.h.

◆ start

Point souffle::SrcLocation::start = {}

The start location.

Definition at line 72 of file SrcLocation.h.


The documentation for this class was generated from the following files:
souffle::SrcLocation::start
Point start
The start location.
Definition: SrcLocation.h:72
souffle::SrcLocation::end
Point end
The End location.
Definition: SrcLocation.h:75
souffle::SrcLocation::Point::column
int column
The column in the source file.
Definition: SrcLocation.h:52
souffle::SrcLocation::filenames
std::vector< std::string > filenames
The file referred to.
Definition: SrcLocation.h:69
i
size_t i
Definition: json11.h:663
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::line
int line
The line in the source file.
Definition: SrcLocation.h:49
souffle::getCurrentFilename
std::string getCurrentFilename(const std::vector< std::string > &filenames)
Definition: SrcLocation.cpp:33
souffle::SrcLocation::extloc
std::string extloc() const
An extended string describing this location in a end-user friendly way.
Definition: SrcLocation.cpp:93