Pyrogenesis trunk
PreprocessorWrapper.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_PREPROCESSORWRAPPER
19#define INCLUDED_PREPROCESSORWRAPPER
20
21#include "ps/CStr.h"
23
24#include <functional>
25#include <unordered_map>
26
27class CShaderDefines;
28
29/**
30 * Convenience wrapper around CPreprocessor.
31 */
33{
34public:
35 using IncludeRetrieverCallback = std::function<bool(const CStr&, CStr& out)>;
36
38 CPreprocessorWrapper(const IncludeRetrieverCallback& includeCallback);
39
40 void AddDefine(const char* name, const char* value);
41
42 void AddDefines(const CShaderDefines& defines);
43
44 bool TestConditional(const CStr& expr);
45
46 // Find all #include directives in the input and replace them by
47 // by a file content from the directive's argument. Parsing is strict
48 // and simple. The directive will be expanded in comments and multiline
49 // strings.
50 CStr ResolveIncludes(const CStr& source);
51
52 CStr Preprocess(const CStr& input);
53
54 static void PyrogenesisShaderError(int iLine, const char* iError, const Ogre::CPreprocessor::Token* iToken);
55
56private:
59 std::unordered_map<CStr, CStr> m_IncludeCache;
60};
61
62#endif // INCLUDED_PREPROCESSORWRAPPER
Convenience wrapper around CPreprocessor.
Definition: PreprocessorWrapper.h:33
void AddDefines(const CShaderDefines &defines)
Definition: PreprocessorWrapper.cpp:191
CPreprocessorWrapper()
Definition: PreprocessorWrapper.cpp:175
CStr Preprocess(const CStr &input)
Definition: PreprocessorWrapper.cpp:252
bool TestConditional(const CStr &expr)
Definition: PreprocessorWrapper.cpp:198
std::unordered_map< CStr, CStr > m_IncludeCache
Definition: PreprocessorWrapper.h:59
std::function< bool(const CStr &, CStr &out)> IncludeRetrieverCallback
Definition: PreprocessorWrapper.h:35
void AddDefine(const char *name, const char *value)
Definition: PreprocessorWrapper.cpp:186
IncludeRetrieverCallback m_IncludeCallback
Definition: PreprocessorWrapper.h:58
Ogre::CPreprocessor m_Preprocessor
Definition: PreprocessorWrapper.h:57
CStr ResolveIncludes(const CStr &source)
Definition: PreprocessorWrapper.cpp:229
static void PyrogenesisShaderError(int iLine, const char *iError, const Ogre::CPreprocessor::Token *iToken)
Definition: PreprocessorWrapper.cpp:167
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
Definition: ShaderDefines.h:147
A input token.
Definition: OgreGLSLPreprocessor.h:85
This is a simplistic C/C++-like preprocessor.
Definition: OgreGLSLPreprocessor.h:69
static void out(const wchar_t *fmt,...)
Definition: wdbg_sym.cpp:407