@@ -94,53 +94,65 @@ private void Process(CsStruct csStruct)
9494 if ( csStruct . IsFullyMapped )
9595 return ;
9696
97- // Set IsFullyMappy in order to avoid recursive mapping
98- csStruct . IsFullyMapped = true ;
97+ // Set IsFullyMappy in order to avoid recursive mapping
98+ csStruct . IsFullyMapped = true ;
9999
100- // Get the associated CppStruct and CSharpTag
101- var cppStruct = ( CppStruct ) csStruct . CppElement ;
102- bool hasMarshalType = csStruct . HasMarshalType ;
100+ // Get the associated CppStruct and CSharpTag
101+ var cppStruct = ( CppStruct ) csStruct . CppElement ;
102+ bool hasMarshalType = csStruct . HasMarshalType ;
103103
104- // If this structure need to me moved to another container, move it now
105- foreach ( var keyValuePair in _mapMoveStructToInner )
104+ // If this structure need to me moved to another container, move it now
105+ foreach ( var keyValuePair in _mapMoveStructToInner )
106+ {
107+ if ( keyValuePair . Key . Match ( csStruct . CppElementName ) . Success )
106108 {
107- if ( keyValuePair . Key . Match ( csStruct . CppElementName ) . Success )
108- {
109- string cppName = keyValuePair . Key . Replace ( csStruct . CppElementName , keyValuePair . Value ) ;
110- var destSharpStruct = ( CsStruct ) Manager . FindBindType ( cppName ) ;
111- // Remove the struct from his container
112- csStruct . Parent . Remove ( csStruct ) ;
113- // Add this struct to the new container struct
114- destSharpStruct . Add ( csStruct ) ;
115- }
109+ string cppName = keyValuePair . Key . Replace ( csStruct . CppElementName , keyValuePair . Value ) ;
110+ var destSharpStruct = ( CsStruct ) Manager . FindBindType ( cppName ) ;
111+ // Remove the struct from his container
112+ csStruct . Parent . Remove ( csStruct ) ;
113+ // Add this struct to the new container struct
114+ destSharpStruct . Add ( csStruct ) ;
116115 }
116+ }
117+
118+ // Current offset of a field
119+ int currentFieldAbsoluteOffset = 0 ;
117120
118- // Current offset of a field
119- int currentFieldAbsoluteOffset = 0 ;
121+ // Last field offset
122+ int previousFieldOffsetIndex = - 1 ;
120123
121- int fieldCount = cppStruct . IsEmpty ? 0 : cppStruct . Items . Count ;
124+ // Size of the last field
125+ int previousFieldSize = 0 ;
122126
127+ //
128+ int maxSizeOfField = 0 ;
123129
124- // Last field offset
125- int previousFieldOffsetIndex = - 1 ;
130+ bool isInUnion = false ;
126131
127- // Size of the last field
128- int previousFieldSize = 0 ;
132+ int cumulatedBitOffset = 0 ;
129133
130- //
131- int maxSizeOfField = 0 ;
132134
133- bool isInUnion = false ;
135+ var inheritedStructs = new Stack < CppStruct > ( ) ;
136+ var currentStruct = cppStruct ;
137+ while ( currentStruct != null && currentStruct . ParentName != currentStruct . Name )
138+ {
139+ inheritedStructs . Push ( currentStruct ) ;
140+ currentStruct = Manager . FindBindType ( currentStruct . ParentName ) ? . CppElement as CppStruct ;
141+ }
134142
135- int cumulatedBitOffset = 0 ;
143+ while ( inheritedStructs . Count > 0 )
144+ {
145+ currentStruct = inheritedStructs . Pop ( ) ;
146+
147+ int fieldCount = currentStruct . IsEmpty ? 0 : currentStruct . Items . Count ;
136148
137149 // -------------------------------------------------------------------------------
138150 // Iterate on all fields and perform mapping
139151 // -------------------------------------------------------------------------------
140152 for ( int fieldIndex = 0 ; fieldIndex < fieldCount ; fieldIndex ++ )
141153 {
142- var cppField = ( CppField ) cppStruct . Items [ fieldIndex ] ;
143- Logger . RunInContext ( cppField . ToString ( ) , ( ) =>
154+ var cppField = ( CppField ) currentStruct . Items [ fieldIndex ] ;
155+ Logger . RunInContext ( cppField . ToString ( ) , ( ) =>
144156 {
145157 var fieldStruct = Manager . GetCsType < CsField > ( cppField , true ) ;
146158 csStruct . Add ( fieldStruct ) ;
@@ -196,9 +208,9 @@ private void Process(CsStruct csStruct)
196208
197209 var nextFieldIndex = fieldIndex + 1 ;
198210 if ( ( previousFieldOffsetIndex == cppField . Offset )
199- || ( nextFieldIndex < fieldCount && ( ( CppField ) cppStruct . Items [ nextFieldIndex ] ) . Offset == cppField . Offset ) )
211+ || ( nextFieldIndex < fieldCount && ( ( CppField ) currentStruct . Items [ nextFieldIndex ] ) . Offset == cppField . Offset ) )
200212 {
201- if ( previousFieldOffsetIndex != cppField . Offset )
213+ if ( previousFieldOffsetIndex != cppField . Offset )
202214 {
203215 maxSizeOfField = 0 ;
204216 }
@@ -214,10 +226,11 @@ private void Process(CsStruct csStruct)
214226 previousFieldOffsetIndex = cppField . Offset ;
215227 } ) ;
216228 }
229+ }
217230
218231 // In case of explicit layout, check that we can safely generate it on both x86 and x64 (in case of an union
219232 // using pointers, we can't)
220- if ( csStruct . ExplicitLayout )
233+ if ( csStruct . ExplicitLayout )
221234 {
222235 var fieldList = csStruct . Fields . ToList ( ) ;
223236 for ( int i = 0 ; i < fieldList . Count ; i ++ )
0 commit comments