// // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // #ifndef COMPILER_PREPROCESSOR_MACROEXPANDER_H_ #define COMPILER_PREPROCESSOR_MACROEXPANDER_H_ #include #include #include "compiler/preprocessor/Lexer.h" #include "compiler/preprocessor/Macro.h" namespace pp { class Diagnostics; struct SourceLocation; class MacroExpander : public Lexer { public: MacroExpander(Lexer *lexer, MacroSet *macroSet, Diagnostics *diagnostics, int allowedMacroExpansionDepth); ~MacroExpander() override; void lex(Token *token) override; private: void getToken(Token *token); void ungetToken(const Token &token); bool isNextTokenLeftParen(); bool pushMacro(std::shared_ptr macro, const Token &identifier); void popMacro(); bool expandMacro(const Macro ¯o, const Token &identifier, std::vector *replacements); typedef std::vector MacroArg; bool collectMacroArgs(const Macro ¯o, const Token &identifier, std::vector *args, SourceLocation *closingParenthesisLocation); void replaceMacroParams(const Macro ¯o, const std::vector &args, std::vector *replacements); struct MacroContext { MacroContext(); ~MacroContext(); bool empty() const; const Token &get(); void unget(); std::shared_ptr macro; std::size_t index; std::vector replacements; }; Lexer *mLexer; MacroSet *mMacroSet; Diagnostics *mDiagnostics; std::unique_ptr mReserveToken; std::vector mContextStack; size_t mTotalTokensInContexts; int mAllowedMacroExpansionDepth; bool mDeferReenablingMacros; std::vector> mMacrosToReenable; class ScopedMacroReenabler; }; } // namespace pp #endif // COMPILER_PREPROCESSOR_MACROEXPANDER_H_