Browse Source

Improved Abstract method/function detection. Fixes #309

woollybah 7 years ago
parent
commit
c7f8441b1c
18 changed files with 44 additions and 53 deletions
  1. 1 1
      base.stringhelper.bmx
  2. 1 1
      base64.bmx
  3. 1 1
      bcc.bmx
  4. 9 3
      config.bmx
  5. 1 1
      ctranslator.bmx
  6. 15 32
      decl.bmx
  7. 4 2
      expr.bmx
  8. 1 1
      iparser.bmx
  9. 2 2
      options.bmx
  10. 1 1
      parser.bmx
  11. 1 1
      stmt.bmx
  12. 1 1
      stringbuffer_common.bmx
  13. 1 1
      stringbuffer_core.bmx
  14. 1 1
      stringbuffer_glue.c
  15. 1 1
      toker.bmx
  16. 1 1
      transform.c
  17. 1 1
      translator.bmx
  18. 1 1
      type.bmx

+ 1 - 1
base.stringhelper.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2014-2017 Bruce A Henderson
+' Copyright (c) 2014-2018 Bruce A Henderson
 ' Copyright (c) 2014-2017 Ronny Otto
 '
 ' This software is provided 'as-is', without any express or implied

+ 1 - 1
base64.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2008-2017 Bruce A Henderson
+' Copyright (c) 2008-2018 Bruce A Henderson
 ' 
 ' Permission is hereby granted, free of charge, to any person obtaining a copy
 ' of this software and associated documentation files (the "Software"), to deal

+ 1 - 1
bcc.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2017 Bruce A Henderson
+' Copyright (c) 2013-2018 Bruce A Henderson
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '

+ 9 - 3
config.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2017 Bruce A Henderson
+' Copyright (c) 2013-2018 Bruce A Henderson
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '
@@ -424,7 +424,11 @@ Type TTemplateRecord
 	Method ToString:String()
 
 		Local s:Byte Ptr = source.ToUTF8String()
+?Not bmxng
 		Local slen:Int = strlen_(s)
+?bmxng
+		Local slen:UInt = strlen_(s)
+?
 
 ?Not bmxng		
 		Local dlen:Int = slen + 12
@@ -459,9 +463,11 @@ Type TTemplateRecord
 		Local data:Byte[dlen]
 		
 		Local s:Byte[] = TBase64.Decode(source)
-		
+?Not bmxng
 		uncompress(data, dlen, s, s.length)
-	
+?bmxng
+		uncompress(data, dlen, s, UInt(s.length))
+?	
 		Return New TTemplateRecord.Create(start, file, String.FromUTF8String(data))
 	End Function
 End Type

+ 1 - 1
ctranslator.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2017 Bruce A Henderson
+' Copyright (c) 2013-2018 Bruce A Henderson
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '

+ 15 - 32
decl.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2017 Bruce A Henderson
+' Copyright (c) 2013-2018 Bruce A Henderson
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '
@@ -2715,18 +2715,7 @@ End Rem
 		'If IsTemplateInst()
 		'	Return
 		'EndIf
-		
-		'Are we abstract?
-		If Not IsAbstract()
-			For Local decl:TDecl=EachIn _decls
-				Local fdecl:TFuncDecl=TFuncDecl( decl )
-				If fdecl And fdecl.IsAbstract()
-					attrs:|DECL_ABSTRACT
-					Exit
-				EndIf
-			Next
-		EndIf
-		
+				
 		If Not lastOffset And superClass Then
 			lastOffset = superClass.LastOffset
 		End If
@@ -2868,28 +2857,22 @@ End Rem
 		PushErr errInfo
 		
 		If Not IsInterface()
-			'
-			'check for duplicate fields! - BlitzMax supports fields with the same name in subclasses..
-			'
-			'For Local decl:TDecl=EachIn Semanted()
-			'	Local fdecl:TFieldDecl=TFieldDecl( decl )
-			'	If Not fdecl Continue
-			'	Local cdecl:TClassDecl=superClass
-			'	While cdecl
-			'		For Local decl:TDecl=EachIn cdecl.Semanted()
-			'			If decl.ident=fdecl.ident Err "Field '"+fdecl.ident+"' in class "+ToString()+" overrides existing declaration in class "+cdecl.ToString()
-			'		Next
-			'		cdecl=cdecl.superClass
-			'	Wend
-			'Next
-			'
-			'Check we implement all abstract methods!
-			'
+
+			' BlitzMax types are promoted to Abstract if they have an abstract method
+			If Not IsAbstract()
+				For Local fdecl:TFuncDecl = EachIn GetAllFuncDecls()
+					If fdecl.IsMethod() And fdecl.IsAbstract()
+						attrs:|DECL_ABSTRACT
+					End If
+				Next
+			End If
+
+			' Check we implement all abstract methods!
 			If IsInstanced()
 				Local cdecl:TClassDecl=Self
 				Local impls:TList=New TList'<TFuncDecl>
 				While cdecl
-					For Local decl:TFuncDecl=EachIn cdecl.SemantedMethods()
+					For Local decl:TFuncDecl=EachIn cdecl.SemantedFuncs()
 						If decl.IsAbstract()
 							Local found:Int
 							For Local decl2:TFuncDecl=EachIn impls
@@ -2899,7 +2882,7 @@ End Rem
 								EndIf
 							Next
 							If Not found
-								Err "Can't create instance of type "+ToString()+" due to abstract method "+decl.ToString()+"."
+                                Err "Can't create instance of type "+ToString()+" due to abstract method "+decl.ToString()+"."
 							EndIf
 						Else
 							impls.AddLast decl

+ 4 - 2
expr.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2017 Bruce A Henderson
+' Copyright (c) 2013-2018 Bruce A Henderson
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '
@@ -850,7 +850,8 @@ Type TNewObjectExpr Extends TExpr
 
 		If Not instanceExpr Then
 			If classDecl.IsInterface() Err "Cannot create instance of an interface."
-			If classDecl.IsAbstract() Err "Cannot create instance of an abstract class."
+			If classDecl.IsAbstract() Err "Cannot create instance of abstract type " + classDecl.ToString() + ..
+				", which is either declared Abstract or has (or inherits) an abstract Method."
 		End If
 		'If classDecl.IsTemplateArg() Err "Cannot create instance of a generic argument."
 		If classDecl.args And Not classDecl.instanceof Err "Cannot create instance of a generic class."
@@ -2724,6 +2725,7 @@ Type TIdentExpr Extends TExpr
 			If expr And Not static Then
 				Return New TInvokeMemberExpr.Create( expr,fdecl,args ).Semant()
 			Else
+				If fdecl.IsStatic() And fdecl.IsAbstract() Err "Cannot call abstract " + fdecl.ToString()
 				Return New TInvokeExpr.Create( fdecl,args, funcCall ).Semant()
 			End If
 		EndIf

+ 1 - 1
iparser.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2017 Bruce A Henderson
+' Copyright (c) 2013-2018 Bruce A Henderson
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 ' 

+ 2 - 2
options.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2017 Bruce A Henderson
+' Copyright (c) 2013-2018 Bruce A Henderson
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '
@@ -25,7 +25,7 @@ SuperStrict
 
 Import "base.configmap.bmx"
 
-Const version:String = "0.92"
+Const version:String = "0.93"
 
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_MODULE:Int = 1

+ 1 - 1
parser.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2017 Bruce A Henderson
+' Copyright (c) 2013-2018 Bruce A Henderson
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '

+ 1 - 1
stmt.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2017 Bruce A Henderson
+' Copyright (c) 2013-2018 Bruce A Henderson
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '

+ 1 - 1
stringbuffer_common.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2016-2017 Bruce A Henderson
+' Copyright (c) 2016-2018 Bruce A Henderson
 ' 
 ' Permission is hereby granted, free of charge, to any person obtaining a copy
 ' of this software and associated documentation files (the "Software"), to deal

+ 1 - 1
stringbuffer_core.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2016-2017 Bruce A Henderson
+' Copyright (c) 2016-2018 Bruce A Henderson
 ' 
 ' Permission is hereby granted, free of charge, to any person obtaining a copy
 ' of this software and associated documentation files (the "Software"), to deal

+ 1 - 1
stringbuffer_glue.c

@@ -1,5 +1,5 @@
 /*
-  Copyright (c) 2016-2017 Bruce A Henderson
+  Copyright (c) 2016-2018 Bruce A Henderson
  
   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal

+ 1 - 1
toker.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2017 Bruce A Henderson
+' Copyright (c) 2013-2018 Bruce A Henderson
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '

+ 1 - 1
transform.c

@@ -1,4 +1,4 @@
-/* Copyright (c) 2014-2017 Bruce A Henderson
+/* Copyright (c) 2014-2018 Bruce A Henderson
 
   This software is provided 'as-is', without any express or implied
   warranty. In no event will the authors be held liable for any damages

+ 1 - 1
translator.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2017 Bruce A Henderson
+' Copyright (c) 2013-2018 Bruce A Henderson
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '

+ 1 - 1
type.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2017 Bruce A Henderson
+' Copyright (c) 2013-2018 Bruce A Henderson
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '