Commit e592a53a authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 49274b42
...@@ -188,6 +188,7 @@ func (p *Package) parseTraceEvent(srcfile *ast.File, pos token.Position, text st ...@@ -188,6 +188,7 @@ func (p *Package) parseTraceEvent(srcfile *ast.File, pos token.Position, text st
// packageTrace returns tracing information about a package // packageTrace returns tracing information about a package
func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) (*Package, error) { func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) (*Package, error) {
fmt.Println("package trace:", pkgi.Pkg.Path())
// prepare Package with typechecker ready to typecheck trace files // prepare Package with typechecker ready to typecheck trace files
// (to get trace func argument types) // (to get trace func argument types)
tconf := &types.Config{ tconf := &types.Config{
...@@ -226,10 +227,11 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) (*Package, err ...@@ -226,10 +227,11 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) (*Package, err
// go through files of the original package and process //trace: directives // go through files of the original package and process //trace: directives
for _, file := range pkgi.Files { // ast.File for _, file := range pkgi.Files { // ast.File
fmt.Println("\tfile:", prog.Fset.Position(file.Pos()))
for _, commgroup := range file.Comments { // ast.CommentGroup for _, commgroup := range file.Comments { // ast.CommentGroup
for _, comment := range commgroup.List { // ast.Comment for _, comment := range commgroup.List { // ast.Comment
pos := prog.Fset.Position(comment.Slash) pos := prog.Fset.Position(comment.Slash)
//fmt.Printf("%v %q\n", pos, comment.Text) fmt.Printf("%v %q\n", pos, comment.Text)
// only directives starting from beginning of line // only directives starting from beginning of line
if pos.Column != 1 { if pos.Column != 1 {
...@@ -248,6 +250,7 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) (*Package, err ...@@ -248,6 +250,7 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) (*Package, err
directive, arg := textv[0], textv[1] directive, arg := textv[0], textv[1]
switch directive { switch directive {
case "//trace:event": case "//trace:event":
fmt.Println("*", textv)
event, err := p.parseTraceEvent(file, pos, arg) event, err := p.parseTraceEvent(file, pos, arg)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -128,15 +128,17 @@ func TestGoTraceGen(t *testing.T) { ...@@ -128,15 +128,17 @@ func TestGoTraceGen(t *testing.T) {
// test build context with GOPATH set to work tree // test build context with GOPATH set to work tree
var tBuildCtx = &build.Context{ var tBuildCtx = &build.Context{
GOARCH: "amd64", GOARCH: "amd64",
GOOS: "linux", GOOS: "linux",
GOROOT: runtime.GOROOT(), GOROOT: runtime.GOROOT(),
GOPATH: work, GOPATH: work,
Compiler: runtime.Compiler, CgoEnabled: true,
Compiler: runtime.Compiler,
} }
// XXX autodetect (go list ?) // XXX autodetect (go list ?)
testv := []string{"a/pkg1", "b/pkg2", "c/pkg3", "d/pkg4"} //testv := []string{"a/pkg1", "b/pkg2", "c/pkg3", "d/pkg4"}
testv := []string{"a/pkg1"}
for _, tpkg := range testv { for _, tpkg := range testv {
err = tracegen(tpkg, tBuildCtx, "" /* = local imorts disabled */) err = tracegen(tpkg, tBuildCtx, "" /* = local imorts disabled */)
......
package pkg1
/*
#include <stdio.h>
void hello() {
printf("Hello World (from C)\n");
}
*/
import "C"
// trace event defined in a cgo file
//trace:event traceHello()
func Hello() {
traceHello()
C.hello()
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment