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 { OptionsOptions27 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<std::string> intrinsicModuleDirectories; 36 std::vector<Predefinition> predefinitions; 37 bool instrumentedParse{false}; 38 bool isModuleFile{false}; 39 bool needProvenanceRangeToCharBlockMappings{false}; 40 Fortran::parser::Encoding encoding{Fortran::parser::Encoding::UTF_8}; 41 bool prescanAndReformat{false}; // -E 42 }; 43 44 class Parsing { 45 public: 46 explicit Parsing(AllCookedSources &); 47 ~Parsing(); 48 consumedWholeFile()49 bool consumedWholeFile() const { return consumedWholeFile_; } finalRestingPlace()50 const char *finalRestingPlace() const { return finalRestingPlace_; } allCooked()51 AllCookedSources &allCooked() { return allCooked_; } allCooked()52 const AllCookedSources &allCooked() const { return allCooked_; } messages()53 Messages &messages() { return messages_; } parseTree()54 std::optional<Program> &parseTree() { return parseTree_; } 55 cooked()56 const CookedSource &cooked() const { return DEREF(currentCooked_); } 57 58 const SourceFile *Prescan(const std::string &path, Options); 59 void EmitPreprocessedSource( 60 llvm::raw_ostream &, bool lineDirectives = true) const; 61 void DumpCookedChars(llvm::raw_ostream &) const; 62 void DumpProvenance(llvm::raw_ostream &) const; 63 void DumpParsingLog(llvm::raw_ostream &) const; 64 void Parse(llvm::raw_ostream &debugOutput); 65 void ClearLog(); 66 67 void EmitMessage(llvm::raw_ostream &o, const char *at, 68 const std::string &message, bool echoSourceLine = false) const { 69 allCooked_.allSources().EmitMessage(o, 70 allCooked_.GetProvenanceRange(CharBlock(at)), message, echoSourceLine); 71 } 72 73 private: 74 Options options_; 75 AllCookedSources &allCooked_; 76 CookedSource *currentCooked_{nullptr}; 77 Messages messages_; 78 bool consumedWholeFile_{false}; 79 const char *finalRestingPlace_{nullptr}; 80 std::optional<Program> parseTree_; 81 ParsingLog log_; 82 }; 83 } // namespace Fortran::parser 84 #endif // FORTRAN_PARSER_PARSING_H_ 85