mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
implement parsing for reusable and scriptstring and string
This commit is contained in:
parent
873c23fb56
commit
48e3738c05
@ -18,4 +18,15 @@ SequenceReusable::SequenceReusable()
|
|||||||
|
|
||||||
void SequenceReusable::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
void SequenceReusable::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||||
{
|
{
|
||||||
|
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE);
|
||||||
|
|
||||||
|
StructureInformation* type;
|
||||||
|
std::vector<MemberInformation*> members;
|
||||||
|
if (!state->GetTypenameAndMembersFromTypename(typeNameToken.TypeNameValue(), type, members))
|
||||||
|
throw ParsingException(typeNameToken.GetPos(), "Unknown type");
|
||||||
|
|
||||||
|
if (members.empty())
|
||||||
|
throw ParsingException(typeNameToken.GetPos(), "Need to specify a member when trying to mark as reusable.");
|
||||||
|
|
||||||
|
members.back()->m_is_reusable = true;
|
||||||
}
|
}
|
||||||
|
@ -18,4 +18,23 @@ SequenceScriptString::SequenceScriptString()
|
|||||||
|
|
||||||
void SequenceScriptString::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
void SequenceScriptString::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||||
{
|
{
|
||||||
|
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE);
|
||||||
|
|
||||||
|
StructureInformation* type;
|
||||||
|
std::vector<MemberInformation*> members;
|
||||||
|
if (!state->GetTypenameAndMembersFromTypename(typeNameToken.TypeNameValue(), type, members))
|
||||||
|
throw ParsingException(typeNameToken.GetPos(), "Unknown type");
|
||||||
|
|
||||||
|
if (members.empty())
|
||||||
|
throw ParsingException(typeNameToken.GetPos(), "Need to specify a member when trying to mark as script string.");
|
||||||
|
|
||||||
|
auto* lastMember = members.back();
|
||||||
|
const auto* dataDef = lastMember->m_member->m_type_declaration->m_type;
|
||||||
|
while (dataDef->GetType() == DataDefinitionType::TYPEDEF)
|
||||||
|
dataDef = dynamic_cast<const TypedefDefinition*>(dataDef)->m_type_declaration->m_type;
|
||||||
|
|
||||||
|
if (dataDef->GetType() != DataDefinitionType::BASE_TYPE)
|
||||||
|
throw ParsingException(typeNameToken.GetPos(), "Invalid type for script string, must be a base type");
|
||||||
|
|
||||||
|
members.back()->m_is_script_string = true;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#include "SequenceString.h"
|
#include "SequenceString.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||||
|
|
||||||
@ -18,4 +21,45 @@ SequenceString::SequenceString()
|
|||||||
|
|
||||||
void SequenceString::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
void SequenceString::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||||
{
|
{
|
||||||
|
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE);
|
||||||
|
|
||||||
|
StructureInformation* type;
|
||||||
|
std::vector<MemberInformation*> members;
|
||||||
|
if (!state->GetTypenameAndMembersFromTypename(typeNameToken.TypeNameValue(), type, members))
|
||||||
|
throw ParsingException(typeNameToken.GetPos(), "Unknown type");
|
||||||
|
|
||||||
|
if (members.empty())
|
||||||
|
throw ParsingException(typeNameToken.GetPos(), "Need to specify a member when trying to mark as string.");
|
||||||
|
|
||||||
|
auto* lastMember = members.back();
|
||||||
|
auto* typeDecl = lastMember->m_member->m_type_declaration.get();
|
||||||
|
auto hasPointerRef = false;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (!hasPointerRef)
|
||||||
|
{
|
||||||
|
const auto& modifiers = typeDecl->m_declaration_modifiers;
|
||||||
|
hasPointerRef = std::any_of(modifiers.begin(), modifiers.end(), [](const std::unique_ptr<DeclarationModifier>& modifier)
|
||||||
|
{
|
||||||
|
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeDecl->m_type->GetType() == DataDefinitionType::TYPEDEF)
|
||||||
|
{
|
||||||
|
const auto* typedefDef = dynamic_cast<const TypedefDefinition*>(typeDecl->m_type);
|
||||||
|
typeDecl = typedefDef->m_type_declaration.get();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasPointerRef)
|
||||||
|
throw ParsingException(typeNameToken.GetPos(), "Invalid type for string, must be a pointer");
|
||||||
|
|
||||||
|
if (typeDecl->m_type->GetType() != DataDefinitionType::BASE_TYPE)
|
||||||
|
throw ParsingException(typeNameToken.GetPos(), "Invalid type for string, must be a base type");
|
||||||
|
|
||||||
|
lastMember->m_is_string = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user