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 "instrumented-parser.h"
13#include "message.h"
14#include "options.h"
15#include "parse-tree.h"
16#include "provenance.h"
17#include "flang/Parser/preprocessor.h"
18#include "flang/Support/LangOptions.h"
19#include "llvm/Support/raw_ostream.h"
20#include <optional>
21#include <string>
22
23namespace Fortran::parser {
24
25class Parsing {
26public:
27 explicit Parsing(AllCookedSources &);
28 ~Parsing();
29
30 bool consumedWholeFile() const { return consumedWholeFile_; }
31 const char *finalRestingPlace() const { return finalRestingPlace_; }
32 AllCookedSources &allCooked() { return allCooked_; }
33 const AllCookedSources &allCooked() const { return allCooked_; }
34 Messages &messages() { return messages_; }
35 std::optional<Program> &parseTree() { return parseTree_; }
36
37 const CookedSource &cooked() const { return DEREF(currentCooked_); }
38
39 const SourceFile *Prescan(const std::string &path, Options);
40 void EmitPreprocessedSource(
41 llvm::raw_ostream &, bool lineDirectives = true) const;
42 void EmitPreprocessorMacros(llvm::raw_ostream &) const;
43 void DumpCookedChars(llvm::raw_ostream &) const;
44 void DumpProvenance(llvm::raw_ostream &) const;
45 void DumpParsingLog(llvm::raw_ostream &) const;
46 void Parse(
47 llvm::raw_ostream &debugOutput, const common::LangOptions &langOptions);
48 void ClearLog();
49
50 void EmitMessage(llvm::raw_ostream &o, const char *at,
51 const std::string &message, const std::string &prefix,
52 llvm::raw_ostream::Colors color = llvm::raw_ostream::SAVEDCOLOR,
53 bool echoSourceLine = false) const {
54 allCooked_.allSources().EmitMessage(o,
55 allCooked_.GetProvenanceRange(CharBlock(at)), message, prefix, color,
56 echoSourceLine);
57 }
58
59private:
60 Options options_;
61 AllCookedSources &allCooked_;
62 CookedSource *currentCooked_{nullptr};
63 Messages messages_;
64 bool consumedWholeFile_{false};
65 const char *finalRestingPlace_{nullptr};
66 std::optional<Program> parseTree_;
67 ParsingLog log_;
68 Preprocessor preprocessor_{allCooked_.allSources()};
69};
70} // namespace Fortran::parser
71#endif // FORTRAN_PARSER_PARSING_H_
Definition LangOptions.h:70
Definition provenance.h:286
Definition char-block.h:26
Definition provenance.h:238
Definition message.h:332
Definition instrumented-parser.h:25
Definition preprocessor.h:74
Definition source.h:52
Definition check-expression.h:19
Definition options.h:21