Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
b873512b
Commit
b873512b
authored
Jun 28, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
c92cd912
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
7 deletions
+28
-7
go/xcommon/tracing/cmd/gotrace/gotrace.go
go/xcommon/tracing/cmd/gotrace/gotrace.go
+28
-7
No files found.
go/xcommon/tracing/cmd/gotrace/gotrace.go
View file @
b873512b
...
...
@@ -91,6 +91,21 @@ func (v byPkgPath) Less(i, j int) bool { return v[i].PkgPath < v[j].PkgPath }
func
(
v
byPkgPath
)
Swap
(
i
,
j
int
)
{
v
[
i
],
v
[
j
]
=
v
[
j
],
v
[
i
]
}
func
(
v
byPkgPath
)
Len
()
int
{
return
len
(
v
)
}
// progImporter is types.Importer that imports packages from loaded loader.Program
type
progImporter
{
prog
*
loader
.
Program
}
func
(
pi
*
progImporter
)
Import
(
path
string
)
(
*
types
.
Package
,
error
)
{
pkgi
:=
pi
.
prog
.
Package
(
path
)
if
pkgi
==
nil
{
return
nil
,
fmt
.
Errorf
(
"package %q not found"
,
path
)
}
return
pkgi
.
Pkg
,
nil
}
// parseTraceEvent parses trace event definition into traceEvent
// text is text argument after "//trace:event "
func
parseTraceEvent
(
pkgi
*
loader
.
PackageInfo
,
text
string
)
(
*
traceEvent
,
error
)
{
...
...
@@ -98,17 +113,17 @@ func parseTraceEvent(pkgi *loader.PackageInfo, text string) (*traceEvent, error)
return
nil
,
fmt
.
Errorf
(
"trace event must start with
\"
trace
\"
"
)
// XXX pos
}
// trace event definition as func declaration
buf
:=
&
Buffer
{}
// XXX package name must be from trace definition context
//
prepare artificial package with
trace event definition as func declaration
buf
:=
&
Buffer
{}
// XXX package name must be from trace definition context
?
buf
.
emit
(
"package xxx"
)
// add
//
1. all imports from original source file TODO
//
2. add dot-import of original package TODO
// so inside it all looks like as if it was in original source context
//
1. all imports from original source file
//
2. dot-import of original package
// so
that
inside it all looks like as if it was in original source context
buf
.
emit
(
"
\n
import ("
)
for
_
,
imp
:=
range
file
.
Imports
{
for
_
,
imp
:=
range
src
file
.
Imports
{
impline
:=
""
if
imp
.
Name
!=
nil
{
impline
+=
imp
.
Name
.
Name
+
" "
...
...
@@ -120,7 +135,9 @@ func parseTraceEvent(pkgi *loader.PackageInfo, text string) (*traceEvent, error)
buf
.
emit
(
"
\t
. %q"
,
pkgi
.
Pkg
.
Path
)
buf
.
emit
(
")"
)
text
=
"
\n
func "
+
text
// func itself
buf
.
emit
(
"
\n
func "
+
text
)
// XXX add all imports from file of trace event definition context
fset
:=
token
.
NewFileSet
()
// XXX
filename
:=
"tracefunc.go"
// XXX -> original_file.go:<lineno> ?
...
...
@@ -142,6 +159,10 @@ func parseTraceEvent(pkgi *loader.PackageInfo, text string) (*traceEvent, error)
return
nil
,
fmt
.
Errorf
(
"trace event must not return results"
)
}
// typecheck prepared package to get trace func argument types
Importer
:
&
progImporter
{
lprog
}
// XXX +pos
return
&
traceEvent
{
pkgi
,
declf
},
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment