diff --git a/src/ZoneCodeGenerator/Parsing/C_Header/Impl/HeaderParserState.cs b/src/ZoneCodeGenerator/Parsing/C_Header/Impl/HeaderParserState.cs index 28d480af..9cfecacd 100644 --- a/src/ZoneCodeGenerator/Parsing/C_Header/Impl/HeaderParserState.cs +++ b/src/ZoneCodeGenerator/Parsing/C_Header/Impl/HeaderParserState.cs @@ -11,7 +11,7 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl class HeaderParserState : IHeaderParserState { private const int DefaultPack = 8; - + private readonly Block defaultBlock; private readonly Stack packStack; private readonly Stack blockStack; @@ -78,8 +78,9 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl { var existingForwardDeclaration = forwardDeclarations[forwardDeclaration.FullName]; - if(existingForwardDeclaration.Type != forwardDeclaration.Type) - throw new ParserException($"Forward declaration of type '{forwardDeclaration.FullName}' already done with different type."); + if (existingForwardDeclaration.Type != forwardDeclaration.Type) + throw new ParserException( + $"Forward declaration of type '{forwardDeclaration.FullName}' already done with different type."); } else { @@ -91,7 +92,8 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl { var currentNamespaceTypename = Namespace.Combine(CurrentNamespace, typename); - var baseType = DataTypeBaseType.BASE_TYPES.FirstOrDefault(databaseBaseType => databaseBaseType.Name.Equals(typename)); + var baseType = + DataTypeBaseType.BASE_TYPES.FirstOrDefault(databaseBaseType => databaseBaseType.Name.Equals(typename)); if (baseType != null) return baseType; @@ -100,7 +102,7 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl { return dataTypes[typename]; } - + if (dataTypes.ContainsKey(currentNamespaceTypename)) { return dataTypes[currentNamespaceTypename]; @@ -121,7 +123,7 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl public EnumMember FindEnumMember(string enumMemberName) { - foreach(var block in blockStack) + foreach (var block in blockStack) { if (!(block is BlockEnum blockEnum)) continue; @@ -147,7 +149,7 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl private void ResolveForwardDeclarations() { - foreach(var forwardDeclaration in forwardDeclarations.Values) + foreach (var forwardDeclaration in forwardDeclarations.Values) { var foundType = FindType(forwardDeclaration.FullName); @@ -159,19 +161,25 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl foreach (var dataType in dataTypes.Values) { - if (!(dataType is DataTypeWithMembers dataTypeWithMembers)) continue; - - foreach (var variable in dataTypeWithMembers.Members) + if (dataType is DataTypeWithMembers dataTypeWithMembers) { - if (variable.VariableType.Type is ForwardDeclaration forwardDeclaration) - variable.VariableType.Type = forwardDeclaration.ForwardedType; + foreach (var variable in dataTypeWithMembers.Members) + { + if (variable.VariableType.Type is ForwardDeclaration forwardDeclaration) + variable.VariableType.Type = forwardDeclaration.ForwardedType; + } + } + else if (dataType is DataTypeTypedef typeDef) + { + if (typeDef.TypeDefinition.Type is ForwardDeclaration forwardDeclaration) + typeDef.TypeDefinition.Type = forwardDeclaration.ForwardedType; } } } public void FinishAndSaveTo(IDataRepository dataRepository) { - if(blockStack.Count > 0) + if (blockStack.Count > 0) throw new ParserException($"Parsing finished but {blockStack.Count} blocks were not closed."); ResolveForwardDeclarations(); @@ -205,4 +213,4 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Impl return CurrentBlock.GetAvailableTests(); } } -} +} \ No newline at end of file diff --git a/src/ZoneCodeGenerator/Persistence/InMemoryDataRepository.cs b/src/ZoneCodeGenerator/Persistence/InMemoryDataRepository.cs index 2b1f010f..720272eb 100644 --- a/src/ZoneCodeGenerator/Persistence/InMemoryDataRepository.cs +++ b/src/ZoneCodeGenerator/Persistence/InMemoryDataRepository.cs @@ -112,7 +112,14 @@ namespace ZoneCodeGenerator.Persistence { StructureInformation memberStructureInformation = null; - if (member.VariableType.Type is DataTypeWithMembers memberType) + var memberDataType = member.VariableType.Type; + + while (memberDataType is DataTypeTypedef typedef) + { + memberDataType = typedef.TypeDefinition.Type; + } + + if (memberDataType is DataTypeWithMembers memberType) { memberStructureInformation = GetInformationFor(memberType); }