ソースを参照

Structs don't actually extend from Object.

woollybah 6 年 前
コミット
d220a4b610
4 ファイル変更36 行追加21 行削除
  1. 23 19
      ctranslator.bmx
  2. 11 0
      decl.bmx
  3. 1 1
      options.bmx
  4. 1 1
      parser.bmx

+ 23 - 19
ctranslator.bmx

@@ -3960,23 +3960,25 @@ End Rem
 	
 			EmitClassDeclNewList(classDecl)
 			
-			' process nested functions for delete
-			decl = classDecl.FindFuncDecl("delete",,,,,,SCOPE_CLASS_HEIRARCHY)
-			If decl Then
-				decl.Semant
-				' emit nested protos
-				For Local fdecl:TFuncDecl = EachIn decl._decls
-					EmitFuncDecl(fdecl, True, False)
-				Next
-				
-				' emit nested bodies
-				For Local fdecl:TFuncDecl = EachIn decl._decls
-					EmitFuncDecl(fdecl, False, False)
-				Next
-			End If
-	
-			If classHierarchyHasFunction(classDecl, "Delete") Then
-				EmitClassDeclDelete(classDecl)
+			If Not (classDecl.attrs & CLASS_STRUCT) Then
+				' process nested functions for delete
+				decl = classDecl.FindFuncDecl("delete",,,,,,SCOPE_CLASS_HEIRARCHY)
+				If decl Then
+					decl.Semant
+					' emit nested protos
+					For Local fdecl:TFuncDecl = EachIn decl._decls
+						EmitFuncDecl(fdecl, True, False)
+					Next
+					
+					' emit nested bodies
+					For Local fdecl:TFuncDecl = EachIn decl._decls
+						EmitFuncDecl(fdecl, False, False)
+					Next
+				End If
+		
+				If classHierarchyHasFunction(classDecl, "Delete") Then
+					EmitClassDeclDelete(classDecl)
+				End If
 			End If
 	
 			Rem
@@ -4304,7 +4306,10 @@ End Rem
 	
 	Method EmitClassDeclNew( classDecl:TClassDecl, fdecl:TFuncDecl )
 		Local classid$=classDecl.munged
-		Local superid$=classDecl.superClass.actual.munged
+		Local superid$
+		If classDecl.superClass Then
+			superid = classDecl.superClass.actual.munged
+		End If
 
 		Local t:String = "void _" 
 		
@@ -4447,7 +4452,6 @@ End Rem
 
 	Method EmitClassDeclNewList( classDecl:TClassDecl )
 		Local classid$=classDecl.munged
-		Local superid$=classDecl.superClass.actual.munged
 
 		Local newDecls:TFuncDeclList = TFuncDeclList(classdecl.FindDeclList("new", True,,,True))
 		

+ 11 - 0
decl.bmx

@@ -3032,6 +3032,17 @@ End Rem
 			End If
 		Next
 
+		' structs have a default New
+		' if we haven't defined one, create one
+		If attrs & CLASS_STRUCT Then
+			Local func:TFuncDecl = FindFuncDecl("new", Null,True,,,,0)
+			If Not func Then
+				func = New TNewDecl.CreateF("New", Null, Null, FUNC_CTOR | FUNC_METHOD)
+				TNewDecl(func).cdecl = Self
+				InsertDecl(func)
+			End If
+		End If
+		
 		'NOTE: do this AFTER super semant so UpdateAttrs order is cool.
 
 		If AppScope() Then

+ 1 - 1
options.bmx

@@ -25,7 +25,7 @@ SuperStrict
 
 Import "base.configmap.bmx"
 
-Const version:String = "0.101"
+Const version:String = "0.102"
 
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_MODULE:Int = 1

+ 1 - 1
parser.bmx

@@ -3115,7 +3115,7 @@ End Rem
 				superTy=ParseIdentType()
 			EndIf
 		Else
-			If Not (attrs & DECL_EXTERN) Then
+			If Not (attrs & DECL_EXTERN) And Not (attrs & CLASS_STRUCT) Then
 				superTy=New TIdentType.Create( "brl.classes.object" )
 			End If
 		EndIf