1 //===-- include/flang/Parser/parsing.h --------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef FORTRAN_PARSER_PARSING_H_ 10 #define FORTRAN_PARSER_PARSING_H_ 11 12 #include "characters.h" 13 #include "instrumented-parser.h" 14 #include "message.h" 15 #include "parse-tree.h" 16 #include "provenance.h" 17 #include "flang/Common/Fortran-features.h" 18 #include "llvm/Support/raw_ostream.h" 19 #include <optional> 20 #include <string> 21 #include <utility> 22 #include <vector> 23 24 namespace Fortran::parser { 25 26 struct Options { 27 Options() {} 28 29 using Predefinition = std::pair<std::string, std::optional<std::string>>; 30 31 bool isFixedForm{false}; 32 int fixedFormColumns{72}; 33 common::LanguageFeatureControl features; 34 std::vector<std::string> searchDirectories; 35 std::vector<Predefinition> predefinitions; 36 bool instrumentedParse{false}; 37 bool isModuleFile{false}; 38 bool needProvenanceRangeToCharBlockMappings{false}; 39 Fortran::parser::Encoding encoding{Fortran::parser::Encoding::UTF_8}; 40 }; 41 42 class Parsing { 43 public: 44 explicit Parsing(AllCookedSources &); 45 ~Parsing(); 46 47 bool consumedWholeFile() const { return consumedWholeFile_; } 48 const char *finalRestingPlace() const { return finalRestingPlace_; } 49 AllCookedSources &allCooked() { return allCooked_; } 50 Messages &messages() { return messages_; } 51 std::optional<Program> &parseTree() { return parseTree_; } 52 53 const CookedSource &cooked() const { return DEREF(currentCooked_); } 54 55 const SourceFile *Prescan(const std::string &path, Options); 56 void DumpCookedChars(llvm::raw_ostream &) const; 57 void DumpProvenance(llvm::raw_ostream &) const; 58 void DumpParsingLog(llvm::raw_ostream &) const; 59 void Parse(llvm::raw_ostream &debugOutput); 60 void ClearLog(); 61 62 void EmitMessage(llvm::raw_ostream &o, const char *at, 63 const std::string &message, bool echoSourceLine = false) const { 64 allCooked_.allSources().EmitMessage(o, 65 allCooked_.GetProvenanceRange(CharBlock(at)), message, echoSourceLine); 66 } 67 68 private: 69 Options options_; 70 AllCookedSources &allCooked_; 71 CookedSource *currentCooked_{nullptr}; 72 Messages messages_; 73 bool consumedWholeFile_{false}; 74 const char *finalRestingPlace_{nullptr}; 75 std::optional<Program> parseTree_; 76 ParsingLog log_; 77 }; 78 } // namespace Fortran::parser 79 #endif // FORTRAN_PARSER_PARSING_H_ 80