Path: blob/main_old/src/compiler/preprocessor/MacroExpander.h
1693 views
//1// Copyright 2012 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56#ifndef COMPILER_PREPROCESSOR_MACROEXPANDER_H_7#define COMPILER_PREPROCESSOR_MACROEXPANDER_H_89#include <memory>10#include <vector>1112#include "compiler/preprocessor/Lexer.h"13#include "compiler/preprocessor/Macro.h"14#include "compiler/preprocessor/Preprocessor.h"1516namespace angle17{1819namespace pp20{2122class Diagnostics;23struct SourceLocation;2425class MacroExpander : public Lexer26{27public:28MacroExpander(Lexer *lexer,29MacroSet *macroSet,30Diagnostics *diagnostics,31const PreprocessorSettings &settings,32bool parseDefined);33~MacroExpander() override;3435void lex(Token *token) override;3637private:38void getToken(Token *token);39void ungetToken(const Token &token);40bool isNextTokenLeftParen();4142bool pushMacro(std::shared_ptr<Macro> macro, const Token &identifier);43void popMacro();4445bool expandMacro(const Macro ¯o, const Token &identifier, std::vector<Token> *replacements);4647typedef std::vector<Token> MacroArg;48bool collectMacroArgs(const Macro ¯o,49const Token &identifier,50std::vector<MacroArg> *args,51SourceLocation *closingParenthesisLocation);52void replaceMacroParams(const Macro ¯o,53const std::vector<MacroArg> &args,54std::vector<Token> *replacements);5556struct MacroContext57{58MacroContext();59~MacroContext();60bool empty() const;61const Token &get();62void unget();6364std::shared_ptr<Macro> macro;65std::size_t index;66std::vector<Token> replacements;67};6869Lexer *mLexer;70MacroSet *mMacroSet;71Diagnostics *mDiagnostics;72bool mParseDefined;7374std::unique_ptr<Token> mReserveToken;75std::vector<MacroContext *> mContextStack;76size_t mTotalTokensInContexts;7778PreprocessorSettings mSettings;7980bool mDeferReenablingMacros;81std::vector<std::shared_ptr<Macro>> mMacrosToReenable;8283class ScopedMacroReenabler;84};8586} // namespace pp8788} // namespace angle8990#endif // COMPILER_PREPROCESSOR_MACROEXPANDER_H_919293