mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-13 00:08:26 -05:00
Make DefinesProxy expand nested macros independently to avoid recursion
This commit is contained in:
@ -5,8 +5,10 @@
|
||||
#include "Parsing/Simple/Expression/ISimpleExpression.h"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
class DefinesStreamProxy final : public AbstractDirectiveStreamProxy
|
||||
{
|
||||
@ -44,15 +46,6 @@ public:
|
||||
Define();
|
||||
Define(std::string name, std::string value);
|
||||
void IdentifyParameters(const std::vector<std::string>& parameterNames);
|
||||
_NODISCARD std::string Render(const std::vector<std::string>& parameterValues) const;
|
||||
};
|
||||
|
||||
private:
|
||||
enum class BlockMode : uint8_t
|
||||
{
|
||||
NOT_IN_BLOCK,
|
||||
IN_BLOCK,
|
||||
BLOCK_BLOCKED
|
||||
};
|
||||
|
||||
enum class ParameterState : uint8_t
|
||||
@ -63,6 +56,26 @@ private:
|
||||
AFTER_COMMA
|
||||
};
|
||||
|
||||
class MacroParameterState
|
||||
{
|
||||
public:
|
||||
ParameterState m_parameter_state;
|
||||
std::ostringstream m_current_parameter;
|
||||
std::vector<std::string> m_parameters;
|
||||
std::stack<char> m_bracket_depth;
|
||||
|
||||
MacroParameterState();
|
||||
};
|
||||
|
||||
private:
|
||||
enum class BlockMode : uint8_t
|
||||
|
||||
{
|
||||
NOT_IN_BLOCK,
|
||||
IN_BLOCK,
|
||||
BLOCK_BLOCKED
|
||||
};
|
||||
|
||||
IParserLineStream* const m_stream;
|
||||
const bool m_skip_directive_lines;
|
||||
std::map<std::string, Define> m_defines;
|
||||
@ -76,10 +89,7 @@ private:
|
||||
std::vector<std::string> m_current_define_parameters;
|
||||
|
||||
const Define* m_current_macro;
|
||||
ParameterState m_macro_parameter_state;
|
||||
std::vector<std::string> m_macro_parameters;
|
||||
std::ostringstream m_current_macro_parameter;
|
||||
std::stack<char> m_macro_bracket_depth;
|
||||
MacroParameterState m_multi_line_macro_parameters;
|
||||
|
||||
static int GetLineEndEscapePos(const ParserLine& line);
|
||||
void MatchDefineParameters(const ParserLine& line, unsigned& currentPos);
|
||||
@ -94,16 +104,28 @@ private:
|
||||
_NODISCARD bool MatchEndifDirective(const ParserLine& line, unsigned directiveStartPosition, unsigned directiveEndPosition);
|
||||
_NODISCARD bool MatchDirectives(ParserLine& line);
|
||||
|
||||
void ExtractParametersFromDefineUsage(const ParserLine& line, unsigned parameterStart, unsigned& parameterEnd);
|
||||
bool FindDefineForWord(const std::string& line, unsigned wordStart, unsigned wordEnd, const Define*& value) const;
|
||||
void ExtractParametersFromMacroUsage(const ParserLine& line, unsigned& linePos, MacroParameterState& state, const std::string& input, unsigned& inputPos);
|
||||
bool FindMacroForIdentifier(const std::string& input, unsigned wordStart, unsigned wordEnd, const Define*& value) const;
|
||||
|
||||
static bool MatchDefinedExpression(const ParserLine& line, unsigned& pos, std::string& definitionName);
|
||||
void ExpandDefinedExpressions(ParserLine& line) const;
|
||||
|
||||
void ContinueMacroParameters(const ParserLine& line, unsigned& pos);
|
||||
void ContinueMacro(ParserLine& line);
|
||||
void ProcessDefine(const ParserLine& line, unsigned& pos, std::ostringstream& out);
|
||||
bool FindNextDefine(const std::string& line, unsigned& pos, unsigned& defineStart, const DefinesStreamProxy::Define*& define);
|
||||
bool FindNextMacro(const std::string& input, unsigned& inputPos, unsigned& defineStart, const DefinesStreamProxy::Define*& define);
|
||||
|
||||
void InsertMacroParameters(std::ostringstream& out, const DefinesStreamProxy::Define* macro, std::vector<std::string>& parameterValues);
|
||||
void ExpandMacro(ParserLine& line,
|
||||
unsigned& linePos,
|
||||
std::ostringstream& out,
|
||||
std::vector<const Define*>& callstack,
|
||||
const DefinesStreamProxy::Define* macro,
|
||||
std::vector<std::string>& parameterValues);
|
||||
|
||||
void ContinueMacroParameters(const ParserLine& line, unsigned& linePos, MacroParameterState& state, const std::string& input, unsigned& inputPos);
|
||||
void ContinueMultiLineMacro(ParserLine& line);
|
||||
|
||||
void ProcessNestedMacros(ParserLine& line, unsigned& linePos, std::vector<const Define*>& callstack, std::string& input, unsigned& inputPos);
|
||||
void ProcessMacrosSingleLine(ParserLine& line);
|
||||
void ProcessMacrosMultiLine(ParserLine& line);
|
||||
|
||||
public:
|
||||
explicit DefinesStreamProxy(IParserLineStream* stream, bool skipDirectiveLines = false);
|
||||
@ -111,8 +133,6 @@ public:
|
||||
void AddDefine(Define define);
|
||||
void Undefine(const std::string& name);
|
||||
|
||||
void ExpandDefines(ParserLine& line);
|
||||
|
||||
_NODISCARD std::unique_ptr<ISimpleExpression> ParseExpression(std::shared_ptr<std::string> fileName, int lineNumber, std::string expressionString);
|
||||
|
||||
ParserLine NextLine() override;
|
||||
|
Reference in New Issue
Block a user