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

@ -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));
}