modernc.org/ccgo/v3@v3.16.14/lib/cover.go (about)

     1  // Copyright 2020 The CCGO Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ccgo // import "modernc.org/ccgo/v3/lib"
     6  
     7  import (
     8  	"fmt"
     9  	"runtime"
    10  	"sort"
    11  	"strings"
    12  )
    13  
    14  var (
    15  	coverMap = map[uintptr]struct{}{}
    16  )
    17  
    18  func pc2origin(pc uintptr) string {
    19  	f := runtime.FuncForPC(pc)
    20  	var fn, fns string
    21  	var fl int
    22  	if f != nil {
    23  		fn, fl = f.FileLine(pc)
    24  		fns = f.Name()
    25  		if x := strings.LastIndex(fns, "."); x > 0 {
    26  			fns = fns[x+1:]
    27  		}
    28  	}
    29  	return fmt.Sprintf("%s:%d:%s", fn, fl, fns)
    30  }
    31  
    32  func coverReport() string {
    33  	var a []string
    34  	for pc := range coverMap {
    35  		a = append(a, pc2origin(pc))
    36  	}
    37  	sort.Strings(a)
    38  	return strings.Join(a, "\n")
    39  }