mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
handle variable defines in child block close
This commit is contained in:
parent
fb55cdb468
commit
f0753c7e3c
@ -12,7 +12,8 @@ HeaderBlockStruct::HeaderBlockStruct(std::string name, const bool isTypedef)
|
|||||||
m_struct_definition(nullptr),
|
m_struct_definition(nullptr),
|
||||||
m_custom_alignment(0),
|
m_custom_alignment(0),
|
||||||
m_is_typedef(isTypedef),
|
m_is_typedef(isTypedef),
|
||||||
m_has_custom_align(false)
|
m_has_custom_align(false),
|
||||||
|
m_is_anonymous(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,27 +39,26 @@ void HeaderBlockStruct::OnOpen(HeaderParserState* state)
|
|||||||
{
|
{
|
||||||
m_namespace = state->m_namespace.ToString();
|
m_namespace = state->m_namespace.ToString();
|
||||||
|
|
||||||
if (!m_type_name.empty())
|
if (m_type_name.empty())
|
||||||
|
{
|
||||||
|
m_is_anonymous = true;
|
||||||
|
m_type_name = NameUtils::GenerateRandomName();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
state->m_namespace.Push(m_type_name);
|
state->m_namespace.Push(m_type_name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HeaderBlockStruct::OnClose(HeaderParserState* state)
|
void HeaderBlockStruct::OnClose(HeaderParserState* state)
|
||||||
{
|
{
|
||||||
if (!m_type_name.empty())
|
if (!m_is_anonymous)
|
||||||
state->m_namespace.Pop();
|
state->m_namespace.Pop();
|
||||||
|
|
||||||
auto isAnonymous = false;
|
auto structDefinition = std::make_unique<StructDefinition>(m_namespace, m_type_name, state->m_pack_value_supplier->GetCurrentPack());
|
||||||
auto typeName = m_type_name;
|
|
||||||
if(typeName.empty())
|
|
||||||
{
|
|
||||||
isAnonymous = true;
|
|
||||||
typeName = NameUtils::GenerateRandomName();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto structDefinition = std::make_unique<StructDefinition>(m_namespace, std::move(typeName), state->m_pack_value_supplier->GetCurrentPack());
|
|
||||||
m_struct_definition = structDefinition.get();
|
m_struct_definition = structDefinition.get();
|
||||||
|
|
||||||
if (isAnonymous)
|
if (m_is_anonymous)
|
||||||
structDefinition->m_anonymous = true;
|
structDefinition->m_anonymous = true;
|
||||||
|
|
||||||
for (auto& member : m_members)
|
for (auto& member : m_members)
|
||||||
@ -72,6 +72,10 @@ void HeaderBlockStruct::OnClose(HeaderParserState* state)
|
|||||||
|
|
||||||
void HeaderBlockStruct::OnChildBlockClose(HeaderParserState* state, IHeaderBlock* block)
|
void HeaderBlockStruct::OnChildBlockClose(HeaderParserState* state, IHeaderBlock* block)
|
||||||
{
|
{
|
||||||
|
auto* variableDefining = dynamic_cast<IHeaderBlockVariableDefining*>(block);
|
||||||
|
|
||||||
|
if (variableDefining && variableDefining->IsDefiningVariable())
|
||||||
|
m_members.emplace_back(std::make_shared<Variable>(variableDefining->GetVariableName(), std::make_unique<TypeDeclaration>(variableDefining->GetVariableType())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeaderBlockStruct::AddVariable(std::shared_ptr<Variable> variable)
|
void HeaderBlockStruct::AddVariable(std::shared_ptr<Variable> variable)
|
||||||
|
@ -19,6 +19,7 @@ class HeaderBlockStruct final : public IHeaderBlock, public IHeaderBlockNameHold
|
|||||||
|
|
||||||
bool m_is_typedef;
|
bool m_is_typedef;
|
||||||
bool m_has_custom_align;
|
bool m_has_custom_align;
|
||||||
|
bool m_is_anonymous;
|
||||||
|
|
||||||
std::string m_variable_name;
|
std::string m_variable_name;
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ HeaderBlockUnion::HeaderBlockUnion(std::string name, const bool isTypedef)
|
|||||||
m_union_definition(nullptr),
|
m_union_definition(nullptr),
|
||||||
m_custom_alignment(0),
|
m_custom_alignment(0),
|
||||||
m_is_typedef(isTypedef),
|
m_is_typedef(isTypedef),
|
||||||
m_has_custom_align(false)
|
m_has_custom_align(false),
|
||||||
|
m_is_anonymous(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,27 +39,26 @@ void HeaderBlockUnion::OnOpen(HeaderParserState* state)
|
|||||||
{
|
{
|
||||||
m_namespace = state->m_namespace.ToString();
|
m_namespace = state->m_namespace.ToString();
|
||||||
|
|
||||||
if (!m_type_name.empty())
|
if (m_type_name.empty())
|
||||||
|
{
|
||||||
|
m_is_anonymous = true;
|
||||||
|
m_type_name = NameUtils::GenerateRandomName();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
state->m_namespace.Push(m_type_name);
|
state->m_namespace.Push(m_type_name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HeaderBlockUnion::OnClose(HeaderParserState* state)
|
void HeaderBlockUnion::OnClose(HeaderParserState* state)
|
||||||
{
|
{
|
||||||
if (!m_type_name.empty())
|
if (!m_is_anonymous)
|
||||||
state->m_namespace.Pop();
|
state->m_namespace.Pop();
|
||||||
|
|
||||||
auto isAnonymous = false;
|
auto unionDefinition = std::make_unique<UnionDefinition>(m_namespace, m_type_name, state->m_pack_value_supplier->GetCurrentPack());
|
||||||
auto typeName = m_type_name;
|
|
||||||
if (typeName.empty())
|
|
||||||
{
|
|
||||||
isAnonymous = true;
|
|
||||||
typeName = NameUtils::GenerateRandomName();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto unionDefinition = std::make_unique<UnionDefinition>(m_namespace, std::move(typeName), state->m_pack_value_supplier->GetCurrentPack());
|
|
||||||
m_union_definition = unionDefinition.get();
|
m_union_definition = unionDefinition.get();
|
||||||
|
|
||||||
if (isAnonymous)
|
if (m_is_anonymous)
|
||||||
unionDefinition->m_anonymous = true;
|
unionDefinition->m_anonymous = true;
|
||||||
|
|
||||||
for (auto& member : m_members)
|
for (auto& member : m_members)
|
||||||
@ -72,6 +72,10 @@ void HeaderBlockUnion::OnClose(HeaderParserState* state)
|
|||||||
|
|
||||||
void HeaderBlockUnion::OnChildBlockClose(HeaderParserState* state, IHeaderBlock* block)
|
void HeaderBlockUnion::OnChildBlockClose(HeaderParserState* state, IHeaderBlock* block)
|
||||||
{
|
{
|
||||||
|
auto* variableDefining = dynamic_cast<IHeaderBlockVariableDefining*>(block);
|
||||||
|
|
||||||
|
if (variableDefining && variableDefining->IsDefiningVariable())
|
||||||
|
m_members.emplace_back(std::make_shared<Variable>(variableDefining->GetVariableName(), std::make_unique<TypeDeclaration>(variableDefining->GetVariableType())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeaderBlockUnion::AddVariable(std::shared_ptr<Variable> variable)
|
void HeaderBlockUnion::AddVariable(std::shared_ptr<Variable> variable)
|
||||||
|
@ -15,6 +15,7 @@ class HeaderBlockUnion final : public IHeaderBlock, public IHeaderBlockNameHolde
|
|||||||
|
|
||||||
bool m_is_typedef;
|
bool m_is_typedef;
|
||||||
bool m_has_custom_align;
|
bool m_has_custom_align;
|
||||||
|
bool m_is_anonymous;
|
||||||
|
|
||||||
std::string m_variable_name;
|
std::string m_variable_name;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user