//===--- RewriteMacros.cpp - Rewrite macros into their expansions ---------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This code rewrites macro invocations into their expansions. This gives you // a macro expanded file that retains comments and #includes. // //===----------------------------------------------------------------------===// #include "clang/Basic/SourceManager.h" #include "clang/Lex/Preprocessor.h" #include "clang/Rewrite/Core/Rewriter.h" #include "clang/Rewrite/Frontend/Rewriters.h" #include "llvm/ADT/RewriteBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include <cstdio> #include <memory> usingnamespaceclang; RewriteBuffer; /// isSameToken - Return true if the two specified tokens start have the same /// content. static bool isSameToken(Token &RawTok, Token &PPTok) { … } /// GetNextRawTok - Return the next raw token in the stream, skipping over /// comments if ReturnComment is false. static const Token &GetNextRawTok(const std::vector<Token> &RawTokens, unsigned &CurTok, bool ReturnComment) { … } /// LexRawTokensFromMainFile - Lets all the raw tokens from the main file into /// the specified vector. static void LexRawTokensFromMainFile(Preprocessor &PP, std::vector<Token> &RawTokens) { … } /// RewriteMacrosInInput - Implement -rewrite-macros mode. void clang::RewriteMacrosInInput(Preprocessor &PP, raw_ostream *OS) { … }