mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-05-07 13:04:58 +00:00
refactor: fix additional zcg x64 warnings
This commit is contained in:
parent
d938f91541
commit
3adbe5a275
@ -13,12 +13,22 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
bool IsStringizeParameterForwardLookup(const std::string& value, size_t pos)
|
constexpr auto DEFINE_DIRECTIVE = "define";
|
||||||
|
constexpr auto UNDEF_DIRECTIVE = "undef";
|
||||||
|
constexpr auto IF_DIRECTIVE = "if";
|
||||||
|
constexpr auto ELIF_DIRECTIVE = "elif";
|
||||||
|
constexpr auto IFDEF_DIRECTIVE = "ifdef";
|
||||||
|
constexpr auto IFNDEF_DIRECTIVE = "ifndef";
|
||||||
|
constexpr auto ELSE_DIRECTIVE = "else";
|
||||||
|
constexpr auto ENDIF_DIRECTIVE = "endif";
|
||||||
|
constexpr auto DEFINED_KEYWORD = "defined";
|
||||||
|
|
||||||
|
bool IsStringizeParameterForwardLookup(const std::string& value, const size_t pos)
|
||||||
{
|
{
|
||||||
return pos + 1 && (isalpha(value[pos + 1]) || value[pos + 1] == '_');
|
return pos + 1 && (isalpha(value[pos + 1]) || value[pos + 1] == '_');
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsTokenPastingOperatorForwardLookup(const std::string& value, size_t pos)
|
bool IsTokenPastingOperatorForwardLookup(const std::string& value, const size_t pos)
|
||||||
{
|
{
|
||||||
return pos + 1 < value.size() && value[pos + 1] == '#';
|
return pos + 1 < value.size() && value[pos + 1] == '#';
|
||||||
}
|
}
|
||||||
@ -31,7 +41,7 @@ DefinesStreamProxy::DefineParameterPosition::DefineParameterPosition()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DefinesStreamProxy::DefineParameterPosition::DefineParameterPosition(const unsigned index, const size_t position, const bool stringize)
|
DefinesStreamProxy::DefineParameterPosition::DefineParameterPosition(const unsigned index, const unsigned position, const bool stringize)
|
||||||
: m_parameter_index(index),
|
: m_parameter_index(index),
|
||||||
m_parameter_position(position),
|
m_parameter_position(position),
|
||||||
m_stringize(stringize)
|
m_stringize(stringize)
|
||||||
@ -591,7 +601,6 @@ bool DefinesStreamProxy::FindNextMacro(const std::string& input, unsigned& input
|
|||||||
{
|
{
|
||||||
const auto inputSize = input.size();
|
const auto inputSize = input.size();
|
||||||
auto wordStart = 0u;
|
auto wordStart = 0u;
|
||||||
auto lastWordEnd = 0u;
|
|
||||||
auto inWord = false;
|
auto inWord = false;
|
||||||
auto inString = false;
|
auto inString = false;
|
||||||
auto stringEscape = false;
|
auto stringEscape = false;
|
||||||
@ -763,8 +772,7 @@ namespace
|
|||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void DefinesStreamProxy::ProcessTokenPastingOperators(
|
void DefinesStreamProxy::ProcessTokenPastingOperators(const ParserLine& line, const unsigned& linePos, std::string& input)
|
||||||
const ParserLine& line, const unsigned& linePos, std::vector<const Define*>& callstack, std::string& input, unsigned& inputPos)
|
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
|
|
||||||
@ -853,18 +861,17 @@ void DefinesStreamProxy::ExpandMacro(ParserLine& line,
|
|||||||
unsigned& linePos,
|
unsigned& linePos,
|
||||||
std::ostringstream& out,
|
std::ostringstream& out,
|
||||||
std::vector<const Define*>& callstack,
|
std::vector<const Define*>& callstack,
|
||||||
const DefinesStreamProxy::Define* macro,
|
const Define* macro,
|
||||||
const std::vector<std::string>& parameterValues)
|
const std::vector<std::string>& parameterValues)
|
||||||
{
|
{
|
||||||
std::ostringstream rawOutput;
|
std::ostringstream rawOutput;
|
||||||
InsertMacroParameters(rawOutput, macro, parameterValues);
|
InsertMacroParameters(rawOutput, macro, parameterValues);
|
||||||
|
|
||||||
std::string str = rawOutput.str();
|
std::string str = rawOutput.str();
|
||||||
unsigned nestedPos = 0;
|
ProcessNestedMacros(line, linePos, callstack, str);
|
||||||
ProcessNestedMacros(line, linePos, callstack, str, nestedPos);
|
|
||||||
|
|
||||||
if (macro->m_contains_token_pasting_operators)
|
if (macro->m_contains_token_pasting_operators)
|
||||||
ProcessTokenPastingOperators(line, linePos, callstack, str, nestedPos);
|
ProcessTokenPastingOperators(line, linePos, str);
|
||||||
|
|
||||||
out << str;
|
out << str;
|
||||||
}
|
}
|
||||||
@ -966,7 +973,7 @@ void DefinesStreamProxy::ContinueMultiLineMacro(ParserLine& line)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefinesStreamProxy::ProcessNestedMacros(ParserLine& line, unsigned& linePos, std::vector<const Define*>& callstack, std::string& input, unsigned& inputPos)
|
void DefinesStreamProxy::ProcessNestedMacros(ParserLine& line, unsigned& linePos, std::vector<const Define*>& callstack, std::string& input)
|
||||||
{
|
{
|
||||||
bool usesDefines = false;
|
bool usesDefines = false;
|
||||||
|
|
||||||
@ -1021,7 +1028,7 @@ void DefinesStreamProxy::ProcessMacrosSingleLine(ParserLine& line)
|
|||||||
{
|
{
|
||||||
unsigned pos = 0;
|
unsigned pos = 0;
|
||||||
std::vector<const Define*> callstack;
|
std::vector<const Define*> callstack;
|
||||||
ProcessNestedMacros(line, pos, callstack, line.m_line, pos);
|
ProcessNestedMacros(line, pos, callstack, line.m_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefinesStreamProxy::ProcessMacrosMultiLine(ParserLine& line)
|
void DefinesStreamProxy::ProcessMacrosMultiLine(ParserLine& line)
|
||||||
|
@ -13,42 +13,30 @@
|
|||||||
|
|
||||||
class DefinesStreamProxy final : public AbstractDirectiveStreamProxy
|
class DefinesStreamProxy final : public AbstractDirectiveStreamProxy
|
||||||
{
|
{
|
||||||
static constexpr const char* DEFINE_DIRECTIVE = "define";
|
|
||||||
static constexpr const char* UNDEF_DIRECTIVE = "undef";
|
|
||||||
static constexpr const char* IF_DIRECTIVE = "if";
|
|
||||||
static constexpr const char* ELIF_DIRECTIVE = "elif";
|
|
||||||
static constexpr const char* IFDEF_DIRECTIVE = "ifdef";
|
|
||||||
static constexpr const char* IFNDEF_DIRECTIVE = "ifndef";
|
|
||||||
static constexpr const char* ELSE_DIRECTIVE = "else";
|
|
||||||
static constexpr const char* ENDIF_DIRECTIVE = "endif";
|
|
||||||
static constexpr const char* DEFINED_KEYWORD = "defined";
|
|
||||||
|
|
||||||
static constexpr auto MAX_DEFINE_ITERATIONS = 128u;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class DefineParameterPosition
|
class DefineParameterPosition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
unsigned m_parameter_index;
|
|
||||||
size_t m_parameter_position;
|
|
||||||
bool m_stringize;
|
|
||||||
|
|
||||||
DefineParameterPosition();
|
DefineParameterPosition();
|
||||||
DefineParameterPosition(unsigned index, size_t position, bool stringize);
|
DefineParameterPosition(unsigned index, unsigned position, bool stringize);
|
||||||
|
|
||||||
|
unsigned m_parameter_index;
|
||||||
|
unsigned m_parameter_position;
|
||||||
|
bool m_stringize;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Define
|
class Define
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Define();
|
||||||
|
Define(std::string name, std::string value);
|
||||||
|
void IdentifyParameters(const std::vector<std::string>& parameterNames);
|
||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
std::string m_value;
|
std::string m_value;
|
||||||
std::vector<DefineParameterPosition> m_parameter_positions;
|
std::vector<DefineParameterPosition> m_parameter_positions;
|
||||||
bool m_contains_token_pasting_operators;
|
bool m_contains_token_pasting_operators;
|
||||||
|
|
||||||
Define();
|
|
||||||
Define(std::string name, std::string value);
|
|
||||||
void IdentifyParameters(const std::vector<std::string>& parameterNames);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void IdentifyTokenPasteOperatorOnly();
|
void IdentifyTokenPasteOperatorOnly();
|
||||||
};
|
};
|
||||||
@ -64,14 +52,27 @@ public:
|
|||||||
class MacroParameterState
|
class MacroParameterState
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
MacroParameterState();
|
||||||
|
|
||||||
ParameterState m_parameter_state;
|
ParameterState m_parameter_state;
|
||||||
std::ostringstream m_current_parameter;
|
std::ostringstream m_current_parameter;
|
||||||
std::vector<std::string> m_parameters;
|
std::vector<std::string> m_parameters;
|
||||||
std::stack<char> m_bracket_depth;
|
std::stack<char> m_bracket_depth;
|
||||||
|
|
||||||
MacroParameterState();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
explicit DefinesStreamProxy(IParserLineStream* stream, bool skipDirectiveLines = false);
|
||||||
|
|
||||||
|
void AddDefine(Define define);
|
||||||
|
void Undefine(const std::string& name);
|
||||||
|
|
||||||
|
[[nodiscard]] std::unique_ptr<ISimpleExpression> ParseExpression(std::shared_ptr<std::string> fileName, int lineNumber, std::string expressionString);
|
||||||
|
|
||||||
|
ParserLine NextLine() override;
|
||||||
|
bool IncludeFile(const std::string& filename) override;
|
||||||
|
void PopCurrentFile() override;
|
||||||
|
[[nodiscard]] bool IsOpen() const override;
|
||||||
|
[[nodiscard]] bool Eof() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class BlockMode : uint8_t
|
enum class BlockMode : uint8_t
|
||||||
|
|
||||||
@ -81,6 +82,45 @@ private:
|
|||||||
BLOCK_BLOCKED
|
BLOCK_BLOCKED
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int GetLineEndEscapePos(const ParserLine& line);
|
||||||
|
void MatchDefineParameters(const ParserLine& line, size_t& currentPos);
|
||||||
|
void ContinueDefine(const ParserLine& line, size_t currentPos);
|
||||||
|
void ContinueParameters(const ParserLine& line, size_t& currentPos);
|
||||||
|
[[nodiscard]] bool MatchDefineDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
||||||
|
[[nodiscard]] bool MatchUndefDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
||||||
|
[[nodiscard]] bool MatchIfDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
||||||
|
[[nodiscard]] bool MatchElIfDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
||||||
|
[[nodiscard]] bool MatchIfdefDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
||||||
|
[[nodiscard]] bool MatchElseDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
||||||
|
[[nodiscard]] bool MatchEndifDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
||||||
|
[[nodiscard]] bool MatchDirectives(const ParserLine& line);
|
||||||
|
|
||||||
|
static void ExtractParametersFromMacroUsage(
|
||||||
|
const ParserLine& line, const unsigned& linePos, MacroParameterState& state, const std::string& input, unsigned& inputPos);
|
||||||
|
bool FindMacroForIdentifier(const std::string& input, unsigned identifierStart, unsigned identifierEnd, const Define*& value) const;
|
||||||
|
|
||||||
|
static bool MatchDefinedExpression(const ParserLine& line, size_t& pos, std::string& definitionName);
|
||||||
|
void ExpandDefinedExpressions(ParserLine& line) const;
|
||||||
|
|
||||||
|
bool FindNextMacro(const std::string& input, unsigned& inputPos, unsigned& defineStart, const DefinesStreamProxy::Define*& define) const;
|
||||||
|
|
||||||
|
static void ProcessTokenPastingOperators(const ParserLine& line, const unsigned& linePos, std::string& input);
|
||||||
|
static void InsertMacroParameters(std::ostringstream& out, const DefinesStreamProxy::Define* macro, const std::vector<std::string>& parameterValues);
|
||||||
|
void ExpandMacro(ParserLine& line,
|
||||||
|
unsigned& linePos,
|
||||||
|
std::ostringstream& out,
|
||||||
|
std::vector<const Define*>& callstack,
|
||||||
|
const DefinesStreamProxy::Define* macro,
|
||||||
|
const std::vector<std::string>& parameterValues);
|
||||||
|
|
||||||
|
static void
|
||||||
|
ContinueMacroParameters(const ParserLine& line, const 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);
|
||||||
|
void ProcessMacrosSingleLine(ParserLine& line);
|
||||||
|
void ProcessMacrosMultiLine(ParserLine& line);
|
||||||
|
|
||||||
IParserLineStream* const m_stream;
|
IParserLineStream* const m_stream;
|
||||||
const bool m_skip_directive_lines;
|
const bool m_skip_directive_lines;
|
||||||
std::map<std::string, Define> m_defines;
|
std::map<std::string, Define> m_defines;
|
||||||
@ -95,58 +135,4 @@ private:
|
|||||||
|
|
||||||
const Define* m_current_macro;
|
const Define* m_current_macro;
|
||||||
MacroParameterState m_multi_line_macro_parameters;
|
MacroParameterState m_multi_line_macro_parameters;
|
||||||
|
|
||||||
static int GetLineEndEscapePos(const ParserLine& line);
|
|
||||||
void MatchDefineParameters(const ParserLine& line, size_t& currentPos);
|
|
||||||
void ContinueDefine(const ParserLine& line, size_t currentPos);
|
|
||||||
void ContinueParameters(const ParserLine& line, size_t& currentPos);
|
|
||||||
_NODISCARD bool MatchDefineDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
|
||||||
_NODISCARD bool MatchUndefDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
|
||||||
_NODISCARD bool MatchIfDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
|
||||||
_NODISCARD bool MatchElIfDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
|
||||||
_NODISCARD bool MatchIfdefDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
|
||||||
_NODISCARD bool MatchElseDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
|
||||||
_NODISCARD bool MatchEndifDirective(const ParserLine& line, size_t directiveStartPosition, size_t directiveEndPosition);
|
|
||||||
_NODISCARD bool MatchDirectives(const ParserLine& line);
|
|
||||||
|
|
||||||
static void ExtractParametersFromMacroUsage(
|
|
||||||
const ParserLine& line, const unsigned& linePos, MacroParameterState& state, const std::string& input, unsigned& inputPos);
|
|
||||||
bool FindMacroForIdentifier(const std::string& input, unsigned identifierStart, unsigned identifierEnd, const Define*& value) const;
|
|
||||||
|
|
||||||
static bool MatchDefinedExpression(const ParserLine& line, size_t& pos, std::string& definitionName);
|
|
||||||
void ExpandDefinedExpressions(ParserLine& line) const;
|
|
||||||
|
|
||||||
bool FindNextMacro(const std::string& input, unsigned& inputPos, unsigned& defineStart, const DefinesStreamProxy::Define*& define) const;
|
|
||||||
|
|
||||||
static void ProcessTokenPastingOperators(
|
|
||||||
const ParserLine& line, const unsigned& linePos, std::vector<const Define*>& callstack, std::string& input, unsigned& inputPos);
|
|
||||||
static void InsertMacroParameters(std::ostringstream& out, const DefinesStreamProxy::Define* macro, const std::vector<std::string>& parameterValues);
|
|
||||||
void ExpandMacro(ParserLine& line,
|
|
||||||
unsigned& linePos,
|
|
||||||
std::ostringstream& out,
|
|
||||||
std::vector<const Define*>& callstack,
|
|
||||||
const DefinesStreamProxy::Define* macro,
|
|
||||||
const std::vector<std::string>& parameterValues);
|
|
||||||
|
|
||||||
static void
|
|
||||||
ContinueMacroParameters(const ParserLine& line, const 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);
|
|
||||||
|
|
||||||
void AddDefine(Define define);
|
|
||||||
void Undefine(const std::string& name);
|
|
||||||
|
|
||||||
_NODISCARD std::unique_ptr<ISimpleExpression> ParseExpression(std::shared_ptr<std::string> fileName, int lineNumber, std::string expressionString);
|
|
||||||
|
|
||||||
ParserLine NextLine() override;
|
|
||||||
bool IncludeFile(const std::string& filename) override;
|
|
||||||
void PopCurrentFile() override;
|
|
||||||
_NODISCARD bool IsOpen() const override;
|
|
||||||
_NODISCARD bool Eof() const override;
|
|
||||||
};
|
};
|
||||||
|
@ -80,7 +80,7 @@ public:
|
|||||||
result.m_fabricated_tokens.push_back(m_transform_func(tokens));
|
result.m_fabricated_tokens.push_back(m_transform_func(tokens));
|
||||||
|
|
||||||
result.m_matched_tokens.clear();
|
result.m_matched_tokens.clear();
|
||||||
result.m_matched_tokens.emplace_back(result.m_fabricated_tokens.size() - 1, true);
|
result.m_matched_tokens.emplace_back(static_cast<unsigned>(result.m_fabricated_tokens.size()) - 1u, true);
|
||||||
}
|
}
|
||||||
else if (result.m_matched_tokens.empty())
|
else if (result.m_matched_tokens.empty())
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
template<typename TokenType> class MatcherFactoryWrapper
|
template<typename TokenType> class MatcherFactoryWrapper
|
||||||
{
|
{
|
||||||
// TokenType must inherit IParserValue
|
// TokenType must inherit IParserValue
|
||||||
static_assert(std::is_base_of<IParserValue, TokenType>::value);
|
static_assert(std::is_base_of_v<IParserValue, TokenType>);
|
||||||
|
|
||||||
std::unique_ptr<AbstractMatcher<TokenType>> m_matcher;
|
std::unique_ptr<AbstractMatcher<TokenType>> m_matcher;
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ public:
|
|||||||
template<typename TokenType> class AbstractMatcherFactory
|
template<typename TokenType> class AbstractMatcherFactory
|
||||||
{
|
{
|
||||||
// TokenType must inherit IParserValue
|
// TokenType must inherit IParserValue
|
||||||
static_assert(std::is_base_of<IParserValue, TokenType>::value);
|
static_assert(std::is_base_of_v<IParserValue, TokenType>);
|
||||||
|
|
||||||
const IMatcherForLabelSupplier<TokenType>* m_label_supplier;
|
const IMatcherForLabelSupplier<TokenType>* m_label_supplier;
|
||||||
|
|
||||||
@ -85,52 +85,52 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
_NODISCARD MatcherFactoryWrapper<TokenType> False() const
|
[[nodiscard]] MatcherFactoryWrapper<TokenType> False() const
|
||||||
{
|
{
|
||||||
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherFalse<TokenType>>());
|
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherFalse<TokenType>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
_NODISCARD MatcherFactoryWrapper<TokenType> True() const
|
[[nodiscard]] MatcherFactoryWrapper<TokenType> True() const
|
||||||
{
|
{
|
||||||
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherTrue<TokenType>>());
|
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherTrue<TokenType>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
_NODISCARD MatcherFactoryWrapper<TokenType> And(std::initializer_list<Movable<std::unique_ptr<AbstractMatcher<TokenType>>>> matchers) const
|
[[nodiscard]] MatcherFactoryWrapper<TokenType> And(std::initializer_list<Movable<std::unique_ptr<AbstractMatcher<TokenType>>>> matchers) const
|
||||||
{
|
{
|
||||||
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherAnd<TokenType>>(matchers));
|
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherAnd<TokenType>>(matchers));
|
||||||
}
|
}
|
||||||
|
|
||||||
_NODISCARD MatcherFactoryWrapper<TokenType> And(std::vector<std::unique_ptr<AbstractMatcher<TokenType>>> matchers) const
|
[[nodiscard]] MatcherFactoryWrapper<TokenType> And(std::vector<std::unique_ptr<AbstractMatcher<TokenType>>> matchers) const
|
||||||
{
|
{
|
||||||
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherAnd<TokenType>>(std::move(matchers)));
|
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherAnd<TokenType>>(std::move(matchers)));
|
||||||
}
|
}
|
||||||
|
|
||||||
_NODISCARD MatcherFactoryWrapper<TokenType> Or(std::initializer_list<Movable<std::unique_ptr<AbstractMatcher<TokenType>>>> matchers) const
|
[[nodiscard]] MatcherFactoryWrapper<TokenType> Or(std::initializer_list<Movable<std::unique_ptr<AbstractMatcher<TokenType>>>> matchers) const
|
||||||
{
|
{
|
||||||
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherOr<TokenType>>(matchers));
|
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherOr<TokenType>>(matchers));
|
||||||
}
|
}
|
||||||
|
|
||||||
_NODISCARD MatcherFactoryWrapper<TokenType> Or(std::vector<std::unique_ptr<AbstractMatcher<TokenType>>> matchers) const
|
[[nodiscard]] MatcherFactoryWrapper<TokenType> Or(std::vector<std::unique_ptr<AbstractMatcher<TokenType>>> matchers) const
|
||||||
{
|
{
|
||||||
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherOr<TokenType>>(std::move(matchers)));
|
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherOr<TokenType>>(std::move(matchers)));
|
||||||
}
|
}
|
||||||
|
|
||||||
_NODISCARD MatcherFactoryWrapper<TokenType> Loop(std::unique_ptr<AbstractMatcher<TokenType>> matcher) const
|
[[nodiscard]] MatcherFactoryWrapper<TokenType> Loop(std::unique_ptr<AbstractMatcher<TokenType>> matcher) const
|
||||||
{
|
{
|
||||||
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherLoop<TokenType>>(std::move(matcher)));
|
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherLoop<TokenType>>(std::move(matcher)));
|
||||||
}
|
}
|
||||||
|
|
||||||
_NODISCARD MatcherFactoryWrapper<TokenType> OptionalLoop(std::unique_ptr<AbstractMatcher<TokenType>> matcher) const
|
[[nodiscard]] MatcherFactoryWrapper<TokenType> OptionalLoop(std::unique_ptr<AbstractMatcher<TokenType>> matcher) const
|
||||||
{
|
{
|
||||||
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherOptional<TokenType>>(std::make_unique<MatcherLoop<TokenType>>(std::move(matcher))));
|
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherOptional<TokenType>>(std::make_unique<MatcherLoop<TokenType>>(std::move(matcher))));
|
||||||
}
|
}
|
||||||
|
|
||||||
_NODISCARD MatcherFactoryWrapper<TokenType> Optional(std::unique_ptr<AbstractMatcher<TokenType>> matcher) const
|
[[nodiscard]] MatcherFactoryWrapper<TokenType> Optional(std::unique_ptr<AbstractMatcher<TokenType>> matcher) const
|
||||||
{
|
{
|
||||||
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherOptional<TokenType>>(std::move(matcher)));
|
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherOptional<TokenType>>(std::move(matcher)));
|
||||||
}
|
}
|
||||||
|
|
||||||
_NODISCARD MatcherFactoryWrapper<TokenType> Label(const int label) const
|
[[nodiscard]] MatcherFactoryWrapper<TokenType> Label(const int label) const
|
||||||
{
|
{
|
||||||
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherLabel<TokenType>>(m_label_supplier, label));
|
return MatcherFactoryWrapper<TokenType>(std::make_unique<MatcherLabel<TokenType>>(m_label_supplier, label));
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// The highest bit is the fabricated flag
|
// The highest bit is the fabricated flag
|
||||||
constexpr size_t FABRICATED_FLAG_MASK = 1uz << (sizeof(size_t) * 8uz - 1uz);
|
constexpr unsigned FABRICATED_FLAG_MASK = 1u << (sizeof(unsigned) * 8u - 1u);
|
||||||
constexpr size_t TOKEN_INDEX_MASK = ~FABRICATED_FLAG_MASK;
|
constexpr unsigned TOKEN_INDEX_MASK = ~FABRICATED_FLAG_MASK;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
MatcherResultTokenIndex::MatcherResultTokenIndex(const size_t index, const bool isFabricated)
|
MatcherResultTokenIndex::MatcherResultTokenIndex(const unsigned index, const bool isFabricated)
|
||||||
{
|
{
|
||||||
m_token_index = index & TOKEN_INDEX_MASK;
|
m_token_index = index & TOKEN_INDEX_MASK;
|
||||||
if (isFabricated)
|
if (isFabricated)
|
||||||
@ -19,7 +19,7 @@ bool MatcherResultTokenIndex::IsFabricated() const
|
|||||||
return m_token_index & FABRICATED_FLAG_MASK;
|
return m_token_index & FABRICATED_FLAG_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t MatcherResultTokenIndex::GetTokenIndex() const
|
unsigned MatcherResultTokenIndex::GetTokenIndex() const
|
||||||
{
|
{
|
||||||
return m_token_index & TOKEN_INDEX_MASK;
|
return m_token_index & TOKEN_INDEX_MASK;
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,12 @@
|
|||||||
class MatcherResultTokenIndex
|
class MatcherResultTokenIndex
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MatcherResultTokenIndex(size_t index, bool isFabricated);
|
MatcherResultTokenIndex(unsigned index, bool isFabricated);
|
||||||
[[nodiscard]] bool IsFabricated() const;
|
[[nodiscard]] bool IsFabricated() const;
|
||||||
[[nodiscard]] size_t GetTokenIndex() const;
|
[[nodiscard]] unsigned GetTokenIndex() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t m_token_index;
|
unsigned m_token_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MatcherResultCapture
|
class MatcherResultCapture
|
||||||
@ -54,8 +54,9 @@ public:
|
|||||||
for (const auto& capture : other.m_captures)
|
for (const auto& capture : other.m_captures)
|
||||||
{
|
{
|
||||||
if (capture.m_token_index.IsFabricated())
|
if (capture.m_token_index.IsFabricated())
|
||||||
m_captures.emplace_back(capture.GetCaptureId(),
|
m_captures.emplace_back(
|
||||||
MatcherResultTokenIndex(m_fabricated_tokens.size() + capture.m_token_index.GetTokenIndex(), true));
|
capture.GetCaptureId(),
|
||||||
|
MatcherResultTokenIndex(static_cast<unsigned>(m_fabricated_tokens.size()) + capture.m_token_index.GetTokenIndex(), true));
|
||||||
else
|
else
|
||||||
m_captures.emplace_back(capture.GetCaptureId(), capture.m_token_index);
|
m_captures.emplace_back(capture.GetCaptureId(), capture.m_token_index);
|
||||||
}
|
}
|
||||||
@ -63,7 +64,7 @@ public:
|
|||||||
for (const auto& token : other.m_matched_tokens)
|
for (const auto& token : other.m_matched_tokens)
|
||||||
{
|
{
|
||||||
if (token.IsFabricated())
|
if (token.IsFabricated())
|
||||||
m_matched_tokens.emplace_back(m_fabricated_tokens.size() + token.GetTokenIndex(), true);
|
m_matched_tokens.emplace_back(static_cast<unsigned>(m_fabricated_tokens.size()) + token.GetTokenIndex(), true);
|
||||||
else
|
else
|
||||||
m_matched_tokens.emplace_back(token.GetTokenIndex(), false);
|
m_matched_tokens.emplace_back(token.GetTokenIndex(), false);
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ std::unique_ptr<ISimpleExpression> SimpleExpressionMatchers::ProcessExpression(S
|
|||||||
if (operationIndex < 0 || operationIndex >= static_cast<int>(SimpleBinaryOperationId::COUNT))
|
if (operationIndex < 0 || operationIndex >= static_cast<int>(SimpleBinaryOperationId::COUNT))
|
||||||
throw ParsingException(TokenPos(), "Invalid binary operation id @ Expression");
|
throw ParsingException(TokenPos(), "Invalid binary operation id @ Expression");
|
||||||
|
|
||||||
operators.emplace_back(operators.size(), SimpleExpressionBinaryOperationType::ALL_OPERATION_TYPES[operationIndex]);
|
operators.emplace_back(static_cast<unsigned>(operators.size()), SimpleExpressionBinaryOperationType::ALL_OPERATION_TYPES[operationIndex]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
@ -10,17 +10,17 @@ class SimpleMatcherFactory : public AbstractMatcherFactory<SimpleParserValue>
|
|||||||
public:
|
public:
|
||||||
explicit SimpleMatcherFactory(const IMatcherForLabelSupplier<SimpleParserValue>* labelSupplier);
|
explicit SimpleMatcherFactory(const IMatcherForLabelSupplier<SimpleParserValue>* labelSupplier);
|
||||||
|
|
||||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Type(SimpleParserValueType type) const;
|
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> Type(SimpleParserValueType type) const;
|
||||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Keyword(std::string value) const;
|
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> Keyword(std::string value) const;
|
||||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> KeywordIgnoreCase(std::string value) const;
|
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> KeywordIgnoreCase(std::string value) const;
|
||||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> KeywordPrefix(std::string value) const;
|
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> KeywordPrefix(std::string value) const;
|
||||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Identifier() const;
|
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> Identifier() const;
|
||||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> String() const;
|
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> String() const;
|
||||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Integer() const;
|
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> Integer() const;
|
||||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> IntegerWithSign() const;
|
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> IntegerWithSign() const;
|
||||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> FloatingPoint() const;
|
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> FloatingPoint() const;
|
||||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> FloatingPointWithSign() const;
|
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> FloatingPointWithSign() const;
|
||||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Char(char c) const;
|
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> Char(char c) const;
|
||||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> MultiChar(int multiCharacterSequenceId) const;
|
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> MultiChar(int multiCharacterSequenceId) const;
|
||||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> AnyCharBesides(std::vector<char> chars) const;
|
[[nodiscard]] MatcherFactoryWrapper<SimpleParserValue> AnyCharBesides(std::vector<char> chars) const;
|
||||||
};
|
};
|
||||||
|
@ -79,7 +79,7 @@ bool SimpleLexer::ReadMultiCharacterToken(const MultiCharacterTokenLookupEntry*
|
|||||||
linePos++;
|
linePos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_current_line_offset = m_current_line_offset - 1 + multiTokenLookup->m_value.size();
|
m_current_line_offset = m_current_line_offset - 1 + static_cast<unsigned>(multiTokenLookup->m_value.size());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ bool ArgumentParser::ParseArguments(std::vector<std::string>& args)
|
|||||||
m_matched_options[matchedOption] = std::vector<std::string>();
|
m_matched_options[matchedOption] = std::vector<std::string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto parameterCount = matchedOption->m_parameters.size();
|
const auto parameterCount = static_cast<unsigned>(matchedOption->m_parameters.size());
|
||||||
if (argIndex + parameterCount >= argCount)
|
if (argIndex + parameterCount >= argCount)
|
||||||
{
|
{
|
||||||
std::cout << std::format("Not enough parameters for option '{}'.\n", arg);
|
std::cout << std::format("Not enough parameters for option '{}'.\n", arg);
|
||||||
|
@ -130,7 +130,7 @@ bool CommandsParserState::GetTypenameAndMembersFromTypename(const std::string& t
|
|||||||
|
|
||||||
if (foundDefinition == nullptr)
|
if (foundDefinition == nullptr)
|
||||||
{
|
{
|
||||||
currentSeparatorPos = typeNameValue.size();
|
currentSeparatorPos = static_cast<unsigned>(typeNameValue.size());
|
||||||
foundDefinition = m_repository->GetDataDefinitionByName(typeNameValue);
|
foundDefinition = m_repository->GetDataDefinitionByName(typeNameValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@ std::unique_ptr<IEvaluation>
|
|||||||
operands.emplace_back(std::move(firstStatementPart));
|
operands.emplace_back(std::move(firstStatementPart));
|
||||||
|
|
||||||
if (result.PeekAndRemoveIfTag(TAG_EVALUATION_OPERATION) == TAG_EVALUATION_OPERATION)
|
if (result.PeekAndRemoveIfTag(TAG_EVALUATION_OPERATION) == TAG_EVALUATION_OPERATION)
|
||||||
operators.emplace_back(operators.size(), result.NextCapture(CAPTURE_BINARY_OPERATION_TYPE).OpTypeValue());
|
operators.emplace_back(static_cast<unsigned>(operators.size()), result.NextCapture(CAPTURE_BINARY_OPERATION_TYPE).OpTypeValue());
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user