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:
@ -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();
|
||||
|
@ -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));
|
||||
}
|
||||
|
Reference in New Issue
Block a user