Procházet zdrojové kódy

Added coverage support.

Brucey před 2 roky
rodič
revize
ec835b2bba
16 změnil soubory, kde provedl 189 přidání a 18 odebrání
  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. 87 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
 '

+ 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
 '
@@ -573,6 +573,10 @@ Function FileMung:String(makeApp:Int = False)
 		m :+ "debug"
 	End If
 	
+	If opt_coverage Then
+		m :+ ".cov"
+	End If
+
 '	If opt_threaded Then
 '		m :+ ".mt"
 '	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
 '
@@ -3693,6 +3693,10 @@ End Rem
 
 			If Not proto Then
 
+				If opt_coverage Then
+					EmitCoverageFunction(decl)
+				End If
+
 				If PROFILER Then
 					Select decl.ident
 						Case "WritePixel", "PixelPtr", "CopyPixels", "ConvertPixels", "ConvertPixelsToStdFormat", "ConvertPixelsFromStdFormat"
@@ -6588,6 +6592,73 @@ End If
 			End If
 		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 "int " + app.munged + "(){"
@@ -6660,6 +6731,11 @@ End If
 			Emit decl.munged + "_BBEnum_impl = (BBEnum *)&" + decl.munged + "_BBEnum;"
 		Next
 
+		' initialise coverage
+		If opt_coverage And covCount Then
+			Emit "bbCoverageRegisterFile(coverage_files);"
+		End If
+
 		' register types
 		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
 '

+ 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
 '

+ 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
 ' 

+ 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
 '
@@ -25,7 +25,7 @@ SuperStrict
 
 Import "base.configmap.bmx"
 
-Const version:String = "0.137"
+Const version:String = "0.138"
 
 Const BUILDTYPE_APP:Int = 0
 Const BUILDTYPE_MODULE:Int = 1
@@ -133,6 +133,8 @@ Global opt_legacy_incbin:Int = False
 
 Global opt_filepath:String
 
+Global opt_coverage:Int = False
+
 Function CmdError(details:String = Null, fullUsage:Int = False)
 	Local s:String = "Compile Error"
 	If details Then
@@ -245,6 +247,8 @@ Function ParseArgs:String[](args:String[])
 				opt_need_strict=True
 			Case "ib"
 				opt_legacy_incbin=True
+			Case "cov"
+				opt_coverage=True
 		End Select
 	
 		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
 '
@@ -4723,6 +4723,8 @@ Function EvalS$( source$,ty:TType )
 		
 	' new compiler
 	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?
 	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
 '

+ 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
 ' 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
 ' 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
   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
 '

+ 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
   warranty. In no event will the authors be held liable for any damages

+ 87 - 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
 '
@@ -59,6 +59,9 @@ Type TTranslator
 	
 	Field processingReturnStatement:Int
 
+	Field coverageFileInfo:TMap = New TMap
+	Field coverageFunctionFileInfo:TMap = New TMap
+
 	Method PushVarScope()
 		varStack.Push customVarStack
 		customVarStack = New TStack
@@ -817,6 +820,7 @@ op = mapSymbol(op)
 		MungDecl tmp
 		Emit TransLocalDecl( tmp,expr, True, init )+";"
 
+		EmitCoverage(_errInfo)
 		EmitGDBDebug(_errInfo)
 		
 		Return tmp.munged
@@ -1483,6 +1487,7 @@ End Rem
 			
 			End If
 
+			EmitCoverage(stmt)
 			EmitGDBDebug(stmt)
 			
 			If TReturnStmt(stmt) And Not tryStack.IsEmpty() Then
@@ -1995,12 +2000,92 @@ End Rem
 			End If
 		End If
 	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]
+
+		' 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 EmitClassDeclDeleteDtor( classDecl:TClassDecl )
 	End Method
 	
 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
 
 	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
 '