2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-07-01 16:51:56 +00:00

create enum definitions from headers

This commit is contained in:
Jan
2021-02-18 17:15:46 +01:00
parent 3c1599c1a0
commit 5d5fc86923
34 changed files with 350 additions and 163 deletions

View File

@ -1,6 +1,6 @@
#include "SequenceCloseBlock.h"
#include "Parsing/Header/Block/IHeaderBlockVariableDefining.h"
#include "Parsing/Header/Block/IHeaderBlockNameHolder.h"
#include "Parsing/Header/Matcher/HeaderMatcherFactory.h"
#include "Parsing/Header/Matcher/HeaderCommonMatchers.h"
@ -22,7 +22,7 @@ void SequenceCloseBlock::ProcessMatch(HeaderParserState* state, SequenceResult<H
{
if (result.NextTag() == TAG_SEMICOLON)
{
if(!m_semicolon_required)
if (!m_semicolon_required)
throw ParsingException(result.NextCapture(CAPTURE_CLOSING_PARENTHESIS).GetPos(), "Block should not be closed with semicolon");
}
else
@ -33,13 +33,13 @@ void SequenceCloseBlock::ProcessMatch(HeaderParserState* state, SequenceResult<H
if (result.HasNextCapture(CAPTURE_NAME))
{
auto* variableDefiningBlock = dynamic_cast<IHeaderBlockVariableDefining*>(state->GetBlock());
auto* variableDefiningBlock = dynamic_cast<IHeaderBlockNameHolder*>(state->GetBlock());
const auto& name = result.NextCapture(CAPTURE_NAME);
if (variableDefiningBlock == nullptr)
throw ParsingException(name.GetPos(), "Block does not support holding names.");
variableDefiningBlock->SetVariableName(name.IdentifierValue());
variableDefiningBlock->SetBlockName(name.GetPos(), name.IdentifierValue());
}
state->PopBlock();

View File

@ -23,5 +23,27 @@ SequenceEnum::SequenceEnum()
void SequenceEnum::ProcessMatch(HeaderParserState* state, SequenceResult<HeaderParserValue>& result) const
{
state->PushBlock(std::make_unique<HeaderBlockEnum>());
auto isTypedef = result.PeekAndRemoveIfTag(TAG_TYPEDEF) == TAG_TYPEDEF;
std::string name;
const auto* parentType = BaseTypeDefinition::INT;
if (result.HasNextCapture(CAPTURE_NAME))
name = result.NextCapture(CAPTURE_NAME).IdentifierValue();
if(result.HasNextCapture(CAPTURE_PARENT_TYPE))
{
const auto& typeNameToken = result.NextCapture(CAPTURE_PARENT_TYPE);
const auto* foundTypeDefinition = state->FindType(typeNameToken.TypeNameValue());
if (foundTypeDefinition == nullptr)
throw ParsingException(typeNameToken.GetPos(), "Cannot find type");
while (foundTypeDefinition->GetType() == DataDefinitionType::TYPEDEF)
foundTypeDefinition = dynamic_cast<const TypedefDefinition*>(foundTypeDefinition)->m_type_declaration->m_type;
if (foundTypeDefinition->GetType() != DataDefinitionType::BASE_TYPE)
throw ParsingException(typeNameToken.GetPos(), "Enums can only have base types as parent type");
}
state->PushBlock(std::make_unique<HeaderBlockEnum>(name, parentType, isTypedef));
}