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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/angle/src/compiler/preprocessor/MacroExpander.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     1.4 +//
     1.5 +// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
     1.6 +// Use of this source code is governed by a BSD-style license that can be
     1.7 +// found in the LICENSE file.
     1.8 +//
     1.9 +
    1.10 +#ifndef COMPILER_PREPROCESSOR_MACRO_EXPANDER_H_
    1.11 +#define COMPILER_PREPROCESSOR_MACRO_EXPANDER_H_
    1.12 +
    1.13 +#include <cassert>
    1.14 +#include <memory>
    1.15 +#include <vector>
    1.16 +
    1.17 +#include "Lexer.h"
    1.18 +#include "Macro.h"
    1.19 +#include "pp_utils.h"
    1.20 +
    1.21 +namespace pp
    1.22 +{
    1.23 +
    1.24 +class Diagnostics;
    1.25 +
    1.26 +class MacroExpander : public Lexer
    1.27 +{
    1.28 +  public:
    1.29 +    MacroExpander(Lexer* lexer, MacroSet* macroSet, Diagnostics* diagnostics);
    1.30 +    virtual ~MacroExpander();
    1.31 +
    1.32 +    virtual void lex(Token* token);
    1.33 +
    1.34 +  private:
    1.35 +    PP_DISALLOW_COPY_AND_ASSIGN(MacroExpander);
    1.36 +
    1.37 +    void getToken(Token* token);
    1.38 +    void ungetToken(const Token& token);
    1.39 +    bool isNextTokenLeftParen();
    1.40 +
    1.41 +    bool pushMacro(const Macro& macro, const Token& identifier);
    1.42 +    void popMacro();
    1.43 +
    1.44 +    bool expandMacro(const Macro& macro,
    1.45 +                     const Token& identifier,
    1.46 +                     std::vector<Token>* replacements);
    1.47 +
    1.48 +    typedef std::vector<Token> MacroArg;
    1.49 +    bool collectMacroArgs(const Macro& macro,
    1.50 +                          const Token& identifier,
    1.51 +                          std::vector<MacroArg>* args);
    1.52 +    void replaceMacroParams(const Macro& macro,
    1.53 +                            const std::vector<MacroArg>& args,
    1.54 +                            std::vector<Token>* replacements);
    1.55 +
    1.56 +    struct MacroContext
    1.57 +    {
    1.58 +        const Macro* macro;
    1.59 +        std::size_t index;
    1.60 +        std::vector<Token> replacements;
    1.61 +
    1.62 +        MacroContext() : macro(0), index(0) { }
    1.63 +        bool empty() const { return index == replacements.size(); }
    1.64 +        const Token& get() { return replacements[index++]; }
    1.65 +        void unget() { assert(index > 0); --index; }
    1.66 +    };
    1.67 +
    1.68 +    Lexer* mLexer;
    1.69 +    MacroSet* mMacroSet;
    1.70 +    Diagnostics* mDiagnostics;
    1.71 +
    1.72 +    std::auto_ptr<Token> mReserveToken;
    1.73 +    std::vector<MacroContext*> mContextStack;
    1.74 +};
    1.75 +
    1.76 +}  // namespace pp
    1.77 +#endif  // COMPILER_PREPROCESSOR_MACRO_EXPANDER_H_
    1.78 +

mercurial