Browse Source

Reworked inner type instance creation. Fixes #318

woollybah 7 years ago
parent
commit
6e22c31145
3 changed files with 38 additions and 17 deletions
  1. 0 9
      config.bmx
  2. 27 3
      decl.bmx
  3. 11 5
      parser.bmx

+ 0 - 9
config.bmx

@@ -472,15 +472,6 @@ Type TTemplateRecord
 	End Function
 End Type
 
-Type TGenProcessor Abstract
-
-	Global processor:TGenProcessor
-
-	Method ParseGeneric:Object(templ:TTemplateRecord)
-	End Method
-	
-End Type
-
 Type TCallback
 	Method Callback(obj:Object) Abstract
 End Type

+ 27 - 3
decl.bmx

@@ -1145,7 +1145,7 @@ Type TScopeDecl Extends TDecl
 			If cdecl
 				cdecl.AssertAccess
 				If Not cdecl.instanceof Then
-					cdecl=cdecl.GenClassInstance( args, False, callback )
+					cdecl=cdecl.GenClassInstance( args, False, callback, Null )
 					cdecl.Semant
 				End If
 				Return cdecl.objectType
@@ -2286,7 +2286,7 @@ Rem
 		Return inst
 	End Method
 End Rem
-	Method GenClassInstance:TClassDecl( instArgs:TType[], declImported:Int = False, callback:TCallback = Null )
+	Method GenClassInstance:TClassDecl( instArgs:TType[], declImported:Int = False, callback:TCallback = Null, templateDets:TTemplateDets = Null )
 
 		If instanceof InternalErr
 		
@@ -2314,8 +2314,12 @@ End Rem
 			Next
 			If equal Return inst
 		Next
+		
+		If Not templateDets Then
+			templateDets = New TTemplateDets.Create(instArgs)
+		End If
 
-		Local inst:TClassDecl = TClassDecl(TGenProcessor.processor.ParseGeneric(templateSource))
+		Local inst:TClassDecl = TClassDecl(TGenProcessor.processor.ParseGeneric(templateSource, templateDets))
 		inst.ident=ident
 		inst.args=Null
 		inst.instances = Null
@@ -3661,3 +3665,23 @@ Type TStringConst
 	Field count:Int
 
 End Type
+
+Type TTemplateDets
+
+	Field instArgs:TType[]
+
+	Method Create:TTemplateDets(instArgs:TType[])
+		Self.instArgs = instArgs
+		Return Self
+	End Method
+
+End Type
+
+Type TGenProcessor Abstract
+
+	Global processor:TGenProcessor
+
+	Method ParseGeneric:Object(templ:TTemplateRecord, dets:TTemplateDets)
+	End Method
+	
+End Type

+ 11 - 5
parser.bmx

@@ -2949,7 +2949,7 @@ End Rem
 	End Method
 	
 
-	Method ParseClassDecl:TClassDecl( toke$,attrs:Int )
+	Method ParseClassDecl:TClassDecl( toke$,attrs:Int, templateDets:TTemplateDets = Null )
 		SetErr
 
 		Local calculatedStartLine:Int = _toker.Line()
@@ -3267,7 +3267,13 @@ End Rem
 				Local decl:TFuncDecl=ParseFuncDecl( _toke,decl_attrs,classDecl )
 				classDecl.InsertDecl decl
 			Case "type"
-				classDecl.InsertDecl ParseClassDecl( _toke,DECL_NESTED)
+				If templateDets Then
+					Local cdecl:TClassDecl = ParseClassDecl( _toke,DECL_NESTED, templateDets)
+					cdecl = cdecl.GenClassInstance(templateDets.instArgs, False, Null, templateDets)
+					classDecl.InsertDecl cdecl, True
+				Else
+					classDecl.InsertDecl ParseClassDecl( _toke,DECL_NESTED)
+				End If
 			Default
 				Err "Syntax error - expecting class member declaration, not '" + _toke + "'"
 			End Select
@@ -3720,7 +3726,7 @@ End Rem
 		Return attrs
 	End Method
 
-	Method ParseGeneric:Object(templateSource:TTemplateRecord)
+	Method ParseGeneric:Object(templateSource:TTemplateRecord, templateDets:TTemplateDets)
 		Local toker:TToker = New TToker.Create(templateSource.file, templateSource.source, False, templateSource.start)
 		Local parser:TParser = New TParser.Create( toker, _appInstance )
 		
@@ -3731,9 +3737,9 @@ End Rem
 		
 		Select parser._toke
 		Case "type"
-			cdecl = parser.ParseClassDecl(parser._toke,0)
+			cdecl = parser.ParseClassDecl(parser._toke,0, templateDets )
 		Case "interface"
-			cdecl = parser.ParseClassDecl(parser._toke, CLASS_INTERFACE|DECL_ABSTRACT )
+			cdecl = parser.ParseClassDecl(parser._toke, CLASS_INTERFACE|DECL_ABSTRACT, templateDets )
 		End Select
 		
 		Return cdecl