@@ -21,8 +21,8 @@ public enum ImportResult
2121 private readonly Dictionary < string , CompilationUnity > importTable ;
2222 private readonly List < GlobalVariable > globals ;
2323 private readonly Dictionary < string , GlobalVariable > globalTable ;
24- private readonly List < StructType > structs ;
25- private readonly Dictionary < string , StructType > structTable ;
24+ private readonly List < FieldAggregationType > fieldAggregations ;
25+ private readonly Dictionary < string , FieldAggregationType > fieldAggregationTable ;
2626 private readonly List < TypeSetType > typeSets ;
2727 private readonly Dictionary < string , TypeSetType > typeSetTable ;
2828 private readonly List < Function > functions ;
@@ -66,7 +66,7 @@ public int GlobalVariableSize
6666 private set ;
6767 }
6868
69- public int StructCount => structs . Count ;
69+ public int FieldAggregationCount => fieldAggregations . Count ;
7070
7171 public int TypeSetCount => typeSets . Count ;
7272
@@ -99,8 +99,8 @@ internal CompilationUnity(Compiler compiler, string name, string fileName, bool
9999 importTable = new ( ) ;
100100 globals = new ( ) ;
101101 globalTable = new ( ) ;
102- structs = new ( ) ;
103- structTable = new ( ) ;
102+ fieldAggregations = new ( ) ;
103+ fieldAggregationTable = new ( ) ;
104104 typeSets = new ( ) ;
105105 typeSetTable = new ( ) ;
106106 functions = new ( ) ;
@@ -216,16 +216,16 @@ internal GlobalVariable DeclareGlobalVariable(string name, AbstractType type, So
216216 return result ;
217217 }
218218
219- public StructType FindStruct ( string name , bool searchInImports = true )
219+ public FieldAggregationType FindFieldAggregation ( string name , bool searchInImports = true )
220220 {
221- if ( structTable . TryGetValue ( name , out StructType result ) )
221+ if ( fieldAggregationTable . TryGetValue ( name , out FieldAggregationType result ) )
222222 return result ;
223223
224224 if ( searchInImports )
225225 {
226226 foreach ( CompilationUnity unity in imports )
227227 {
228- result = unity . FindStruct ( name , false ) ;
228+ result = unity . FindFieldAggregation ( name , false ) ;
229229 if ( result != null )
230230 return result ;
231231 }
@@ -234,9 +234,9 @@ public StructType FindStruct(string name, bool searchInImports = true)
234234 return null ;
235235 }
236236
237- public StructType GetStruct ( int index )
237+ public FieldAggregationType GeFieldAggregation ( int index )
238238 {
239- return structs [ index ] ;
239+ return fieldAggregations [ index ] ;
240240 }
241241
242242 internal StructType DeclareStruct ( string name , SourceInterval interval )
@@ -246,8 +246,20 @@ internal StructType DeclareStruct(string name, SourceInterval interval)
246246 return null ;
247247
248248 StructType result = new ( this , name , interval ) ;
249- structs . Add ( result ) ;
250- structTable . Add ( name , result ) ;
249+ fieldAggregations . Add ( result ) ;
250+ fieldAggregationTable . Add ( name , result ) ;
251+ return result ;
252+ }
253+
254+ internal ClassType DeclareClass ( string name , SourceInterval interval )
255+ {
256+ NamedType nt = FindNamedType ( name ) ;
257+ if ( nt != null )
258+ return null ;
259+
260+ ClassType result = new ( this , name , interval ) ;
261+ fieldAggregations . Add ( result ) ;
262+ fieldAggregationTable . Add ( name , result ) ;
251263 return result ;
252264 }
253265
@@ -288,7 +300,7 @@ internal TypeSetType DeclareTypeSet(string name, AbstractType type, SourceInterv
288300
289301 public NamedType FindNamedType ( string name )
290302 {
291- StructType st = FindStruct ( name ) ;
303+ FieldAggregationType st = FindFieldAggregation ( name ) ;
292304 return st != null ? st : FindTypeSet ( name ) ;
293305 }
294306
@@ -310,13 +322,13 @@ public Function FindFunction(string name, bool searchInImports = true)
310322 return null ;
311323 }
312324
313- internal Function DeclareFunction ( string name , SourceInterval interval , bool isExtern )
325+ internal Function DeclareFunction ( FieldAggregationType declaringType , string name , SourceInterval interval , bool isExtern )
314326 {
315327 Function result = FindFunction ( name ) ;
316328 if ( result != null )
317329 return null ;
318330
319- result = new Function ( this , name , interval , isExtern ) ;
331+ result = new Function ( this , declaringType , name , interval , isExtern ) ;
320332 functions . Add ( result ) ;
321333 functionTable . Add ( name , result ) ;
322334 return result ;
@@ -347,6 +359,7 @@ public UnresolvedType GetUndeclaredType(int index)
347359 internal void Compile ( Assembler assembler )
348360 {
349361 Compiler . unity = this ;
362+ Compiler . declaringType = null ;
350363
351364 GlobalStartOffset = Compiler . globalVariableOffset ;
352365
@@ -373,12 +386,12 @@ internal void Resolve()
373386 {
374387 foreach ( UnresolvedType type in undeclaredTypes )
375388 {
376- StructType st = FindStruct ( type . Name ) ;
389+ FieldAggregationType st = FindFieldAggregation ( type . Name ) ;
377390
378391 type . ReferencedType = st ?? throw new CompilerException ( type . Interval , $ "Tipo não declarado: '{ type . Name } '.") ;
379392 }
380393
381- foreach ( StructType st in structs )
394+ foreach ( FieldAggregationType st in fieldAggregations )
382395 st . Resolve ( ) ;
383396
384397 foreach ( TypeSetType ts in typeSets )
0 commit comments