forked from OSchip/llvm-project
[flang] Impose a directory structure. Move files around. Introduce
an intermediate "parser" namespace. Original-commit: flang-compiler/f18@690b6f0d1e Reviewed-on: https://github.com/flang-compiler/f18/pull/4 Tree-same-pre-rewrite: false
This commit is contained in:
parent
6e22a3563e
commit
0ba1a14be2
|
@ -1,7 +1,7 @@
|
||||||
Debug
|
Debug
|
||||||
Release
|
Release
|
||||||
tags
|
tags
|
||||||
f18
|
./f18
|
||||||
*.o
|
*.o
|
||||||
*~
|
*~
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
|
|
|
@ -9,14 +9,14 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH true)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++17")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++17")
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
char-buffer.cc
|
tools/f18/f18.cc
|
||||||
f2018-demo.cc
|
lib/parser/char-buffer.cc
|
||||||
idioms.cc
|
lib/parser/idioms.cc
|
||||||
message.cc
|
lib/parser/message.cc
|
||||||
parse-tree.cc
|
lib/parser/parse-tree.cc
|
||||||
position.cc
|
lib/parser/position.cc
|
||||||
preprocessor.cc
|
lib/parser/preprocessor.cc
|
||||||
prescan.cc
|
lib/parser/prescan.cc
|
||||||
source.cc
|
lib/parser/source.cc
|
||||||
)
|
)
|
||||||
add_executable(f18 ${SOURCES})
|
add_executable(f18 ${SOURCES})
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
// fail<A>("...") returns a parser that never succeeds. It reports an
|
// fail<A>("...") returns a parser that never succeeds. It reports an
|
||||||
// error message at the current position. The result type is unused,
|
// error message at the current position. The result type is unused,
|
||||||
|
@ -1316,5 +1317,6 @@ constexpr struct GetPosition {
|
||||||
}
|
}
|
||||||
} getPosition;
|
} getPosition;
|
||||||
|
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_BASIC_PARSERS_H_
|
#endif // FORTRAN_BASIC_PARSERS_H_
|
|
@ -4,6 +4,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
char *CharBuffer::FreeSpace(size_t *n) {
|
char *CharBuffer::FreeSpace(size_t *n) {
|
||||||
int offset{LastBlockOffset()};
|
int offset{LastBlockOffset()};
|
||||||
|
@ -45,4 +46,5 @@ void CharBuffer::CopyToContiguous(char *data) {
|
||||||
}
|
}
|
||||||
CHECK(to == data + bytes_);
|
CHECK(to == data + bytes_);
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
|
@ -10,6 +10,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
class CharBuffer {
|
class CharBuffer {
|
||||||
public:
|
public:
|
||||||
|
@ -113,5 +114,6 @@ private:
|
||||||
size_t bytes_{0};
|
size_t bytes_{0};
|
||||||
bool lastBlockEmpty_{false};
|
bool lastBlockEmpty_{false};
|
||||||
};
|
};
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_CHAR_BUFFER_H_
|
#endif // FORTRAN_CHAR_BUFFER_H_
|
|
@ -9,6 +9,7 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
template<char goal> struct ExactRaw {
|
template<char goal> struct ExactRaw {
|
||||||
using resultType = char;
|
using resultType = char;
|
||||||
|
@ -107,5 +108,6 @@ private:
|
||||||
constexpr RawStringMatch operator""_raw(const char str[], size_t n) {
|
constexpr RawStringMatch operator""_raw(const char str[], size_t n) {
|
||||||
return RawStringMatch{str, n};
|
return RawStringMatch{str, n};
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_CHAR_PARSERS_H_
|
#endif // FORTRAN_CHAR_PARSERS_H_
|
|
@ -18,6 +18,7 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
constexpr struct FixedFormPadding {
|
constexpr struct FixedFormPadding {
|
||||||
using resultType = char;
|
using resultType = char;
|
||||||
|
@ -210,5 +211,6 @@ static inline bool ConsumedAllInput(const ParseState &state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr StatePredicateGuardParser consumedAllInput{ConsumedAllInput};
|
constexpr StatePredicateGuardParser consumedAllInput{ConsumedAllInput};
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_COOKED_CHARS_H_
|
#endif // FORTRAN_COOKED_CHARS_H_
|
|
@ -18,6 +18,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
class CharPredicateGuardParser {
|
class CharPredicateGuardParser {
|
||||||
public:
|
public:
|
||||||
|
@ -430,5 +431,6 @@ template<typename PA> inline constexpr auto optionalBeforeColons(const PA &p) {
|
||||||
return "," >> p / "::" || "::" >> construct<typename PA::resultType>{} ||
|
return "," >> p / "::" || "::" >> construct<typename PA::resultType>{} ||
|
||||||
!","_tok >> construct<typename PA::resultType>{};
|
!","_tok >> construct<typename PA::resultType>{};
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_COOKED_TOKENS_H_
|
#endif // FORTRAN_COOKED_TOKENS_H_
|
|
@ -12,6 +12,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
class DebugParser {
|
class DebugParser {
|
||||||
public:
|
public:
|
||||||
|
@ -34,5 +35,6 @@ private:
|
||||||
constexpr DebugParser operator""_debug(const char str[], size_t n) {
|
constexpr DebugParser operator""_debug(const char str[], size_t n) {
|
||||||
return DebugParser{str, n};
|
return DebugParser{str, n};
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_DEBUG_PARSER_H_
|
#endif // FORTRAN_DEBUG_PARSER_H_
|
|
@ -24,6 +24,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
// The productions that follow are derived from the draft Fortran 2018
|
// The productions that follow are derived from the draft Fortran 2018
|
||||||
// standard, with some necessary modifications to remove left recursion
|
// standard, with some necessary modifications to remove left recursion
|
||||||
|
@ -3643,5 +3644,6 @@ TYPE_CONTEXT_PARSER("PAUSE statement",
|
||||||
// is used only via scalar-int-variable
|
// is used only via scalar-int-variable
|
||||||
// R1030 default-char-constant-expr -> default-char-expr
|
// R1030 default-char-constant-expr -> default-char-expr
|
||||||
// is only used via scalar-default-char-constant-expr
|
// is only used via scalar-default-char-constant-expr
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_GRAMMAR_H_
|
#endif // FORTRAN_GRAMMAR_H_
|
|
@ -4,6 +4,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
[[noreturn]] void die(const char *msg, ...) {
|
[[noreturn]] void die(const char *msg, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
@ -18,4 +19,5 @@ namespace Fortran {
|
||||||
std::ostream &operator<<(std::ostream &o, const std::monostate &) {
|
std::ostream &operator<<(std::ostream &o, const std::monostate &) {
|
||||||
return o << "(empty variant)";
|
return o << "(empty variant)";
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
|
@ -34,6 +34,7 @@ struct is_trivially_copy_constructible<optional<list<A>>> : false_type {};
|
||||||
using namespace std::string_literals; // enable "this is a std::string"s
|
using namespace std::string_literals; // enable "this is a std::string"s
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
// Helper templates for combining a list of lambdas into an anonymous
|
// Helper templates for combining a list of lambdas into an anonymous
|
||||||
// struct for use with std::visit() on a std::variant<> sum type.
|
// struct for use with std::visit() on a std::variant<> sum type.
|
||||||
|
@ -57,6 +58,7 @@ template<typename... LAMBDAS> visitors(LAMBDAS... x)->visitors<LAMBDAS...>;
|
||||||
template<typename A> bool operator!(const std::optional<A> &x) {
|
template<typename A> bool operator!(const std::optional<A> &x) {
|
||||||
return !x.has_value();
|
return !x.has_value();
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
|
|
||||||
// For switch statements without default: labels.
|
// For switch statements without default: labels.
|
||||||
|
@ -73,6 +75,7 @@ template<typename A> struct BadType : std::false_type {};
|
||||||
|
|
||||||
// Formatting
|
// Formatting
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
template<typename A>
|
template<typename A>
|
||||||
std::ostream &operator<<(std::ostream &o, const std::optional<A> &x) {
|
std::ostream &operator<<(std::ostream &o, const std::optional<A> &x) {
|
||||||
if (x.has_value()) {
|
if (x.has_value()) {
|
||||||
|
@ -116,5 +119,6 @@ std::ostream &operator<<(std::ostream &o, const std::variant<As...> &x) {
|
||||||
return std::visit(
|
return std::visit(
|
||||||
[&o](const auto &y) -> std::ostream & { return o << y; }, x);
|
[&o](const auto &y) -> std::ostream & { return o << y; }, x);
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_IDIOMS_H_
|
#endif // FORTRAN_IDIOMS_H_
|
|
@ -11,6 +11,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
template<typename A> class Indirection {
|
template<typename A> class Indirection {
|
||||||
public:
|
public:
|
||||||
|
@ -54,5 +55,6 @@ template<typename A>
|
||||||
std::ostream &operator<<(std::ostream &o, const Indirection<A> &x) {
|
std::ostream &operator<<(std::ostream &o, const Indirection<A> &x) {
|
||||||
return o << *x;
|
return o << *x;
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_INDIRECTION_H_
|
#endif // FORTRAN_INDIRECTION_H_
|
|
@ -1,6 +1,7 @@
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &o, const Message &msg) {
|
std::ostream &operator<<(std::ostream &o, const Message &msg) {
|
||||||
if (msg.context()) {
|
if (msg.context()) {
|
||||||
|
@ -21,4 +22,5 @@ std::ostream &operator<<(std::ostream &o, const Messages &ms) {
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
|
@ -13,6 +13,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
class Message;
|
class Message;
|
||||||
using MessageContext = std::shared_ptr<Message>;
|
using MessageContext = std::shared_ptr<Message>;
|
||||||
|
@ -103,5 +104,6 @@ private:
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &, const Message &);
|
std::ostream &operator<<(std::ostream &, const Message &);
|
||||||
std::ostream &operator<<(std::ostream &, const Messages &);
|
std::ostream &operator<<(std::ostream &, const Messages &);
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_MESSAGE_H_
|
#endif // FORTRAN_MESSAGE_H_
|
|
@ -17,6 +17,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
class UserState;
|
class UserState;
|
||||||
|
|
||||||
|
@ -228,5 +229,6 @@ private:
|
||||||
// reflected in the copy and move constructors defined at the top of this
|
// reflected in the copy and move constructors defined at the top of this
|
||||||
// class definition!
|
// class definition!
|
||||||
};
|
};
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_PARSE_STATE_H_
|
#endif // FORTRAN_PARSE_STATE_H_
|
|
@ -4,6 +4,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
#define UNION_FORMATTER(TYPE) \
|
#define UNION_FORMATTER(TYPE) \
|
||||||
std::ostream &operator<<(std::ostream &o, const TYPE &x) { \
|
std::ostream &operator<<(std::ostream &o, const TYPE &x) { \
|
||||||
|
@ -1085,4 +1086,5 @@ std::ostream &operator<<(std::ostream &o, const ProcedureStmt &x) {
|
||||||
std::ostream &operator<<(std::ostream &o, const Suffix &x) {
|
std::ostream &operator<<(std::ostream &o, const Suffix &x) {
|
||||||
return o << "(Suffix " << x.binding << ' ' << x.resultName << ')';
|
return o << "(Suffix " << x.binding << ' ' << x.resultName << ')';
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
|
@ -83,6 +83,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
// These are the unavoidable recursively-defined productions of Fortran.
|
// These are the unavoidable recursively-defined productions of Fortran.
|
||||||
// Some references to the representations of their parses require
|
// Some references to the representations of their parses require
|
||||||
|
@ -3222,5 +3223,6 @@ std::ostream &operator<<(std::ostream &o, const LoopBounds<A> &x) {
|
||||||
return o << "(LoopBounds " << x.name << ' ' << x.lower << ' ' << x.upper
|
return o << "(LoopBounds " << x.name << ' ' << x.lower << ' ' << x.upper
|
||||||
<< ' ' << x.step << ')';
|
<< ' ' << x.step << ')';
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_PARSE_TREE_H_
|
#endif // FORTRAN_PARSE_TREE_H_
|
|
@ -1,7 +1,9 @@
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
std::ostream &operator<<(std::ostream &o, const Position &x) {
|
std::ostream &operator<<(std::ostream &o, const Position &x) {
|
||||||
return o << "(at line " << x.lineNumber() << ", column " << x.column() << ')';
|
return o << "(at line " << x.lineNumber() << ", column " << x.column() << ')';
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
|
@ -8,6 +8,7 @@
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
class Position {
|
class Position {
|
||||||
public:
|
public:
|
||||||
|
@ -70,5 +71,6 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &, const Position &);
|
std::ostream &operator<<(std::ostream &, const Position &);
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_POSITION_H_
|
#endif // FORTRAN_POSITION_H_
|
|
@ -13,6 +13,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
bool CharPointerWithLength::IsBlank() const {
|
bool CharPointerWithLength::IsBlank() const {
|
||||||
for (size_t j{0}; j < bytes_; ++j) {
|
for (size_t j{0}; j < bytes_; ++j) {
|
||||||
|
@ -937,4 +938,5 @@ bool Preprocessor::IsIfPredicateTrue(
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
|
@ -19,6 +19,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
class CharBuffer;
|
class CharBuffer;
|
||||||
class Prescanner;
|
class Prescanner;
|
||||||
|
@ -50,11 +51,12 @@ private:
|
||||||
const char *data_{nullptr};
|
const char *data_{nullptr};
|
||||||
size_t bytes_{0};
|
size_t bytes_{0};
|
||||||
};
|
};
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
|
|
||||||
// Specializations to enable std::unordered_map<CharPointerWithLength, ...>
|
// Specializations to enable std::unordered_map<CharPointerWithLength, ...>
|
||||||
template<> struct std::hash<Fortran::CharPointerWithLength> {
|
template<> struct std::hash<Fortran::parser::CharPointerWithLength> {
|
||||||
size_t operator()(const Fortran::CharPointerWithLength &x) const {
|
size_t operator()(const Fortran::parser::CharPointerWithLength &x) const {
|
||||||
size_t hash{0}, bytes{x.size()};
|
size_t hash{0}, bytes{x.size()};
|
||||||
for (size_t j{0}; j < bytes; ++j) {
|
for (size_t j{0}; j < bytes; ++j) {
|
||||||
hash = (hash * 31) ^ x[j];
|
hash = (hash * 31) ^ x[j];
|
||||||
|
@ -63,9 +65,9 @@ template<> struct std::hash<Fortran::CharPointerWithLength> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct std::equal_to<Fortran::CharPointerWithLength> {
|
template<> struct std::equal_to<Fortran::parser::CharPointerWithLength> {
|
||||||
bool operator()(const Fortran::CharPointerWithLength &x,
|
bool operator()(const Fortran::parser::CharPointerWithLength &x,
|
||||||
const Fortran::CharPointerWithLength &y) const {
|
const Fortran::parser::CharPointerWithLength &y) const {
|
||||||
return x.size() == y.size() &&
|
return x.size() == y.size() &&
|
||||||
std::memcmp(static_cast<const void *>(&x[0]),
|
std::memcmp(static_cast<const void *>(&x[0]),
|
||||||
static_cast<const void *>(&y[0]), x.size()) == 0;
|
static_cast<const void *>(&y[0]), x.size()) == 0;
|
||||||
|
@ -73,6 +75,7 @@ template<> struct std::equal_to<Fortran::CharPointerWithLength> {
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
// Buffers a contiguous sequence of characters that has been partitioned into
|
// Buffers a contiguous sequence of characters that has been partitioned into
|
||||||
// a sequence of preprocessing tokens.
|
// a sequence of preprocessing tokens.
|
||||||
|
@ -199,5 +202,6 @@ private:
|
||||||
std::unordered_map<CharPointerWithLength, Definition> definitions_;
|
std::unordered_map<CharPointerWithLength, Definition> definitions_;
|
||||||
std::stack<CanDeadElseAppear> ifStack_;
|
std::stack<CanDeadElseAppear> ifStack_;
|
||||||
};
|
};
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_PREPROCESSOR_H_
|
#endif // FORTRAN_PREPROCESSOR_H_
|
|
@ -8,6 +8,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
CharBuffer Prescanner::Prescan(const SourceFile &source) {
|
CharBuffer Prescanner::Prescan(const SourceFile &source) {
|
||||||
sourceFile_ = &source;
|
sourceFile_ = &source;
|
||||||
|
@ -490,4 +491,5 @@ void Prescanner::PayNewlineDebt(CharBuffer *out) {
|
||||||
out->Put('\n');
|
out->Put('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
|
@ -20,6 +20,7 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
class Prescanner {
|
class Prescanner {
|
||||||
public:
|
public:
|
||||||
|
@ -109,5 +110,6 @@ private:
|
||||||
int delimiterNesting_{0};
|
int delimiterNesting_{0};
|
||||||
Preprocessor preprocessor_;
|
Preprocessor preprocessor_;
|
||||||
};
|
};
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_PRESCAN_H_
|
#endif // FORTRAN_PRESCAN_H_
|
|
@ -14,6 +14,7 @@
|
||||||
// TODO: Port to Windows &c.
|
// TODO: Port to Windows &c.
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
SourceFile::~SourceFile() { Close(); }
|
SourceFile::~SourceFile() { Close(); }
|
||||||
|
|
||||||
|
@ -122,4 +123,5 @@ void SourceFile::Close() {
|
||||||
}
|
}
|
||||||
path_.clear();
|
path_.clear();
|
||||||
}
|
}
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
|
@ -9,6 +9,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
|
|
||||||
class SourceFile {
|
class SourceFile {
|
||||||
public:
|
public:
|
||||||
|
@ -27,5 +28,6 @@ private:
|
||||||
const char *content_{nullptr};
|
const char *content_{nullptr};
|
||||||
size_t bytes_{0};
|
size_t bytes_{0};
|
||||||
};
|
};
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_SOURCE_H_
|
#endif // FORTRAN_SOURCE_H_
|
|
@ -10,6 +10,7 @@
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
class UserState {
|
class UserState {
|
||||||
public:
|
public:
|
||||||
using Label = std::uint64_t;
|
using Label = std::uint64_t;
|
||||||
|
@ -35,5 +36,6 @@ private:
|
||||||
std::unordered_set<Label> doLabels_;
|
std::unordered_set<Label> doLabels_;
|
||||||
int nonlabelDoConstructNestingDepth_{0};
|
int nonlabelDoConstructNestingDepth_{0};
|
||||||
};
|
};
|
||||||
}; // namespace Fortran
|
} // namespace parser
|
||||||
|
} // namespace Fortran
|
||||||
#endif // FORTRAN_USER_STATE_H_
|
#endif // FORTRAN_USER_STATE_H_
|
|
@ -1,15 +1,15 @@
|
||||||
// Temporary Fortran front end driver main program for development scaffolding.
|
// Temporary Fortran front end driver main program for development scaffolding.
|
||||||
|
|
||||||
#include "basic-parsers.h"
|
#include "../../lib/parser/basic-parsers.h"
|
||||||
#include "char-buffer.h"
|
#include "../../lib/parser/char-buffer.h"
|
||||||
#include "cooked-chars.h"
|
#include "../../lib/parser/cooked-chars.h"
|
||||||
#include "grammar.h"
|
#include "../../lib/parser/grammar.h"
|
||||||
#include "idioms.h"
|
#include "../../lib/parser/idioms.h"
|
||||||
#include "message.h"
|
#include "../../lib/parser/message.h"
|
||||||
#include "parse-tree.h"
|
#include "../../lib/parser/parse-tree.h"
|
||||||
#include "prescan.h"
|
#include "../../lib/parser/prescan.h"
|
||||||
#include "source.h"
|
#include "../../lib/parser/source.h"
|
||||||
#include "user-state.h"
|
#include "../../lib/parser/user-state.h"
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -36,9 +36,11 @@ std::list<std::string> argList(int argc, char *const argv[]) {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace Fortran {
|
namespace Fortran {
|
||||||
|
namespace parser {
|
||||||
constexpr auto grammar = program;
|
constexpr auto grammar = program;
|
||||||
|
} // namespace parser
|
||||||
} // namespace Fortran
|
} // namespace Fortran
|
||||||
using Fortran::grammar;
|
using Fortran::parser::grammar;
|
||||||
|
|
||||||
int main(int argc, char *const argv[]) {
|
int main(int argc, char *const argv[]) {
|
||||||
|
|
||||||
|
@ -97,7 +99,7 @@ int main(int argc, char *const argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Fortran::SourceFile source;
|
Fortran::parser::SourceFile source;
|
||||||
std::stringstream error;
|
std::stringstream error;
|
||||||
if (!source.Open(path, &error)) {
|
if (!source.Open(path, &error)) {
|
||||||
std::cerr << error.str() << '\n';
|
std::cerr << error.str() << '\n';
|
||||||
|
@ -108,9 +110,9 @@ int main(int argc, char *const argv[]) {
|
||||||
size_t sourceBytes{source.bytes()};
|
size_t sourceBytes{source.bytes()};
|
||||||
std::unique_ptr<char[]> prescanned;
|
std::unique_ptr<char[]> prescanned;
|
||||||
if (prescan) {
|
if (prescan) {
|
||||||
Fortran::Messages messages;
|
Fortran::parser::Messages messages;
|
||||||
Fortran::Prescanner prescanner{messages};
|
Fortran::parser::Prescanner prescanner{messages};
|
||||||
Fortran::CharBuffer buffer{
|
Fortran::parser::CharBuffer buffer{
|
||||||
prescanner.set_fixedForm(fixedForm)
|
prescanner.set_fixedForm(fixedForm)
|
||||||
.set_enableBackslashEscapesInCharLiterals(backslashEscapes)
|
.set_enableBackslashEscapesInCharLiterals(backslashEscapes)
|
||||||
.set_fixedFormColumnLimit(columns)
|
.set_fixedFormColumnLimit(columns)
|
||||||
|
@ -128,7 +130,7 @@ int main(int argc, char *const argv[]) {
|
||||||
columns = std::numeric_limits<int>::max();
|
columns = std::numeric_limits<int>::max();
|
||||||
}
|
}
|
||||||
|
|
||||||
Fortran::ParseState state{sourceContent, sourceBytes};
|
Fortran::parser::ParseState state{sourceContent, sourceBytes};
|
||||||
state.set_prescanned(prescan);
|
state.set_prescanned(prescan);
|
||||||
state.set_inFixedForm(fixedForm);
|
state.set_inFixedForm(fixedForm);
|
||||||
state.set_enableBackslashEscapesInCharLiterals(backslashEscapes);
|
state.set_enableBackslashEscapesInCharLiterals(backslashEscapes);
|
||||||
|
@ -136,11 +138,12 @@ int main(int argc, char *const argv[]) {
|
||||||
state.set_columns(columns);
|
state.set_columns(columns);
|
||||||
state.set_enableOldDebugLines(enableOldDebugLines);
|
state.set_enableOldDebugLines(enableOldDebugLines);
|
||||||
state.PushContext("source file '"s + path + "'");
|
state.PushContext("source file '"s + path + "'");
|
||||||
Fortran::UserState ustate;
|
Fortran::parser::UserState ustate;
|
||||||
state.set_userState(&ustate);
|
state.set_userState(&ustate);
|
||||||
|
|
||||||
if (dumpCookedChars) {
|
if (dumpCookedChars) {
|
||||||
while (std::optional<char> och{Fortran::cookedNextChar.Parse(&state)}) {
|
while (std::optional<char>
|
||||||
|
och{Fortran::parser::cookedNextChar.Parse(&state)}) {
|
||||||
std::cout << *och;
|
std::cout << *och;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -149,7 +152,7 @@ int main(int argc, char *const argv[]) {
|
||||||
std::optional<typename decltype(grammar)::resultType> result;
|
std::optional<typename decltype(grammar)::resultType> result;
|
||||||
#if 0
|
#if 0
|
||||||
for (int j = 0; j < 1000; ++j) {
|
for (int j = 0; j < 1000; ++j) {
|
||||||
Fortran::ParseState state1{state};
|
Fortran::parser::ParseState state1{state};
|
||||||
result = grammar.Parse(&state1);
|
result = grammar.Parse(&state1);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
std::cerr << "demo FAIL in timing loop\n";
|
std::cerr << "demo FAIL in timing loop\n";
|
Loading…
Reference in New Issue