1 //===- PreprocessorOptions.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 /// \file 10 /// This file contains the declaration of the PreprocessorOptions class, which 11 /// is the class for all preprocessor options. 12 /// 13 //===----------------------------------------------------------------------===// 14 // 15 // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/ 16 // 17 //===----------------------------------------------------------------------===// 18 19 #ifndef FORTRAN_FRONTEND_PREPROCESSOROPTIONS_H 20 #define FORTRAN_FRONTEND_PREPROCESSOROPTIONS_H 21 22 #include "llvm/ADT/StringRef.h" 23 24 namespace Fortran::frontend { 25 26 /// Communicates whether to include/exclude predefined and command 27 /// line preprocessor macros 28 enum class PPMacrosFlag : uint8_t { 29 /// Use the file extension to decide 30 Unknown, 31 32 Include, 33 Exclude 34 }; 35 36 /// This class is used for passing the various options used 37 /// in preprocessor initialization to the parser options. 38 struct PreprocessorOptions { 39 PreprocessorOptions() {} 40 41 std::vector<std::pair<std::string, /*isUndef*/ bool>> macros; 42 43 // Search directories specified by the user with -I 44 // TODO: When adding support for more options related to search paths, 45 // consider collecting them in a separate aggregate. For now we keep it here 46 // as there is no point creating a class for just one field. 47 std::vector<std::string> searchDirectoriesFromDashI; 48 // Search directories specified by the user with -fintrinsic-modules-path 49 std::vector<std::string> searchDirectoriesFromIntrModPath; 50 51 PPMacrosFlag macrosFlag = PPMacrosFlag::Unknown; 52 53 // -P: Suppress #line directives in -E output 54 bool noLineDirectives{false}; 55 56 // -fno-reformat: Emit cooked character stream as -E output 57 bool noReformat{false}; 58 59 // -fpreprocess-include-lines: Treat INCLUDE as #include for -E output 60 bool preprocessIncludeLines{false}; 61 62 // -dM: Show macro definitions with -dM -E 63 bool showMacros{false}; 64 65 void addMacroDef(llvm::StringRef name) { 66 macros.emplace_back(std::string(name), false); 67 } 68 69 void addMacroUndef(llvm::StringRef name) { 70 macros.emplace_back(std::string(name), true); 71 } 72 }; 73 74 } // namespace Fortran::frontend 75 76 #endif // FORTRAN_FRONTEND_PREPROCESSOROPTIONS_H 77