2018-02-16 20:42:17 +01:00
|
|
|
#ifndef FORTRAN_PARSER_SOURCE_H_
|
|
|
|
#define FORTRAN_PARSER_SOURCE_H_
|
2018-01-30 20:55:03 +01:00
|
|
|
|
|
|
|
// Source file content is lightly normalized when the file is read.
|
|
|
|
// - Line ending markers are converted to single newline characters
|
|
|
|
// - A newline character is added to the last line of the file if one is needed
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2018-02-09 23:04:11 +01:00
|
|
|
#include <utility>
|
2018-02-07 22:18:36 +01:00
|
|
|
#include <vector>
|
2018-01-30 20:55:03 +01:00
|
|
|
|
|
|
|
namespace Fortran {
|
2018-02-07 21:04:42 +01:00
|
|
|
namespace parser {
|
2018-01-30 20:55:03 +01:00
|
|
|
|
2018-02-14 00:24:43 +01:00
|
|
|
std::string DirectoryName(std::string path);
|
|
|
|
std::string LocateSourceFile(
|
|
|
|
std::string name, const std::vector<std::string> &searchPath);
|
|
|
|
|
2018-01-30 20:55:03 +01:00
|
|
|
class SourceFile {
|
2018-02-05 21:54:36 +01:00
|
|
|
public:
|
2018-01-30 20:55:03 +01:00
|
|
|
SourceFile() {}
|
|
|
|
~SourceFile();
|
2018-02-02 00:01:23 +01:00
|
|
|
std::string path() const { return path_; }
|
2018-01-30 20:55:03 +01:00
|
|
|
const char *content() const { return content_; }
|
|
|
|
size_t bytes() const { return bytes_; }
|
2018-02-07 22:18:36 +01:00
|
|
|
size_t lines() const { return lineStart_.size(); }
|
2018-02-14 00:24:43 +01:00
|
|
|
|
|
|
|
bool Open(std::string path, std::stringstream *error);
|
|
|
|
void Close();
|
2018-02-09 23:04:11 +01:00
|
|
|
std::pair<int, int> FindOffsetLineAndColumn(size_t) const;
|
2018-02-15 22:13:28 +01:00
|
|
|
size_t GetLineStartOffset(int lineNumber) const {
|
|
|
|
return lineStart_.at(lineNumber - 1);
|
|
|
|
}
|
2018-02-05 23:29:26 +01:00
|
|
|
|
2018-02-05 21:54:36 +01:00
|
|
|
private:
|
2018-01-30 20:55:03 +01:00
|
|
|
std::string path_;
|
|
|
|
int fileDescriptor_{-1};
|
|
|
|
bool isMemoryMapped_{false};
|
|
|
|
const char *content_{nullptr};
|
|
|
|
size_t bytes_{0};
|
2018-02-07 22:18:36 +01:00
|
|
|
std::vector<size_t> lineStart_;
|
2018-01-30 20:55:03 +01:00
|
|
|
};
|
2018-02-07 21:04:42 +01:00
|
|
|
} // namespace parser
|
2018-01-30 20:55:03 +01:00
|
|
|
} // namespace Fortran
|
2018-02-16 20:42:17 +01:00
|
|
|
#endif // FORTRAN_PARSER_SOURCE_H_
|