FLANG

parsing.h
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 };
40
41 class Parsing {
42 public:
43 explicit Parsing(AllSources &);
44 ~Parsing();
45
46 bool consumedWholeFile() const { return consumedWholeFile_; }
47 const char *finalRestingPlace() const { return finalRestingPlace_; }
48 CookedSource &cooked() { return cooked_; }
49 Messages &messages() { return messages_; }
50 std::optional<Program> &parseTree() { return parseTree_; }
51
52 const SourceFile *Prescan(const std::string &path, Options);
53 void DumpCookedChars(llvm::raw_ostream &) const;
54 void DumpProvenance(llvm::raw_ostream &) const;
55 void DumpParsingLog(llvm::raw_ostream &) const;
56 void Parse(llvm::raw_ostream &debugOutput);
57 void ClearLog();
58
59 void EmitMessage(llvm::raw_ostream &o, const char *at,
60 const std::string &message, bool echoSourceLine = false) const {
61 cooked_.allSources().EmitMessage(
62 o, cooked_.GetProvenanceRange(CharBlock(at)), message, echoSourceLine);
63 }
64
65 bool ForTesting(std::string path, llvm::raw_ostream &);
66
67 private:
68 Options options_;
69 CookedSource cooked_;
70 Messages messages_;
71 bool consumedWholeFile_{false};
72 const char *finalRestingPlace_{nullptr};
73 std::optional<Program> parseTree_;
74 ParsingLog log_;
75 };
76 } // namespace Fortran::parser
77 #endif // FORTRAN_PARSER_PARSING_H_
Fortran::parser::SourceFile
Definition: source.h:41
Fortran::parser::AllSources
Definition: provenance.h:137
Fortran::parser::Parsing
Definition: parsing.h:41
Fortran::parser::CookedSource
Definition: provenance.h:216
Fortran::common::LanguageFeatureControl
Definition: Fortran-features.h:35
Fortran::parser::Messages
Definition: message.h:213
Fortran::parser::Options
Definition: parsing.h:26
Fortran::parser::CharBlock
Definition: char-block.h:28
Fortran::parser::ParsingLog
Definition: instrumented-parser.h:25
Fortran::parser
Definition: check-expression.h:19