FLANG
unparse.h
1//===-- include/flang/Parser/unparse.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_UNPARSE_H_
10#define FORTRAN_PARSER_UNPARSE_H_
11
12#include "char-block.h"
13#include "characters.h"
14#include <functional>
15
16namespace llvm {
17class raw_ostream;
18}
19
20namespace Fortran::common {
21class LangOptions;
22}
23
24namespace Fortran::evaluate {
27class ProcedureRef;
28} // namespace Fortran::evaluate
29
30namespace Fortran::parser {
31
32struct Program;
33struct Expr;
34
35// A function called before each Statement is unparsed.
36using preStatementType =
37 std::function<void(const CharBlock &, llvm::raw_ostream &, int)>;
38
39// Functions to handle unparsing of analyzed expressions and related
40// objects rather than their original parse trees.
42 std::function<void(llvm::raw_ostream &, const evaluate::GenericExprWrapper &)>
43 expr;
44 std::function<void(
45 llvm::raw_ostream &, const evaluate::GenericAssignmentWrapper &)>
46 assignment;
47 std::function<void(llvm::raw_ostream &, const evaluate::ProcedureRef &)> call;
48};
49
50// Converts parsed program (or fragment) to out as Fortran.
51template <typename A>
52void Unparse(llvm::raw_ostream &out, const A &root,
53 const common::LangOptions &langOpts, Encoding encoding = Encoding::UTF_8,
54 bool capitalizeKeywords = true, bool backslashEscapes = true,
55 preStatementType *preStatement = nullptr,
56 AnalyzedObjectsAsFortran * = nullptr);
57
58extern template void Unparse(llvm::raw_ostream &out, const Program &program,
59 const common::LangOptions &langOpts, Encoding encoding,
60 bool capitalizeKeywords, bool backslashEscapes,
61 preStatementType *preStatement, AnalyzedObjectsAsFortran *);
62extern template void Unparse(llvm::raw_ostream &out, const Expr &expr,
63 const common::LangOptions &langOpts, Encoding encoding,
64 bool capitalizeKeywords, bool backslashEscapes,
65 preStatementType *preStatement, AnalyzedObjectsAsFortran *);
66} // namespace Fortran::parser
67
68#endif
Definition LangOptions.h:58
Definition call.h:234
Definition char-block.h:26
Definition bit-population-count.h:20
Definition call.h:34
Definition check-expression.h:19
Definition expression.h:938
Definition parse-tree.h:1735