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.

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

mercurial