gfx/angle/src/compiler/preprocessor/MacroExpander.h

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 //
michael@0 2 // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
michael@0 3 // Use of this source code is governed by a BSD-style license that can be
michael@0 4 // found in the LICENSE file.
michael@0 5 //
michael@0 6
michael@0 7 #ifndef COMPILER_PREPROCESSOR_MACRO_EXPANDER_H_
michael@0 8 #define COMPILER_PREPROCESSOR_MACRO_EXPANDER_H_
michael@0 9
michael@0 10 #include <cassert>
michael@0 11 #include <memory>
michael@0 12 #include <vector>
michael@0 13
michael@0 14 #include "Lexer.h"
michael@0 15 #include "Macro.h"
michael@0 16 #include "pp_utils.h"
michael@0 17
michael@0 18 namespace pp
michael@0 19 {
michael@0 20
michael@0 21 class Diagnostics;
michael@0 22
michael@0 23 class MacroExpander : public Lexer
michael@0 24 {
michael@0 25 public:
michael@0 26 MacroExpander(Lexer* lexer, MacroSet* macroSet, Diagnostics* diagnostics);
michael@0 27 virtual ~MacroExpander();
michael@0 28
michael@0 29 virtual void lex(Token* token);
michael@0 30
michael@0 31 private:
michael@0 32 PP_DISALLOW_COPY_AND_ASSIGN(MacroExpander);
michael@0 33
michael@0 34 void getToken(Token* token);
michael@0 35 void ungetToken(const Token& token);
michael@0 36 bool isNextTokenLeftParen();
michael@0 37
michael@0 38 bool pushMacro(const Macro& macro, const Token& identifier);
michael@0 39 void popMacro();
michael@0 40
michael@0 41 bool expandMacro(const Macro& macro,
michael@0 42 const Token& identifier,
michael@0 43 std::vector<Token>* replacements);
michael@0 44
michael@0 45 typedef std::vector<Token> MacroArg;
michael@0 46 bool collectMacroArgs(const Macro& macro,
michael@0 47 const Token& identifier,
michael@0 48 std::vector<MacroArg>* args);
michael@0 49 void replaceMacroParams(const Macro& macro,
michael@0 50 const std::vector<MacroArg>& args,
michael@0 51 std::vector<Token>* replacements);
michael@0 52
michael@0 53 struct MacroContext
michael@0 54 {
michael@0 55 const Macro* macro;
michael@0 56 std::size_t index;
michael@0 57 std::vector<Token> replacements;
michael@0 58
michael@0 59 MacroContext() : macro(0), index(0) { }
michael@0 60 bool empty() const { return index == replacements.size(); }
michael@0 61 const Token& get() { return replacements[index++]; }
michael@0 62 void unget() { assert(index > 0); --index; }
michael@0 63 };
michael@0 64
michael@0 65 Lexer* mLexer;
michael@0 66 MacroSet* mMacroSet;
michael@0 67 Diagnostics* mDiagnostics;
michael@0 68
michael@0 69 std::auto_ptr<Token> mReserveToken;
michael@0 70 std::vector<MacroContext*> mContextStack;
michael@0 71 };
michael@0 72
michael@0 73 } // namespace pp
michael@0 74 #endif // COMPILER_PREPROCESSOR_MACRO_EXPANDER_H_
michael@0 75

mercurial