Jelajahi Sumber

Improved enum support.

woollybah 6 tahun lalu
induk
melakukan
39c3109a6a
3 mengubah file dengan 33 tambahan dan 0 penghapusan
  1. 5 0
      ctranslator.bmx
  2. 9 0
      decl.bmx
  3. 19 0
      iparser.bmx

+ 5 - 0
ctranslator.bmx

@@ -1846,6 +1846,7 @@ t:+"NULLNULLNULL"
 					Return Bra( Bra(Bra("BBObject*") + t )+"!= &bbNullObject" )
 				End If
 			End If
+			If TEnumType( src ) Return Bra( t+"!=0" )
 		Else If TIntType( dst )
 			If TBoolType( src ) Return Bra( t )
 			If TByteType( src) Return Bra("(BBINT)"+t)
@@ -5192,6 +5193,10 @@ End Rem
 			End If
 		EndIf
 
+		If TEnumType(expr.exprType) Then
+			Return Expr.Eval()
+		End If
+
 		'If TObjectType(expr.exprType) And TNullDecl(TObjectType(expr.exprType).classDecl) Then
 		'	Return Enquote("bbNullObject")
 		'End If

+ 9 - 0
decl.bmx

@@ -450,6 +450,12 @@ Type TValDecl Extends TDecl
 			PushEnv(newScope)
 		End If
 	
+		' for imported enum args with a default value, we need to set the type of the value to the enum
+		' since at this point it's just a number with no context
+		If TArgDecl(Self) And declInit And scope And scope.declImported And TEnumType(ty) Then
+			declInit = New TConstExpr.Create(ty, TConstExpr(declInit).value).Semant()
+		End If
+			
 		If declTy
 			If declInit Then
 				If TFunctionPtrType(ty) Then
@@ -699,6 +705,9 @@ Type TArgDecl Extends TLocalDecl
 			If TInvokeExpr(init) And TFunctionPtrType(TInvokeExpr(init).exprType) Then
 				Return
 			End If
+			If TIdentEnumExpr(init) Then
+				Return
+			End If
 			Err "Function defaults must be constant"
 		End If
 	End Method

+ 19 - 0
iparser.bmx

@@ -719,6 +719,7 @@ Type TIParser
 				NextToke
 				
 				Local decl:TFuncDecl = ParseFuncDecl( _toke,method_attrs|FUNC_METHOD, ,classDecl )
+				decl.declImported = True
 				'If decl.IsCtor() decl.retTypeExpr=New TObjectType.Create( classDecl )
 				classDecl.InsertDecl decl
 				
@@ -726,6 +727,7 @@ Type TIParser
 				NextToke
 				
 				Local decl:TFuncDecl = ParseFuncDecl( _toke,method_attrs )
+				decl.declImported = True
 				'If decl.IsCtor() decl.retTypeExpr=New TObjectType.Create( classDecl )
 				classDecl.InsertDecl decl
 
@@ -1628,6 +1630,23 @@ End Rem
 			While CParse( "*" )
 				ty = TType.MapToPointerType(ty)
 			Wend
+		Case "/"
+			NextToke
+			ty=ParseNewType()
+
+			If CParse("*") Then
+				If TIdentType(ty) Then
+					ty = TType.MapToPointerType(ty)
+
+					While CParse( "*" )
+						ty = TType.MapToPointerType(ty)
+					Wend
+
+				End If
+			End If
+			
+			CParse("&")
+
 ' TODO
 '		Case "!" ' BaH Double
 '			NextToke