Przeglądaj źródła

Added -w option.

woollybah 9 lat temu
rodzic
commit
f29bf51696
3 zmienionych plików z 49 dodań i 5 usunięć
  1. 7 0
      config.bmx
  2. 34 5
      decl.bmx
  3. 8 0
      options.bmx

+ 7 - 0
config.bmx

@@ -63,6 +63,13 @@ Function Err( err$ )
 	Throw "Compile Error: "+err + "~n" + _errInfo + "~n"
 End Function
 
+Function Warn( err$ )
+	'If DEBUGSTOP_ON_ERROR Then
+	'	DebugStop ' useful for debugging!
+	'End If
+	Print "Compile Warning: "+err + "~n" + _errInfo + "~n"
+End Function
+
 Function FormatError:String(path:String, line:Int, char:Int)
 	Return "[" + path + ";" + line + ";" + char + "]"
 End Function

+ 34 - 5
decl.bmx

@@ -1105,13 +1105,26 @@ End Rem
 		Local matches:TList = New TList
 
 		Local noExtendString:Int = True
+		Local generateWarnings:Int = False
 
 		' double test for matches.
-		' first time through we don't allow up-casting args to String
-		'   if we get a match on the first pass, we'll take it.
-		' second iteration we allow up-casting numerics to string
+		' * first time through we don't allow up-casting args to String
+		'    if we get a match on the first pass, we'll take it.
+		' * second iteration we allow up-casting numerics to string
+		' * third iteration is valid if opt_warnover is enabled
+		'    this will allow down-casting of numerics (eg. double->float)
+		'    warnings will be generated if this produces valid results.
 		' if after all that, there's no match, then we can fail it.
-		For Local n:Int = 0 Until 2
+		For Local n:Int = 0 Until 3
+		
+			If n > 1 Then
+				If Not opt_warnover Then
+					Continue
+				Else
+					DebugStop
+					generateWarnings = True
+				End If
+			End If
 		
 			errorDetails = ""
 		
@@ -1198,7 +1211,23 @@ End Rem
 						
 						exact=False
 						
-						If Not explicit And exprTy.ExtendsType( declTy, noExtendString, widensTest ) Continue
+						If Not generateWarnings Then
+							If Not explicit And exprTy.ExtendsType( declTy, noExtendString, widensTest ) Continue
+						Else
+							If Not explicit Then
+								' fails widen test
+								If Not exprTy.ExtendsType( declTy, noExtendString, True ) Then
+									' but passes non-widen test
+									If exprTy.ExtendsType( declTy, noExtendString, False ) Then
+										' generate a warning, and accept it
+										Warn "In call to " + func.ToString()+ ". Argument #"+(i+1)+" is ~q" + exprTy.ToString()+"~q but declaration is ~q"+declTy.ToString()+"~q. "
+										Continue
+									End If
+								Else
+									Continue
+								End If
+							End If
+						End If
 	
 						' make a more helpful error message
 						errorDetails :+ "Argument #"+(i+1)+" is ~q" + exprTy.ToString()+"~q but declaration is ~q"+declTy.ToString()+"~q. "

+ 8 - 0
options.bmx

@@ -97,6 +97,10 @@ Global opt_gdbdebug:Int = False
 '    upgrade strict subclass method/function return types to match superstrict superclass.
 '    default is to auto-upgrade. Set flag if you want to throw an error - because of mismatch. (strict is Int, superstrict is Void).
 Global opt_strictupgrade:Int = True
+' overload warnings
+'    generate warnings (and accept) instead of errors for calling methods with arguments that need to be cast down.
+'    May cause issues using overloaded methods.
+Global opt_warnover:Int = False
 
 Global opt_filepath:String
 
@@ -188,6 +192,8 @@ Function ParseArgs:String[](args:String[])
 				opt_framework = args[count]
 			Case "d"
 				opt_gdbdebug=True
+			Case "w"
+				opt_warnover=True
 		End Select
 	
 		count:+ 1
@@ -214,6 +220,8 @@ Function DefaultOptions()
 	opt_arch = "x64"
 ?arm
 	opt_arch = "arm"
+?arm64
+	opt_arch = "arm64"
 ?armeabi
 	opt_arch = "armeabi"
 ?armeabiv7a