llvm/flang/lib/parser/source.h
peter klausler 424ec7b35b [flang] Handle empty files gracefully.
Create interval.h.  Use std::size_t instead of bare size_t.  Redefine parser::Name to not be just a bare string.

Break out and rename CharBlock from token-sequence.h for use in the parse tree.

Incremental replacement of name strings with pointers to cooked characters.

Fix case sensitivity problem.

Use new CharBlock encoding to replace strings for real literal constants.

Normalized cooked character stream to lower case.

Simplify parsing now that cooked stream is lower case.  Replace Keyword in parse tree.

Add static_asserts to || and recovery parsers to enforce same result types.

Remove needless TODO comment inserted earlier.

Fix case conversion on prefixed character literals (f90_correct/dc04.f90).

Use CharBlock in user-state.h.

Complete transition from nextChar to nextCh (i.e., always use pointers).

Document extensions.  Begin work on compiler directive lines.

More documentation work.

Reformat prescan.cc.

More work on compiler directive scanning.

Original-commit: flang-compiler/f18@38d0404e16
Reviewed-on: https://github.com/flang-compiler/f18/pull/29
Tree-same-pre-rewrite: false
2018-03-23 13:32:55 -07:00

47 lines
1.3 KiB
C++

#ifndef FORTRAN_PARSER_SOURCE_H_
#define FORTRAN_PARSER_SOURCE_H_
// 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 <cstddef>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
namespace Fortran {
namespace parser {
std::string DirectoryName(std::string path);
std::string LocateSourceFile(
std::string name, const std::vector<std::string> &searchPath);
class SourceFile {
public:
SourceFile() {}
~SourceFile();
std::string path() const { return path_; }
const char *content() const { return content_; }
std::size_t bytes() const { return bytes_; }
std::size_t lines() const { return lineStart_.size(); }
bool Open(std::string path, std::stringstream *error);
void Close();
std::pair<int, int> FindOffsetLineAndColumn(std::size_t) const;
std::size_t GetLineStartOffset(int lineNumber) const {
return lineStart_.at(lineNumber - 1);
}
private:
std::string path_;
int fileDescriptor_{-1};
bool isMemoryMapped_{false};
const char *content_{nullptr};
std::size_t bytes_{0};
std::vector<std::size_t> lineStart_;
};
} // namespace parser
} // namespace Fortran
#endif // FORTRAN_PARSER_SOURCE_H_