فهرست منبع

Merge pull request #618 from bmx-ng/feature/coverage

Added coverage support.
Brucey 2 سال پیش
والد
کامیت
ce1184480e
16فایلهای تغییر یافته به همراه184 افزوده شده و 18 حذف شده
  1. 1 1
      bcc.bmx
  2. 5 1
      config.bmx
  3. 77 1
      ctranslator.bmx
  4. 1 1
      decl.bmx
  5. 1 1
      expr.bmx
  6. 1 1
      iparser.bmx
  7. 6 2
      options.bmx
  8. 3 1
      parser.bmx
  9. 1 1
      stmt.bmx
  10. 1 1
      stringbuffer_common.bmx
  11. 1 1
      stringbuffer_core.bmx
  12. 1 1
      stringbuffer_glue.c
  13. 1 1
      toker.bmx
  14. 1 1
      transform.c
  15. 82 2
      translator.bmx
  16. 1 1
      type.bmx

+ 1 - 1
bcc.bmx

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

+ 5 - 1
config.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2022 Bruce A Henderson
+' Copyright (c) 2013-2023 Bruce A Henderson
 '
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '
 '
@@ -573,6 +573,10 @@ Function FileMung:String(makeApp:Int = False)
 		m :+ "debug"
 		m :+ "debug"
 	End If
 	End If
 	
 	
+	If opt_coverage Then
+		m :+ ".cov"
+	End If
+
 '	If opt_threaded Then
 '	If opt_threaded Then
 '		m :+ ".mt"
 '		m :+ ".mt"
 '	End If
 '	End If

+ 77 - 1
ctranslator.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2022 Bruce A Henderson
+' Copyright (c) 2013-2023 Bruce A Henderson
 '
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '
 '
@@ -3693,6 +3693,10 @@ End Rem
 
 
 			If Not proto Then
 			If Not proto Then
 
 
+				If opt_coverage Then
+					EmitCoverageFunction(decl)
+				End If
+
 				If PROFILER Then
 				If PROFILER Then
 					Select decl.ident
 					Select decl.ident
 						Case "WritePixel", "PixelPtr", "CopyPixels", "ConvertPixels", "ConvertPixelsToStdFormat", "ConvertPixelsFromStdFormat"
 						Case "WritePixel", "PixelPtr", "CopyPixels", "ConvertPixels", "ConvertPixelsToStdFormat", "ConvertPixelsFromStdFormat"
@@ -6588,6 +6592,73 @@ End If
 			End If
 			End If
 		Next
 		Next
 
 
+		' coverage
+		Local covCount:Int
+		If opt_coverage Then
+			Local id:Int
+			For Local file:String = EachIn coverageFileInfo.Keys()
+				Local covFile:TCoverageLineInfo = TCoverageLineInfo(coverageFileInfo.ValueForKey(file))
+				Local t:String
+
+				Emit "static int coverage_lines_" + id + "[] = {"
+
+				For Local i:Int = 0 Until covFile.lines.Length
+					If i And i Mod 40 = 0 Then
+						If i Then
+							t :+ ","
+						End If
+						Emit t
+						t = ""
+					Else
+						If i Then
+							t :+ ","
+						End If
+					End If
+					t :+ covFile.lines[i]
+				Next
+
+				If t Then
+					Emit t
+				End If
+
+				Emit "};"
+
+				Emit "static BBCoverageFunctionInfo coverage_funcs_" + id + "[] = {"
+				Local covFuncFile:TCoverageFunctionLineInfo = TCoverageFunctionLineInfo(coverageFunctionFileInfo.ValueForKey(file))
+
+				For Local i:Int = 0 Until covFuncFile.funcs.Length
+					Emit "{ " + Enquote(covFuncFile.funcs[i].name) + ", " + covFuncFile.funcs[i].line + " },"
+				Next
+
+				Emit "};"
+
+				id :+ 1
+			Next
+
+			covCount = id
+			If id Then
+				id = 0
+				Emit "static BBCoverageFileInfo coverage_files[] = {"
+				For Local file:String = EachIn coverageFileInfo.Keys()
+					Local covFile:TCoverageLineInfo = TCoverageLineInfo(coverageFileInfo.ValueForKey(file))
+					
+					Emit "{"
+					Emit Enquote(file) + ","
+					Emit "coverage_lines_" + id + ","
+					Emit "sizeof(coverage_lines_" + id + ") / sizeof(coverage_lines_" + id + "[0]),"
+					Emit "NULL,"
+					Emit "coverage_funcs_" + id + ","
+					Emit "sizeof(coverage_funcs_" + id + ") / sizeof(coverage_funcs_" + id + "[0]),"
+					Emit "NULL,"
+					Emit "},"
+
+					id :+ 1
+				Next
+				Emit "{ NULL, NULL, 0, NULL, NULL, 0, NULL }"
+				Emit "};"
+			End If
+		End If
+
 		Emit "static int " + app.munged + "_inited" + " = 0;"
 		Emit "static int " + app.munged + "_inited" + " = 0;"
 
 
 		Emit "int " + app.munged + "(){"
 		Emit "int " + app.munged + "(){"
@@ -6660,6 +6731,11 @@ End If
 			Emit decl.munged + "_BBEnum_impl = (BBEnum *)&" + decl.munged + "_BBEnum;"
 			Emit decl.munged + "_BBEnum_impl = (BBEnum *)&" + decl.munged + "_BBEnum;"
 		Next
 		Next
 
 
+		' initialise coverage
+		If opt_coverage And covCount Then
+			Emit "bbCoverageRegisterFile(coverage_files);"
+		End If
+
 		' register types
 		' register types
 		For Local decl:TDecl=EachIn app.Semanted()
 		For Local decl:TDecl=EachIn app.Semanted()
 
 

+ 1 - 1
decl.bmx

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

+ 1 - 1
expr.bmx

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

+ 1 - 1
iparser.bmx

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

+ 6 - 2
options.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2022 Bruce A Henderson
+' Copyright (c) 2013-2023 Bruce A Henderson
 '
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '
 '
@@ -25,7 +25,7 @@ SuperStrict
 
 
 Import "base.configmap.bmx"
 Import "base.configmap.bmx"
 
 
-Const version:String = "0.137"
+Const version:String = "0.138"
 
 
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_MODULE:Int = 1
 Const BUILDTYPE_MODULE:Int = 1
@@ -133,6 +133,8 @@ Global opt_legacy_incbin:Int = False
 
 
 Global opt_filepath:String
 Global opt_filepath:String
 
 
+Global opt_coverage:Int = False
+
 Function CmdError(details:String = Null, fullUsage:Int = False)
 Function CmdError(details:String = Null, fullUsage:Int = False)
 	Local s:String = "Compile Error"
 	Local s:String = "Compile Error"
 	If details Then
 	If details Then
@@ -245,6 +247,8 @@ Function ParseArgs:String[](args:String[])
 				opt_need_strict=True
 				opt_need_strict=True
 			Case "ib"
 			Case "ib"
 				opt_legacy_incbin=True
 				opt_legacy_incbin=True
+			Case "cov"
+				opt_coverage=True
 		End Select
 		End Select
 	
 	
 		count:+ 1
 		count:+ 1

+ 3 - 1
parser.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2022 Bruce A Henderson
+' Copyright (c) 2013-2023 Bruce A Henderson
 '
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '
 '
@@ -4723,6 +4723,8 @@ Function EvalS$( source$,ty:TType )
 		
 		
 	' new compiler
 	' new compiler
 	env.InsertDecl New TConstDecl.Create( "bmxng",New TIntType,New TConstExpr.Create( New TIntType, True ),0 )
 	env.InsertDecl New TConstDecl.Create( "bmxng",New TIntType,New TConstExpr.Create( New TIntType, True ),0 )
+	' coverage
+	env.InsertDecl New TConstDecl.Create( "coverage",New TIntType,New TConstExpr.Create( New TIntType, opt_coverage ),0 )
 
 
 	' console or gui build?
 	' console or gui build?
 	env.InsertDecl New TConstDecl.Create( "console",New TIntType,New TConstExpr.Create( New TIntType, opt_apptype = APPTYPE_CONSOLE ),0 )
 	env.InsertDecl New TConstDecl.Create( "console",New TIntType,New TConstExpr.Create( New TIntType, opt_apptype = APPTYPE_CONSOLE ),0 )

+ 1 - 1
stmt.bmx

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

+ 1 - 1
stringbuffer_common.bmx

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

+ 1 - 1
stringbuffer_core.bmx

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

+ 1 - 1
stringbuffer_glue.c

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

+ 1 - 1
toker.bmx

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

+ 1 - 1
transform.c

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

+ 82 - 2
translator.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2013-2022 Bruce A Henderson
+' Copyright (c) 2013-2023 Bruce A Henderson
 '
 '
 ' Based on the public domain Monkey "trans" by Mark Sibly
 ' Based on the public domain Monkey "trans" by Mark Sibly
 '
 '
@@ -59,6 +59,9 @@ Type TTranslator
 	
 	
 	Field processingReturnStatement:Int
 	Field processingReturnStatement:Int
 
 
+	Field coverageFileInfo:TMap = New TMap
+	Field coverageFunctionFileInfo:TMap = New TMap
+
 	Method PushVarScope()
 	Method PushVarScope()
 		varStack.Push customVarStack
 		varStack.Push customVarStack
 		customVarStack = New TStack
 		customVarStack = New TStack
@@ -817,6 +820,7 @@ op = mapSymbol(op)
 		MungDecl tmp
 		MungDecl tmp
 		Emit TransLocalDecl( tmp,expr, True, init )+";"
 		Emit TransLocalDecl( tmp,expr, True, init )+";"
 
 
+		EmitCoverage(_errInfo)
 		EmitGDBDebug(_errInfo)
 		EmitGDBDebug(_errInfo)
 		
 		
 		Return tmp.munged
 		Return tmp.munged
@@ -1483,6 +1487,7 @@ End Rem
 			
 			
 			End If
 			End If
 
 
+			EmitCoverage(stmt)
 			EmitGDBDebug(stmt)
 			EmitGDBDebug(stmt)
 			
 			
 			If TReturnStmt(stmt) And Not tryStack.IsEmpty() Then
 			If TReturnStmt(stmt) And Not tryStack.IsEmpty() Then
@@ -1995,12 +2000,87 @@ End Rem
 			End If
 			End If
 		End If
 		End If
 	End Method
 	End Method
-	
+
+	Method EmitCoverage(obj:Object)
+		If opt_coverage Then
+			If TStmt(obj) Then
+				Local stmt:TStmt = TStmt(obj)
+				Local infoArray:String[] = stmt.errInfo[1..stmt.errInfo.length-1].Split(";")
+				If Not stmt.generated Then
+					GenerateCoverageLine(infoArray)
+				End If
+			Else If TDecl(obj) Then
+				Local decl:TDecl = TDecl(obj)
+				Local infoArray:String[] = decl.errInfo[1..decl.errInfo.length-1].Split(";")
+				GenerateCoverageLine(infoArray)
+			Else If String(obj) Then
+				Local errInfo:String = String(obj)
+				Local infoArray:String[] = errInfo[1..errInfo.length-1].Split(";")
+				GenerateCoverageLine(infoArray)
+			End If
+		End If
+	End Method
+
+	Method GenerateCoverageLine(infoArray:String[])
+		Emit "bbCoverageUpdateLineInfo(" + Enquote(infoArray[0]) + ", " + infoArray[1] + ");"
+
+		Local filename:String = infoArray[0]
+		Local line:Int = Int(infoArray[1])
+		Local lineInfo:TCoverageLineInfo = TCoverageLineInfo(coverageFileInfo.ValueForKey(filename))
+		If Not lineInfo Then
+			lineInfo = New TCoverageLineInfo
+			lineInfo.lines = New Int[0]
+			coverageFileInfo.Insert(filename, lineInfo)
+		End If
+		' Don't add duplicate lines
+		If Not lineInfo.lines.Length Or lineInfo.lines[lineInfo.lines.Length-1] <> line Then
+			lineInfo.lines :+ [line]
+		End If
+	End Method
+
+	Method EmitCoverageFunction(decl:TFuncDecl)
+		If opt_coverage Then
+			Local infoArray:String[] = decl.errInfo[1..decl.errInfo.length-1].Split(";")
+			GenerateCoverageFunctionLine(infoArray, decl.ident)
+		End If
+	End Method
+
+	Method GenerateCoverageFunctionLine(infoArray:String[], name:String)
+		Emit "bbCoverageUpdateFunctionLineInfo(" + Enquote(infoArray[0]) + ", " + Enquote(name) + ", " + infoArray[1] + ");"
+
+		Local filename:String = infoArray[0]
+		Local line:Int = Int(infoArray[1])
+		Local funcInfo:TCoverageFunctionLineInfo = TCoverageFunctionLineInfo(coverageFunctionFileInfo.ValueForKey(filename))
+		If Not funcInfo Then
+			funcInfo = New TCoverageFunctionLineInfo
+			coverageFunctionFileInfo.Insert(filename, funcInfo)
+		End If
+
+		Local func:TCoverageFunctionInfo = New TCoverageFunctionInfo
+		func.name = name
+		func.line = line
+
+		funcInfo.funcs :+ [func]
+	End Method
+
 	Method EmitClassDeclDeleteDtor( classDecl:TClassDecl )
 	Method EmitClassDeclDeleteDtor( classDecl:TClassDecl )
 	End Method
 	End Method
 	
 	
 End Type
 End Type
 
 
+Type TCoverageLineInfo
+	Field lines:Int[]
+End Type
+
+Type TCoverageFunctionLineInfo
+	Field funcs:TCoverageFunctionInfo[]
+End Type
+
+Type TCoverageFunctionInfo
+	Field name:String
+	Field line:Int
+End Type
+
 Type TTryBreakCheck
 Type TTryBreakCheck
 
 
 	Field contId:Int
 	Field contId:Int

+ 1 - 1
type.bmx

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