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 #include <iosfwd> 16 17 namespace llvm { 18 class raw_ostream; 19 } 20 21 namespace Fortran::evaluate { 22 struct GenericExprWrapper; 23 struct GenericAssignmentWrapper; 24 class ProcedureRef; 25 } // namespace Fortran::evaluate 26 27 namespace Fortran::parser { 28 29 struct Program; 30 struct Expr; 31 32 // A function called before each Statement is unparsed. 33 using preStatementType = 34 std::function<void(const CharBlock &, llvm::raw_ostream &, int)>; 35 36 // Functions to handle unparsing of analyzed expressions and related 37 // objects rather than their original parse trees. 38 struct AnalyzedObjectsAsFortran { 39 std::function<void(llvm::raw_ostream &, const evaluate::GenericExprWrapper &)> 40 expr; 41 std::function<void( 42 llvm::raw_ostream &, const evaluate::GenericAssignmentWrapper &)> 43 assignment; 44 std::function<void(llvm::raw_ostream &, const evaluate::ProcedureRef &)> call; 45 }; 46 47 // Converts parsed program (or fragment) to out as Fortran. 48 template <typename A> 49 void Unparse(llvm::raw_ostream &out, const A &root, 50 Encoding encoding = Encoding::UTF_8, bool capitalizeKeywords = true, 51 bool backslashEscapes = true, preStatementType *preStatement = nullptr, 52 AnalyzedObjectsAsFortran * = nullptr); 53 54 extern template void Unparse(llvm::raw_ostream &out, const Program &program, 55 Encoding encoding, bool capitalizeKeywords, bool backslashEscapes, 56 preStatementType *preStatement, AnalyzedObjectsAsFortran *); 57 extern template void Unparse(llvm::raw_ostream &out, const Expr &expr, 58 Encoding encoding, bool capitalizeKeywords, bool backslashEscapes, 59 preStatementType *preStatement, AnalyzedObjectsAsFortran *); 60 } // namespace Fortran::parser 61 62 #endif 63