kythe.io@v0.0.68-0.20240422202219-7225dbc01741/third_party/llvm/src/cxx_extractor_preprocessor_utils.h (about) 1 // cxx_extractor_preprocessor_utils.h - Preprocessor utilities -*- C++ -*--===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===--------------------------------------------------------------------===// 9 /// \file 10 /// This file contains code from PreprocessorTracker.cpp from the modularize 11 /// project in clang-tools-extra; more details on its provenance and license 12 /// are available in //third_party/llvm. 13 //===--------------------------------------------------------------------===// 14 // This file uses the Clang style conventions. 15 #ifndef KYTHE_CXX_EXTRACTOR_EXTRACTOR_PREPROCESSOR_UTILS_H_ 16 #define KYTHE_CXX_EXTRACTOR_EXTRACTOR_PREPROCESSOR_UTILS_H_ 17 18 #include "clang/Lex/MacroArgs.h" 19 #include "clang/Lex/Preprocessor.h" 20 21 namespace kythe { 22 /// \brief Get the string for the Unexpanded macro instance. 23 /// 24 /// The sourceRange is expected to end at the last token 25 /// for the macro instance, which in the case of a function-style 26 /// macro will be a ')', but for an object-style macro, it 27 /// will be the macro name itself. 28 std::string getMacroUnexpandedString(clang::SourceRange Range, 29 clang::Preprocessor &PP, 30 llvm::StringRef MacroName, 31 const clang::MacroInfo *MI); 32 33 /// \brief Get the expansion for a macro instance, given the information 34 /// provided by PPCallbacks. 35 /// 36 /// FIXME: This doesn't support function-style macro instances 37 /// passed as arguments to another function-style macro. However, 38 /// since it still expands the inner arguments, it still 39 /// allows modularize to effectively work with respect to macro 40 /// consistency checking, although it displays the incorrect 41 /// expansion in error messages. 42 std::string getMacroExpandedString(clang::Preprocessor &PP, 43 llvm::StringRef MacroName, 44 const clang::MacroInfo *MI, 45 const clang::MacroArgs *Args); 46 47 /// \brief Returns the source text in `Range` with whitespace trimmed off. 48 /// \param Range The source range to return text from. 49 /// \param PP The preprocessor instance to interrogate. 50 std::string getSourceString(clang::Preprocessor &PP, clang::SourceRange Range); 51 } 52 53 #endif