├── .gitattributes
├── .gitignore
├── AUTHORS
├── CONTRIBUTING.md
├── CONTRIBUTORS
├── LICENSE
├── PATENTS
├── README
├── README.md
├── benchmark
└── parse
│ ├── parse.go
│ └── parse_test.go
├── blog
├── atom
│ └── atom.go
└── blog.go
├── cmd
├── benchcmp
│ ├── benchcmp.go
│ ├── benchcmp_test.go
│ ├── compare.go
│ ├── compare_test.go
│ └── doc.go
├── bundle
│ ├── main.go
│ ├── main_test.go
│ └── testdata
│ │ ├── out.golden
│ │ └── src
│ │ └── initial
│ │ ├── a.go
│ │ └── b.go
├── callgraph
│ ├── main.go
│ ├── main_test.go
│ └── testdata
│ │ └── src
│ │ └── pkg
│ │ ├── pkg.go
│ │ └── pkg_test.go
├── cover
│ ├── README
│ ├── cover.go
│ ├── cover_test.go
│ ├── doc.go
│ ├── func.go
│ ├── html.go
│ └── testdata
│ │ ├── main.go
│ │ └── test.go
├── digraph
│ ├── digraph.go
│ └── digraph_test.go
├── eg
│ └── eg.go
├── fiximports
│ ├── main.go
│ ├── main_test.go
│ └── testdata
│ │ └── src
│ │ ├── fruit.io
│ │ ├── banana
│ │ │ └── banana.go
│ │ ├── orange
│ │ │ └── orange.go
│ │ └── pear
│ │ │ └── pear.go
│ │ ├── new.com
│ │ └── one
│ │ │ └── one.go
│ │ ├── old.com
│ │ ├── bad
│ │ │ └── bad.go
│ │ └── one
│ │ │ └── one.go
│ │ └── titanic.biz
│ │ ├── bar
│ │ └── bar.go
│ │ └── foo
│ │ └── foo.go
├── godex
│ ├── doc.go
│ ├── gc.go
│ ├── gc14.go
│ ├── gccgo.go
│ ├── gccgo14.go
│ ├── godex.go
│ ├── godex14.go
│ ├── print.go
│ ├── print14.go
│ ├── source.go
│ ├── source14.go
│ ├── writetype.go
│ └── writetype14.go
├── godoc
│ ├── README.godoc-app
│ ├── appinit.go
│ ├── blog.go
│ ├── codewalk.go
│ ├── dl.go
│ ├── doc.go
│ ├── godoc_test.go
│ ├── handlers.go
│ ├── index.go
│ ├── main.go
│ ├── play.go
│ ├── remotesearch.go
│ ├── setup-godoc-app.bash
│ └── x.go
├── goimports
│ ├── doc.go
│ └── goimports.go
├── gomvpkg
│ └── main.go
├── gorename
│ └── main.go
├── gotype
│ ├── doc.go
│ ├── gotype.go
│ └── gotype14.go
├── guru
│ ├── callees.go
│ ├── callers.go
│ ├── callstack.go
│ ├── definition.go
│ ├── describe.go
│ ├── emacs-test.bash
│ ├── freevars.go
│ ├── go-guru.el
│ ├── guru.go
│ ├── guru.vim
│ ├── guru_test.go
│ ├── implements.go
│ ├── main.go
│ ├── peers.go
│ ├── pointsto.go
│ ├── pos.go
│ ├── referrers.go
│ ├── serial
│ │ └── serial.go
│ ├── testdata
│ │ └── src
│ │ │ ├── calls-json
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── calls
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── describe-json
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── describe
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── freevars
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── implements-json
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── implements-methods-json
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── implements-methods
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── implements
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── imports
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── lib
│ │ │ └── lib.go
│ │ │ ├── main
│ │ │ └── multi.go
│ │ │ ├── peers-json
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── peers
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── pointsto-json
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── pointsto
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── referrers-json
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── referrers
│ │ │ ├── ext_test.go
│ │ │ ├── int_test.go
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── reflection
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── what-json
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ ├── what
│ │ │ ├── main.go
│ │ │ └── main.golden
│ │ │ └── whicherrs
│ │ │ ├── main.go
│ │ │ └── main.golden
│ ├── what.go
│ └── whicherrs.go
├── html2article
│ └── conv.go
├── oracle
│ ├── emacs-test.bash
│ ├── main.go
│ ├── oracle.el
│ └── oracle.vim
├── present
│ ├── appengine.go
│ ├── dir.go
│ ├── doc.go
│ ├── local.go
│ ├── play.go
│ ├── play_http.go
│ ├── play_socket.go
│ ├── static
│ │ ├── article.css
│ │ ├── dir.css
│ │ ├── dir.js
│ │ ├── favicon.ico
│ │ ├── jquery-ui.js
│ │ ├── notes.css
│ │ ├── notes.js
│ │ ├── slides.js
│ │ └── styles.css
│ └── templates
│ │ ├── action.tmpl
│ │ ├── article.tmpl
│ │ ├── dir.tmpl
│ │ └── slides.tmpl
├── ssadump
│ ├── main.go
│ └── main14.go
├── stress
│ └── stress.go
├── stringer
│ ├── endtoend_test.go
│ ├── golden_test.go
│ ├── stringer.go
│ ├── stringer14.go
│ ├── testdata
│ │ ├── cgo.go
│ │ ├── day.go
│ │ ├── gap.go
│ │ ├── num.go
│ │ ├── number.go
│ │ ├── prime.go
│ │ ├── unum.go
│ │ └── unum2.go
│ └── util_test.go
├── tip
│ ├── Dockerfile
│ ├── README
│ ├── godoc.go
│ ├── godoc.yaml
│ ├── talks.go
│ ├── talks.yaml
│ └── tip.go
└── vet
│ ├── asmdecl.go
│ ├── assign.go
│ ├── atomic.go
│ ├── bool.go
│ ├── buildtag.go
│ ├── composite.go
│ ├── copylock.go
│ ├── deadcode.go
│ ├── doc.go
│ ├── example.go
│ ├── main.go
│ ├── method.go
│ ├── nilfunc.go
│ ├── print.go
│ ├── rangeloop.go
│ ├── shadow.go
│ ├── shift.go
│ ├── structtag.go
│ ├── testdata
│ ├── asm.go
│ ├── asm1.s
│ ├── asm2.s
│ ├── asm3.s
│ ├── asm4.s
│ ├── assign.go
│ ├── atomic.go
│ ├── bool.go
│ ├── buildtag.go
│ ├── buildtag_bad.go
│ ├── composite.go
│ ├── copylock_func.go
│ ├── copylock_range.go
│ ├── deadcode.go
│ ├── divergent
│ │ ├── buf.go
│ │ └── buf_test.go
│ ├── examples_test.go
│ ├── incomplete
│ │ └── examples_test.go
│ ├── method.go
│ ├── nilfunc.go
│ ├── print.go
│ ├── rangeloop.go
│ ├── shadow.go
│ ├── shift.go
│ ├── structtag.go
│ ├── tagtest
│ │ ├── file1.go
│ │ └── file2.go
│ ├── unsafeptr.go
│ └── unused.go
│ ├── types.go
│ ├── unsafeptr.go
│ ├── unused.go
│ ├── vet_test.go
│ └── whitelist
│ └── whitelist.go
├── codereview.cfg
├── container
└── intsets
│ ├── popcnt_amd64.go
│ ├── popcnt_amd64.s
│ ├── popcnt_gccgo.go
│ ├── popcnt_gccgo_c.c
│ ├── popcnt_generic.go
│ ├── sparse.go
│ ├── sparse_test.go
│ ├── util.go
│ └── util_test.go
├── cover
└── profile.go
├── go
├── ast
│ └── astutil
│ │ ├── enclosing.go
│ │ ├── enclosing_test.go
│ │ ├── imports.go
│ │ ├── imports_test.go
│ │ └── util.go
├── buildutil
│ ├── allpackages.go
│ ├── allpackages_test.go
│ ├── fakecontext.go
│ ├── tags.go
│ ├── tags_test.go
│ ├── util.go
│ ├── util_test.go
│ └── util_windows_test.go
├── callgraph
│ ├── callgraph.go
│ ├── cha
│ │ ├── cha.go
│ │ ├── cha14.go
│ │ ├── cha14_test.go
│ │ ├── cha_test.go
│ │ └── testdata
│ │ │ ├── func.go
│ │ │ ├── iface.go
│ │ │ └── recv.go
│ ├── rta
│ │ ├── rta.go
│ │ ├── rta14.go
│ │ ├── rta14_test.go
│ │ ├── rta_test.go
│ │ └── testdata
│ │ │ ├── func.go
│ │ │ ├── iface.go
│ │ │ └── rtype.go
│ ├── static
│ │ ├── static.go
│ │ └── static_test.go
│ └── util.go
├── exact
│ ├── exact.go
│ ├── exact_test.go
│ ├── go13.go
│ └── go14.go
├── gccgoimporter
│ ├── gccgoinstallation.go
│ ├── gccgoinstallation_test.go
│ ├── importer.go
│ ├── importer_test.go
│ ├── parser.go
│ ├── parser_test.go
│ └── testdata
│ │ ├── complexnums.go
│ │ ├── complexnums.gox
│ │ ├── imports.go
│ │ ├── imports.gox
│ │ ├── pointer.go
│ │ └── pointer.gox
├── gcimporter
│ ├── exportdata.go
│ ├── gcimporter.go
│ ├── gcimporter_test.go
│ └── testdata
│ │ └── exports.go
├── gcimporter15
│ ├── bexport.go
│ ├── bexport_test.go
│ ├── bimport.go
│ ├── exportdata.go
│ ├── gcimporter.go
│ ├── gcimporter16_test.go
│ ├── gcimporter_test.go
│ ├── setname15.go
│ ├── setname16.go
│ ├── setname_test.go
│ └── testdata
│ │ ├── a.go
│ │ ├── b.go
│ │ └── exports.go
├── importer
│ ├── export.go
│ ├── import.go
│ ├── import_test.go
│ └── predefined.go
├── loader
│ ├── cgo.go
│ ├── cgo14.go
│ ├── doc.go
│ ├── example14_test.go
│ ├── example15_test.go
│ ├── example_test.go
│ ├── go16.go
│ ├── go16_test.go
│ ├── loader.go
│ ├── loader14.go
│ ├── loader14_test.go
│ ├── loader_test.go
│ ├── stdlib14_test.go
│ ├── stdlib_test.go
│ ├── testdata
│ │ ├── a.go
│ │ ├── b.go
│ │ └── badpkgdecl.go
│ └── util.go
├── pointer
│ ├── TODO
│ ├── analysis.go
│ ├── analysis14.go
│ ├── api.go
│ ├── api14.go
│ ├── callgraph.go
│ ├── constraint.go
│ ├── constraint14.go
│ ├── doc.go
│ ├── doc14.go
│ ├── example_test.go
│ ├── gen.go
│ ├── gen14.go
│ ├── hvn.go
│ ├── hvn14.go
│ ├── intrinsics.go
│ ├── intrinsics14.go
│ ├── labels.go
│ ├── labels14.go
│ ├── opt.go
│ ├── pointer14_test.go
│ ├── pointer_test.go
│ ├── print.go
│ ├── reflect.go
│ ├── reflect14.go
│ ├── solve.go
│ ├── solve14.go
│ ├── stdlib_test.go
│ ├── testdata
│ │ ├── a_test.go
│ │ ├── another.go
│ │ ├── arrayreflect.go
│ │ ├── arrays.go
│ │ ├── channels.go
│ │ ├── chanreflect.go
│ │ ├── chanreflect1.go
│ │ ├── context.go
│ │ ├── conv.go
│ │ ├── finalizer.go
│ │ ├── flow.go
│ │ ├── fmtexcerpt.go
│ │ ├── func.go
│ │ ├── funcreflect.go
│ │ ├── hello.go
│ │ ├── interfaces.go
│ │ ├── issue9002.go
│ │ ├── mapreflect.go
│ │ ├── maps.go
│ │ ├── panic.go
│ │ ├── recur.go
│ │ ├── reflect.go
│ │ ├── rtti.go
│ │ ├── structreflect.go
│ │ ├── structs.go
│ │ └── timer.go
│ ├── util.go
│ └── util14.go
├── ssa
│ ├── blockopt.go
│ ├── builder.go
│ ├── builder14.go
│ ├── builder14_test.go
│ ├── builder_test.go
│ ├── const.go
│ ├── const14.go
│ ├── const15.go
│ ├── create.go
│ ├── create14.go
│ ├── doc.go
│ ├── dom.go
│ ├── emit.go
│ ├── emit14.go
│ ├── example14_test.go
│ ├── example_test.go
│ ├── func.go
│ ├── func14.go
│ ├── interp
│ │ ├── external.go
│ │ ├── external14.go
│ │ ├── external_darwin.go
│ │ ├── external_freebsd.go
│ │ ├── external_plan9.go
│ │ ├── external_unix.go
│ │ ├── external_windows.go
│ │ ├── interp.go
│ │ ├── interp14.go
│ │ ├── interp14_test.go
│ │ ├── interp_test.go
│ │ ├── map.go
│ │ ├── map14.go
│ │ ├── ops.go
│ │ ├── ops14.go
│ │ ├── reflect.go
│ │ ├── reflect14.go
│ │ ├── testdata
│ │ │ ├── a_test.go
│ │ │ ├── b_test.go
│ │ │ ├── boundmeth.go
│ │ │ ├── callstack.go
│ │ │ ├── complit.go
│ │ │ ├── coverage.go
│ │ │ ├── defer.go
│ │ │ ├── fieldprom.go
│ │ │ ├── ifaceconv.go
│ │ │ ├── ifaceprom.go
│ │ │ ├── initorder.go
│ │ │ ├── methprom.go
│ │ │ ├── mrvchain.go
│ │ │ ├── range.go
│ │ │ ├── recover.go
│ │ │ ├── reflect.go
│ │ │ └── static.go
│ │ ├── value.go
│ │ └── value14.go
│ ├── lift.go
│ ├── lift14.go
│ ├── lvalue.go
│ ├── lvalue14.go
│ ├── methods.go
│ ├── methods14.go
│ ├── mode.go
│ ├── print.go
│ ├── print14.go
│ ├── sanity.go
│ ├── sanity14.go
│ ├── source.go
│ ├── source14.go
│ ├── source14_test.go
│ ├── source_test.go
│ ├── ssa.go
│ ├── ssa14.go
│ ├── ssautil
│ │ ├── load.go
│ │ ├── load14.go
│ │ ├── load14_test.go
│ │ ├── load_test.go
│ │ ├── switch.go
│ │ ├── switch14.go
│ │ ├── switch_test.go
│ │ ├── testdata
│ │ │ └── switches.go
│ │ └── visit.go
│ ├── stdlib_test.go
│ ├── testdata
│ │ ├── objlookup.go
│ │ └── valueforexpr.go
│ ├── testmain.go
│ ├── testmain14.go
│ ├── testmain_test.go
│ ├── util.go
│ ├── util14.go
│ ├── wrappers.go
│ └── wrappers14.go
├── types
│ ├── api.go
│ ├── api_test.go
│ ├── assignments.go
│ ├── builtins.go
│ ├── builtins_test.go
│ ├── call.go
│ ├── check.go
│ ├── check_test.go
│ ├── conversions.go
│ ├── decl.go
│ ├── errors.go
│ ├── eval.go
│ ├── eval_test.go
│ ├── expr.go
│ ├── exprstring.go
│ ├── exprstring_test.go
│ ├── hilbert_test.go
│ ├── initorder.go
│ ├── issues_test.go
│ ├── labels.go
│ ├── lookup.go
│ ├── methodset.go
│ ├── object.go
│ ├── objset.go
│ ├── operand.go
│ ├── ordering.go
│ ├── package.go
│ ├── predicates.go
│ ├── resolver.go
│ ├── resolver_test.go
│ ├── return.go
│ ├── scope.go
│ ├── selection.go
│ ├── self_test.go
│ ├── sizes.go
│ ├── stdlib_test.go
│ ├── stmt.go
│ ├── testdata
│ │ ├── blank.src
│ │ ├── builtins.src
│ │ ├── const0.src
│ │ ├── const1.src
│ │ ├── constdecl.src
│ │ ├── conversions.src
│ │ ├── cycles.src
│ │ ├── cycles1.src
│ │ ├── cycles2.src
│ │ ├── cycles3.src
│ │ ├── cycles4.src
│ │ ├── decls0.src
│ │ ├── decls1.src
│ │ ├── decls2a.src
│ │ ├── decls2b.src
│ │ ├── decls3.src
│ │ ├── errors.src
│ │ ├── expr0.src
│ │ ├── expr1.src
│ │ ├── expr2.src
│ │ ├── expr3.src
│ │ ├── gotos.src
│ │ ├── importdecl0a.src
│ │ ├── importdecl0b.src
│ │ ├── importdecl1a.src
│ │ ├── importdecl1b.src
│ │ ├── init0.src
│ │ ├── init1.src
│ │ ├── init2.src
│ │ ├── issues.src
│ │ ├── labels.src
│ │ ├── methodsets.src
│ │ ├── shifts.src
│ │ ├── stmt0.src
│ │ ├── stmt1.src
│ │ └── vardecl.src
│ ├── token_test.go
│ ├── type.go
│ ├── typestring.go
│ ├── typestring_test.go
│ ├── typeutil
│ │ ├── example_test.go
│ │ ├── imports.go
│ │ ├── imports14.go
│ │ ├── imports14_test.go
│ │ ├── imports_test.go
│ │ ├── map.go
│ │ ├── map14.go
│ │ ├── map14_test.go
│ │ ├── map_test.go
│ │ ├── methodsetcache.go
│ │ ├── methodsetcache14.go
│ │ ├── ui.go
│ │ └── ui14.go
│ ├── typexpr.go
│ └── universe.go
└── vcs
│ ├── discovery.go
│ ├── env.go
│ ├── http.go
│ ├── vcs.go
│ └── vcs_test.go
├── godoc
├── analysis
│ ├── README
│ ├── analysis.go
│ ├── analysis14.go
│ ├── callgraph.go
│ ├── callgraph14.go
│ ├── implements.go
│ ├── implements14.go
│ ├── json.go
│ ├── peers.go
│ ├── peers14.go
│ ├── typeinfo.go
│ └── typeinfo14.go
├── appengine.go
├── cmdline.go
├── cmdline_test.go
├── corpus.go
├── dirtrees.go
├── dl
│ ├── dl.go
│ ├── dl_test.go
│ └── tmpl.go
├── format.go
├── godoc.go
├── godoc_test.go
├── index.go
├── index_test.go
├── linkify.go
├── meta.go
├── page.go
├── parser.go
├── pres.go
├── proxy
│ └── proxy.go
├── redirect
│ ├── hash.go
│ ├── redirect.go
│ └── redirect_test.go
├── search.go
├── server.go
├── short
│ ├── short.go
│ └── tmpl.go
├── snippet.go
├── spec.go
├── spot.go
├── static
│ ├── analysis
│ │ ├── call-eg.png
│ │ ├── call3.png
│ │ ├── callers1.png
│ │ ├── callers2.png
│ │ ├── chan1.png
│ │ ├── chan2a.png
│ │ ├── chan2b.png
│ │ ├── error1.png
│ │ ├── help.html
│ │ ├── ident-def.png
│ │ ├── ident-field.png
│ │ ├── ident-func.png
│ │ ├── ipcg-func.png
│ │ ├── ipcg-pkg.png
│ │ ├── typeinfo-pkg.png
│ │ └── typeinfo-src.png
│ ├── callgraph.html
│ ├── codewalk.html
│ ├── codewalkdir.html
│ ├── dirlist.html
│ ├── doc.go
│ ├── error.html
│ ├── example.html
│ ├── gen.go
│ ├── godoc.html
│ ├── godocs.js
│ ├── images
│ │ ├── minus.gif
│ │ ├── plus.gif
│ │ ├── treeview-black-line.gif
│ │ ├── treeview-black.gif
│ │ ├── treeview-default-line.gif
│ │ ├── treeview-default.gif
│ │ ├── treeview-gray-line.gif
│ │ └── treeview-gray.gif
│ ├── implements.html
│ ├── jquery.js
│ ├── jquery.treeview.css
│ ├── jquery.treeview.edit.js
│ ├── jquery.treeview.js
│ ├── makestatic.go
│ ├── methodset.html
│ ├── opensearch.xml
│ ├── package.html
│ ├── package.txt
│ ├── play.js
│ ├── playground.js
│ ├── search.html
│ ├── search.txt
│ ├── searchcode.html
│ ├── searchdoc.html
│ ├── searchtxt.html
│ ├── static.go
│ └── style.css
├── tab.go
├── template.go
├── util
│ ├── throttle.go
│ └── util.go
└── vfs
│ ├── gatefs
│ └── gatefs.go
│ ├── httpfs
│ └── httpfs.go
│ ├── mapfs
│ ├── mapfs.go
│ └── mapfs_test.go
│ ├── namespace.go
│ ├── os.go
│ ├── vfs.go
│ └── zipfs
│ ├── zipfs.go
│ └── zipfs_test.go
├── imports
├── fix.go
├── fix_test.go
├── imports.go
├── mkindex.go
├── mkstdlib.go
├── sortimports.go
└── zstdlib.go
├── oracle
├── TODO
├── callees.go
├── callees14.go
├── callers.go
├── callstack.go
├── definition.go
├── definition14.go
├── describe.go
├── describe14.go
├── describe15.go
├── freevars.go
├── freevars14.go
├── implements.go
├── implements14.go
├── oracle.go
├── oracle14.go
├── oracle_test.go
├── peers.go
├── peers14.go
├── pointsto.go
├── pointsto14.go
├── pos.go
├── referrers.go
├── referrers14.go
├── serial
│ └── serial.go
├── testdata
│ └── src
│ │ ├── calls-json
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── calls
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── describe-json
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── describe
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── freevars
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── implements-json
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── implements-methods-json
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── implements-methods
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── implements
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── imports
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── lib
│ │ └── lib.go
│ │ ├── main
│ │ └── multi.go
│ │ ├── peers-json
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── peers
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── pointsto-json
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── pointsto
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── referrers-json
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── referrers
│ │ ├── ext_test.go
│ │ ├── int_test.go
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── reflection
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── what-json
│ │ ├── main.go
│ │ └── main.golden
│ │ ├── what
│ │ ├── main.go
│ │ └── main.golden
│ │ └── whicherrs
│ │ ├── main.go
│ │ └── main.golden
├── what.go
├── whicherrs.go
└── whicherrs14.go
├── playground
├── appengine.go
├── appenginevm.go
├── common.go
├── local.go
└── socket
│ ├── socket.go
│ └── socket_test.go
├── present
├── args.go
├── background.go
├── caption.go
├── code.go
├── doc.go
├── html.go
├── iframe.go
├── image.go
├── link.go
├── link_test.go
├── parse.go
├── style.go
├── style_test.go
└── video.go
└── refactor
├── README
├── eg
├── eg.go
├── eg14.go
├── eg14_test.go
├── eg_test.go
├── match.go
├── match14.go
├── rewrite.go
├── rewrite14.go
└── testdata
│ ├── A.template
│ ├── A1.go
│ ├── A1.golden
│ ├── A2.go
│ ├── A2.golden
│ ├── B.template
│ ├── B1.go
│ ├── B1.golden
│ ├── C.template
│ ├── C1.go
│ ├── C1.golden
│ ├── D.template
│ ├── D1.go
│ ├── D1.golden
│ ├── E.template
│ ├── E1.go
│ ├── E1.golden
│ ├── F.template
│ ├── F1.go
│ ├── F1.golden
│ ├── G.template
│ ├── G1.go
│ ├── G1.golden
│ ├── H.template
│ ├── H1.go
│ ├── H1.golden
│ ├── bad_type.template
│ ├── expr_type_mismatch.template
│ ├── no_after_return.template
│ ├── no_before.template
│ └── type_mismatch.template
├── importgraph
├── graph.go
└── graph_test.go
├── rename
├── check.go
├── check14.go
├── go-rename.el
├── mvpkg.go
├── mvpkg_test.go
├── rename.go
├── rename14.go
├── rename_test.go
├── spec.go
├── spec14.go
├── util.go
└── util14.go
└── satisfy
├── find.go
└── find14.go
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Treat all files in this repo as binary, with no git magic updating
2 | # line endings. Windows users contributing to Go will need to use a
3 | # modern version of git and editors capable of LF line endings.
4 | #
5 | # We'll prevent accidental CRLF line endings from entering the repo
6 | # via the git-review gofmt checks.
7 | #
8 | # See golang.org/issue/9281
9 |
10 | * -text
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Add no patterns to .gitignore except for files generated by the build.
2 | last-change
3 |
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 | # This source code refers to The Go Authors for copyright purposes.
2 | # The master list of authors is in the main Go distribution,
3 | # visible at http://tip.golang.org/AUTHORS.
4 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to Go
2 |
3 | Go is an open source project.
4 |
5 | It is the work of hundreds of contributors. We appreciate your help!
6 |
7 |
8 | ## Filing issues
9 |
10 | When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions:
11 |
12 | 1. What version of Go are you using (`go version`)?
13 | 2. What operating system and processor architecture are you using?
14 | 3. What did you do?
15 | 4. What did you expect to see?
16 | 5. What did you see instead?
17 |
18 | General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker.
19 | The gophers there will answer or ask you to file an issue if you've tripped over a bug.
20 |
21 | ## Contributing code
22 |
23 | Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html)
24 | before sending patches.
25 |
26 | **We do not accept GitHub pull requests**
27 | (we use [Gerrit](https://code.google.com/p/gerrit/) instead for code review).
28 |
29 | Unless otherwise noted, the Go source files are distributed under
30 | the BSD-style license found in the LICENSE file.
31 |
32 |
--------------------------------------------------------------------------------
/CONTRIBUTORS:
--------------------------------------------------------------------------------
1 | # This source code was written by the Go contributors.
2 | # The master list of contributors is in the main Go distribution,
3 | # visible at http://tip.golang.org/CONTRIBUTORS.
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009 The Go Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/PATENTS:
--------------------------------------------------------------------------------
1 | Additional IP Rights Grant (Patents)
2 |
3 | "This implementation" means the copyrightable works distributed by
4 | Google as part of the Go project.
5 |
6 | Google hereby grants to You a perpetual, worldwide, non-exclusive,
7 | no-charge, royalty-free, irrevocable (except as stated in this section)
8 | patent license to make, have made, use, offer to sell, sell, import,
9 | transfer and otherwise run, modify and propagate the contents of this
10 | implementation of Go, where such license applies only to those patent
11 | claims, both currently owned or controlled by Google and acquired in
12 | the future, licensable by Google that are necessarily infringed by this
13 | implementation of Go. This grant does not include claims that would be
14 | infringed only as a consequence of further modification of this
15 | implementation. If you or your agent or exclusive licensee institute or
16 | order or agree to the institution of patent litigation against any
17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging
18 | that this implementation of Go or any code incorporated within this
19 | implementation of Go constitutes direct or contributory patent
20 | infringement, or inducement of patent infringement, then any patent
21 | rights granted to you under this License for this implementation of Go
22 | shall terminate as of the date such litigation is filed.
23 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | This subrepository holds the source for various packages and tools that support
2 | the Go programming language.
3 |
4 | Some of the tools, godoc and vet for example, are included in binary Go distributions.
5 | Others, including the Go oracle and the test coverage tool, can be fetched with "go get".
6 |
7 | Packages include a type-checker for Go and an implementation of the
8 | Static Single Assignment form (SSA) representation for Go programs.
9 |
10 | To submit changes to this repository, see http://golang.org/doc/contribute.html.
11 |
--------------------------------------------------------------------------------
/cmd/benchcmp/benchcmp_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "reflect"
5 | "testing"
6 |
7 | "golang.org/x/tools/benchmark/parse"
8 | )
9 |
10 | func TestSelectBest(t *testing.T) {
11 | have := parse.Set{
12 | "Benchmark1": []*parse.Benchmark{
13 | {
14 | Name: "Benchmark1",
15 | N: 10, NsPerOp: 100, Measured: parse.NsPerOp,
16 | Ord: 0,
17 | },
18 | {
19 | Name: "Benchmark1",
20 | N: 10, NsPerOp: 50, Measured: parse.NsPerOp,
21 | Ord: 3,
22 | },
23 | },
24 | "Benchmark2": []*parse.Benchmark{
25 | {
26 | Name: "Benchmark2",
27 | N: 10, NsPerOp: 60, Measured: parse.NsPerOp,
28 | Ord: 1,
29 | },
30 | {
31 | Name: "Benchmark2",
32 | N: 10, NsPerOp: 500, Measured: parse.NsPerOp,
33 | Ord: 2,
34 | },
35 | },
36 | }
37 |
38 | want := parse.Set{
39 | "Benchmark1": []*parse.Benchmark{
40 | {
41 | Name: "Benchmark1",
42 | N: 10, NsPerOp: 50, Measured: parse.NsPerOp,
43 | Ord: 0,
44 | },
45 | },
46 | "Benchmark2": []*parse.Benchmark{
47 | {
48 | Name: "Benchmark2",
49 | N: 10, NsPerOp: 60, Measured: parse.NsPerOp,
50 | Ord: 1,
51 | },
52 | },
53 | }
54 |
55 | selectBest(have)
56 | if !reflect.DeepEqual(want, have) {
57 | t.Errorf("filtered bench set incorrectly, want %v have %v", want, have)
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/cmd/benchcmp/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | /*
6 |
7 | The benchcmp command displays performance changes between benchmarks.
8 |
9 | Benchcmp parses the output of two 'go test' benchmark runs,
10 | correlates the results per benchmark, and displays the deltas.
11 |
12 | To measure the performance impact of a change, use 'go test'
13 | to run benchmarks before and after the change:
14 |
15 | go test -run=NONE -bench=. ./... > old.txt
16 | # make changes
17 | go test -run=NONE -bench=. ./... > new.txt
18 |
19 | Then feed the benchmark results to benchcmp:
20 |
21 | benchcmp old.txt new.txt
22 |
23 | Benchcmp will summarize and display the performance changes,
24 | in a format like this:
25 |
26 | $ benchcmp old.txt new.txt
27 | benchmark old ns/op new ns/op delta
28 | BenchmarkConcat 523 68.6 -86.88%
29 |
30 | benchmark old allocs new allocs delta
31 | BenchmarkConcat 3 1 -66.67%
32 |
33 | benchmark old bytes new bytes delta
34 | BenchmarkConcat 80 48 -40.00%
35 |
36 | */
37 | package main // import "golang.org/x/tools/cmd/benchcmp"
38 |
--------------------------------------------------------------------------------
/cmd/bundle/testdata/out.golden:
--------------------------------------------------------------------------------
1 | // Code generated by golang.org/x/tools/cmd/bundle.
2 | // $ bundle
3 |
4 | // The package doc comment
5 | //
6 |
7 | package dest
8 |
9 | import (
10 | "fmt"
11 | )
12 |
13 | // init functions are not renamed
14 | func init() { prefixfoo() }
15 |
16 | // Type S.
17 | type prefixS struct {
18 | prefixt
19 | u int
20 | }
21 |
22 | // Function bar.
23 | func prefixbar(s *prefixS) { fmt.Println(s.prefixt, s.u) }
24 |
25 | type prefixt int
26 |
27 | const prefixc = 1
28 |
29 | func prefixfoo() {
30 | fmt.Println()
31 | }
32 |
--------------------------------------------------------------------------------
/cmd/bundle/testdata/src/initial/a.go:
--------------------------------------------------------------------------------
1 | package initial
2 |
3 | import "fmt"
4 |
5 | // init functions are not renamed
6 | func init() { foo() }
7 |
8 | // Type S.
9 | type S struct {
10 | t
11 | u int
12 | }
13 |
14 | // Function bar.
15 | func bar(s *S) { fmt.Println(s.t, s.u) }
16 |
--------------------------------------------------------------------------------
/cmd/bundle/testdata/src/initial/b.go:
--------------------------------------------------------------------------------
1 | // The package doc comment
2 | package initial
3 |
4 | import "fmt"
5 |
6 | type t int
7 |
8 | const c = 1
9 |
10 | func foo() {
11 | fmt.Println()
12 | }
13 |
--------------------------------------------------------------------------------
/cmd/callgraph/testdata/src/pkg/pkg.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | type I interface {
4 | f()
5 | }
6 |
7 | type C int
8 |
9 | func (C) f() {}
10 |
11 | type D int
12 |
13 | func (D) f() {}
14 |
15 | func main() {
16 | var i I = C(0)
17 | i.f() // dynamic call
18 |
19 | main2()
20 | }
21 |
22 | func main2() {
23 | var i I = D(0)
24 | i.f() // dynamic call
25 | }
26 |
--------------------------------------------------------------------------------
/cmd/callgraph/testdata/src/pkg/pkg_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Don't import "testing", it adds a lot of callgraph edges.
4 |
5 | func Example() {
6 | C(0).f()
7 | }
8 |
--------------------------------------------------------------------------------
/cmd/cover/README:
--------------------------------------------------------------------------------
1 | NOTE: For Go releases 1.5 and later, this tool lives in the
2 | standard repository. The code here is not maintained.
3 |
--------------------------------------------------------------------------------
/cmd/cover/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 | /*
6 | Cover is a program for analyzing the coverage profiles generated by
7 | 'go test -coverprofile=cover.out'.
8 |
9 | Cover is also used by 'go test -cover' to rewrite the source code with
10 | annotations to track which parts of each function are executed.
11 | It operates on one Go source file at a time, computing approximate
12 | basic block information by studying the source. It is thus more portable
13 | than binary-rewriting coverage tools, but also a little less capable.
14 | For instance, it does not probe inside && and || expressions, and can
15 | be mildly confused by single statements with multiple function literals.
16 |
17 | For usage information, please see:
18 | go help testflag
19 | go tool cover -help
20 |
21 | No longer maintained:
22 |
23 | For Go releases 1.5 and later, this tool lives in the
24 | standard repository. The code here is not maintained.
25 |
26 | */
27 | package main // import "golang.org/x/tools/cmd/cover"
28 |
--------------------------------------------------------------------------------
/cmd/fiximports/testdata/src/fruit.io/banana/banana.go:
--------------------------------------------------------------------------------
1 | package banana
2 |
3 | import (
4 | _ "old.com/one"
5 | _ "titanic.biz/bar"
6 | _ "titanic.biz/foo"
7 | )
8 |
--------------------------------------------------------------------------------
/cmd/fiximports/testdata/src/fruit.io/orange/orange.go:
--------------------------------------------------------------------------------
1 | package orange
2 |
3 | import _ "fruit.io/pear"
4 |
--------------------------------------------------------------------------------
/cmd/fiximports/testdata/src/fruit.io/pear/pear.go:
--------------------------------------------------------------------------------
1 | package pear
2 |
3 | import _ "fruit.io/banana"
4 |
--------------------------------------------------------------------------------
/cmd/fiximports/testdata/src/new.com/one/one.go:
--------------------------------------------------------------------------------
1 | package one // import "new.com/one"
2 |
--------------------------------------------------------------------------------
/cmd/fiximports/testdata/src/old.com/bad/bad.go:
--------------------------------------------------------------------------------
1 | // This ill-formed Go source file is here to ensure the tool is robust
2 | // against bad packages in the workspace.
3 |
--------------------------------------------------------------------------------
/cmd/fiximports/testdata/src/old.com/one/one.go:
--------------------------------------------------------------------------------
1 | package one // import "new.com/one"
2 |
--------------------------------------------------------------------------------
/cmd/fiximports/testdata/src/titanic.biz/bar/bar.go:
--------------------------------------------------------------------------------
1 | // This package is moving to new.com too.
2 | package bar // import "new.com/bar"
3 |
--------------------------------------------------------------------------------
/cmd/fiximports/testdata/src/titanic.biz/foo/foo.go:
--------------------------------------------------------------------------------
1 | // This package hasn't jumped ship yet.
2 | package foo
3 |
--------------------------------------------------------------------------------
/cmd/godex/gc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build go1.5
6 |
7 | // This file implements access to gc-generated export data.
8 |
9 | package main
10 |
11 | import (
12 | "golang.org/x/tools/go/gcimporter"
13 | )
14 |
15 | func init() {
16 | register("gc", gcimporter.Import)
17 | }
18 |
--------------------------------------------------------------------------------
/cmd/godex/gc14.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build !go1.5
6 |
7 | // This file implements access to gc-generated export data.
8 |
9 | package main
10 |
11 | import (
12 | "golang.org/x/tools/go/gcimporter"
13 | )
14 |
15 | func init() {
16 | register("gc", gcimporter.Import)
17 | }
18 |
--------------------------------------------------------------------------------
/cmd/godex/gccgo.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build go1.5
6 |
7 | // This file implements access to gccgo-generated export data.
8 |
9 | package main
10 |
11 | import (
12 | "golang.org/x/tools/go/gccgoimporter"
13 | "golang.org/x/tools/go/types"
14 | )
15 |
16 | var (
17 | initmap = make(map[*types.Package]gccgoimporter.InitData)
18 | )
19 |
20 | func init() {
21 | incpaths := []string{"/"}
22 |
23 | // importer for default gccgo
24 | var inst gccgoimporter.GccgoInstallation
25 | inst.InitFromDriver("gccgo")
26 | register("gccgo", inst.GetImporter(incpaths, initmap))
27 | }
28 |
29 | // Print the extra gccgo compiler data for this package, if it exists.
30 | func (p *printer) printGccgoExtra(pkg *types.Package) {
31 | if initdata, ok := initmap[pkg]; ok {
32 | p.printf("/*\npriority %d\n", initdata.Priority)
33 |
34 | p.printDecl("init", len(initdata.Inits), func() {
35 | for _, init := range initdata.Inits {
36 | p.printf("%s %s %d\n", init.Name, init.InitFunc, init.Priority)
37 | }
38 | })
39 |
40 | p.print("*/\n")
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/cmd/godex/gccgo14.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build !go1.5
6 |
7 | // This file implements access to gccgo-generated export data.
8 |
9 | package main
10 |
11 | import (
12 | "golang.org/x/tools/go/gccgoimporter"
13 | "golang.org/x/tools/go/types"
14 | )
15 |
16 | var (
17 | initmap = make(map[*types.Package]gccgoimporter.InitData)
18 | )
19 |
20 | func init() {
21 | incpaths := []string{"/"}
22 |
23 | // importer for default gccgo
24 | var inst gccgoimporter.GccgoInstallation
25 | inst.InitFromDriver("gccgo")
26 | register("gccgo", inst.GetImporter(incpaths, initmap))
27 | }
28 |
29 | // Print the extra gccgo compiler data for this package, if it exists.
30 | func (p *printer) printGccgoExtra(pkg *types.Package) {
31 | if initdata, ok := initmap[pkg]; ok {
32 | p.printf("/*\npriority %d\n", initdata.Priority)
33 |
34 | p.printDecl("init", len(initdata.Inits), func() {
35 | for _, init := range initdata.Inits {
36 | p.printf("%s %s %d\n", init.Name, init.InitFunc, init.Priority)
37 | }
38 | })
39 |
40 | p.print("*/\n")
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/cmd/godex/source.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build go1.5
6 |
7 | // This file implements access to export data from source.
8 |
9 | package main
10 |
11 | import (
12 | "golang.org/x/tools/go/types"
13 | )
14 |
15 | func init() {
16 | register("source", sourceImporter)
17 | }
18 |
19 | func sourceImporter(packages map[string]*types.Package, path string) (*types.Package, error) {
20 | panic("unimplemented")
21 | }
22 |
--------------------------------------------------------------------------------
/cmd/godex/source14.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build !go1.5
6 |
7 | // This file implements access to export data from source.
8 |
9 | package main
10 |
11 | import (
12 | "golang.org/x/tools/go/types"
13 | )
14 |
15 | func init() {
16 | register("source", sourceImporter)
17 | }
18 |
19 | func sourceImporter(packages map[string]*types.Package, path string) (*types.Package, error) {
20 | panic("unimplemented")
21 | }
22 |
--------------------------------------------------------------------------------
/cmd/godoc/README.godoc-app:
--------------------------------------------------------------------------------
1 | godoc on appengine
2 | ------------------
3 |
4 | Prerequisites
5 | -------------
6 |
7 | * Go appengine SDK
8 | https://developers.google.com/appengine/downloads#Google_App_Engine_SDK_for_Go
9 |
10 | * Go sources at tip under $GOROOT
11 |
12 | * Godoc sources at tip inside $GOPATH
13 | (go get -d golang.org/x/tools/cmd/godoc)
14 |
15 |
16 | Directory structure
17 | -------------------
18 |
19 | * Let $APPDIR be the directory containing the app engine files.
20 | (e.g., $APPDIR=$HOME/godoc-app)
21 |
22 | * $APPDIR contains the following entries (this may change depending on
23 | app-engine release and version of godoc):
24 |
25 | app.yaml
26 | golang.org/x/tools/cmd/godoc
27 | godoc.zip
28 | index.split.*
29 |
30 | * The app.yaml file is set up per app engine documentation.
31 | For instance:
32 |
33 | application: godoc-app
34 | version: 1
35 | runtime: go
36 | api_version: go1
37 |
38 | handlers:
39 | - url: /.*
40 | script: _go_app
41 |
42 |
43 | Configuring and running godoc
44 | -----------------------------
45 |
46 | To configure godoc, run
47 |
48 | bash setup-godoc-app.bash
49 |
50 | to prepare an $APPDIR as described above. See the script for details on usage.
51 |
52 | To run godoc locally, using the App Engine development server, run
53 |
54 | /dev_appserver.py $APPDIR
55 |
56 | godoc should come up at http://localhost:8080 .
57 |
--------------------------------------------------------------------------------
/cmd/godoc/dl.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build !appengine
6 |
7 | package main
8 |
9 | import "net/http"
10 |
11 | // Register a redirect handler for /dl/ to the golang.org download page.
12 | // This file will not be included when deploying godoc to golang.org.
13 |
14 | func init() {
15 | http.Handle("/dl/", http.RedirectHandler("https://golang.org/dl/", http.StatusFound))
16 | }
17 |
--------------------------------------------------------------------------------
/cmd/godoc/index.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go 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 main
6 |
7 | import "strings"
8 |
9 | func indexDirectoryDefault(dir string) bool {
10 | return dir != "/pkg" && !strings.HasPrefix(dir, "/pkg/")
11 | }
12 |
--------------------------------------------------------------------------------
/cmd/godoc/play.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go 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 | // +build !appengine
6 |
7 | package main
8 |
9 | // This package registers "/compile" and "/share" handlers
10 | // that redirect to the golang.org playground.
11 | import _ "golang.org/x/tools/playground"
12 |
--------------------------------------------------------------------------------
/cmd/goimports/doc.go:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Command goimports updates your Go import lines,
4 | adding missing ones and removing unreferenced ones.
5 |
6 | $ go get golang.org/x/tools/cmd/goimports
7 |
8 | It's a drop-in replacement for your editor's gofmt-on-save hook.
9 | It has the same command-line interface as gofmt and formats
10 | your code in the same way.
11 |
12 | For emacs, make sure you have the latest go-mode.el:
13 | https://github.com/dominikh/go-mode.el
14 | Then in your .emacs file:
15 | (setq gofmt-command "goimports")
16 | (add-to-list 'load-path "/home/you/somewhere/emacs/")
17 | (require 'go-mode-load)
18 | (add-hook 'before-save-hook 'gofmt-before-save)
19 |
20 | For vim, set "gofmt_command" to "goimports":
21 | https://golang.org/change/39c724dd7f252
22 | https://golang.org/wiki/IDEsAndTextEditorPlugins
23 | etc
24 |
25 | For GoSublime, follow the steps described here:
26 | http://michaelwhatcott.com/gosublime-goimports/
27 |
28 | For other editors, you probably know what to do.
29 |
30 | Happy hacking!
31 |
32 | */
33 | package main // import "golang.org/x/tools/cmd/goimports"
34 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/calls-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of call-graph queries, -format=json.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See calls-json.golden for expected query results.
6 |
7 | func call(f func()) {
8 | f() // @callees @callees-f "f"
9 | }
10 |
11 | func main() {
12 | call(func() {
13 | // @callers callers-main.anon "^"
14 | // @callstack callstack-main.anon "^"
15 | })
16 | }
17 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/calls-json/main.golden:
--------------------------------------------------------------------------------
1 | -------- @callees @callees-f --------
2 | {
3 | "mode": "callees",
4 | "callees": {
5 | "pos": "testdata/src/calls-json/main.go:8:3",
6 | "desc": "dynamic function call",
7 | "callees": [
8 | {
9 | "name": "calls-json.main$1",
10 | "pos": "testdata/src/calls-json/main.go:12:7"
11 | }
12 | ]
13 | }
14 | }
15 | -------- @callstack callstack-main.anon --------
16 | {
17 | "mode": "callstack",
18 | "callstack": {
19 | "pos": "testdata/src/calls-json/main.go:12:7",
20 | "target": "calls-json.main$1",
21 | "callers": [
22 | {
23 | "pos": "testdata/src/calls-json/main.go:8:3",
24 | "desc": "dynamic function call",
25 | "caller": "calls-json.call"
26 | },
27 | {
28 | "pos": "testdata/src/calls-json/main.go:12:6",
29 | "desc": "static function call",
30 | "caller": "calls-json.main"
31 | }
32 | ]
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/describe-json/main.go:
--------------------------------------------------------------------------------
1 | package describe // @describe pkgdecl "describe"
2 |
3 | // Tests of 'describe' query, -format=json.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See describe-json.golden for expected query results.
6 |
7 | func main() {
8 | var s struct{ x [3]int }
9 | p := &s.x[0] // @describe desc-val-p "p"
10 | _ = p
11 |
12 | var i I = C(0)
13 | if i == nil {
14 | i = new(D)
15 | }
16 | print(i) // @describe desc-val-i "\\bi\\b"
17 |
18 | go main() // @describe desc-stmt "go"
19 | }
20 |
21 | type I interface {
22 | f()
23 | }
24 |
25 | type C int // @describe desc-type-C "C"
26 | type D struct{}
27 |
28 | func (c C) f() {}
29 | func (d *D) f() {}
30 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/freevars/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'freevars' query.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See freevars.golden for expected query results.
6 |
7 | // TODO(adonovan): it's hard to test this query in a single line of gofmt'd code.
8 |
9 | type T struct {
10 | a, b int
11 | }
12 |
13 | type S struct {
14 | x int
15 | t T
16 | }
17 |
18 | func f(int) {}
19 |
20 | func main() {
21 | type C int
22 | x := 1
23 | const exp = 6
24 | if y := 2; x+y+int(C(3)) != exp { // @freevars fv1 "if.*{"
25 | panic("expected 6")
26 | }
27 |
28 | var s S
29 |
30 | for x, y := range "foo" {
31 | println(s.x + s.t.a + s.t.b + x + int(y)) // @freevars fv2 "print.*y."
32 | }
33 |
34 | f(x) // @freevars fv3 "f.x."
35 |
36 | loop: // @freevars fv-def-label "loop:"
37 | for {
38 | break loop // @freevars fv-ref-label "break loop"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/freevars/main.golden:
--------------------------------------------------------------------------------
1 | -------- @freevars fv1 --------
2 | Free identifiers:
3 | type C
4 | const exp int
5 | var x int
6 |
7 | -------- @freevars fv2 --------
8 | Free identifiers:
9 | var s.t.a int
10 | var s.t.b int
11 | var s.x int
12 | var x int
13 | var y rune
14 |
15 | -------- @freevars fv3 --------
16 | Free identifiers:
17 | var x int
18 |
19 | -------- @freevars fv-def-label --------
20 | No free identifiers.
21 |
22 | -------- @freevars fv-ref-label --------
23 | Free identifiers:
24 | label loop
25 |
26 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/implements-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'implements' query, -output=json.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See implements.golden for expected query results.
6 |
7 | func main() {
8 | }
9 |
10 | type E interface{} // @implements E "E"
11 |
12 | type F interface { // @implements F "F"
13 | f()
14 | }
15 |
16 | type FG interface { // @implements FG "FG"
17 | f()
18 | g() []int // @implements slice "..int"
19 | }
20 |
21 | type C int // @implements C "C"
22 | type D struct{}
23 |
24 | func (c *C) f() {} // @implements starC ".C"
25 | func (d D) f() {} // @implements D "D"
26 |
27 | func (d *D) g() []int { return nil } // @implements starD ".D"
28 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/implements-methods-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'implements' query applied to methods, -output=json.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See implements-methods.golden for expected query results.
6 |
7 | import _ "lib"
8 |
9 | func main() {
10 | }
11 |
12 | type F interface {
13 | f() // @implements F.f "f"
14 | }
15 |
16 | type FG interface {
17 | f() // @implements FG.f "f"
18 | g() []int // @implements FG.g "g"
19 | }
20 |
21 | type C int
22 | type D struct{}
23 |
24 | func (c *C) f() {} // @implements *C.f "f"
25 | func (d D) f() {} // @implements D.f "f"
26 |
27 | func (d *D) g() []int { return nil } // @implements *D.g "g"
28 |
29 | type sorter []int
30 |
31 | func (sorter) Len() int { return 0 } // @implements Len "Len"
32 | func (sorter) Less(i, j int) bool { return false }
33 | func (sorter) Swap(i, j int) {}
34 |
35 | type I interface {
36 | Method(*int) *int // @implements I.Method "Method"
37 | }
38 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/implements-methods/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'implements' query applied to methods.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See implements-methods.golden for expected query results.
6 |
7 | import _ "lib"
8 |
9 | func main() {
10 | }
11 |
12 | type F interface {
13 | f() // @implements F.f "f"
14 | }
15 |
16 | type FG interface {
17 | f() // @implements FG.f "f"
18 | g() []int // @implements FG.g "g"
19 | }
20 |
21 | type C int
22 | type D struct{}
23 |
24 | func (c *C) f() {} // @implements *C.f "f"
25 | func (d D) f() {} // @implements D.f "f"
26 |
27 | func (d *D) g() []int { return nil } // @implements *D.g "g"
28 |
29 | type sorter []int
30 |
31 | func (sorter) Len() int { return 0 } // @implements Len "Len"
32 | func (sorter) Less(i, j int) bool { return false }
33 | func (sorter) Swap(i, j int) {}
34 |
35 | type I interface {
36 | Method(*int) *int // @implements I.Method "Method"
37 | }
38 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/implements-methods/main.golden:
--------------------------------------------------------------------------------
1 | -------- @implements F.f --------
2 | abstract method func (F).f()
3 | is implemented by method (*C).f
4 | is implemented by method (D).f
5 | is implemented by method (FG).f
6 |
7 | -------- @implements FG.f --------
8 | abstract method func (FG).f()
9 | is implemented by method (*D).f
10 | implements method (F).f
11 |
12 | -------- @implements FG.g --------
13 | abstract method func (FG).g() []int
14 | is implemented by method (*D).g
15 |
16 | -------- @implements *C.f --------
17 | concrete method func (*C).f()
18 | implements method (F).f
19 |
20 | -------- @implements D.f --------
21 | concrete method func (D).f()
22 | implements method (F).f
23 | concrete method func (D).f()
24 | implements method (FG).f
25 |
26 | -------- @implements *D.g --------
27 | concrete method func (*D).g() []int
28 | implements method (FG).g
29 |
30 | -------- @implements Len --------
31 | concrete method func (sorter).Len() int
32 | implements method (lib.Sorter).Len
33 |
34 | -------- @implements I.Method --------
35 | abstract method func (I).Method(*int) *int
36 | is implemented by method (lib.Type).Method
37 |
38 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/implements/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'implements' query.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See implements.golden for expected query results.
6 |
7 | import _ "lib"
8 |
9 | func main() {
10 | }
11 |
12 | type E interface{} // @implements E "E"
13 |
14 | type F interface { // @implements F "F"
15 | f()
16 | }
17 |
18 | type FG interface { // @implements FG "FG"
19 | f()
20 | g() []int // @implements slice "..int"
21 | }
22 |
23 | type C int // @implements C "C"
24 | type D struct{}
25 |
26 | func (c *C) f() {} // @implements starC ".C"
27 | func (d D) f() {} // @implements D "D"
28 |
29 | func (d *D) g() []int { return nil } // @implements starD ".D"
30 |
31 | type sorter []int // @implements sorter "sorter"
32 |
33 | func (sorter) Len() int { return 0 }
34 | func (sorter) Less(i, j int) bool { return false }
35 | func (sorter) Swap(i, j int) {}
36 |
37 | type I interface { // @implements I "I"
38 | Method(*int) *int
39 | }
40 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/implements/main.golden:
--------------------------------------------------------------------------------
1 | -------- @implements E --------
2 | empty interface type E
3 |
4 | -------- @implements F --------
5 | interface type F
6 | is implemented by pointer type *C
7 | is implemented by struct type D
8 | is implemented by interface type FG
9 |
10 | -------- @implements FG --------
11 | interface type FG
12 | is implemented by pointer type *D
13 | implements F
14 |
15 | -------- @implements slice --------
16 | slice type []int implements only interface{}
17 |
18 | -------- @implements C --------
19 | pointer type *C
20 | implements F
21 |
22 | -------- @implements starC --------
23 | pointer type *C
24 | implements F
25 |
26 | -------- @implements D --------
27 | struct type D
28 | implements F
29 | pointer type *D
30 | implements FG
31 |
32 | -------- @implements starD --------
33 | pointer type *D
34 | implements F
35 | implements FG
36 |
37 | -------- @implements sorter --------
38 | slice type sorter
39 | implements lib.Sorter
40 |
41 | -------- @implements I --------
42 | interface type I
43 | is implemented by basic type lib.Type
44 |
45 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/imports/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "hash/fnv" // @describe ref-pkg-import2 "fnv"
5 | "lib" // @describe ref-pkg-import "lib"
6 | )
7 |
8 | // Tests that import another package. (To make the tests run quickly,
9 | // we avoid using imports in all the other tests. Remember, each
10 | // query causes parsing and typechecking of the whole program.)
11 | //
12 | // See go.tools/guru/guru_test.go for explanation.
13 | // See imports.golden for expected query results.
14 |
15 | var a int
16 |
17 | func main() {
18 | const c = lib.Const // @describe ref-const "Const"
19 | lib.Func() // @describe ref-func "Func"
20 | lib.Var++ // @describe ref-var "Var"
21 | var t lib.Type // @describe ref-type "Type"
22 | p := t.Method(&a) // @describe ref-method "Method"
23 |
24 | print(*p + 1) // @pointsto p "p "
25 |
26 | var _ lib.Type // @describe ref-pkg "lib"
27 |
28 | fnv.New32()
29 | }
30 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/lib/lib.go:
--------------------------------------------------------------------------------
1 | package lib
2 |
3 | type Type int
4 |
5 | func (Type) Method(x *int) *int {
6 | return x
7 | }
8 |
9 | func Func() {
10 | }
11 |
12 | const Const = 3
13 |
14 | var Var = 0
15 |
16 | type Sorter interface {
17 | Len() int
18 | Less(i, j int) bool
19 | Swap(i, j int)
20 | }
21 |
22 | type Outer struct {
23 | A int
24 | b int
25 | inner
26 | }
27 |
28 | type inner struct {
29 | C bool
30 | d string
31 | recursive
32 | }
33 |
34 | type recursive struct {
35 | E bool
36 | *inner
37 | }
38 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/main/multi.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func g(x int) {
4 | }
5 |
6 | func f() {
7 | x := 1
8 | g(x) // "g(x)" is the selection for multiple queries
9 | }
10 |
11 | func main() {
12 | f()
13 | }
14 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/peers-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of channel 'peers' query, -format=json.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See peers-json.golden for expected query results.
6 |
7 | func main() {
8 | chA := make(chan *int)
9 | <-chA
10 | select {
11 | case <-chA: // @peers peer-recv-chA "<-"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/peers-json/main.golden:
--------------------------------------------------------------------------------
1 | -------- @peers peer-recv-chA --------
2 | {
3 | "mode": "peers",
4 | "peers": {
5 | "pos": "testdata/src/peers-json/main.go:11:7",
6 | "type": "chan *int",
7 | "allocs": [
8 | "testdata/src/peers-json/main.go:8:13"
9 | ],
10 | "receives": [
11 | "testdata/src/peers-json/main.go:9:2",
12 | "testdata/src/peers-json/main.go:11:7"
13 | ]
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/peers/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of channel 'peers' query.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See peers.golden for expected query results.
6 |
7 | var a2 int
8 |
9 | func main() {
10 | chA := make(chan *int)
11 | a1 := 1
12 | chA <- &a1
13 |
14 | chA2 := make(chan *int, 2)
15 | if a2 == 0 {
16 | chA = chA2
17 | }
18 |
19 | chB := make(chan *int)
20 | b := 3
21 | chB <- &b
22 |
23 | <-chA // @pointsto pointsto-chA "chA"
24 | <-chA2 // @pointsto pointsto-chA2 "chA2"
25 | <-chB // @pointsto pointsto-chB "chB"
26 |
27 | select {
28 | case rA := <-chA: // @peers peer-recv-chA "<-"
29 | _ = rA // @pointsto pointsto-rA "rA"
30 | case rB := <-chB: // @peers peer-recv-chB "<-"
31 | _ = rB // @pointsto pointsto-rB "rB"
32 |
33 | case <-chA: // @peers peer-recv-chA' "<-"
34 |
35 | case chA2 <- &a2: // @peers peer-send-chA' "<-"
36 | }
37 |
38 | for _ = range chA {
39 | }
40 |
41 | close(chA) // @peers peer-close-chA "chA"
42 |
43 | chC := make(chan *int)
44 | (close)(chC) // @peers peer-close-chC "chC"
45 |
46 | close := func(ch chan *int) chan *int {
47 | return ch
48 | }
49 |
50 | close(chC) <- &b // @peers peer-send-chC "chC"
51 | <-close(chC) // @peers peer-recv-chC "chC"
52 | }
53 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/pointsto-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'pointsto' queries, -format=json.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See pointsto-json.golden for expected query results.
6 |
7 | func main() { //
8 | var s struct{ x [3]int }
9 | p := &s.x[0] // @pointsto val-p "p"
10 | _ = p
11 |
12 | var i I = C(0)
13 | if i == nil {
14 | i = new(D)
15 | }
16 | print(i) // @pointsto val-i "\\bi\\b"
17 | }
18 |
19 | type I interface {
20 | f()
21 | }
22 |
23 | type C int
24 | type D struct{}
25 |
26 | func (c C) f() {}
27 | func (d *D) f() {}
28 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/pointsto-json/main.golden:
--------------------------------------------------------------------------------
1 | -------- @pointsto val-p --------
2 | {
3 | "mode": "pointsto",
4 | "pointsto": [
5 | {
6 | "type": "*int",
7 | "labels": [
8 | {
9 | "pos": "testdata/src/pointsto-json/main.go:8:6",
10 | "desc": "s.x[*]"
11 | }
12 | ]
13 | }
14 | ]
15 | }
16 | -------- @pointsto val-i --------
17 | {
18 | "mode": "pointsto",
19 | "pointsto": [
20 | {
21 | "type": "*D",
22 | "namepos": "testdata/src/pointsto-json/main.go:24:6",
23 | "labels": [
24 | {
25 | "pos": "testdata/src/pointsto-json/main.go:14:10",
26 | "desc": "new"
27 | }
28 | ]
29 | },
30 | {
31 | "type": "C",
32 | "namepos": "testdata/src/pointsto-json/main.go:23:6"
33 | }
34 | ]
35 | }
36 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/referrers-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'referrers' query.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See referrers.golden for expected query results.
6 |
7 | import "lib"
8 |
9 | type s struct {
10 | f int
11 | }
12 |
13 | func main() {
14 | var v lib.Type = lib.Const // @referrers ref-package "lib"
15 | _ = v.Method // @referrers ref-method "Method"
16 | _ = v.Method
17 | v++ //@referrers ref-local "v"
18 | v++
19 |
20 | _ = s{}.f // @referrers ref-field "f"
21 |
22 | var s2 s
23 | s2.f = 1
24 | }
25 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/referrers/ext_test.go:
--------------------------------------------------------------------------------
1 | package main_test
2 |
3 | import (
4 | "lib"
5 | renamed "referrers" // package has name "main", path "referrers", local name "renamed"
6 | )
7 |
8 | func _() {
9 | // This reference should be found by the ref-method query.
10 | _ = (lib.Type).Method // ref from external test package
11 | var _ renamed.T
12 | }
13 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/referrers/int_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "lib"
4 |
5 | func _() {
6 | // This reference should be found by the ref-method query.
7 | _ = (lib.Type).Method // ref from internal test package
8 | }
9 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/referrers/main.go:
--------------------------------------------------------------------------------
1 | package main // @referrers package-decl "main"
2 |
3 | // Tests of 'referrers' query.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See referrers.golden for expected query results.
6 |
7 | import "lib"
8 |
9 | type s struct { // @referrers type " s "
10 | f int
11 | }
12 |
13 | type T int
14 |
15 | func main() {
16 | var v lib.Type = lib.Const // @referrers ref-package "lib"
17 | _ = v.Method // @referrers ref-method "Method"
18 | _ = v.Method
19 | v++ //@referrers ref-local "v"
20 | v++
21 |
22 | _ = s{}.f // @referrers ref-field "f"
23 |
24 | var s2 s
25 | s2.f = 1
26 | }
27 |
28 | // Test //line directives:
29 |
30 | type U int // @referrers ref-type-U "U"
31 |
32 | //line nosuchfile.y:123
33 | var u1 U
34 | var u2 U
35 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/referrers/main.golden:
--------------------------------------------------------------------------------
1 | -------- @referrers package-decl --------
2 | 1 references to package main ("referrers")
3 | var _ renamed.T
4 |
5 | -------- @referrers type --------
6 | 2 references to type s struct{f int}
7 | _ = s{}.f // @referrers ref-field "f"
8 | var s2 s
9 |
10 | -------- @referrers ref-package --------
11 | 4 references to package lib
12 | _ = (lib.Type).Method // ref from external test package
13 | _ = (lib.Type).Method // ref from internal test package
14 | var v lib.Type = lib.Const // @referrers ref-package "lib"
15 | var v lib.Type = lib.Const // @referrers ref-package "lib"
16 |
17 | -------- @referrers ref-method --------
18 | 7 references to func (lib.Type).Method(x *int) *int
19 | p := t.Method(&a) // @describe ref-method "Method"
20 | _ = v.Method // @referrers ref-method "Method"
21 | _ = v.Method
22 | _ = (lib.Type).Method // ref from external test package
23 | _ = (lib.Type).Method // ref from internal test package
24 | _ = v.Method // @referrers ref-method "Method"
25 | _ = v.Method
26 |
27 | -------- @referrers ref-local --------
28 | 4 references to var v lib.Type
29 | _ = v.Method // @referrers ref-method "Method"
30 | _ = v.Method
31 | v++ //@referrers ref-local "v"
32 | v++
33 |
34 | -------- @referrers ref-field --------
35 | 2 references to field f int
36 | _ = s{}.f // @referrers ref-field "f"
37 | s2.f = 1
38 |
39 | -------- @referrers ref-type-U --------
40 | 2 references to type U int
41 | open testdata/src/referrers/nosuchfile.y: no such file or directory (+ 1 more refs in this file)
42 |
43 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/reflection/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // This is a test of 'pointsto', but we split it into a separate file
4 | // so that pointsto.go doesn't have to import "reflect" each time.
5 |
6 | import "reflect"
7 |
8 | var a int
9 | var b bool
10 |
11 | func main() {
12 | m := make(map[*int]*bool)
13 | m[&a] = &b
14 |
15 | mrv := reflect.ValueOf(m)
16 | if a > 0 {
17 | mrv = reflect.ValueOf(&b)
18 | }
19 | if a > 0 {
20 | mrv = reflect.ValueOf(&a)
21 | }
22 |
23 | _ = mrv // @pointsto mrv "mrv"
24 | p1 := mrv.Interface() // @pointsto p1 "p1"
25 | p2 := mrv.MapKeys() // @pointsto p2 "p2"
26 | p3 := p2[0] // @pointsto p3 "p3"
27 | p4 := reflect.TypeOf(p1) // @pointsto p4 "p4"
28 |
29 | _, _, _, _ = p1, p2, p3, p4
30 | }
31 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/reflection/main.golden:
--------------------------------------------------------------------------------
1 | -------- @pointsto mrv --------
2 | this reflect.Value may contain these dynamic types:
3 | *bool, may point to:
4 | reflection.b
5 | *int, may point to:
6 | reflection.a
7 | map[*int]*bool, may point to:
8 | makemap
9 |
10 | -------- @pointsto p1 --------
11 | this interface{} may contain these dynamic types:
12 | *bool, may point to:
13 | reflection.b
14 | *int, may point to:
15 | reflection.a
16 | map[*int]*bool, may point to:
17 | makemap
18 |
19 | -------- @pointsto p2 --------
20 | this []reflect.Value may point to these objects:
21 |
22 |
23 | -------- @pointsto p3 --------
24 | this reflect.Value may contain these dynamic types:
25 | *int, may point to:
26 | reflection.a
27 |
28 | -------- @pointsto p4 --------
29 | this reflect.Type may contain these dynamic types:
30 | *reflect.rtype, may point to:
31 | *bool
32 | *int
33 | map[*int]*bool
34 |
35 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/what-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'what' queries, -format=json.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See what-json.golden for expected query results.
6 |
7 | func main() {
8 | f() // @what call "f"
9 | }
10 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/what-json/main.golden:
--------------------------------------------------------------------------------
1 | -------- @what call --------
2 | {
3 | "mode": "what",
4 | "what": {
5 | "enclosing": [
6 | {
7 | "desc": "identifier",
8 | "start": 175,
9 | "end": 176
10 | },
11 | {
12 | "desc": "function call (or conversion)",
13 | "start": 175,
14 | "end": 178
15 | },
16 | {
17 | "desc": "expression statement",
18 | "start": 175,
19 | "end": 178
20 | },
21 | {
22 | "desc": "block",
23 | "start": 172,
24 | "end": 198
25 | },
26 | {
27 | "desc": "function declaration",
28 | "start": 160,
29 | "end": 198
30 | },
31 | {
32 | "desc": "source file",
33 | "start": 0,
34 | "end": 198
35 | }
36 | ],
37 | "modes": [
38 | "callees",
39 | "callers",
40 | "callstack",
41 | "definition",
42 | "describe",
43 | "freevars",
44 | "implements",
45 | "pointsto",
46 | "referrers"
47 | ],
48 | "srcdir": "testdata/src",
49 | "importpath": "what-json"
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/what/main.go:
--------------------------------------------------------------------------------
1 | package main // @what pkgdecl "main"
2 |
3 | // Tests of 'what' queries.
4 | // See go.tools/guru/guru_test.go for explanation.
5 | // See what.golden for expected query results.
6 |
7 | func main() {
8 | f() // @what call "f"
9 | var ch chan int // @what var "var"
10 | <-ch // @what recv "ch"
11 | }
12 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/what/main.golden:
--------------------------------------------------------------------------------
1 | -------- @what pkgdecl --------
2 | identifier
3 | source file
4 | modes: [definition describe freevars implements pointsto referrers]
5 | srcdir: testdata/src
6 | import path: what
7 |
8 | -------- @what call --------
9 | identifier
10 | function call (or conversion)
11 | expression statement
12 | block
13 | function declaration
14 | source file
15 | modes: [callees callers callstack definition describe freevars implements pointsto referrers]
16 | srcdir: testdata/src
17 | import path: what
18 |
19 | -------- @what var --------
20 | variable declaration
21 | variable declaration statement
22 | block
23 | function declaration
24 | source file
25 | modes: [callers callstack describe freevars pointsto]
26 | srcdir: testdata/src
27 | import path: what
28 |
29 | -------- @what recv --------
30 | identifier
31 | unary <- operation
32 | expression statement
33 | block
34 | function declaration
35 | source file
36 | modes: [callers callstack definition describe freevars implements peers pointsto referrers]
37 | srcdir: testdata/src
38 | import path: what
39 | ch
40 | ch
41 |
42 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/whicherrs/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | type errType string
4 |
5 | const constErr errType = "blah"
6 |
7 | func (et errType) Error() string {
8 | return string(et)
9 | }
10 |
11 | var errVar error = errType("foo")
12 |
13 | func genErr(i int) error {
14 | switch i {
15 | case 0:
16 | return constErr
17 | case 1:
18 | return errVar
19 | default:
20 | return nil
21 | }
22 | }
23 |
24 | func main() {
25 | err := genErr(0) // @whicherrs localerrs "err"
26 | _ = err
27 | }
28 |
--------------------------------------------------------------------------------
/cmd/guru/testdata/src/whicherrs/main.golden:
--------------------------------------------------------------------------------
1 | -------- @whicherrs localerrs --------
2 | this error may point to these globals:
3 | errVar
4 | this error may contain these constants:
5 | constErr
6 | this error may contain these dynamic types:
7 | errType
8 |
9 |
--------------------------------------------------------------------------------
/cmd/present/appengine.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go 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 | // +build appengine
6 |
7 | package main
8 |
9 | import (
10 | "mime"
11 |
12 | "golang.org/x/tools/present"
13 | )
14 |
15 | func init() {
16 | initTemplates("./present/")
17 | present.PlayEnabled = true
18 | initPlayground("./present/", nil)
19 |
20 | // App Engine has no /etc/mime.types
21 | mime.AddExtensionType(".svg", "image/svg+xml")
22 | }
23 |
--------------------------------------------------------------------------------
/cmd/present/play.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go 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 main
6 |
7 | import (
8 | "bytes"
9 | "fmt"
10 | "io/ioutil"
11 | "net/http"
12 | "path/filepath"
13 | "time"
14 |
15 | "golang.org/x/tools/godoc/static"
16 | )
17 |
18 | var scripts = []string{"jquery.js", "jquery-ui.js", "playground.js", "play.js"}
19 |
20 | // playScript registers an HTTP handler at /play.js that serves all the
21 | // scripts specified by the variable above, and appends a line that
22 | // initializes the playground with the specified transport.
23 | func playScript(root, transport string) {
24 | modTime := time.Now()
25 | var buf bytes.Buffer
26 | for _, p := range scripts {
27 | if s, ok := static.Files[p]; ok {
28 | buf.WriteString(s)
29 | continue
30 | }
31 | b, err := ioutil.ReadFile(filepath.Join(root, "static", p))
32 | if err != nil {
33 | panic(err)
34 | }
35 | buf.Write(b)
36 | }
37 | fmt.Fprintf(&buf, "\ninitPlayground(new %v());\n", transport)
38 | b := buf.Bytes()
39 | http.HandleFunc("/play.js", func(w http.ResponseWriter, r *http.Request) {
40 | w.Header().Set("Content-type", "application/javascript")
41 | http.ServeContent(w, r, "", modTime, bytes.NewReader(b))
42 | })
43 | }
44 |
--------------------------------------------------------------------------------
/cmd/present/play_http.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go 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 | // +build appengine appenginevm
6 |
7 | package main
8 |
9 | import (
10 | "net/url"
11 |
12 | "golang.org/x/tools/present"
13 |
14 | _ "golang.org/x/tools/playground"
15 | )
16 |
17 | func initPlayground(basepath string, origin *url.URL) {
18 | playScript(basepath, "HTTPTransport")
19 | }
20 |
21 | func playable(c present.Code) bool {
22 | return present.PlayEnabled && c.Play && c.Ext == ".go"
23 | }
24 |
--------------------------------------------------------------------------------
/cmd/present/play_socket.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go 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 | // +build !appengine,!appenginevm
6 |
7 | package main
8 |
9 | import (
10 | "net/http"
11 | "net/url"
12 | "runtime"
13 |
14 | "golang.org/x/tools/playground/socket"
15 | "golang.org/x/tools/present"
16 | )
17 |
18 | func initPlayground(basepath string, origin *url.URL) {
19 | if present.PlayEnabled {
20 | if *nativeClient {
21 | socket.RunScripts = false
22 | socket.Environ = func() []string {
23 | if runtime.GOARCH == "amd64" {
24 | return environ("GOOS=nacl", "GOARCH=amd64p32")
25 | }
26 | return environ("GOOS=nacl")
27 | }
28 | }
29 | playScript(basepath, "SocketTransport")
30 | http.Handle("/socket", socket.NewHandler(origin))
31 | }
32 | }
33 |
34 | func playable(c present.Code) bool {
35 | return present.PlayEnabled && c.Play
36 | }
37 |
--------------------------------------------------------------------------------
/cmd/present/static/dir.js:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go 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 | // copied from $GOROOT/doc/godocs.js
6 |
7 | function bindEvent(el, e, fn) {
8 | if (el.addEventListener){
9 | el.addEventListener(e, fn, false);
10 | } else if (el.attachEvent){
11 | el.attachEvent('on'+e, fn);
12 | }
13 | }
14 |
15 | function godocs_bindSearchEvents() {
16 | var search = document.getElementById('search');
17 | if (!search) {
18 | // no search box (index disabled)
19 | return;
20 | }
21 | function clearInactive() {
22 | if (search.className == "inactive") {
23 | search.value = "";
24 | search.className = "";
25 | }
26 | }
27 | function restoreInactive() {
28 | if (search.value !== "") {
29 | return;
30 | }
31 | if (search.type != "search") {
32 | search.value = search.getAttribute("placeholder");
33 | }
34 | search.className = "inactive";
35 | }
36 | restoreInactive();
37 | bindEvent(search, 'focus', clearInactive);
38 | bindEvent(search, 'blur', restoreInactive);
39 | }
40 |
41 | bindEvent(window, 'load', godocs_bindSearchEvents);
42 |
--------------------------------------------------------------------------------
/cmd/present/static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/cmd/present/static/favicon.ico
--------------------------------------------------------------------------------
/cmd/present/static/notes.css:
--------------------------------------------------------------------------------
1 | p {
2 | margin: 10px;
3 | }
4 |
5 | #presenter-slides {
6 | display: block;
7 | margin-top: -10px;
8 | margin-left: -17px;
9 | position: fixed;
10 | border: 0;
11 |
12 | transform: scale(0.7, 0.7);
13 | transform-origin: top left;
14 | -moz-transform: scale(0.7);
15 | -moz-transform-origin: top left;
16 | -o-transform: scale(0.7);
17 | -o-transform-origin: top left;
18 | -webkit-transform: scale(0.7);
19 | -webkit-transform-origin: top left;
20 | }
21 |
22 | #presenter-notes {
23 | margin-top: -180px;
24 | font-family: 'Open Sans', Arial, sans-serif;
25 | height: 30%;
26 | width: 100%;
27 | overflow: scroll;
28 | position: fixed;
29 | top: 706px;
30 | }
31 |
--------------------------------------------------------------------------------
/cmd/stringer/testdata/cgo.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // Import "C" shouldn't be imported.
6 |
7 | package main
8 |
9 | /*
10 | #define HELLO 1
11 | */
12 | import "C"
13 |
14 | import "fmt"
15 |
16 | type Cgo uint32
17 |
18 | const (
19 | // MustScanSubDirs indicates that events were coalesced hierarchically.
20 | MustScanSubDirs Cgo = 1 << iota
21 | )
22 |
23 | func main() {
24 | _ = C.HELLO
25 | ck(MustScanSubDirs, "MustScanSubDirs")
26 | }
27 |
28 | func ck(day Cgo, str string) {
29 | if fmt.Sprint(day) != str {
30 | panic("cgo.go: " + str)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/cmd/stringer/testdata/day.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // Simple test: enumeration of type int starting at 0.
6 |
7 | package main
8 |
9 | import "fmt"
10 |
11 | type Day int
12 |
13 | const (
14 | Monday Day = iota
15 | Tuesday
16 | Wednesday
17 | Thursday
18 | Friday
19 | Saturday
20 | Sunday
21 | )
22 |
23 | func main() {
24 | ck(Monday, "Monday")
25 | ck(Tuesday, "Tuesday")
26 | ck(Wednesday, "Wednesday")
27 | ck(Thursday, "Thursday")
28 | ck(Friday, "Friday")
29 | ck(Saturday, "Saturday")
30 | ck(Sunday, "Sunday")
31 | ck(-127, "Day(-127)")
32 | ck(127, "Day(127)")
33 | }
34 |
35 | func ck(day Day, str string) {
36 | if fmt.Sprint(day) != str {
37 | panic("day.go: " + str)
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/cmd/stringer/testdata/gap.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // Gaps and an offset.
6 |
7 | package main
8 |
9 | import "fmt"
10 |
11 | type Gap int
12 |
13 | const (
14 | Two Gap = 2
15 | Three Gap = 3
16 | Five Gap = 5
17 | Six Gap = 6
18 | Seven Gap = 7
19 | Eight Gap = 8
20 | Nine Gap = 9
21 | Eleven Gap = 11
22 | )
23 |
24 | func main() {
25 | ck(0, "Gap(0)")
26 | ck(1, "Gap(1)")
27 | ck(Two, "Two")
28 | ck(Three, "Three")
29 | ck(4, "Gap(4)")
30 | ck(Five, "Five")
31 | ck(Six, "Six")
32 | ck(Seven, "Seven")
33 | ck(Eight, "Eight")
34 | ck(Nine, "Nine")
35 | ck(10, "Gap(10)")
36 | ck(Eleven, "Eleven")
37 | ck(12, "Gap(12)")
38 | }
39 |
40 | func ck(gap Gap, str string) {
41 | if fmt.Sprint(gap) != str {
42 | panic("gap.go: " + str)
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/cmd/stringer/testdata/num.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // Signed integers spanning zero.
6 |
7 | package main
8 |
9 | import "fmt"
10 |
11 | type Num int
12 |
13 | const (
14 | m_2 Num = -2 + iota
15 | m_1
16 | m0
17 | m1
18 | m2
19 | )
20 |
21 | func main() {
22 | ck(-3, "Num(-3)")
23 | ck(m_2, "m_2")
24 | ck(m_1, "m_1")
25 | ck(m0, "m0")
26 | ck(m1, "m1")
27 | ck(m2, "m2")
28 | ck(3, "Num(3)")
29 | }
30 |
31 | func ck(num Num, str string) {
32 | if fmt.Sprint(num) != str {
33 | panic("num.go: " + str)
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/cmd/stringer/testdata/number.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // Enumeration with an offset.
6 | // Also includes a duplicate.
7 |
8 | package main
9 |
10 | import "fmt"
11 |
12 | type Number int
13 |
14 | const (
15 | _ Number = iota
16 | One
17 | Two
18 | Three
19 | AnotherOne = One // Duplicate; note that AnotherOne doesn't appear below.
20 | )
21 |
22 | func main() {
23 | ck(One, "One")
24 | ck(Two, "Two")
25 | ck(Three, "Three")
26 | ck(AnotherOne, "One")
27 | ck(127, "Number(127)")
28 | }
29 |
30 | func ck(num Number, str string) {
31 | if fmt.Sprint(num) != str {
32 | panic("number.go: " + str)
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/cmd/stringer/testdata/prime.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // Enough gaps to trigger a map implementation of the method.
6 | // Also includes a duplicate to test that it doesn't cause problems
7 |
8 | package main
9 |
10 | import "fmt"
11 |
12 | type Prime int
13 |
14 | const (
15 | p2 Prime = 2
16 | p3 Prime = 3
17 | p5 Prime = 5
18 | p7 Prime = 7
19 | p77 Prime = 7 // Duplicate; note that p77 doesn't appear below.
20 | p11 Prime = 11
21 | p13 Prime = 13
22 | p17 Prime = 17
23 | p19 Prime = 19
24 | p23 Prime = 23
25 | p29 Prime = 29
26 | p37 Prime = 31
27 | p41 Prime = 41
28 | p43 Prime = 43
29 | )
30 |
31 | func main() {
32 | ck(0, "Prime(0)")
33 | ck(1, "Prime(1)")
34 | ck(p2, "p2")
35 | ck(p3, "p3")
36 | ck(4, "Prime(4)")
37 | ck(p5, "p5")
38 | ck(p7, "p7")
39 | ck(p77, "p7")
40 | ck(p11, "p11")
41 | ck(p13, "p13")
42 | ck(p17, "p17")
43 | ck(p19, "p19")
44 | ck(p23, "p23")
45 | ck(p29, "p29")
46 | ck(p37, "p37")
47 | ck(p41, "p41")
48 | ck(p43, "p43")
49 | ck(44, "Prime(44)")
50 | }
51 |
52 | func ck(prime Prime, str string) {
53 | if fmt.Sprint(prime) != str {
54 | panic("prime.go: " + str)
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/cmd/stringer/testdata/unum.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // Unsigned integers spanning zero.
6 |
7 | package main
8 |
9 | import "fmt"
10 |
11 | type Unum uint8
12 |
13 | const (
14 | m_2 Unum = iota + 253
15 | m_1
16 | )
17 |
18 | const (
19 | m0 Unum = iota
20 | m1
21 | m2
22 | )
23 |
24 | func main() {
25 | ck(^Unum(0)-3, "Unum(252)")
26 | ck(m_2, "m_2")
27 | ck(m_1, "m_1")
28 | ck(m0, "m0")
29 | ck(m1, "m1")
30 | ck(m2, "m2")
31 | ck(3, "Unum(3)")
32 | }
33 |
34 | func ck(unum Unum, str string) {
35 | if fmt.Sprint(unum) != str {
36 | panic("unum.go: " + str)
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/cmd/stringer/testdata/unum2.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // Unsigned integers - check maximum size
6 |
7 | package main
8 |
9 | import "fmt"
10 |
11 | type Unum2 uint8
12 |
13 | const (
14 | Zero Unum2 = iota
15 | One
16 | Two
17 | )
18 |
19 | func main() {
20 | ck(Zero, "Zero")
21 | ck(One, "One")
22 | ck(Two, "Two")
23 | ck(3, "Unum2(3)")
24 | ck(255, "Unum2(255)")
25 | }
26 |
27 | func ck(unum Unum2, str string) {
28 | if fmt.Sprint(unum) != str {
29 | panic("unum.go: " + str)
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/cmd/tip/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM golang:1.5
2 |
3 | RUN apt-get update && apt-get install --no-install-recommends -y -q build-essential git
4 |
5 | # golang puts its go install here (weird but true)
6 | ENV GOROOT_BOOTSTRAP /usr/local/go
7 |
8 | # golang sets GOPATH=/go
9 | ADD . /go/src/tip
10 | RUN go install tip
11 | ENTRYPOINT ["/go/bin/tip"]
12 | # Kubernetes expects us to listen on port 8080
13 | EXPOSE 8080
14 |
--------------------------------------------------------------------------------
/cmd/tip/README:
--------------------------------------------------------------------------------
1 | 1. Deploy the app.
2 |
3 | To deploy tip.golang.org:
4 | $ gcloud --project golang-org preview app deploy --no-promote godoc.yaml
5 |
6 | To deploy talks.golang.org:
7 | $ gcloud --project golang-org preview app deploy --no-promote talks.yaml
8 |
9 | 2. Wait until the deployed version is serving requests.
10 |
11 | 3. Go to the developer console and upgrade the default version.
12 | https://console.developers.google.com/appengine/versions?project=golang-org&moduleId=tip
13 |
14 | 4. Clean up any old versions (they continue to use at least one instance).
15 |
--------------------------------------------------------------------------------
/cmd/tip/godoc.yaml:
--------------------------------------------------------------------------------
1 | module: tip
2 | runtime: custom
3 | vm: true
4 |
5 | automatic_scaling:
6 | min_num_instances: 1
7 | max_num_instances: 2
8 |
9 | env_variables:
10 | TIP_BUILDER: 'godoc'
11 |
12 | health_check:
13 | enable_health_check: True
14 | check_interval_sec: 5
15 | timeout_sec: 4
16 | unhealthy_threshold: 2
17 | healthy_threshold: 2
18 | restart_threshold: 240
19 |
--------------------------------------------------------------------------------
/cmd/tip/talks.yaml:
--------------------------------------------------------------------------------
1 | module: talks
2 | runtime: custom
3 | vm: true
4 |
5 | automatic_scaling:
6 | min_num_instances: 1
7 | max_num_instances: 5
8 |
9 | env_variables:
10 | TIP_BUILDER: 'talks'
11 |
12 | health_check:
13 | enable_health_check: True
14 | check_interval_sec: 5
15 | timeout_sec: 4
16 | unhealthy_threshold: 2
17 | healthy_threshold: 2
18 | restart_threshold: 240
19 |
--------------------------------------------------------------------------------
/cmd/vet/assign.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 | /*
6 | This file contains the code to check for useless assignments.
7 | */
8 |
9 | package main
10 |
11 | import (
12 | "go/ast"
13 | "go/token"
14 | "reflect"
15 | )
16 |
17 | func init() {
18 | register("assign",
19 | "check for useless assignments",
20 | checkAssignStmt,
21 | assignStmt)
22 | }
23 |
24 | // TODO: should also check for assignments to struct fields inside methods
25 | // that are on T instead of *T.
26 |
27 | // checkAssignStmt checks for assignments of the form " = ".
28 | // These are almost always useless, and even when they aren't they are usually a mistake.
29 | func checkAssignStmt(f *File, node ast.Node) {
30 | stmt := node.(*ast.AssignStmt)
31 | if stmt.Tok != token.ASSIGN {
32 | return // ignore :=
33 | }
34 | if len(stmt.Lhs) != len(stmt.Rhs) {
35 | // If LHS and RHS have different cardinality, they can't be the same.
36 | return
37 | }
38 | for i, lhs := range stmt.Lhs {
39 | rhs := stmt.Rhs[i]
40 | if reflect.TypeOf(lhs) != reflect.TypeOf(rhs) {
41 | continue // short-circuit the heavy-weight gofmt check
42 | }
43 | le := f.gofmt(lhs)
44 | re := f.gofmt(rhs)
45 | if le == re {
46 | f.Badf(stmt.Pos(), "self-assignment of %s to %s", re, le)
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/asm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2010 The Go 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 | // +build ignore
6 |
7 | // This file contains declarations to test the assembly in test_asm.s.
8 |
9 | package testdata
10 |
11 | func arg1(x int8, y uint8)
12 | func arg2(x int16, y uint16)
13 | func arg4(x int32, y uint32)
14 | func arg8(x int64, y uint64)
15 | func argint(x int, y uint)
16 | func argptr(x *byte, y *byte, c chan int, m map[int]int, f func())
17 | func argstring(x, y string)
18 | func argslice(x, y []string)
19 | func argiface(x interface{}, y interface {
20 | m()
21 | })
22 | func returnint() int
23 | func returnbyte(x int) byte
24 | func returnnamed(x byte) (r1 int, r2 int16, r3 string, r4 byte)
25 | func returnintmissing() int
26 | func leaf(x, y int) int
27 |
28 | func noprof(x int)
29 | func dupok(x int)
30 | func nosplit(x int)
31 | func rodata(x int)
32 | func noptr(x int)
33 | func wrapper(x int)
34 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/asm4.s:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 | // +build amd64
6 | // +build vet_test
7 |
8 | // Test cases for symbolic NOSPLIT etc. on TEXT symbols.
9 |
10 | TEXT ·noprof(SB),NOPROF,$0-8
11 | RET
12 |
13 | TEXT ·dupok(SB),DUPOK,$0-8
14 | RET
15 |
16 | TEXT ·nosplit(SB),NOSPLIT,$0
17 | RET
18 |
19 | TEXT ·rodata(SB),RODATA,$0-8
20 | RET
21 |
22 | TEXT ·noptr(SB),NOPTR|NOSPLIT,$0
23 | RET
24 |
25 | TEXT ·wrapper(SB),WRAPPER,$0-8
26 | RET
27 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/assign.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 | // This file contains tests for the useless-assignment checker.
6 |
7 | package testdata
8 |
9 | type ST struct {
10 | x int
11 | }
12 |
13 | func (s *ST) SetX(x int) {
14 | // Accidental self-assignment; it should be "s.x = x"
15 | x = x // ERROR "self-assignment of x to x"
16 | // Another mistake
17 | s.x = s.x // ERROR "self-assignment of s.x to s.x"
18 | }
19 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/buildtag.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 | // This file contains tests for the buildtag checker.
6 |
7 | // +builder // ERROR "possible malformed \+build comment"
8 | // +build !ignore
9 |
10 | package testdata
11 |
12 | // +build toolate // ERROR "build comment must appear before package clause and be followed by a blank line"
13 |
14 | var _ = 3
15 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/buildtag_bad.go:
--------------------------------------------------------------------------------
1 | // This file contains misplaced or malformed build constraints.
2 | // The Go tool will skip it, because the constraints are invalid.
3 | // It serves only to test the tag checker during make test.
4 |
5 | // Mention +build // ERROR "possible malformed \+build comment"
6 |
7 | // +build !!bang // ERROR "invalid double negative in build constraint"
8 | // +build @#$ // ERROR "invalid non-alphanumeric build constraint"
9 |
10 | // +build toolate // ERROR "build comment must appear before package clause and be followed by a blank line"
11 | package bad
12 |
13 | // This is package 'bad' rather than 'main' so the erroneous build
14 | // tag doesn't end up looking like a package doc for the vet command
15 | // when examined by godoc.
16 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/composite.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go 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 | // This file contains tests for the untagged struct literal checker.
6 |
7 | // This file contains the test for untagged struct literals.
8 |
9 | package testdata
10 |
11 | import (
12 | "flag"
13 | "go/scanner"
14 | )
15 |
16 | var Okay1 = []string{
17 | "Name",
18 | "Usage",
19 | "DefValue",
20 | }
21 |
22 | var Okay2 = map[string]bool{
23 | "Name": true,
24 | "Usage": true,
25 | "DefValue": true,
26 | }
27 |
28 | var Okay3 = struct {
29 | X string
30 | Y string
31 | Z string
32 | }{
33 | "Name",
34 | "Usage",
35 | "DefValue",
36 | }
37 |
38 | type MyStruct struct {
39 | X string
40 | Y string
41 | Z string
42 | }
43 |
44 | var Okay4 = MyStruct{
45 | "Name",
46 | "Usage",
47 | "DefValue",
48 | }
49 |
50 | // Testing is awkward because we need to reference things from a separate package
51 | // to trigger the warnings.
52 |
53 | var BadStructLiteralUsedInTests = flag.Flag{ // ERROR "unkeyed fields"
54 | "Name",
55 | "Usage",
56 | nil, // Value
57 | "DefValue",
58 | }
59 |
60 | // Used to test the check for slices and arrays: If that test is disabled and
61 | // vet is run with --compositewhitelist=false, this line triggers an error.
62 | // Clumsy but sufficient.
63 | var scannerErrorListTest = scanner.ErrorList{nil, nil}
64 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/divergent/buf.go:
--------------------------------------------------------------------------------
1 | // Test of examples with divergent packages.
2 |
3 | // Package buf ...
4 | package buf
5 |
6 | // Buf is a ...
7 | type Buf []byte
8 |
9 | // Append ...
10 | func (*Buf) Append([]byte) {}
11 |
12 | func (Buf) Reset() {}
13 |
14 | func (Buf) Len() int { return 0 }
15 |
16 | // DefaultBuf is a ...
17 | var DefaultBuf Buf
18 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/divergent/buf_test.go:
--------------------------------------------------------------------------------
1 | // Test of examples with divergent packages.
2 |
3 | package buf_test
4 |
5 | func Example() {} // OK because is package-level.
6 |
7 | func Example_suffix() // OK because refers to suffix annotation.
8 |
9 | func Example_BadSuffix() // ERROR "Example_BadSuffix has malformed example suffix: BadSuffix"
10 |
11 | func ExampleBuf() // OK because refers to known top-level type.
12 |
13 | func ExampleBuf_Append() {} // OK because refers to known method.
14 |
15 | func ExampleBuf_Clear() {} // ERROR "ExampleBuf_Clear refers to unknown field or method: Buf.Clear"
16 |
17 | func ExampleBuf_suffix() {} // OK because refers to suffix annotation.
18 |
19 | func ExampleBuf_Append_Bad() {} // ERROR "ExampleBuf_Append_Bad has malformed example suffix: Bad"
20 |
21 | func ExampleBuf_Append_suffix() {} // OK because refers to known method with valid suffix.
22 |
23 | func ExampleDefaultBuf() {} // OK because refers to top-level identifier.
24 |
25 | func ExampleBuf_Reset() bool { return true } // ERROR "ExampleBuf_Reset should return nothing"
26 |
27 | func ExampleBuf_Len(i int) {} // ERROR "ExampleBuf_Len should be niladic"
28 |
29 | // "Puffer" is German for "Buffer".
30 |
31 | func ExamplePuffer() // ERROR "ExamplePuffer refers to unknown identifier: Puffer"
32 |
33 | func ExamplePuffer_Append() // ERROR "ExamplePuffer_Append refers to unknown identifier: Puffer"
34 |
35 | func ExamplePuffer_suffix() // ERROR "ExamplePuffer_suffix refers to unknown identifier: Puffer"
36 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/incomplete/examples_test.go:
--------------------------------------------------------------------------------
1 | // Test of examples.
2 |
3 | package testdata
4 |
5 | func Example() {} // OK because is package-level.
6 |
7 | func Example_suffix() // OK because refers to suffix annotation.
8 |
9 | func Example_BadSuffix() // OK because non-test package was excluded. No false positives wanted.
10 |
11 | func ExampleBuf() // OK because non-test package was excluded. No false positives wanted.
12 |
13 | func ExampleBuf_Append() {} // OK because non-test package was excluded. No false positives wanted.
14 |
15 | func ExampleBuf_Clear() {} // OK because non-test package was excluded. No false positives wanted.
16 |
17 | func ExampleBuf_suffix() {} // OK because refers to suffix annotation.
18 |
19 | func ExampleBuf_Append_Bad() {} // OK because non-test package was excluded. No false positives wanted.
20 |
21 | func ExampleBuf_Append_suffix() {} // OK because refers to known method with valid suffix.
22 |
23 | func ExampleBuf_Reset() bool { return true } // ERROR "ExampleBuf_Reset should return nothing"
24 |
25 | func ExampleBuf_Len(i int) {} // ERROR "ExampleBuf_Len should be niladic"
26 |
27 | // "Puffer" is German for "Buffer".
28 |
29 | func ExamplePuffer() // OK because non-test package was excluded. No false positives wanted.
30 |
31 | func ExamplePuffer_Append() // OK because non-test package was excluded. No false positives wanted.
32 |
33 | func ExamplePuffer_suffix() // OK because non-test package was excluded. No false positives wanted.
34 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/method.go:
--------------------------------------------------------------------------------
1 | // Copyright 2010 The Go 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 | // This file contains tests for the canonical method checker.
6 |
7 | // This file contains the code to check canonical methods.
8 |
9 | package testdata
10 |
11 | import (
12 | "fmt"
13 | )
14 |
15 | type MethodTest int
16 |
17 | func (t *MethodTest) Scan(x fmt.ScanState, c byte) { // ERROR "should have signature Scan"
18 | }
19 |
20 | type MethodTestInterface interface {
21 | ReadByte() byte // ERROR "should have signature ReadByte"
22 | }
23 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/nilfunc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 testdata
6 |
7 | func F() {}
8 |
9 | type T struct {
10 | F func()
11 | }
12 |
13 | func (T) M() {}
14 |
15 | var Fv = F
16 |
17 | func Comparison() {
18 | var t T
19 | var fn func()
20 | if fn == nil || Fv == nil || t.F == nil {
21 | // no error; these func vars or fields may be nil
22 | }
23 | if F == nil { // ERROR "comparison of function F == nil is always false"
24 | panic("can't happen")
25 | }
26 | if t.M == nil { // ERROR "comparison of function M == nil is always false"
27 | panic("can't happen")
28 | }
29 | if F != nil { // ERROR "comparison of function F != nil is always true"
30 | if t.M != nil { // ERROR "comparison of function M != nil is always true"
31 | return
32 | }
33 | }
34 | panic("can't happen")
35 | }
36 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/tagtest/file1.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go 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 | // +build testtag
6 |
7 | package main
8 |
9 | func main() {
10 | }
11 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/tagtest/file2.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go 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 | // +build !testtag
6 |
7 | package main
8 |
9 | func ignore() {
10 | }
11 |
--------------------------------------------------------------------------------
/cmd/vet/testdata/unused.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go 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 | // This file contains tests for the unusedresult checker.
6 |
7 | package testdata
8 |
9 | import (
10 | "bytes"
11 | "errors"
12 | "fmt"
13 | )
14 |
15 | func _() {
16 | fmt.Errorf("") // ERROR "result of fmt.Errorf call not used"
17 | _ = fmt.Errorf("")
18 |
19 | errors.New("") // ERROR "result of errors.New call not used"
20 |
21 | err := errors.New("")
22 | err.Error() // ERROR "result of \(error\).Error call not used"
23 |
24 | var buf bytes.Buffer
25 | buf.String() // ERROR "result of \(bytes.Buffer\).String call not used"
26 |
27 | fmt.Sprint("") // ERROR "result of fmt.Sprint call not used"
28 | fmt.Sprintf("") // ERROR "result of fmt.Sprintf call not used"
29 | }
30 |
--------------------------------------------------------------------------------
/codereview.cfg:
--------------------------------------------------------------------------------
1 | issuerepo: golang/go
2 |
--------------------------------------------------------------------------------
/container/intsets/popcnt_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go 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 | // +build amd64,!appengine,!gccgo
6 |
7 | package intsets
8 |
9 | func popcnt(x word) int
10 | func havePOPCNT() bool
11 |
12 | var hasPOPCNT = havePOPCNT()
13 |
14 | // popcount returns the population count (number of set bits) of x.
15 | func popcount(x word) int {
16 | if hasPOPCNT {
17 | return popcnt(x)
18 | }
19 | return popcountTable(x) // faster than Hacker's Delight
20 | }
21 |
--------------------------------------------------------------------------------
/container/intsets/popcnt_amd64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go 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 | // +build amd64,!appengine,!gccgo
6 |
7 | #include "textflag.h"
8 |
9 | // func havePOPCNT() bool
10 | TEXT ·havePOPCNT(SB),4,$0
11 | MOVQ $1, AX
12 | CPUID
13 | SHRQ $23, CX
14 | ANDQ $1, CX
15 | MOVB CX, ret+0(FP)
16 | RET
17 |
18 | // func popcnt(word) int
19 | TEXT ·popcnt(SB),NOSPLIT,$0-8
20 | XORQ AX, AX
21 | MOVQ x+0(FP), SI
22 | // POPCNT (SI), AX is not recognized by Go assembler,
23 | // so we assemble it ourselves.
24 | BYTE $0xf3
25 | BYTE $0x48
26 | BYTE $0x0f
27 | BYTE $0xb8
28 | BYTE $0xc6
29 | MOVQ AX, ret+8(FP)
30 | RET
31 |
--------------------------------------------------------------------------------
/container/intsets/popcnt_gccgo.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go 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 | // +build gccgo
6 |
7 | package intsets
8 |
9 | func popcount(x word) int
10 |
--------------------------------------------------------------------------------
/container/intsets/popcnt_gccgo_c.c:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go 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 | // +build gccgo
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | #define _STRINGIFY2_(x) #x
12 | #define _STRINGIFY_(x) _STRINGIFY2_(x)
13 | #define GOSYM_PREFIX _STRINGIFY_(__USER_LABEL_PREFIX__)
14 |
15 | extern intptr_t popcount(uintptr_t x) __asm__(GOSYM_PREFIX GOPKGPATH ".popcount");
16 |
17 | intptr_t popcount(uintptr_t x) {
18 | return __builtin_popcountl((unsigned long)(x));
19 | }
20 |
--------------------------------------------------------------------------------
/container/intsets/popcnt_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go 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 | // +build !amd64 appengine
6 | // +build !gccgo
7 |
8 | package intsets
9 |
10 | import "runtime"
11 |
12 | // We compared three algorithms---Hacker's Delight, table lookup,
13 | // and AMD64's SSE4.1 hardware POPCNT---on a 2.67GHz Xeon X5550.
14 | //
15 | // % GOARCH=amd64 go test -run=NONE -bench=Popcount
16 | // POPCNT 5.12 ns/op
17 | // Table 8.53 ns/op
18 | // HackersDelight 9.96 ns/op
19 | //
20 | // % GOARCH=386 go test -run=NONE -bench=Popcount
21 | // Table 10.4 ns/op
22 | // HackersDelight 5.23 ns/op
23 | //
24 | // (AMD64's ABM1 hardware supports ntz and nlz too,
25 | // but they aren't critical.)
26 |
27 | // popcount returns the population count (number of set bits) of x.
28 | func popcount(x word) int {
29 | if runtime.GOARCH == "386" {
30 | return popcountHD(uint32(x))
31 | }
32 | return popcountTable(x)
33 | }
34 |
--------------------------------------------------------------------------------
/container/intsets/util_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 intsets
6 |
7 | import (
8 | "math/rand"
9 | "testing"
10 | )
11 |
12 | func TestNLZ(t *testing.T) {
13 | // Test the platform-specific edge case.
14 | // NB: v must be a var (not const) so that the word() conversion is dynamic.
15 | // Otherwise the compiler will report an error.
16 | v := uint64(0x0000801000000000)
17 | n := nlz(word(v))
18 | want := 32 // (on 32-bit)
19 | if bitsPerWord == 64 {
20 | want = 16
21 | }
22 | if n != want {
23 | t.Errorf("%d-bit nlz(%d) = %d, want %d", bitsPerWord, v, n, want)
24 | }
25 | }
26 |
27 | // Backdoor for testing.
28 | func (s *Sparse) Check() error { return s.check() }
29 |
30 | func dumbPopcount(x word) int {
31 | var popcnt int
32 | for i := uint(0); i < bitsPerWord; i++ {
33 | if x&(1< A
22 | // f --> init$1
23 | // f --> init$2
24 |
--------------------------------------------------------------------------------
/go/callgraph/cha/testdata/iface.go:
--------------------------------------------------------------------------------
1 | //+build ignore
2 |
3 | package main
4 |
5 | // Test of interface calls. None of the concrete types are ever
6 | // instantiated or converted to interfaces.
7 |
8 | type I interface {
9 | f()
10 | }
11 |
12 | type J interface {
13 | f()
14 | g()
15 | }
16 |
17 | type C int // implements I
18 |
19 | func (*C) f()
20 |
21 | type D int // implements I and J
22 |
23 | func (*D) f()
24 | func (*D) g()
25 |
26 | func one(i I, j J) {
27 | i.f() // calls *C and *D
28 | }
29 |
30 | func two(i I, j J) {
31 | j.f() // calls *D (but not *C, even though it defines method f)
32 | }
33 |
34 | func three(i I, j J) {
35 | j.g() // calls *D
36 | }
37 |
38 | func four(i I, j J) {
39 | Jf := J.f
40 | if unknown {
41 | Jf = nil // suppress SSA constant propagation
42 | }
43 | Jf(nil) // calls *D
44 | }
45 |
46 | func five(i I, j J) {
47 | jf := j.f
48 | if unknown {
49 | jf = nil // suppress SSA constant propagation
50 | }
51 | jf() // calls *D
52 | }
53 |
54 | var unknown bool
55 |
56 | // WANT:
57 | // Dynamic calls
58 | // (J).f$bound --> (*D).f
59 | // (J).f$thunk --> (*D).f
60 | // five --> (J).f$bound
61 | // four --> (J).f$thunk
62 | // one --> (*C).f
63 | // one --> (*D).f
64 | // three --> (*D).g
65 | // two --> (*D).f
66 |
--------------------------------------------------------------------------------
/go/callgraph/cha/testdata/recv.go:
--------------------------------------------------------------------------------
1 | //+build ignore
2 |
3 | package main
4 |
5 | type I interface {
6 | f()
7 | }
8 |
9 | type J interface {
10 | g()
11 | }
12 |
13 | type C int // C and *C implement I; *C implements J
14 |
15 | func (C) f()
16 | func (*C) g()
17 |
18 | type D int // *D implements I and J
19 |
20 | func (*D) f()
21 | func (*D) g()
22 |
23 | func f(i I) {
24 | i.f() // calls C, *C, *D
25 | }
26 |
27 | func g(j J) {
28 | j.g() // calls *C, *D
29 | }
30 |
31 | // WANT:
32 | // Dynamic calls
33 | // f --> (*C).f
34 | // f --> (*D).f
35 | // f --> (C).f
36 | // g --> (*C).g
37 | // g --> (*D).g
38 |
--------------------------------------------------------------------------------
/go/callgraph/rta/testdata/func.go:
--------------------------------------------------------------------------------
1 | //+build ignore
2 |
3 | package main
4 |
5 | // Test of dynamic function calls.
6 | // No interfaces, so no runtime/reflect types.
7 |
8 | func A1() {
9 | A2(0)
10 | }
11 |
12 | func A2(int) {} // not address-taken
13 |
14 | func B() {} // unreachable
15 |
16 | var (
17 | C = func(int) {}
18 | D = func(int) {}
19 | )
20 |
21 | func main() {
22 | A1()
23 |
24 | pfn := C
25 | pfn(0) // calls C and D but not A2 (same sig but not address-taken)
26 | }
27 |
28 | // WANT:
29 | // Dynamic calls
30 | // main --> init$1
31 | // main --> init$2
32 | // Reachable functions
33 | // A1
34 | // A2
35 | // init$1
36 | // init$2
37 | // Reflect types
38 |
--------------------------------------------------------------------------------
/go/callgraph/rta/testdata/rtype.go:
--------------------------------------------------------------------------------
1 | //+build ignore
2 |
3 | package main
4 |
5 | // Test of runtime types (types for which descriptors are needed).
6 |
7 | func use(interface{})
8 |
9 | type A byte // neither A nor byte are runtime types
10 |
11 | type B struct{ x uint } // B and uint are runtime types, but not the struct
12 |
13 | func main() {
14 | var x int // not a runtime type
15 | print(x)
16 |
17 | var y string // runtime type due to interface conversion
18 | use(y)
19 |
20 | use(struct{ uint64 }{}) // struct is a runtime type
21 |
22 | use(new(B)) // *B is a runtime type
23 | }
24 |
25 | // WANT:
26 | // Dynamic calls
27 | // Reachable functions
28 | // use
29 | // Reflect types
30 | // *B
31 | // B
32 | // string
33 | // struct{uint64}
34 | // uint
35 | // uint64
36 |
--------------------------------------------------------------------------------
/go/callgraph/static/static.go:
--------------------------------------------------------------------------------
1 | // Package static computes the call graph of a Go program containing
2 | // only static call edges.
3 | package static // import "golang.org/x/tools/go/callgraph/static"
4 |
5 | import (
6 | "golang.org/x/tools/go/callgraph"
7 | "golang.org/x/tools/go/ssa"
8 | "golang.org/x/tools/go/ssa/ssautil"
9 | )
10 |
11 | // CallGraph computes the call graph of the specified program
12 | // considering only static calls.
13 | //
14 | func CallGraph(prog *ssa.Program) *callgraph.Graph {
15 | cg := callgraph.New(nil) // TODO(adonovan) eliminate concept of rooted callgraph
16 |
17 | // TODO(adonovan): opt: use only a single pass over the ssa.Program.
18 | // TODO(adonovan): opt: this is slower than RTA (perhaps because
19 | // the lower precision means so many edges are allocated)!
20 | for f := range ssautil.AllFunctions(prog) {
21 | fnode := cg.CreateNode(f)
22 | for _, b := range f.Blocks {
23 | for _, instr := range b.Instrs {
24 | if site, ok := instr.(ssa.CallInstruction); ok {
25 | if g := site.Common().StaticCallee(); g != nil {
26 | gnode := cg.CreateNode(g)
27 | callgraph.AddEdge(fnode, site, gnode)
28 | }
29 | }
30 | }
31 | }
32 | }
33 |
34 | return cg
35 | }
36 |
--------------------------------------------------------------------------------
/go/exact/go13.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build !go1.4
6 |
7 | package exact
8 |
9 | import (
10 | "math"
11 | "math/big"
12 | )
13 |
14 | func ratToFloat32(x *big.Rat) (float32, bool) {
15 | // Before 1.4, there's no Rat.Float32.
16 | // Emulate it, albeit at the cost of
17 | // imprecision in corner cases.
18 | x64, exact := x.Float64()
19 | x32 := float32(x64)
20 | if math.IsInf(float64(x32), 0) {
21 | exact = false
22 | }
23 | return x32, exact
24 | }
25 |
--------------------------------------------------------------------------------
/go/exact/go14.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build go1.4
6 |
7 | package exact
8 |
9 | import "math/big"
10 |
11 | func ratToFloat32(x *big.Rat) (float32, bool) {
12 | return x.Float32()
13 | }
14 |
--------------------------------------------------------------------------------
/go/gccgoimporter/testdata/complexnums.go:
--------------------------------------------------------------------------------
1 | package complexnums
2 |
3 | const NN = -1 - 1i
4 | const NP = -1 + 1i
5 | const PN = 1 - 1i
6 | const PP = 1 + 1i
7 |
--------------------------------------------------------------------------------
/go/gccgoimporter/testdata/complexnums.gox:
--------------------------------------------------------------------------------
1 | v1;
2 | package complexnums;
3 | pkgpath complexnums;
4 | priority 1;
5 | const NN = -0.1E1-0.1E1i ;
6 | const NP = -0.1E1+0.1E1i ;
7 | const PN = 0.1E1-0.1E1i ;
8 | const PP = 0.1E1+0.1E1i ;
9 |
--------------------------------------------------------------------------------
/go/gccgoimporter/testdata/imports.go:
--------------------------------------------------------------------------------
1 | package imports
2 |
3 | import "fmt"
4 |
5 | var Hello = fmt.Sprintf("Hello, world")
6 |
--------------------------------------------------------------------------------
/go/gccgoimporter/testdata/imports.gox:
--------------------------------------------------------------------------------
1 | v1;
2 | package imports;
3 | pkgpath imports;
4 | priority 7;
5 | import fmt fmt "fmt";
6 | init imports imports..import 7 math math..import 1 runtime runtime..import 1 strconv strconv..import 2 io io..import 3 reflect reflect..import 3 syscall syscall..import 3 time time..import 4 os os..import 5 fmt fmt..import 6;
7 | var Hello ;
8 |
--------------------------------------------------------------------------------
/go/gccgoimporter/testdata/pointer.go:
--------------------------------------------------------------------------------
1 | package pointer
2 |
3 | type Int8Ptr *int8
4 |
--------------------------------------------------------------------------------
/go/gccgoimporter/testdata/pointer.gox:
--------------------------------------------------------------------------------
1 | v1;
2 | package pointer;
3 | pkgpath pointer;
4 | type >>;
5 |
--------------------------------------------------------------------------------
/go/gcimporter15/setname15.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go 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 | // +build go1.5,!go1.6
6 |
7 | package gcimporter
8 |
9 | import (
10 | "go/types"
11 | "unsafe"
12 | )
13 |
14 | func setName(pkg *types.Package, name string) {
15 | (*types_Package)(unsafe.Pointer(pkg)).name = name
16 | }
17 |
18 | // The underlying type of types_Package is identical to
19 | // the underlying type of types.Package. We use it with
20 | // package unsafe to set the name field since 1.5 does
21 | // not have the Package.SetName method.
22 | // TestSetName verifies that the layout with respect to
23 | // the name field is correct.
24 | type types_Package struct {
25 | path string
26 | name string
27 | scope *types.Scope
28 | complete bool
29 | imports []*types.Package
30 | fake bool
31 | }
32 |
--------------------------------------------------------------------------------
/go/gcimporter15/setname16.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go 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 | // +build go1.6
6 |
7 | package gcimporter
8 |
9 | import "go/types"
10 |
11 | func setName(pkg *types.Package, name string) {
12 | pkg.SetName(name)
13 | }
14 |
--------------------------------------------------------------------------------
/go/gcimporter15/setname_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go 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 | // +build go1.5
6 |
7 | package gcimporter
8 |
9 | import (
10 | "go/types"
11 | "testing"
12 | )
13 |
14 | func TestSetName(t *testing.T) {
15 | pkg := types.NewPackage("path", "foo")
16 | scope := pkg.Scope()
17 |
18 | // verify setName
19 | setName(pkg, "bar")
20 | if name := pkg.Name(); name != "bar" {
21 | t.Fatalf(`got package name %q; want "bar"`, name)
22 | }
23 |
24 | // verify no other fields are changed
25 | if pkg.Path() != "path" || pkg.Scope() != scope || pkg.Complete() || pkg.Imports() != nil {
26 | t.Fatalf("setName changed other fields")
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/go/gcimporter15/testdata/a.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go 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 | // Input for TestIssue13566
6 |
7 | package a
8 |
9 | import "encoding/json"
10 |
11 | type A struct {
12 | a *A
13 | json json.RawMessage
14 | }
15 |
--------------------------------------------------------------------------------
/go/gcimporter15/testdata/b.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go 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 | // Input for TestIssue13566
6 |
7 | package b
8 |
9 | import "./a"
10 |
11 | type A a.A
12 |
--------------------------------------------------------------------------------
/go/loader/go16.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 | // +build go1.6
6 |
7 | package loader
8 |
9 | import "go/build"
10 |
11 | func init() {
12 | ignoreVendor = build.IgnoreVendor
13 | }
14 |
--------------------------------------------------------------------------------
/go/loader/go16_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 | // +build go1.6
6 | // +build !android
7 |
8 | package loader_test
9 |
10 | func init() {
11 | go16 = true
12 | }
13 |
--------------------------------------------------------------------------------
/go/loader/testdata/a.go:
--------------------------------------------------------------------------------
1 | package P
2 |
--------------------------------------------------------------------------------
/go/loader/testdata/b.go:
--------------------------------------------------------------------------------
1 | package P
2 |
--------------------------------------------------------------------------------
/go/loader/testdata/badpkgdecl.go:
--------------------------------------------------------------------------------
1 | // this file has no package decl
2 |
--------------------------------------------------------------------------------
/go/pointer/TODO:
--------------------------------------------------------------------------------
1 | -*- text -*-
2 |
3 | Pointer analysis to-do list
4 | ===========================
5 |
6 | CONSTRAINT GENERATION:
7 | - support reflection:
8 | - a couple of operators are missing
9 | - reflect.Values may contain lvalues (CanAddr)
10 | - implement native intrinsics. These vary by platform.
11 | - add to pts(a.panic) a label representing all runtime panics, e.g.
12 | runtime.{TypeAssertionError,errorString,errorCString}.
13 |
14 | OPTIMISATIONS
15 | - pre-solver:
16 | pointer equivalence: extend HVN to HRU
17 | location equivalence
18 | - solver: HCD, LCD.
19 | - experiment with map+slice worklist in lieu of bitset.
20 | It may have faster insert.
21 |
22 | MISC:
23 | - Test on all platforms.
24 | Currently we assume these go/build tags: linux, amd64, !cgo.
25 |
26 | MAINTAINABILITY
27 | - Think about ways to make debugging this code easier. PTA logs
28 | routinely exceed a million lines and require training to read.
29 |
30 | BUGS:
31 | - There's a crash bug in stdlib_test + reflection, rVCallConstraint.
32 |
33 |
34 |
--------------------------------------------------------------------------------
/go/pointer/print.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 pointer
6 |
7 | import "fmt"
8 |
9 | func (c *addrConstraint) String() string {
10 | return fmt.Sprintf("addr n%d <- {&n%d}", c.dst, c.src)
11 | }
12 |
13 | func (c *copyConstraint) String() string {
14 | return fmt.Sprintf("copy n%d <- n%d", c.dst, c.src)
15 | }
16 |
17 | func (c *loadConstraint) String() string {
18 | return fmt.Sprintf("load n%d <- n%d[%d]", c.dst, c.src, c.offset)
19 | }
20 |
21 | func (c *storeConstraint) String() string {
22 | return fmt.Sprintf("store n%d[%d] <- n%d", c.dst, c.offset, c.src)
23 | }
24 |
25 | func (c *offsetAddrConstraint) String() string {
26 | return fmt.Sprintf("offsetAddr n%d <- n%d.#%d", c.dst, c.src, c.offset)
27 | }
28 |
29 | func (c *typeFilterConstraint) String() string {
30 | return fmt.Sprintf("typeFilter n%d <- n%d.(%s)", c.dst, c.src, c.typ)
31 | }
32 |
33 | func (c *untagConstraint) String() string {
34 | return fmt.Sprintf("untag n%d <- n%d.(%s)", c.dst, c.src, c.typ)
35 | }
36 |
37 | func (c *invokeConstraint) String() string {
38 | return fmt.Sprintf("invoke n%d.%s(n%d ...)", c.iface, c.method.Name(), c.params)
39 | }
40 |
41 | func (n nodeid) String() string {
42 | return fmt.Sprintf("n%d", n)
43 | }
44 |
--------------------------------------------------------------------------------
/go/pointer/testdata/a_test.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package a
4 |
5 | // This test exercises the synthesis of testmain packages for tests.
6 | // The test framework doesn't directly let us perform negative
7 | // assertions (i.e. that TestingQuux isn't called, or that its
8 | // parameter's PTS is empty) so this test is rather roundabout.
9 |
10 | import "testing"
11 |
12 | func log(f func(*testing.T)) {
13 | // The PTS of f is the set of called tests. TestingQuux is not present.
14 | print(f) // @pointsto main.Test | main.TestFoo
15 | }
16 |
17 | func Test(t *testing.T) {
18 | // Don't assert @pointsto(t) since its label contains a fragile line number.
19 | log(Test)
20 | }
21 |
22 | func TestFoo(t *testing.T) {
23 | // Don't assert @pointsto(t) since its label contains a fragile line number.
24 | log(TestFoo)
25 | }
26 |
27 | func TestingQuux(t *testing.T) {
28 | // We can't assert @pointsto(t) since this is dead code.
29 | log(TestingQuux)
30 | }
31 |
32 | func BenchmarkFoo(b *testing.B) {
33 | }
34 |
35 | func ExampleBar() {
36 | }
37 |
38 | // Excludes TestingQuux.
39 | // @calls testing.tRunner -> main.Test
40 | // @calls testing.tRunner -> main.TestFoo
41 | // @calls testing.runExample -> main.ExampleBar
42 | // @calls (*testing.B).runN -> main.BenchmarkFoo
43 |
--------------------------------------------------------------------------------
/go/pointer/testdata/another.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package main
4 |
5 | var unknown bool
6 |
7 | type S string
8 |
9 | func incr(x int) int { return x + 1 }
10 |
11 | func main() {
12 | var i interface{}
13 | i = 1
14 | if unknown {
15 | i = S("foo")
16 | }
17 | if unknown {
18 | i = (func(int, int))(nil) // NB type compares equal to that below.
19 | }
20 | // Look, the test harness can handle equal-but-not-String-equal
21 | // types because we parse types and using a typemap.
22 | if unknown {
23 | i = (func(x int, y int))(nil)
24 | }
25 | if unknown {
26 | i = incr
27 | }
28 | print(i) // @types int | S | func(int, int) | func(int) int
29 |
30 | // NB, an interface may never directly alias any global
31 | // labels, even though it may contain pointers that do.
32 | print(i) // @pointsto makeinterface:func(x int) int | makeinterface:func(x int, y int) | makeinterface:func(int, int) | makeinterface:int | makeinterface:main.S
33 | print(i.(func(int) int)) // @pointsto main.incr
34 |
35 | print() // regression test for crash
36 | }
37 |
--------------------------------------------------------------------------------
/go/pointer/testdata/chanreflect1.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package main
4 |
5 | import "reflect"
6 |
7 | //
8 | // This test is very sensitive to line-number perturbations!
9 |
10 | // Test of channels with reflection.
11 |
12 | var a, b int
13 |
14 | func chanreflect1() {
15 | ch := make(chan *int, 0)
16 | crv := reflect.ValueOf(ch)
17 | crv.Send(reflect.ValueOf(&a))
18 | print(crv.Interface()) // @types chan *int
19 | print(crv.Interface().(chan *int)) // @pointsto makechan@testdata/chanreflect.go:15:12
20 | print(<-ch) // @pointsto main.a
21 | }
22 |
23 | func chanreflect2() {
24 | ch := make(chan *int, 0)
25 | ch <- &b
26 | crv := reflect.ValueOf(ch)
27 | r, _ := crv.Recv()
28 | print(r.Interface()) // @types *int
29 | print(r.Interface().(*int)) // @pointsto main.b
30 | }
31 |
32 | func main() {
33 | chanreflect1()
34 | chanreflect2()
35 | }
36 |
--------------------------------------------------------------------------------
/go/pointer/testdata/context.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package main
4 |
5 | // Test of context-sensitive treatment of certain function calls,
6 | // e.g. static calls to simple accessor methods.
7 |
8 | var a, b int
9 |
10 | type T struct{ x *int }
11 |
12 | func (t *T) SetX(x *int) { t.x = x }
13 | func (t *T) GetX() *int { return t.x }
14 |
15 | func context1() {
16 | var t1, t2 T
17 | t1.SetX(&a)
18 | t2.SetX(&b)
19 | print(t1.GetX()) // @pointsto main.a
20 | print(t2.GetX()) // @pointsto main.b
21 | }
22 |
23 | func context2() {
24 | id := func(x *int) *int {
25 | print(x) // @pointsto main.a | main.b
26 | return x
27 | }
28 | print(id(&a)) // @pointsto main.a
29 | print(id(&b)) // @pointsto main.b
30 |
31 | // Same again, but anon func has free vars.
32 | var c int // @line context2c
33 | id2 := func(x *int) (*int, *int) {
34 | print(x) // @pointsto main.a | main.b
35 | return x, &c
36 | }
37 | p, q := id2(&a)
38 | print(p) // @pointsto main.a
39 | print(q) // @pointsto c@context2c:6
40 | r, s := id2(&b)
41 | print(r) // @pointsto main.b
42 | print(s) // @pointsto c@context2c:6
43 | }
44 |
45 | func main() {
46 | context1()
47 | context2()
48 | }
49 |
--------------------------------------------------------------------------------
/go/pointer/testdata/conv.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package main
4 |
5 | import "unsafe"
6 |
7 | var a int
8 |
9 | func conv1() {
10 | // Conversions of channel direction.
11 | ch := make(chan int) // @line c1make
12 | print((<-chan int)(ch)) // @pointsto makechan@c1make:12
13 | print((chan<- int)(ch)) // @pointsto makechan@c1make:12
14 | }
15 |
16 | func conv2() {
17 | // string -> []byte/[]rune conversion
18 | s := "foo"
19 | ba := []byte(s) // @line c2ba
20 | ra := []rune(s) // @line c2ra
21 | print(ba) // @pointsto convert@c2ba:14
22 | print(ra) // @pointsto convert@c2ra:14
23 | }
24 |
25 | func conv3() {
26 | // Conversion of same underlying types.
27 | type PI *int
28 | pi := PI(&a)
29 | print(pi) // @pointsto main.a
30 |
31 | pint := (*int)(pi)
32 | print(pint) // @pointsto main.a
33 |
34 | // Conversions between pointers to identical base types.
35 | var y *PI = &pi
36 | var x **int = (**int)(y)
37 | print(*x) // @pointsto main.a
38 | print(*y) // @pointsto main.a
39 | y = (*PI)(x)
40 | print(*y) // @pointsto main.a
41 | }
42 |
43 | func conv4() {
44 | // Handling of unsafe.Pointer conversion is unsound:
45 | // we lose the alias to main.a and get something like new(int) instead.
46 | p := (*int)(unsafe.Pointer(&a)) // @line c2p
47 | print(p) // @pointsto convert@c2p:13
48 | }
49 |
50 | // Regression test for b/8231.
51 | func conv5() {
52 | type P unsafe.Pointer
53 | var i *struct{}
54 | _ = P(i)
55 | }
56 |
57 | func main() {
58 | conv1()
59 | conv2()
60 | conv3()
61 | conv4()
62 | conv5()
63 | }
64 |
--------------------------------------------------------------------------------
/go/pointer/testdata/flow.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package main
4 |
5 | // Demonstration of directionality of flow edges.
6 |
7 | func f1() {}
8 | func f2() {}
9 |
10 | var somepred bool
11 |
12 | // Tracking functions.
13 | func flow1() {
14 | s := f1
15 | p := f2
16 | q := p
17 | r := q
18 | if somepred {
19 | r = s
20 | }
21 | print(s) // @pointsto main.f1
22 | print(p) // @pointsto main.f2
23 | print(q) // @pointsto main.f2
24 | print(r) // @pointsto main.f1 | main.f2
25 | }
26 |
27 | // Tracking concrete types in interfaces.
28 | func flow2() {
29 | var s interface{} = 1
30 | var p interface{} = "foo"
31 | q := p
32 | r := q
33 | if somepred {
34 | r = s
35 | }
36 | print(s) // @types int
37 | print(p) // @types string
38 | print(q) // @types string
39 | print(r) // @types int | string
40 | }
41 |
42 | var g1, g2 int
43 |
44 | // Tracking addresses of globals.
45 | func flow3() {
46 | s := &g1
47 | p := &g2
48 | q := p
49 | r := q
50 | if somepred {
51 | r = s
52 | }
53 | print(s) // @pointsto main.g1
54 | print(p) // @pointsto main.g2
55 | print(q) // @pointsto main.g2
56 | print(r) // @pointsto main.g2 | main.g1
57 | }
58 |
59 | func main() {
60 | flow1()
61 | flow2()
62 | flow3()
63 | }
64 |
--------------------------------------------------------------------------------
/go/pointer/testdata/fmtexcerpt.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | // This is a slice of the fmt package.
4 |
5 | package main
6 |
7 | type pp struct {
8 | field interface{}
9 | }
10 |
11 | func newPrinter() *pp {
12 | return new(pp)
13 | }
14 |
15 | func Fprintln(a ...interface{}) {
16 | p := newPrinter()
17 | p.doPrint(a, true, true)
18 | }
19 |
20 | func Println(a ...interface{}) {
21 | Fprintln(a...)
22 | }
23 |
24 | func (p *pp) doPrint(a []interface{}, addspace, addnewline bool) {
25 | print(a[0]) // @types S | string
26 | stringer := a[0].(interface {
27 | String() string
28 | })
29 |
30 | stringer.String()
31 | print(stringer) // @types S
32 | }
33 |
34 | type S int
35 |
36 | func (S) String() string { return "" }
37 |
38 | func main() {
39 | Println("Hello, World!", S(0))
40 | }
41 |
42 | // @calls (*main.pp).doPrint -> (main.S).String
43 |
--------------------------------------------------------------------------------
/go/pointer/testdata/hello.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package main
4 |
5 | import (
6 | "fmt"
7 | "os"
8 | )
9 |
10 | type S int
11 |
12 | var theS S
13 |
14 | func (s *S) String() string {
15 | print(s) // @pointsto main.theS
16 | return ""
17 | }
18 |
19 | func main() {
20 | // os.Args is considered intrinsically allocated,
21 | // but may also be set explicitly (e.g. on Windows), hence '...'.
22 | print(os.Args) // @pointsto | ...
23 | fmt.Println("Hello, World!", &theS)
24 | }
25 |
26 | // @calls main.main -> fmt.Println
27 | // @calls (*fmt.pp).handleMethods -> (*main.S).String
28 |
--------------------------------------------------------------------------------
/go/pointer/testdata/issue9002.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | // Regression test for golang issue 9002.
5 | //
6 | // The two-result "value,ok" receive operation generated a
7 | // too-wide constraint loading (value int, ok bool), not bool,
8 | // from the channel.
9 | //
10 | // This bug manifested itself in an out-of-bounds array access
11 | // when the makechan object was the highest-numbered node, as in
12 | // this program.
13 | //
14 | // In more realistic programs it silently resulted in bogus
15 | // constraints.
16 | _, _ = <-make(chan int)
17 | }
18 |
--------------------------------------------------------------------------------
/go/pointer/testdata/panic.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package main
4 |
5 | // Test of value flow from panic() to recover().
6 | // We model them as stores/loads of a global location.
7 | // We ignore concrete panic types originating from the runtime.
8 |
9 | var someval int
10 |
11 | type myPanic struct{}
12 |
13 | func f(int) {}
14 |
15 | func g() string { return "" }
16 |
17 | func deadcode() {
18 | panic(123) // not reached
19 | }
20 |
21 | func main() {
22 | switch someval {
23 | case 0:
24 | panic("oops")
25 | case 1:
26 | panic(myPanic{})
27 | case 2:
28 | panic(f)
29 | case 3:
30 | panic(g)
31 | }
32 | ex := recover()
33 | print(ex) // @types myPanic | string | func(int) | func() string
34 | print(ex.(func(int))) // @pointsto main.f
35 | print(ex.(func() string)) // @pointsto main.g
36 | }
37 |
--------------------------------------------------------------------------------
/go/pointer/testdata/recur.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package main
4 |
5 | // Analysis abstraction of recursive calls is finite.
6 |
7 | func main() {
8 | main()
9 | }
10 |
11 | // @calls main.main -> main.main
12 |
--------------------------------------------------------------------------------
/go/pointer/testdata/rtti.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Regression test for oracle crash
4 | // https://code.google.com/p/go/issues/detail?id=6605
5 | //
6 | // Using reflection, methods may be called on types that are not the
7 | // operand of any ssa.MakeInterface instruction. In this example,
8 | // (Y).F is called by deriving the type Y from *Y. Prior to the fix,
9 | // no RTTI (or method set) for type Y was included in the program, so
10 | // the F() call would crash.
11 |
12 | import "reflect"
13 |
14 | var a int
15 |
16 | type X struct{}
17 |
18 | func (X) F() *int {
19 | return &a
20 | }
21 |
22 | type I interface {
23 | F() *int
24 | }
25 |
26 | func main() {
27 | type Y struct{ X }
28 | print(reflect.Indirect(reflect.ValueOf(new(Y))).Interface().(I).F()) // @pointsto main.a
29 | }
30 |
--------------------------------------------------------------------------------
/go/pointer/testdata/structreflect.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package main
4 |
5 | import "reflect"
6 |
7 | type A struct {
8 | f *int
9 | g interface{}
10 | h bool
11 | }
12 |
13 | var dyn string
14 |
15 | func reflectTypeFieldByName() {
16 | f, _ := reflect.TypeOf(A{}).FieldByName("f")
17 | print(f.Type) // @pointsto *int
18 |
19 | g, _ := reflect.TypeOf(A{}).FieldByName("g")
20 | print(g.Type) // @pointsto interface{}
21 | print(reflect.Zero(g.Type)) // @pointsto
22 | print(reflect.Zero(g.Type)) // @types interface{}
23 |
24 | print(reflect.Zero(g.Type).Interface()) // @pointsto
25 | print(reflect.Zero(g.Type).Interface()) // @types
26 |
27 | h, _ := reflect.TypeOf(A{}).FieldByName("h")
28 | print(h.Type) // @pointsto bool
29 |
30 | missing, _ := reflect.TypeOf(A{}).FieldByName("missing")
31 | print(missing.Type) // @pointsto
32 |
33 | dyn, _ := reflect.TypeOf(A{}).FieldByName(dyn)
34 | print(dyn.Type) // @pointsto *int | bool | interface{}
35 | }
36 |
37 | func reflectTypeField() {
38 | fld := reflect.TypeOf(A{}).Field(0)
39 | print(fld.Type) // @pointsto *int | bool | interface{}
40 | }
41 |
42 | func main() {
43 | reflectTypeFieldByName()
44 | reflectTypeField()
45 | }
46 |
--------------------------------------------------------------------------------
/go/pointer/testdata/timer.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package main
4 |
5 | import "time"
6 |
7 | func after() {}
8 |
9 | func main() {
10 | // @calls time.startTimer -> time.sendTime
11 | ticker := time.NewTicker(1)
12 | <-ticker.C
13 |
14 | // @calls time.startTimer -> time.sendTime
15 | timer := time.NewTimer(time.Second)
16 | <-timer.C
17 |
18 | // @calls time.startTimer -> time.goFunc
19 | // @calls time.goFunc -> main.after
20 | timer = time.AfterFunc(time.Second, after)
21 | <-timer.C
22 | }
23 |
24 | // @calls time.sendTime -> time.Now
25 |
--------------------------------------------------------------------------------
/go/ssa/interp/external_darwin.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build darwin
6 |
7 | package interp
8 |
9 | import "syscall"
10 |
11 | func init() {
12 | externals["syscall.Sysctl"] = ext۰syscall۰Sysctl
13 | }
14 |
15 | func ext۰syscall۰Sysctl(fr *frame, args []value) value {
16 | r, err := syscall.Sysctl(args[0].(string))
17 | return tuple{r, wrapError(err)}
18 | }
19 |
--------------------------------------------------------------------------------
/go/ssa/interp/external_freebsd.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build freebsd
6 |
7 | package interp
8 |
9 | import "syscall"
10 |
11 | func init() {
12 | externals["syscall.Sysctl"] = ext۰syscall۰Sysctl
13 | externals["syscall.SysctlUint32"] = ext۰syscall۰SysctlUint32
14 | }
15 |
16 | func ext۰syscall۰Sysctl(fr *frame, args []value) value {
17 | r, err := syscall.Sysctl(args[0].(string))
18 | return tuple{r, wrapError(err)}
19 | }
20 |
21 | func ext۰syscall۰SysctlUint32(fr *frame, args []value) value {
22 | r, err := syscall.SysctlUint32(args[0].(string))
23 | return tuple{r, wrapError(err)}
24 | }
25 |
--------------------------------------------------------------------------------
/go/ssa/interp/testdata/a_test.go:
--------------------------------------------------------------------------------
1 | package a
2 |
3 | import "testing"
4 |
5 | func TestFoo(t *testing.T) {
6 | t.Error("foo")
7 | }
8 |
9 | func TestBar(t *testing.T) {
10 | t.Error("bar")
11 | }
12 |
13 | func BenchmarkWiz(b *testing.B) {
14 | b.Error("wiz")
15 | }
16 |
17 | // Don't test Examples since that testing package needs pipe(2) for that.
18 |
--------------------------------------------------------------------------------
/go/ssa/interp/testdata/b_test.go:
--------------------------------------------------------------------------------
1 | package b
2 |
3 | import "testing"
4 |
5 | func NotATest(t *testing.T) {
6 | t.Error("foo")
7 | }
8 |
9 | func NotABenchmark(b *testing.B) {
10 | b.Error("wiz")
11 | }
12 |
--------------------------------------------------------------------------------
/go/ssa/interp/testdata/callstack.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "path"
6 | "runtime"
7 | "strings"
8 | )
9 |
10 | var stack string
11 |
12 | func f() {
13 | pc := make([]uintptr, 6)
14 | pc = pc[:runtime.Callers(1, pc)]
15 | for _, f := range pc {
16 | Func := runtime.FuncForPC(f)
17 | name := Func.Name()
18 | if strings.Contains(name, "$") || strings.Contains(name, ".func") {
19 | name = "func" // anon funcs vary across toolchains
20 | }
21 | file, line := Func.FileLine(0)
22 | stack += fmt.Sprintf("%s at %s:%d\n", name, path.Base(file), line)
23 | }
24 | }
25 |
26 | func g() { f() }
27 | func h() { g() }
28 | func i() { func() { h() }() }
29 |
30 | // Hack: the 'func' and the call to Caller are on the same line,
31 | // to paper over differences between toolchains.
32 | // (The interpreter's location info isn't yet complete.)
33 | func runtimeCaller0() (uintptr, string, int, bool) { return runtime.Caller(0) }
34 |
35 | func main() {
36 | i()
37 | if stack != `main.f at callstack.go:12
38 | main.g at callstack.go:26
39 | main.h at callstack.go:27
40 | func at callstack.go:28
41 | main.i at callstack.go:28
42 | main.main at callstack.go:35
43 | ` {
44 | panic("unexpected stack: " + stack)
45 | }
46 |
47 | pc, file, line, _ := runtimeCaller0()
48 | got := fmt.Sprintf("%s @ %s:%d", runtime.FuncForPC(pc).Name(), path.Base(file), line)
49 | if got != "main.runtimeCaller0 @ callstack.go:33" {
50 | panic("runtime.Caller: " + got)
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/go/ssa/interp/testdata/defer.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of defer. (Deferred recover() belongs is recover.go.)
4 |
5 | import "fmt"
6 |
7 | func deferMutatesResults(noArgReturn bool) (a, b int) {
8 | defer func() {
9 | if a != 1 || b != 2 {
10 | panic(fmt.Sprint(a, b))
11 | }
12 | a, b = 3, 4
13 | }()
14 | if noArgReturn {
15 | a, b = 1, 2
16 | return
17 | }
18 | return 1, 2
19 | }
20 |
21 | func init() {
22 | a, b := deferMutatesResults(true)
23 | if a != 3 || b != 4 {
24 | panic(fmt.Sprint(a, b))
25 | }
26 | a, b = deferMutatesResults(false)
27 | if a != 3 || b != 4 {
28 | panic(fmt.Sprint(a, b))
29 | }
30 | }
31 |
32 | // We concatenate init blocks to make a single function, but we must
33 | // run defers at the end of each block, not the combined function.
34 | var deferCount = 0
35 |
36 | func init() {
37 | deferCount = 1
38 | defer func() {
39 | deferCount++
40 | }()
41 | // defer runs HERE
42 | }
43 |
44 | func init() {
45 | // Strictly speaking the spec says deferCount may be 0 or 2
46 | // since the relative order of init blocks is unspecified.
47 | if deferCount != 2 {
48 | panic(deferCount) // defer call has not run!
49 | }
50 | }
51 |
52 | func main() {
53 | }
54 |
--------------------------------------------------------------------------------
/go/ssa/interp/testdata/ifaceprom.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Test of promotion of methods of an interface embedded within a
4 | // struct. In particular, this test exercises that the correct
5 | // method is called.
6 |
7 | type I interface {
8 | one() int
9 | two() string
10 | }
11 |
12 | type S struct {
13 | I
14 | }
15 |
16 | type impl struct{}
17 |
18 | func (impl) one() int {
19 | return 1
20 | }
21 |
22 | func (impl) two() string {
23 | return "two"
24 | }
25 |
26 | func main() {
27 | var s S
28 | s.I = impl{}
29 | if one := s.I.one(); one != 1 {
30 | panic(one)
31 | }
32 | if one := s.one(); one != 1 {
33 | panic(one)
34 | }
35 | closOne := s.I.one
36 | if one := closOne(); one != 1 {
37 | panic(one)
38 | }
39 | closOne = s.one
40 | if one := closOne(); one != 1 {
41 | panic(one)
42 | }
43 |
44 | if two := s.I.two(); two != "two" {
45 | panic(two)
46 | }
47 | if two := s.two(); two != "two" {
48 | panic(two)
49 | }
50 | closTwo := s.I.two
51 | if two := closTwo(); two != "two" {
52 | panic(two)
53 | }
54 | closTwo = s.two
55 | if two := closTwo(); two != "two" {
56 | panic(two)
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/go/ssa/interp/testdata/initorder.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | // Test of initialization order of package-level vars.
6 |
7 | var counter int
8 |
9 | func next() int {
10 | c := counter
11 | counter++
12 | return c
13 | }
14 |
15 | func next2() (x int, y int) {
16 | x = next()
17 | y = next()
18 | return
19 | }
20 |
21 | func makeOrder() int {
22 | _, _, _, _ = f, b, d, e
23 | return 0
24 | }
25 |
26 | func main() {
27 | // Initialization constraints:
28 | // - {f,b,c/d,e} < order (ref graph traversal)
29 | // - order < {a} (lexical order)
30 | // - b < c/d < e < f (lexical order)
31 | // Solution: a b c/d e f
32 | abcdef := [6]int{a, b, c, d, e, f}
33 | if abcdef != [6]int{0, 1, 2, 3, 4, 5} {
34 | panic(abcdef)
35 | }
36 | }
37 |
38 | var order = makeOrder()
39 |
40 | var a, b = next(), next()
41 | var c, d = next2()
42 | var e, f = next(), next()
43 |
44 | // ------------------------------------------------------------------------
45 |
46 | var order2 []string
47 |
48 | func create(x int, name string) int {
49 | order2 = append(order2, name)
50 | return x
51 | }
52 |
53 | var C = create(B+1, "C")
54 | var A, B = create(1, "A"), create(2, "B")
55 |
56 | // Initialization order of package-level value specs.
57 | func init() {
58 | x := fmt.Sprint(order2)
59 | // Result varies by toolchain. This is a spec bug.
60 | if x != "[B C A]" && // gc
61 | x != "[A B C]" { // go/types
62 | panic(x)
63 | }
64 | if C != 3 {
65 | panic(c)
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/go/ssa/interp/testdata/methprom.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of method promotion logic.
4 |
5 | type A struct{ magic int }
6 |
7 | func (a A) x() {
8 | if a.magic != 1 {
9 | panic(a.magic)
10 | }
11 | }
12 | func (a *A) y() *A {
13 | return a
14 | }
15 |
16 | type B struct{ magic int }
17 |
18 | func (b B) p() {
19 | if b.magic != 2 {
20 | panic(b.magic)
21 | }
22 | }
23 | func (b *B) q() {
24 | if b != theC.B {
25 | panic("oops")
26 | }
27 | }
28 |
29 | type I interface {
30 | f()
31 | }
32 |
33 | type impl struct{ magic int }
34 |
35 | func (i impl) f() {
36 | if i.magic != 3 {
37 | panic("oops")
38 | }
39 | }
40 |
41 | type C struct {
42 | A
43 | *B
44 | I
45 | }
46 |
47 | func assert(cond bool) {
48 | if !cond {
49 | panic("failed")
50 | }
51 | }
52 |
53 | var theC = C{
54 | A: A{1},
55 | B: &B{2},
56 | I: impl{3},
57 | }
58 |
59 | func addr() *C {
60 | return &theC
61 | }
62 |
63 | func value() C {
64 | return theC
65 | }
66 |
67 | func main() {
68 | // address
69 | addr().x()
70 | if addr().y() != &theC.A {
71 | panic("oops")
72 | }
73 | addr().p()
74 | addr().q()
75 | addr().f()
76 |
77 | // addressable value
78 | var c C = value()
79 | c.x()
80 | if c.y() != &c.A {
81 | panic("oops")
82 | }
83 | c.p()
84 | c.q()
85 | c.f()
86 |
87 | // non-addressable value
88 | value().x()
89 | // value().y() // not in method set
90 | value().p()
91 | value().q()
92 | value().f()
93 | }
94 |
--------------------------------------------------------------------------------
/go/ssa/interp/testdata/range.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of range loops.
4 |
5 | import "fmt"
6 |
7 | // Range over string.
8 | func init() {
9 | if x := len("Hello, 世界"); x != 13 { // bytes
10 | panic(x)
11 | }
12 | var indices []int
13 | var runes []rune
14 | for i, r := range "Hello, 世界" {
15 | runes = append(runes, r)
16 | indices = append(indices, i)
17 | }
18 | if x := fmt.Sprint(runes); x != "[72 101 108 108 111 44 32 19990 30028]" {
19 | panic(x)
20 | }
21 | if x := fmt.Sprint(indices); x != "[0 1 2 3 4 5 6 7 10]" {
22 | panic(x)
23 | }
24 | s := ""
25 | for _, r := range runes {
26 | s = fmt.Sprintf("%s%c", s, r)
27 | }
28 | if s != "Hello, 世界" {
29 | panic(s)
30 | }
31 |
32 | var x int
33 | for range "Hello, 世界" {
34 | x++
35 | }
36 | if x != len(indices) {
37 | panic(x)
38 | }
39 | }
40 |
41 | // Regression test for range of pointer to named array type.
42 | func init() {
43 | type intarr [3]int
44 | ia := intarr{1, 2, 3}
45 | var count int
46 | for _, x := range &ia {
47 | count += x
48 | }
49 | if count != 6 {
50 | panic(count)
51 | }
52 | }
53 |
54 | func main() {
55 | }
56 |
--------------------------------------------------------------------------------
/go/ssa/interp/testdata/recover.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of panic/recover.
4 |
5 | import "fmt"
6 |
7 | func fortyTwo() (r int) {
8 | r = 42
9 | // The next two statements simulate a 'return' statement.
10 | defer func() { recover() }()
11 | panic(nil)
12 | }
13 |
14 | func zero() int {
15 | defer func() { recover() }()
16 | panic(1)
17 | }
18 |
19 | func zeroEmpty() (int, string) {
20 | defer func() { recover() }()
21 | panic(1)
22 | }
23 |
24 | func main() {
25 | if r := fortyTwo(); r != 42 {
26 | panic(r)
27 | }
28 | if r := zero(); r != 0 {
29 | panic(r)
30 | }
31 | if r, s := zeroEmpty(); r != 0 || s != "" {
32 | panic(fmt.Sprint(r, s))
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/go/ssa/interp/testdata/reflect.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "reflect"
4 |
5 | func main() {
6 | // Regression test for issue 9462.
7 | got := reflect.SliceOf(reflect.TypeOf(byte(0))).String()
8 | if got != "[]uint8" && got != "[]byte" { // result varies by toolchain
9 | println("BUG: " + got)
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/go/ssa/interp/testdata/static.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Static tests of SSA builder (via the sanity checker).
4 | // Dynamic semantics are not exercised.
5 |
6 | func init() {
7 | // Regression test for issue 6806.
8 | ch := make(chan int)
9 | select {
10 | case n, _ := <-ch:
11 | _ = n
12 | default:
13 | // The default case disables the simplification of
14 | // select to a simple receive statement.
15 | }
16 |
17 | // value,ok-form receive where TypeOf(ok) is a named boolean.
18 | type mybool bool
19 | var x int
20 | var y mybool
21 | select {
22 | case x, y = <-ch:
23 | default:
24 | // The default case disables the simplification of
25 | // select to a simple receive statement.
26 | }
27 | _ = x
28 | _ = y
29 | }
30 |
31 | var a int
32 |
33 | // Regression test for issue 7840 (covered by SSA sanity checker).
34 | func bug7840() bool {
35 | // This creates a single-predecessor block with a φ-node.
36 | return false && a == 0 && a == 0
37 | }
38 |
39 | // A blocking select (sans "default:") cannot fall through.
40 | // Regression test for issue 7022.
41 | func bug7022() int {
42 | var c1, c2 chan int
43 | select {
44 | case <-c1:
45 | return 123
46 | case <-c2:
47 | return 456
48 | }
49 | }
50 |
51 | // Parens should not prevent intrinsic treatment of built-ins.
52 | // (Regression test for a crash.)
53 | func init() {
54 | _ = (new)(int)
55 | _ = (make)([]int, 0)
56 | }
57 |
58 | func main() {}
59 |
--------------------------------------------------------------------------------
/go/types/objset.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 | // This file implements objsets.
6 | //
7 | // An objset is similar to a Scope but objset elements
8 | // are identified by their unique id, instead of their
9 | // object name.
10 |
11 | package types
12 |
13 | // An objset is a set of objects identified by their unique id.
14 | // The zero value for objset is a ready-to-use empty objset.
15 | type objset map[string]Object // initialized lazily
16 |
17 | // insert attempts to insert an object obj into objset s.
18 | // If s already contains an alternative object alt with
19 | // the same name, insert leaves s unchanged and returns alt.
20 | // Otherwise it inserts obj and returns nil.
21 | func (s *objset) insert(obj Object) Object {
22 | id := obj.Id()
23 | if alt := (*s)[id]; alt != nil {
24 | return alt
25 | }
26 | if *s == nil {
27 | *s = make(map[string]Object)
28 | }
29 | (*s)[id] = obj
30 | return nil
31 | }
32 |
--------------------------------------------------------------------------------
/go/types/testdata/blank.src:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 _ /* ERROR invalid package name */
6 |
--------------------------------------------------------------------------------
/go/types/testdata/cycles1.src:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 p
6 |
7 | type (
8 | A interface {
9 | a() interface {
10 | ABC1
11 | }
12 | }
13 | B interface {
14 | b() interface {
15 | ABC2
16 | }
17 | }
18 | C interface {
19 | c() interface {
20 | ABC3
21 | }
22 | }
23 |
24 | AB interface {
25 | A
26 | B
27 | }
28 | BC interface {
29 | B
30 | C
31 | }
32 |
33 | ABC1 interface {
34 | A
35 | B
36 | C
37 | }
38 | ABC2 interface {
39 | AB
40 | C
41 | }
42 | ABC3 interface {
43 | A
44 | BC
45 | }
46 | )
47 |
48 | var (
49 | x1 ABC1
50 | x2 ABC2
51 | x3 ABC3
52 | )
53 |
54 | func _() {
55 | // all types have the same method set
56 | x1 = x2
57 | x2 = x1
58 |
59 | x1 = x3
60 | x3 = x1
61 |
62 | x2 = x3
63 | x3 = x2
64 |
65 | // all methods return the same type again
66 | x1 = x1.a()
67 | x1 = x1.b()
68 | x1 = x1.c()
69 |
70 | x2 = x2.a()
71 | x2 = x2.b()
72 | x2 = x2.c()
73 |
74 | x3 = x3.a()
75 | x3 = x3.b()
76 | x3 = x3.c()
77 | }
78 |
--------------------------------------------------------------------------------
/go/types/testdata/cycles3.src:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 p
6 |
7 | import "unsafe"
8 |
9 | var (
10 | _ A = A(nil).a().b().c().d().e().f()
11 | _ A = A(nil).b().c().d().e().f()
12 | _ A = A(nil).c().d().e().f()
13 | _ A = A(nil).d().e().f()
14 | _ A = A(nil).e().f()
15 | _ A = A(nil).f()
16 | _ A = A(nil)
17 | )
18 |
19 | type (
20 | A interface {
21 | a() B
22 | B
23 | }
24 |
25 | B interface {
26 | b() C
27 | C
28 | }
29 |
30 | C interface {
31 | c() D
32 | D
33 | }
34 |
35 | D interface {
36 | d() E
37 | E
38 | }
39 |
40 | E interface {
41 | e() F
42 | F
43 | }
44 |
45 | F interface {
46 | f() A
47 | }
48 | )
49 |
50 | type (
51 | U interface {
52 | V
53 | }
54 |
55 | V interface {
56 | v() [unsafe.Sizeof(u)]int
57 | }
58 | )
59 |
60 | var u U
61 |
--------------------------------------------------------------------------------
/go/types/testdata/expr1.src:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go 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 | // binary expressions
6 |
7 | package expr1
8 |
--------------------------------------------------------------------------------
/go/types/testdata/importdecl0a.src:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 importdecl0
6 |
7 | import ()
8 |
9 | import (
10 | // we can have multiple blank imports (was bug)
11 | _ "math"
12 | _ "net/rpc"
13 | init /* ERROR "cannot declare init" */ "fmt"
14 | // reflect defines a type "flag" which shows up in the gc export data
15 | "reflect"
16 | . /* ERROR "imported but not used" */ "reflect"
17 | )
18 |
19 | import "math" /* ERROR "imported but not used" */
20 | import m /* ERROR "imported but not used as m" */ "math"
21 | import _ "math"
22 |
23 | import (
24 | "math/big" /* ERROR "imported but not used" */
25 | b /* ERROR "imported but not used" */ "math/big"
26 | _ "math/big"
27 | )
28 |
29 | import "fmt"
30 | import f1 "fmt"
31 | import f2 "fmt"
32 |
33 | // reflect.flag must not be visible in this package
34 | type flag int
35 | type _ reflect /* ERROR "not exported" */ .flag
36 |
37 | // imported package name may conflict with local objects
38 | type reflect /* ERROR "reflect already declared" */ int
39 |
40 | // dot-imported exported objects may conflict with local objects
41 | type Value /* ERROR "Value already declared through dot-import of package reflect" */ struct{}
42 |
43 | var _ = fmt.Println // use "fmt"
44 |
45 | func _() {
46 | f1.Println() // use "fmt"
47 | }
48 |
49 | func _() {
50 | _ = func() {
51 | f2.Println() // use "fmt"
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/go/types/testdata/importdecl0b.src:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 importdecl0
6 |
7 | import "math"
8 | import m "math"
9 |
10 | import . "testing" // declares T in file scope
11 | import . /* ERROR "imported but not used" */ "unsafe"
12 | import . "fmt" // declares Println in file scope
13 |
14 | import (
15 | // TODO(gri) At the moment, 2 errors are reported because both go/parser
16 | // and the type checker report it. Eventually, this test should not be
17 | // done by the parser anymore.
18 | "" /* ERROR invalid import path */ /* ERROR invalid import path */
19 | "a!b" /* ERROR invalid import path */ /* ERROR invalid import path */
20 | "abc\xffdef" /* ERROR invalid import path */ /* ERROR invalid import path */
21 | )
22 |
23 | // using "math" in this file doesn't affect its use in other files
24 | const Pi0 = math.Pi
25 | const Pi1 = m.Pi
26 |
27 | type _ T // use "testing"
28 |
29 | func _() func() interface{} {
30 | return func() interface{} {
31 | return Println // use "fmt"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/go/types/testdata/importdecl1a.src:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // Test case for issue 8969.
6 |
7 | package importdecl1
8 |
9 | import . "unsafe"
10 |
11 | var _ Pointer // use dot-imported package unsafe
12 |
--------------------------------------------------------------------------------
/go/types/testdata/importdecl1b.src:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 importdecl1
6 |
7 | import . /* ERROR "imported but not used" */ "unsafe"
8 |
--------------------------------------------------------------------------------
/go/types/token_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 | // This file checks invariants of token.Token ordering that we rely on
6 | // since package go/token doesn't provide any guarantees at the moment.
7 |
8 | package types
9 |
10 | import (
11 | "go/token"
12 | "testing"
13 | )
14 |
15 | var assignOps = map[token.Token]token.Token{
16 | token.ADD_ASSIGN: token.ADD,
17 | token.SUB_ASSIGN: token.SUB,
18 | token.MUL_ASSIGN: token.MUL,
19 | token.QUO_ASSIGN: token.QUO,
20 | token.REM_ASSIGN: token.REM,
21 | token.AND_ASSIGN: token.AND,
22 | token.OR_ASSIGN: token.OR,
23 | token.XOR_ASSIGN: token.XOR,
24 | token.SHL_ASSIGN: token.SHL,
25 | token.SHR_ASSIGN: token.SHR,
26 | token.AND_NOT_ASSIGN: token.AND_NOT,
27 | }
28 |
29 | func TestZeroTok(t *testing.T) {
30 | // zero value for token.Token must be token.ILLEGAL
31 | var zero token.Token
32 | if token.ILLEGAL != zero {
33 | t.Errorf("%s == %d; want 0", token.ILLEGAL, zero)
34 | }
35 | }
36 |
37 | func TestAssignOp(t *testing.T) {
38 | // there are fewer than 256 tokens
39 | for i := 0; i < 256; i++ {
40 | tok := token.Token(i)
41 | got := assignOp(tok)
42 | want := assignOps[tok]
43 | if got != want {
44 | t.Errorf("for assignOp(%s): got %s; want %s", tok, got, want)
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/go/types/typeutil/imports.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build go1.5
6 |
7 | package typeutil
8 |
9 | import "go/types"
10 |
11 | // Dependencies returns all dependencies of the specified packages.
12 | //
13 | // Dependent packages appear in topological order: if package P imports
14 | // package Q, Q appears earlier than P in the result.
15 | // The algorithm follows import statements in the order they
16 | // appear in the source code, so the result is a total order.
17 | //
18 | func Dependencies(pkgs ...*types.Package) []*types.Package {
19 | var result []*types.Package
20 | seen := make(map[*types.Package]bool)
21 | var visit func(pkgs []*types.Package)
22 | visit = func(pkgs []*types.Package) {
23 | for _, p := range pkgs {
24 | if !seen[p] {
25 | seen[p] = true
26 | visit(p.Imports())
27 | result = append(result, p)
28 | }
29 | }
30 | }
31 | visit(pkgs)
32 | return result
33 | }
34 |
--------------------------------------------------------------------------------
/go/types/typeutil/imports14.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build !go1.5
6 |
7 | package typeutil
8 |
9 | import "golang.org/x/tools/go/types"
10 |
11 | // Dependencies returns all dependencies of the specified packages.
12 | //
13 | // Dependent packages appear in topological order: if package P imports
14 | // package Q, Q appears earlier than P in the result.
15 | // The algorithm follows import statements in the order they
16 | // appear in the source code, so the result is a total order.
17 | //
18 | func Dependencies(pkgs ...*types.Package) []*types.Package {
19 | var result []*types.Package
20 | seen := make(map[*types.Package]bool)
21 | var visit func(pkgs []*types.Package)
22 | visit = func(pkgs []*types.Package) {
23 | for _, p := range pkgs {
24 | if !seen[p] {
25 | seen[p] = true
26 | visit(p.Imports())
27 | result = append(result, p)
28 | }
29 | }
30 | }
31 | visit(pkgs)
32 | return result
33 | }
34 |
--------------------------------------------------------------------------------
/go/types/typeutil/ui.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build go1.5
6 |
7 | package typeutil
8 |
9 | // This file defines utilities for user interfaces that display types.
10 |
11 | import "go/types"
12 |
13 | // IntuitiveMethodSet returns the intuitive method set of a type, T.
14 | //
15 | // The result contains MethodSet(T) and additionally, if T is a
16 | // concrete type, methods belonging to *T if there is no identically
17 | // named method on T itself. This corresponds to user intuition about
18 | // method sets; this function is intended only for user interfaces.
19 | //
20 | // The order of the result is as for types.MethodSet(T).
21 | //
22 | func IntuitiveMethodSet(T types.Type, msets *MethodSetCache) []*types.Selection {
23 | var result []*types.Selection
24 | mset := msets.MethodSet(T)
25 | if _, ok := T.Underlying().(*types.Interface); ok {
26 | for i, n := 0, mset.Len(); i < n; i++ {
27 | result = append(result, mset.At(i))
28 | }
29 | } else {
30 | pmset := msets.MethodSet(types.NewPointer(T))
31 | for i, n := 0, pmset.Len(); i < n; i++ {
32 | meth := pmset.At(i)
33 | if m := mset.Lookup(meth.Obj().Pkg(), meth.Obj().Name()); m != nil {
34 | meth = m
35 | }
36 | result = append(result, meth)
37 | }
38 | }
39 | return result
40 | }
41 |
--------------------------------------------------------------------------------
/go/types/typeutil/ui14.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 | // +build !go1.5
6 |
7 | package typeutil
8 |
9 | // This file defines utilities for user interfaces that display types.
10 |
11 | import "golang.org/x/tools/go/types"
12 |
13 | // IntuitiveMethodSet returns the intuitive method set of a type, T.
14 | //
15 | // The result contains MethodSet(T) and additionally, if T is a
16 | // concrete type, methods belonging to *T if there is no identically
17 | // named method on T itself. This corresponds to user intuition about
18 | // method sets; this function is intended only for user interfaces.
19 | //
20 | // The order of the result is as for types.MethodSet(T).
21 | //
22 | func IntuitiveMethodSet(T types.Type, msets *MethodSetCache) []*types.Selection {
23 | var result []*types.Selection
24 | mset := msets.MethodSet(T)
25 | if _, ok := T.Underlying().(*types.Interface); ok {
26 | for i, n := 0, mset.Len(); i < n; i++ {
27 | result = append(result, mset.At(i))
28 | }
29 | } else {
30 | pmset := msets.MethodSet(types.NewPointer(T))
31 | for i, n := 0, pmset.Len(); i < n; i++ {
32 | meth := pmset.At(i)
33 | if m := mset.Lookup(meth.Obj().Pkg(), meth.Obj().Name()); m != nil {
34 | meth = m
35 | }
36 | result = append(result, meth)
37 | }
38 | }
39 | return result
40 | }
41 |
--------------------------------------------------------------------------------
/go/vcs/env.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 vcs
6 |
7 | import (
8 | "os"
9 | "strings"
10 | )
11 |
12 | // envForDir returns a copy of the environment
13 | // suitable for running in the given directory.
14 | // The environment is the current process's environment
15 | // but with an updated $PWD, so that an os.Getwd in the
16 | // child will be faster.
17 | func envForDir(dir string) []string {
18 | env := os.Environ()
19 | // Internally we only use rooted paths, so dir is rooted.
20 | // Even if dir is not rooted, no harm done.
21 | return mergeEnvLists([]string{"PWD=" + dir}, env)
22 | }
23 |
24 | // mergeEnvLists merges the two environment lists such that
25 | // variables with the same name in "in" replace those in "out".
26 | func mergeEnvLists(in, out []string) []string {
27 | NextVar:
28 | for _, inkv := range in {
29 | k := strings.SplitAfterN(inkv, "=", 2)[0]
30 | for i, outkv := range out {
31 | if strings.HasPrefix(outkv, k) {
32 | out[i] = inkv
33 | continue NextVar
34 | }
35 | }
36 | out = append(out, inkv)
37 | }
38 | return out
39 | }
40 |
--------------------------------------------------------------------------------
/godoc/appengine.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go 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 | // +build appengine
6 |
7 | package godoc
8 |
9 | import "appengine"
10 |
11 | func init() {
12 | onAppengine = !appengine.IsDevAppServer()
13 | }
14 |
--------------------------------------------------------------------------------
/godoc/page.go:
--------------------------------------------------------------------------------
1 | // Copyright 2009 The Go 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 godoc
6 |
7 | import (
8 | "net/http"
9 | "runtime"
10 | )
11 |
12 | // Page describes the contents of the top-level godoc webpage.
13 | type Page struct {
14 | Title string
15 | Tabtitle string
16 | Subtitle string
17 | Query string
18 | Body []byte
19 | Share bool
20 |
21 | // filled in by servePage
22 | SearchBox bool
23 | Playground bool
24 | Version string
25 | }
26 |
27 | func (p *Presentation) ServePage(w http.ResponseWriter, page Page) {
28 | if page.Tabtitle == "" {
29 | page.Tabtitle = page.Title
30 | }
31 | page.SearchBox = p.Corpus.IndexEnabled
32 | page.Playground = p.ShowPlayground
33 | page.Version = runtime.Version()
34 | applyTemplateToResponseWriter(w, p.GodocHTML, page)
35 | }
36 |
37 | func (p *Presentation) ServeError(w http.ResponseWriter, r *http.Request, relpath string, err error) {
38 | w.WriteHeader(http.StatusNotFound)
39 | p.ServePage(w, Page{
40 | Title: "File " + relpath,
41 | Subtitle: relpath,
42 | Body: applyTemplate(p.ErrorHTML, "errorHTML", err), // err may contain an absolute path!
43 | Share: allowShare(r),
44 | })
45 | }
46 |
47 | var onAppengine = false // overriden in appengine.go when on app engine
48 |
49 | func allowShare(r *http.Request) bool {
50 | if !onAppengine {
51 | return true
52 | }
53 | switch r.Header.Get("X-AppEngine-Country") {
54 | case "", "ZZ", "CN":
55 | return false
56 | }
57 | return true
58 | }
59 |
--------------------------------------------------------------------------------
/godoc/static/analysis/call-eg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/call-eg.png
--------------------------------------------------------------------------------
/godoc/static/analysis/call3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/call3.png
--------------------------------------------------------------------------------
/godoc/static/analysis/callers1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/callers1.png
--------------------------------------------------------------------------------
/godoc/static/analysis/callers2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/callers2.png
--------------------------------------------------------------------------------
/godoc/static/analysis/chan1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/chan1.png
--------------------------------------------------------------------------------
/godoc/static/analysis/chan2a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/chan2a.png
--------------------------------------------------------------------------------
/godoc/static/analysis/chan2b.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/chan2b.png
--------------------------------------------------------------------------------
/godoc/static/analysis/error1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/error1.png
--------------------------------------------------------------------------------
/godoc/static/analysis/ident-def.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/ident-def.png
--------------------------------------------------------------------------------
/godoc/static/analysis/ident-field.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/ident-field.png
--------------------------------------------------------------------------------
/godoc/static/analysis/ident-func.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/ident-func.png
--------------------------------------------------------------------------------
/godoc/static/analysis/ipcg-func.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/ipcg-func.png
--------------------------------------------------------------------------------
/godoc/static/analysis/ipcg-pkg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/ipcg-pkg.png
--------------------------------------------------------------------------------
/godoc/static/analysis/typeinfo-pkg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/typeinfo-pkg.png
--------------------------------------------------------------------------------
/godoc/static/analysis/typeinfo-src.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/analysis/typeinfo-src.png
--------------------------------------------------------------------------------
/godoc/static/callgraph.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
▹ Internal call graph
4 |
5 |
6 |
▾ Internal call graph
7 |
8 | This viewer shows the portion of the internal call
9 | graph of this package that is reachable from this function.
10 | See the package's call
11 | graph for more information.
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/godoc/static/codewalkdir.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 | {{range .}}
9 |
10 | {{$name_html := html .Name}}
11 | {{$name_html}} |
12 | |
13 | {{html .Title}} |
14 |
15 | {{end}}
16 |
17 |
--------------------------------------------------------------------------------
/godoc/static/dirlist.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 | File |
11 | |
12 | Bytes |
13 | |
14 | Modified |
15 |
16 |
17 | .. |
18 |
19 | {{range .}}
20 |
21 | {{$name_html := fileInfoName . | html}}
22 | {{$name_html}} |
23 | |
24 | {{html .Size}} |
25 | |
26 | {{fileInfoTime . | html}} |
27 |
28 | {{end}}
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/godoc/static/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 static exports a map of static file content that supports the godoc
6 | // user interface. The map should be used with the mapfs package, see
7 | // golang.org/x/tools/godoc/vfs/mapfs.
8 | package static // import "golang.org/x/tools/godoc/static"
9 |
--------------------------------------------------------------------------------
/godoc/static/error.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 | {{html .}}
9 |
10 |
--------------------------------------------------------------------------------
/godoc/static/example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
▹ Example{{example_suffix .Name}}
4 |
5 |
6 |
▾ Example{{example_suffix .Name}}
7 | {{with .Doc}}
{{html .}}
{{end}}
8 | {{$output := .Output}}
9 | {{with .Play}}
10 |
21 | {{else}}
22 |
Code:
23 |
{{.Code}}
24 | {{with .Output}}
25 |
Output:
26 |
{{html .}}
27 | {{end}}
28 | {{end}}
29 |
30 |
31 |
--------------------------------------------------------------------------------
/godoc/static/gen.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go 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 static
6 |
7 | //go:generate go run makestatic.go
8 |
--------------------------------------------------------------------------------
/godoc/static/images/minus.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/images/minus.gif
--------------------------------------------------------------------------------
/godoc/static/images/plus.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/images/plus.gif
--------------------------------------------------------------------------------
/godoc/static/images/treeview-black-line.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/images/treeview-black-line.gif
--------------------------------------------------------------------------------
/godoc/static/images/treeview-black.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/images/treeview-black.gif
--------------------------------------------------------------------------------
/godoc/static/images/treeview-default-line.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/images/treeview-default-line.gif
--------------------------------------------------------------------------------
/godoc/static/images/treeview-default.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/images/treeview-default.gif
--------------------------------------------------------------------------------
/godoc/static/images/treeview-gray-line.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/images/treeview-gray-line.gif
--------------------------------------------------------------------------------
/godoc/static/images/treeview-gray.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/audreylim/go-presenter/2f55c61664d46f55863b1cb380348832218a5c90/godoc/static/images/treeview-gray.gif
--------------------------------------------------------------------------------
/godoc/static/implements.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
▾ Implements
7 |
...
8 |
9 |
10 |
--------------------------------------------------------------------------------
/godoc/static/methodset.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
▾ Method set
7 |
...
8 |
9 |
10 |
--------------------------------------------------------------------------------
/godoc/static/opensearch.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | godoc
4 | The Go Programming Language
5 | go golang
6 |
7 |
8 | /favicon.ico
9 | UTF-8
10 | UTF-8
11 |
12 |
--------------------------------------------------------------------------------
/godoc/static/search.html:
--------------------------------------------------------------------------------
1 |
6 | {{with .Alert}}
7 |
8 | {{html .}}
9 |
10 | {{end}}
11 | {{with .Alt}}
12 |
13 | Did you mean:
14 | {{range .Alts}}
15 | {{html .}}
16 | {{end}}
17 |
18 | {{end}}
19 |
--------------------------------------------------------------------------------
/godoc/static/searchdoc.html:
--------------------------------------------------------------------------------
1 |
6 | {{range $key, $val := .Idents}}
7 | {{if $val}}
8 | {{$key.Name}}
9 | {{range $val}}
10 | {{$pkg_html := pkgLink .Path | html}}
11 | {{if eq "Packages" $key.Name}}
12 | {{html .Path}}
13 | {{else}}
14 | {{$doc_html := docLink .Path .Name| html}}
15 | {{html .Package}}.{{.Name}}
16 | {{end}}
17 | {{if .Doc}}
18 | {{comment_html .Doc}}
19 | {{else}}
20 | No documentation available
21 | {{end}}
22 | {{end}}
23 | {{end}}
24 | {{end}}
25 |
--------------------------------------------------------------------------------
/godoc/static/searchtxt.html:
--------------------------------------------------------------------------------
1 |
6 | {{$query_url := urlquery .Query}}
7 | {{with .Textual}}
8 | {{if $.Complete}}
9 | {{html $.Found}} textual occurrences
10 | {{else}}
11 | More than {{html $.Found}} textual occurrences
12 |
13 | Not all files or lines containing "{{html $.Query}}" are shown.
14 |
15 | {{end}}
16 |
17 |
18 | {{range .}}
19 | {{$file := .Filename}}
20 |
21 |
22 | {{$file}}:
23 | |
24 | |
25 | {{len .Lines}} |
26 | |
27 |
28 | {{range .Lines}}
29 | {{html .}}
30 | {{end}}
31 | {{if not $.Complete}}
32 | ...
33 | {{end}}
34 | |
35 |
36 | {{end}}
37 | {{if not $.Complete}}
38 | ... |
39 | {{end}}
40 |
41 |
42 | {{end}}
43 |
--------------------------------------------------------------------------------
/godoc/vfs/vfs.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 vfs defines types for abstract file system access and provides an
6 | // implementation accessing the file system of the underlying OS.
7 | package vfs // import "golang.org/x/tools/godoc/vfs"
8 |
9 | import (
10 | "io"
11 | "io/ioutil"
12 | "os"
13 | )
14 |
15 | // The FileSystem interface specifies the methods godoc is using
16 | // to access the file system for which it serves documentation.
17 | type FileSystem interface {
18 | Opener
19 | Lstat(path string) (os.FileInfo, error)
20 | Stat(path string) (os.FileInfo, error)
21 | ReadDir(path string) ([]os.FileInfo, error)
22 | String() string
23 | }
24 |
25 | // Opener is a minimal virtual filesystem that can only open regular files.
26 | type Opener interface {
27 | Open(name string) (ReadSeekCloser, error)
28 | }
29 |
30 | // A ReadSeekCloser can Read, Seek, and Close.
31 | type ReadSeekCloser interface {
32 | io.Reader
33 | io.Seeker
34 | io.Closer
35 | }
36 |
37 | // ReadFile reads the file named by path from fs and returns the contents.
38 | func ReadFile(fs Opener, path string) ([]byte, error) {
39 | rc, err := fs.Open(path)
40 | if err != nil {
41 | return nil, err
42 | }
43 | defer rc.Close()
44 | return ioutil.ReadAll(rc)
45 | }
46 |
--------------------------------------------------------------------------------
/oracle/testdata/src/calls-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of call-graph queries, -format=json.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See calls-json.golden for expected query results.
6 |
7 | func call(f func()) {
8 | f() // @callees @callees-f "f"
9 | }
10 |
11 | func main() {
12 | call(func() {
13 | // @callers callers-main.anon "^"
14 | // @callstack callstack-main.anon "^"
15 | })
16 | }
17 |
--------------------------------------------------------------------------------
/oracle/testdata/src/calls-json/main.golden:
--------------------------------------------------------------------------------
1 | -------- @callees @callees-f --------
2 | {
3 | "mode": "callees",
4 | "callees": {
5 | "pos": "testdata/src/calls-json/main.go:8:3",
6 | "desc": "dynamic function call",
7 | "callees": [
8 | {
9 | "name": "main.main$1",
10 | "pos": "testdata/src/calls-json/main.go:12:7"
11 | }
12 | ]
13 | }
14 | }
15 | -------- @callstack callstack-main.anon --------
16 | {
17 | "mode": "callstack",
18 | "callstack": {
19 | "pos": "testdata/src/calls-json/main.go:12:7",
20 | "target": "main.main$1",
21 | "callers": [
22 | {
23 | "pos": "testdata/src/calls-json/main.go:8:3",
24 | "desc": "dynamic function call",
25 | "caller": "main.call"
26 | },
27 | {
28 | "pos": "testdata/src/calls-json/main.go:12:6",
29 | "desc": "static function call",
30 | "caller": "main.main"
31 | }
32 | ]
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/oracle/testdata/src/describe-json/main.go:
--------------------------------------------------------------------------------
1 | package describe // @describe pkgdecl "describe"
2 |
3 | // Tests of 'describe' query, -format=json.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See describe-json.golden for expected query results.
6 |
7 | func main() {
8 | var s struct{ x [3]int }
9 | p := &s.x[0] // @describe desc-val-p "p"
10 | _ = p
11 |
12 | var i I = C(0)
13 | if i == nil {
14 | i = new(D)
15 | }
16 | print(i) // @describe desc-val-i "\\bi\\b"
17 |
18 | go main() // @describe desc-stmt "go"
19 | }
20 |
21 | type I interface {
22 | f()
23 | }
24 |
25 | type C int // @describe desc-type-C "C"
26 | type D struct{}
27 |
28 | func (c C) f() {}
29 | func (d *D) f() {}
30 |
--------------------------------------------------------------------------------
/oracle/testdata/src/freevars/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'freevars' query.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See freevars.golden for expected query results.
6 |
7 | // TODO(adonovan): it's hard to test this query in a single line of gofmt'd code.
8 |
9 | type T struct {
10 | a, b int
11 | }
12 |
13 | type S struct {
14 | x int
15 | t T
16 | }
17 |
18 | func f(int) {}
19 |
20 | func main() {
21 | type C int
22 | x := 1
23 | const exp = 6
24 | if y := 2; x+y+int(C(3)) != exp { // @freevars fv1 "if.*{"
25 | panic("expected 6")
26 | }
27 |
28 | var s S
29 |
30 | for x, y := range "foo" {
31 | println(s.x + s.t.a + s.t.b + x + int(y)) // @freevars fv2 "print.*y."
32 | }
33 |
34 | f(x) // @freevars fv3 "f.x."
35 |
36 | // TODO(adonovan): enable when go/types supports labels.
37 | loop: // #@freevars fv-def-label "loop:"
38 | for {
39 | break loop // #@freevars fv-ref-label "break loop"
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/oracle/testdata/src/freevars/main.golden:
--------------------------------------------------------------------------------
1 | -------- @freevars fv1 --------
2 | Free identifiers:
3 | type C
4 | const exp int
5 | var x int
6 |
7 | -------- @freevars fv2 --------
8 | Free identifiers:
9 | var s.t.a int
10 | var s.t.b int
11 | var s.x int
12 | var x int
13 | var y rune
14 |
15 | -------- @freevars fv3 --------
16 | Free identifiers:
17 | var x int
18 |
19 |
--------------------------------------------------------------------------------
/oracle/testdata/src/implements-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'implements' query, -output=json.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See implements.golden for expected query results.
6 |
7 | func main() {
8 | }
9 |
10 | type E interface{} // @implements E "E"
11 |
12 | type F interface { // @implements F "F"
13 | f()
14 | }
15 |
16 | type FG interface { // @implements FG "FG"
17 | f()
18 | g() []int // @implements slice "..int"
19 | }
20 |
21 | type C int // @implements C "C"
22 | type D struct{}
23 |
24 | func (c *C) f() {} // @implements starC ".C"
25 | func (d D) f() {} // @implements D "D"
26 |
27 | func (d *D) g() []int { return nil } // @implements starD ".D"
28 |
--------------------------------------------------------------------------------
/oracle/testdata/src/implements-methods-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'implements' query applied to methods, -output=json.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See implements-methods.golden for expected query results.
6 |
7 | import _ "lib"
8 |
9 | func main() {
10 | }
11 |
12 | type F interface {
13 | f() // @implements F.f "f"
14 | }
15 |
16 | type FG interface {
17 | f() // @implements FG.f "f"
18 | g() []int // @implements FG.g "g"
19 | }
20 |
21 | type C int
22 | type D struct{}
23 |
24 | func (c *C) f() {} // @implements *C.f "f"
25 | func (d D) f() {} // @implements D.f "f"
26 |
27 | func (d *D) g() []int { return nil } // @implements *D.g "g"
28 |
29 | type sorter []int
30 |
31 | func (sorter) Len() int { return 0 } // @implements Len "Len"
32 | func (sorter) Less(i, j int) bool { return false }
33 | func (sorter) Swap(i, j int) {}
34 |
35 | type I interface {
36 | Method(*int) *int // @implements I.Method "Method"
37 | }
38 |
--------------------------------------------------------------------------------
/oracle/testdata/src/implements-methods/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'implements' query applied to methods.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See implements-methods.golden for expected query results.
6 |
7 | import _ "lib"
8 |
9 | func main() {
10 | }
11 |
12 | type F interface {
13 | f() // @implements F.f "f"
14 | }
15 |
16 | type FG interface {
17 | f() // @implements FG.f "f"
18 | g() []int // @implements FG.g "g"
19 | }
20 |
21 | type C int
22 | type D struct{}
23 |
24 | func (c *C) f() {} // @implements *C.f "f"
25 | func (d D) f() {} // @implements D.f "f"
26 |
27 | func (d *D) g() []int { return nil } // @implements *D.g "g"
28 |
29 | type sorter []int
30 |
31 | func (sorter) Len() int { return 0 } // @implements Len "Len"
32 | func (sorter) Less(i, j int) bool { return false }
33 | func (sorter) Swap(i, j int) {}
34 |
35 | type I interface {
36 | Method(*int) *int // @implements I.Method "Method"
37 | }
38 |
--------------------------------------------------------------------------------
/oracle/testdata/src/implements-methods/main.golden:
--------------------------------------------------------------------------------
1 | -------- @implements F.f --------
2 | abstract method func (F).f()
3 | is implemented by method (*C).f
4 | is implemented by method (D).f
5 | is implemented by method (FG).f
6 |
7 | -------- @implements FG.f --------
8 | abstract method func (FG).f()
9 | is implemented by method (*D).f
10 | implements method (F).f
11 |
12 | -------- @implements FG.g --------
13 | abstract method func (FG).g() []int
14 | is implemented by method (*D).g
15 |
16 | -------- @implements *C.f --------
17 | concrete method func (*C).f()
18 | implements method (F).f
19 |
20 | -------- @implements D.f --------
21 | concrete method func (D).f()
22 | implements method (F).f
23 | concrete method func (D).f()
24 | implements method (FG).f
25 |
26 | -------- @implements *D.g --------
27 | concrete method func (*D).g() []int
28 | implements method (FG).g
29 |
30 | -------- @implements Len --------
31 | concrete method func (sorter).Len() int
32 | implements method (lib.Sorter).Len
33 |
34 | -------- @implements I.Method --------
35 | abstract method func (I).Method(*int) *int
36 | is implemented by method (lib.Type).Method
37 | is implemented by method (main.I).Method
38 | implements method (main.I).Method
39 |
40 |
--------------------------------------------------------------------------------
/oracle/testdata/src/implements/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'implements' query.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See implements.golden for expected query results.
6 |
7 | import _ "lib"
8 |
9 | func main() {
10 | }
11 |
12 | type E interface{} // @implements E "E"
13 |
14 | type F interface { // @implements F "F"
15 | f()
16 | }
17 |
18 | type FG interface { // @implements FG "FG"
19 | f()
20 | g() []int // @implements slice "..int"
21 | }
22 |
23 | type C int // @implements C "C"
24 | type D struct{}
25 |
26 | func (c *C) f() {} // @implements starC ".C"
27 | func (d D) f() {} // @implements D "D"
28 |
29 | func (d *D) g() []int { return nil } // @implements starD ".D"
30 |
31 | type sorter []int // @implements sorter "sorter"
32 |
33 | func (sorter) Len() int { return 0 }
34 | func (sorter) Less(i, j int) bool { return false }
35 | func (sorter) Swap(i, j int) {}
36 |
37 | type I interface { // @implements I "I"
38 | Method(*int) *int
39 | }
40 |
--------------------------------------------------------------------------------
/oracle/testdata/src/implements/main.golden:
--------------------------------------------------------------------------------
1 | -------- @implements E --------
2 | empty interface type E
3 |
4 | -------- @implements F --------
5 | interface type F
6 | is implemented by pointer type *C
7 | is implemented by struct type D
8 | is implemented by interface type FG
9 |
10 | -------- @implements FG --------
11 | interface type FG
12 | is implemented by pointer type *D
13 | implements F
14 |
15 | -------- @implements slice --------
16 | slice type []int implements only interface{}
17 |
18 | -------- @implements C --------
19 | pointer type *C
20 | implements F
21 |
22 | -------- @implements starC --------
23 | pointer type *C
24 | implements F
25 |
26 | -------- @implements D --------
27 | struct type D
28 | implements F
29 | pointer type *D
30 | implements FG
31 |
32 | -------- @implements starD --------
33 | pointer type *D
34 | implements F
35 | implements FG
36 |
37 | -------- @implements sorter --------
38 | slice type sorter
39 | implements lib.Sorter
40 |
41 | -------- @implements I --------
42 | interface type I
43 | is implemented by basic type lib.Type
44 | is implemented by interface type main.I
45 | implements main.I
46 |
47 |
--------------------------------------------------------------------------------
/oracle/testdata/src/imports/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "hash/fnv" // @describe ref-pkg-import2 "fnv"
5 | "lib" // @describe ref-pkg-import "lib"
6 | )
7 |
8 | // Tests that import another package. (To make the tests run quickly,
9 | // we avoid using imports in all the other tests. Remember, each
10 | // query causes parsing and typechecking of the whole program.)
11 | //
12 | // See go.tools/oracle/oracle_test.go for explanation.
13 | // See imports.golden for expected query results.
14 |
15 | var a int
16 |
17 | func main() {
18 | const c = lib.Const // @describe ref-const "Const"
19 | lib.Func() // @describe ref-func "Func"
20 | lib.Var++ // @describe ref-var "Var"
21 | var t lib.Type // @describe ref-type "Type"
22 | p := t.Method(&a) // @describe ref-method "Method"
23 |
24 | print(*p + 1) // @pointsto p "p "
25 |
26 | var _ lib.Type // @describe ref-pkg "lib"
27 |
28 | fnv.New32()
29 | }
30 |
--------------------------------------------------------------------------------
/oracle/testdata/src/lib/lib.go:
--------------------------------------------------------------------------------
1 | package lib
2 |
3 | type Type int
4 |
5 | func (Type) Method(x *int) *int {
6 | return x
7 | }
8 |
9 | func Func() {
10 | }
11 |
12 | const Const = 3
13 |
14 | var Var = 0
15 |
16 | type Sorter interface {
17 | Len() int
18 | Less(i, j int) bool
19 | Swap(i, j int)
20 | }
21 |
--------------------------------------------------------------------------------
/oracle/testdata/src/main/multi.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func g(x int) {
4 | }
5 |
6 | func f() {
7 | x := 1
8 | g(x) // "g(x)" is the selection for multiple queries
9 | }
10 |
11 | func main() {
12 | f()
13 | }
14 |
--------------------------------------------------------------------------------
/oracle/testdata/src/peers-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of channel 'peers' query, -format=json.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See peers-json.golden for expected query results.
6 |
7 | func main() {
8 | chA := make(chan *int)
9 | <-chA
10 | select {
11 | case <-chA: // @peers peer-recv-chA "<-"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/oracle/testdata/src/peers-json/main.golden:
--------------------------------------------------------------------------------
1 | -------- @peers peer-recv-chA --------
2 | {
3 | "mode": "peers",
4 | "peers": {
5 | "pos": "testdata/src/peers-json/main.go:11:7",
6 | "type": "chan *int",
7 | "allocs": [
8 | "testdata/src/peers-json/main.go:8:13"
9 | ],
10 | "receives": [
11 | "testdata/src/peers-json/main.go:9:2",
12 | "testdata/src/peers-json/main.go:11:7"
13 | ]
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/oracle/testdata/src/peers/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of channel 'peers' query.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See peers.golden for expected query results.
6 |
7 | var a2 int
8 |
9 | func main() {
10 | chA := make(chan *int)
11 | a1 := 1
12 | chA <- &a1
13 |
14 | chA2 := make(chan *int, 2)
15 | if a2 == 0 {
16 | chA = chA2
17 | }
18 |
19 | chB := make(chan *int)
20 | b := 3
21 | chB <- &b
22 |
23 | <-chA // @pointsto pointsto-chA "chA"
24 | <-chA2 // @pointsto pointsto-chA2 "chA2"
25 | <-chB // @pointsto pointsto-chB "chB"
26 |
27 | select {
28 | case rA := <-chA: // @peers peer-recv-chA "<-"
29 | _ = rA // @pointsto pointsto-rA "rA"
30 | case rB := <-chB: // @peers peer-recv-chB "<-"
31 | _ = rB // @pointsto pointsto-rB "rB"
32 |
33 | case <-chA: // @peers peer-recv-chA' "<-"
34 |
35 | case chA2 <- &a2: // @peers peer-send-chA' "<-"
36 | }
37 |
38 | for _ = range chA {
39 | }
40 |
41 | close(chA) // @peers peer-close-chA "chA"
42 |
43 | chC := make(chan *int)
44 | (close)(chC) // @peers peer-close-chC "chC"
45 |
46 | close := func(ch chan *int) chan *int {
47 | return ch
48 | }
49 |
50 | close(chC) <- &b // @peers peer-send-chC "chC"
51 | <-close(chC) // @peers peer-recv-chC "chC"
52 | }
53 |
--------------------------------------------------------------------------------
/oracle/testdata/src/pointsto-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'pointsto' queries, -format=json.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See pointsto-json.golden for expected query results.
6 |
7 | func main() { //
8 | var s struct{ x [3]int }
9 | p := &s.x[0] // @pointsto val-p "p"
10 | _ = p
11 |
12 | var i I = C(0)
13 | if i == nil {
14 | i = new(D)
15 | }
16 | print(i) // @pointsto val-i "\\bi\\b"
17 | }
18 |
19 | type I interface {
20 | f()
21 | }
22 |
23 | type C int
24 | type D struct{}
25 |
26 | func (c C) f() {}
27 | func (d *D) f() {}
28 |
--------------------------------------------------------------------------------
/oracle/testdata/src/pointsto-json/main.golden:
--------------------------------------------------------------------------------
1 | -------- @pointsto val-p --------
2 | {
3 | "mode": "pointsto",
4 | "pointsto": [
5 | {
6 | "type": "*int",
7 | "labels": [
8 | {
9 | "pos": "testdata/src/pointsto-json/main.go:8:6",
10 | "desc": "s.x[*]"
11 | }
12 | ]
13 | }
14 | ]
15 | }
16 | -------- @pointsto val-i --------
17 | {
18 | "mode": "pointsto",
19 | "pointsto": [
20 | {
21 | "type": "*D",
22 | "namepos": "testdata/src/pointsto-json/main.go:24:6",
23 | "labels": [
24 | {
25 | "pos": "testdata/src/pointsto-json/main.go:14:10",
26 | "desc": "new"
27 | }
28 | ]
29 | },
30 | {
31 | "type": "C",
32 | "namepos": "testdata/src/pointsto-json/main.go:23:6"
33 | }
34 | ]
35 | }
36 |
--------------------------------------------------------------------------------
/oracle/testdata/src/referrers-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'referrers' query.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See referrers.golden for expected query results.
6 |
7 | import "lib"
8 |
9 | type s struct {
10 | f int
11 | }
12 |
13 | func main() {
14 | var v lib.Type = lib.Const // @referrers ref-package "lib"
15 | _ = v.Method // @referrers ref-method "Method"
16 | _ = v.Method
17 | v++ //@referrers ref-local "v"
18 | v++
19 |
20 | _ = s{}.f // @referrers ref-field "f"
21 |
22 | var s2 s
23 | s2.f = 1
24 | }
25 |
--------------------------------------------------------------------------------
/oracle/testdata/src/referrers/ext_test.go:
--------------------------------------------------------------------------------
1 | package main_test
2 |
3 | import (
4 | "lib"
5 | renamed "referrers" // package has name "main", path "referrers", local name "renamed"
6 | )
7 |
8 | func _() {
9 | // This reference should be found by the ref-method query.
10 | _ = (lib.Type).Method // ref from external test package
11 | var _ renamed.T
12 | }
13 |
--------------------------------------------------------------------------------
/oracle/testdata/src/referrers/int_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "lib"
4 |
5 | func _() {
6 | // This reference should be found by the ref-method query.
7 | _ = (lib.Type).Method // ref from internal test package
8 | }
9 |
--------------------------------------------------------------------------------
/oracle/testdata/src/referrers/main.go:
--------------------------------------------------------------------------------
1 | package main // @referrers package-decl "main"
2 |
3 | // Tests of 'referrers' query.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See referrers.golden for expected query results.
6 |
7 | import "lib"
8 |
9 | type s struct { // @referrers type " s "
10 | f int
11 | }
12 |
13 | type T int
14 |
15 | func main() {
16 | var v lib.Type = lib.Const // @referrers ref-package "lib"
17 | _ = v.Method // @referrers ref-method "Method"
18 | _ = v.Method
19 | v++ //@referrers ref-local "v"
20 | v++
21 |
22 | _ = s{}.f // @referrers ref-field "f"
23 |
24 | var s2 s
25 | s2.f = 1
26 | }
27 |
28 | // Test //line directives:
29 |
30 | type U int // @referrers ref-type-U "U"
31 |
32 | //line nosuchfile.y:123
33 | var u1 U
34 | var u2 U
35 |
--------------------------------------------------------------------------------
/oracle/testdata/src/referrers/main.golden:
--------------------------------------------------------------------------------
1 | -------- @referrers package-decl --------
2 | 1 references to package main ("referrers")
3 | var _ renamed.T
4 |
5 | -------- @referrers type --------
6 | 2 references to type s struct{f int}
7 | _ = s{}.f // @referrers ref-field "f"
8 | var s2 s
9 |
10 | -------- @referrers ref-package --------
11 | 4 references to package lib
12 | _ = (lib.Type).Method // ref from external test package
13 | _ = (lib.Type).Method // ref from internal test package
14 | var v lib.Type = lib.Const // @referrers ref-package "lib"
15 | var v lib.Type = lib.Const // @referrers ref-package "lib"
16 |
17 | -------- @referrers ref-method --------
18 | 7 references to func (lib.Type).Method(x *int) *int
19 | p := t.Method(&a) // @describe ref-method "Method"
20 | _ = v.Method // @referrers ref-method "Method"
21 | _ = v.Method
22 | _ = (lib.Type).Method // ref from external test package
23 | _ = (lib.Type).Method // ref from internal test package
24 | _ = v.Method // @referrers ref-method "Method"
25 | _ = v.Method
26 |
27 | -------- @referrers ref-local --------
28 | 4 references to var v lib.Type
29 | _ = v.Method // @referrers ref-method "Method"
30 | _ = v.Method
31 | v++ //@referrers ref-local "v"
32 | v++
33 |
34 | -------- @referrers ref-field --------
35 | 2 references to field f int
36 | _ = s{}.f // @referrers ref-field "f"
37 | s2.f = 1
38 |
39 | -------- @referrers ref-type-U --------
40 | 2 references to type U int
41 | open testdata/src/referrers/nosuchfile.y: no such file or directory (+ 1 more refs in this file)
42 |
43 |
--------------------------------------------------------------------------------
/oracle/testdata/src/reflection/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // This is a test of 'pointsto', but we split it into a separate file
4 | // so that pointsto.go doesn't have to import "reflect" each time.
5 |
6 | import "reflect"
7 |
8 | var a int
9 | var b bool
10 |
11 | func main() {
12 | m := make(map[*int]*bool)
13 | m[&a] = &b
14 |
15 | mrv := reflect.ValueOf(m)
16 | if a > 0 {
17 | mrv = reflect.ValueOf(&b)
18 | }
19 | if a > 0 {
20 | mrv = reflect.ValueOf(&a)
21 | }
22 |
23 | _ = mrv // @pointsto mrv "mrv"
24 | p1 := mrv.Interface() // @pointsto p1 "p1"
25 | p2 := mrv.MapKeys() // @pointsto p2 "p2"
26 | p3 := p2[0] // @pointsto p3 "p3"
27 | p4 := reflect.TypeOf(p1) // @pointsto p4 "p4"
28 |
29 | _, _, _, _ = p1, p2, p3, p4
30 | }
31 |
--------------------------------------------------------------------------------
/oracle/testdata/src/reflection/main.golden:
--------------------------------------------------------------------------------
1 | -------- @pointsto mrv --------
2 | this reflect.Value may contain these dynamic types:
3 | *bool, may point to:
4 | main.b
5 | *int, may point to:
6 | main.a
7 | map[*int]*bool, may point to:
8 | makemap
9 |
10 | -------- @pointsto p1 --------
11 | this interface{} may contain these dynamic types:
12 | *bool, may point to:
13 | main.b
14 | *int, may point to:
15 | main.a
16 | map[*int]*bool, may point to:
17 | makemap
18 |
19 | -------- @pointsto p2 --------
20 | this []reflect.Value may point to these objects:
21 |
22 |
23 | -------- @pointsto p3 --------
24 | this reflect.Value may contain these dynamic types:
25 | *int, may point to:
26 | main.a
27 |
28 | -------- @pointsto p4 --------
29 | this reflect.Type may contain these dynamic types:
30 | *reflect.rtype, may point to:
31 | *bool
32 | *int
33 | map[*int]*bool
34 |
35 |
--------------------------------------------------------------------------------
/oracle/testdata/src/what-json/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Tests of 'what' queries, -format=json.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See what-json.golden for expected query results.
6 |
7 | func main() {
8 | f() // @what call "f"
9 | }
10 |
--------------------------------------------------------------------------------
/oracle/testdata/src/what-json/main.golden:
--------------------------------------------------------------------------------
1 | -------- @what call --------
2 | {
3 | "mode": "what",
4 | "what": {
5 | "enclosing": [
6 | {
7 | "desc": "identifier",
8 | "start": 179,
9 | "end": 180
10 | },
11 | {
12 | "desc": "function call (or conversion)",
13 | "start": 179,
14 | "end": 182
15 | },
16 | {
17 | "desc": "expression statement",
18 | "start": 179,
19 | "end": 182
20 | },
21 | {
22 | "desc": "block",
23 | "start": 176,
24 | "end": 202
25 | },
26 | {
27 | "desc": "function declaration",
28 | "start": 164,
29 | "end": 202
30 | },
31 | {
32 | "desc": "source file",
33 | "start": 0,
34 | "end": 202
35 | }
36 | ],
37 | "modes": [
38 | "callees",
39 | "callers",
40 | "callstack",
41 | "definition",
42 | "describe",
43 | "freevars",
44 | "implements",
45 | "pointsto",
46 | "referrers"
47 | ],
48 | "srcdir": "testdata/src",
49 | "importpath": "what-json"
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/oracle/testdata/src/what/main.go:
--------------------------------------------------------------------------------
1 | package main // @what pkgdecl "main"
2 |
3 | // Tests of 'what' queries.
4 | // See go.tools/oracle/oracle_test.go for explanation.
5 | // See what.golden for expected query results.
6 |
7 | func main() {
8 | f() // @what call "f"
9 | var ch chan int // @what var "var"
10 | <-ch // @what recv "ch"
11 | }
12 |
--------------------------------------------------------------------------------
/oracle/testdata/src/what/main.golden:
--------------------------------------------------------------------------------
1 | -------- @what pkgdecl --------
2 | identifier
3 | source file
4 | modes: [definition describe freevars implements pointsto referrers]
5 | srcdir: testdata/src
6 | import path: what
7 |
8 | -------- @what call --------
9 | identifier
10 | function call (or conversion)
11 | expression statement
12 | block
13 | function declaration
14 | source file
15 | modes: [callees callers callstack definition describe freevars implements pointsto referrers]
16 | srcdir: testdata/src
17 | import path: what
18 |
19 | -------- @what var --------
20 | variable declaration
21 | variable declaration statement
22 | block
23 | function declaration
24 | source file
25 | modes: [callers callstack describe freevars pointsto]
26 | srcdir: testdata/src
27 | import path: what
28 |
29 | -------- @what recv --------
30 | identifier
31 | unary <- operation
32 | expression statement
33 | block
34 | function declaration
35 | source file
36 | modes: [callers callstack definition describe freevars implements peers pointsto referrers]
37 | srcdir: testdata/src
38 | import path: what
39 |
40 |
--------------------------------------------------------------------------------
/oracle/testdata/src/whicherrs/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | type errType string
4 |
5 | const constErr errType = "blah"
6 |
7 | func (et errType) Error() string {
8 | return string(et)
9 | }
10 |
11 | var errVar error = errType("foo")
12 |
13 | func genErr(i int) error {
14 | switch i {
15 | case 0:
16 | return constErr
17 | case 1:
18 | return errVar
19 | default:
20 | return nil
21 | }
22 | }
23 |
24 | func main() {
25 | err := genErr(0) // @whicherrs localerrs "err"
26 | _ = err
27 | }
28 |
--------------------------------------------------------------------------------
/oracle/testdata/src/whicherrs/main.golden:
--------------------------------------------------------------------------------
1 | -------- @whicherrs localerrs --------
2 | this error may point to these globals:
3 | errVar
4 | this error may contain these constants:
5 | constErr
6 | this error may contain these dynamic types:
7 | errType
8 |
9 |
--------------------------------------------------------------------------------
/playground/appengine.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go 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 | // +build appengine
6 |
7 | package playground
8 |
9 | import (
10 | "net/http"
11 |
12 | "appengine"
13 | "appengine/urlfetch"
14 | )
15 |
16 | func init() {
17 | onAppengine = !appengine.IsDevAppServer()
18 | }
19 |
20 | func client(r *http.Request) *http.Client {
21 | return urlfetch.Client(appengine.NewContext(r))
22 | }
23 |
24 | func report(r *http.Request, err error) {
25 | appengine.NewContext(r).Errorf("%v", err)
26 | }
27 |
--------------------------------------------------------------------------------
/playground/appenginevm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go 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 | // +build appenginevm
6 |
7 | package playground
8 |
9 | func init() {
10 | onAppengine = true
11 | }
12 |
--------------------------------------------------------------------------------
/playground/local.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go 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 | // +build !appengine
6 |
7 | package playground
8 |
9 | import (
10 | "log"
11 | "net/http"
12 | )
13 |
14 | func client(r *http.Request) *http.Client {
15 | return http.DefaultClient
16 | }
17 |
18 | func report(r *http.Request, err error) {
19 | log.Println(err)
20 | }
21 |
--------------------------------------------------------------------------------
/present/background.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go 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 present
6 |
7 | import (
8 | "strings"
9 | )
10 |
11 | func init() {
12 | Register("background", parseBackground)
13 | }
14 |
15 | type Background struct {
16 | URL string
17 | }
18 |
19 | func (i Background) TemplateName() string { return "background" }
20 |
21 | func parseBackground(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
22 | args := strings.Fields(text)
23 | background := Background{URL: args[1]}
24 | return background, nil
25 | }
26 |
--------------------------------------------------------------------------------
/present/caption.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go 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 present
6 |
7 | import "strings"
8 |
9 | func init() {
10 | Register("caption", parseCaption)
11 | }
12 |
13 | type Caption struct {
14 | Text string
15 | }
16 |
17 | func (c Caption) TemplateName() string { return "caption" }
18 |
19 | func parseCaption(_ *Context, _ string, _ int, text string) (Elem, error) {
20 | text = strings.TrimSpace(strings.TrimPrefix(text, ".caption"))
21 | return Caption{text}, nil
22 | }
23 |
--------------------------------------------------------------------------------
/present/html.go:
--------------------------------------------------------------------------------
1 | package present
2 |
3 | import (
4 | "errors"
5 | "html/template"
6 | "path/filepath"
7 | "strings"
8 | )
9 |
10 | func init() {
11 | Register("html", parseHTML)
12 | }
13 |
14 | func parseHTML(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
15 | p := strings.Fields(text)
16 | if len(p) != 2 {
17 | return nil, errors.New("invalid .html args")
18 | }
19 | name := filepath.Join(filepath.Dir(fileName), p[1])
20 | b, err := ctx.ReadFile(name)
21 | if err != nil {
22 | return nil, err
23 | }
24 | return HTML{template.HTML(b)}, nil
25 | }
26 |
27 | type HTML struct {
28 | template.HTML
29 | }
30 |
31 | func (s HTML) TemplateName() string { return "html" }
32 |
--------------------------------------------------------------------------------
/present/iframe.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go 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 present
6 |
7 | import (
8 | "fmt"
9 | "strings"
10 | )
11 |
12 | func init() {
13 | Register("iframe", parseIframe)
14 | }
15 |
16 | type Iframe struct {
17 | URL string
18 | Width int
19 | Height int
20 | }
21 |
22 | func (i Iframe) TemplateName() string { return "iframe" }
23 |
24 | func parseIframe(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
25 | args := strings.Fields(text)
26 | i := Iframe{URL: args[1]}
27 | a, err := parseArgs(fileName, lineno, args[2:])
28 | if err != nil {
29 | return nil, err
30 | }
31 | switch len(a) {
32 | case 0:
33 | // no size parameters
34 | case 2:
35 | if v, ok := a[0].(int); ok {
36 | i.Height = v
37 | }
38 | if v, ok := a[1].(int); ok {
39 | i.Width = v
40 | }
41 | default:
42 | return nil, fmt.Errorf("incorrect image invocation: %q", text)
43 | }
44 | return i, nil
45 | }
46 |
--------------------------------------------------------------------------------
/present/image.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go 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 present
6 |
7 | import (
8 | "fmt"
9 | "strings"
10 | )
11 |
12 | func init() {
13 | Register("image", parseImage)
14 | }
15 |
16 | type Image struct {
17 | URL string
18 | Width int
19 | Height int
20 | }
21 |
22 | func (i Image) TemplateName() string { return "image" }
23 |
24 | func parseImage(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
25 | args := strings.Fields(text)
26 | img := Image{URL: args[1]}
27 | a, err := parseArgs(fileName, lineno, args[2:])
28 | if err != nil {
29 | return nil, err
30 | }
31 | switch len(a) {
32 | case 0:
33 | // no size parameters
34 | case 2:
35 | // If a parameter is empty (underscore) or invalid
36 | // leave the field set to zero. The "image" action
37 | // template will then omit that img tag attribute and
38 | // the browser will calculate the value to preserve
39 | // the aspect ratio.
40 | if v, ok := a[0].(int); ok {
41 | img.Height = v
42 | }
43 | if v, ok := a[1].(int); ok {
44 | img.Width = v
45 | }
46 | default:
47 | return nil, fmt.Errorf("incorrect image invocation: %q", text)
48 | }
49 | return img, nil
50 | }
51 |
--------------------------------------------------------------------------------
/present/video.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go 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 present
6 |
7 | import (
8 | "fmt"
9 | "strings"
10 | )
11 |
12 | func init() {
13 | Register("video", parseVideo)
14 | }
15 |
16 | type Video struct {
17 | URL string
18 | SourceType string
19 | Width int
20 | Height int
21 | }
22 |
23 | func (v Video) TemplateName() string { return "video" }
24 |
25 | func parseVideo(ctx *Context, fileName string, lineno int, text string) (Elem, error) {
26 | args := strings.Fields(text)
27 | vid := Video{URL: args[1], SourceType: args[2]}
28 | a, err := parseArgs(fileName, lineno, args[3:])
29 | if err != nil {
30 | return nil, err
31 | }
32 | switch len(a) {
33 | case 0:
34 | // no size parameters
35 | case 2:
36 | // If a parameter is empty (underscore) or invalid
37 | // leave the field set to zero. The "video" action
38 | // template will then omit that vid tag attribute and
39 | // the browser will calculate the value to preserve
40 | // the aspect ratio.
41 | if v, ok := a[0].(int); ok {
42 | vid.Height = v
43 | }
44 | if v, ok := a[1].(int); ok {
45 | vid.Width = v
46 | }
47 | default:
48 | return nil, fmt.Errorf("incorrect video invocation: %q", text)
49 | }
50 | return vid, nil
51 | }
52 |
--------------------------------------------------------------------------------
/refactor/README:
--------------------------------------------------------------------------------
1 | golang.org/x/tools/refactor: libraries for refactoring tools.
2 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/A.template:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package template
4 |
5 | // Basic test of type-aware expression refactoring.
6 |
7 | import (
8 | "errors"
9 | "fmt"
10 | )
11 |
12 | func before(s string) error { return fmt.Errorf("%s", s) }
13 | func after(s string) error { return errors.New(s) }
14 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/A1.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package A1
4 |
5 | import (
6 | . "fmt"
7 | myfmt "fmt"
8 | "os"
9 | "strings"
10 | )
11 |
12 | func example(n int) {
13 | x := "foo" + strings.Repeat("\t", n)
14 | // Match, despite named import.
15 | myfmt.Errorf("%s", x)
16 |
17 | // Match, despite dot import.
18 | Errorf("%s", x)
19 |
20 | // Match: multiple matches in same function are possible.
21 | myfmt.Errorf("%s", x)
22 |
23 | // No match: wildcarded operand has the wrong type.
24 | myfmt.Errorf("%s", 3)
25 |
26 | // No match: function operand doesn't match.
27 | myfmt.Printf("%s", x)
28 |
29 | // No match again, dot import.
30 | Printf("%s", x)
31 |
32 | // Match.
33 | myfmt.Fprint(os.Stderr, myfmt.Errorf("%s", x+"foo"))
34 |
35 | // No match: though this literally matches the template,
36 | // fmt doesn't resolve to a package here.
37 | var fmt struct{ Errorf func(string, string) }
38 | fmt.Errorf("%s", x)
39 |
40 | // Recursive matching:
41 |
42 | // Match: both matches are well-typed, so both succeed.
43 | myfmt.Errorf("%s", myfmt.Errorf("%s", x+"foo").Error())
44 |
45 | // Outer match succeeds, inner doesn't: 3 has wrong type.
46 | myfmt.Errorf("%s", myfmt.Errorf("%s", 3).Error())
47 |
48 | // Inner match succeeds, outer doesn't: the inner replacement
49 | // has the wrong type (error not string).
50 | myfmt.Errorf("%s", myfmt.Errorf("%s", x+"foo"))
51 | }
52 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/A1.golden:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package A1
4 |
5 | import (
6 | "errors"
7 | . "fmt"
8 | myfmt "fmt"
9 | "os"
10 | "strings"
11 | )
12 |
13 | func example(n int) {
14 | x := "foo" + strings.Repeat("\t", n)
15 | // Match, despite named import.
16 | errors.New(x)
17 |
18 | // Match, despite dot import.
19 | errors.New(x)
20 |
21 | // Match: multiple matches in same function are possible.
22 | errors.New(x)
23 |
24 | // No match: wildcarded operand has the wrong type.
25 | myfmt.Errorf("%s", 3)
26 |
27 | // No match: function operand doesn't match.
28 | myfmt.Printf("%s", x)
29 |
30 | // No match again, dot import.
31 | Printf("%s", x)
32 |
33 | // Match.
34 | myfmt.Fprint(os.Stderr, errors.New(x+"foo"))
35 |
36 | // No match: though this literally matches the template,
37 | // fmt doesn't resolve to a package here.
38 | var fmt struct{ Errorf func(string, string) }
39 | fmt.Errorf("%s", x)
40 |
41 | // Recursive matching:
42 |
43 | // Match: both matches are well-typed, so both succeed.
44 | errors.New(errors.New(x + "foo").Error())
45 |
46 | // Outer match succeeds, inner doesn't: 3 has wrong type.
47 | errors.New(myfmt.Errorf("%s", 3).Error())
48 |
49 | // Inner match succeeds, outer doesn't: the inner replacement
50 | // has the wrong type (error not string).
51 | myfmt.Errorf("%s", errors.New(x+"foo"))
52 | }
53 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/A2.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package A2
4 |
5 | // This refactoring causes addition of "errors" import.
6 | // TODO(adonovan): fix: it should also remove "fmt".
7 |
8 | import myfmt "fmt"
9 |
10 | func example(n int) {
11 | myfmt.Errorf("%s", "")
12 | }
13 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/A2.golden:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package A2
4 |
5 | // This refactoring causes addition of "errors" import.
6 | // TODO(adonovan): fix: it should also remove "fmt".
7 |
8 | import (
9 | "errors"
10 | myfmt "fmt"
11 | )
12 |
13 | func example(n int) {
14 | errors.New("")
15 | }
16 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/B.template:
--------------------------------------------------------------------------------
1 | package template
2 |
3 | // Basic test of expression refactoring.
4 | // (Types are not important in this case; it could be done with gofmt -r.)
5 |
6 | import "time"
7 |
8 | func before(t time.Time) time.Duration { return time.Now().Sub(t) }
9 | func after(t time.Time) time.Duration { return time.Since(t) }
10 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/B1.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package B1
4 |
5 | import "time"
6 |
7 | var startup = time.Now()
8 |
9 | func example() time.Duration {
10 | before := time.Now()
11 | time.Sleep(1)
12 | return time.Now().Sub(before)
13 | }
14 |
15 | func msSinceStartup() int64 {
16 | return int64(time.Now().Sub(startup) / time.Millisecond)
17 | }
18 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/B1.golden:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package B1
4 |
5 | import "time"
6 |
7 | var startup = time.Now()
8 |
9 | func example() time.Duration {
10 | before := time.Now()
11 | time.Sleep(1)
12 | return time.Since(before)
13 | }
14 |
15 | func msSinceStartup() int64 {
16 | return int64(time.Since(startup) / time.Millisecond)
17 | }
18 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/C.template:
--------------------------------------------------------------------------------
1 | package template
2 |
3 | // Test of repeated use of wildcard in pattern.
4 |
5 | // NB: multiple patterns would be required to handle variants such as
6 | // s[:len(s)], s[x:len(s)], etc, since a wildcard can't match nothing at all.
7 | // TODO(adonovan): support multiple templates in a single pass.
8 |
9 | func before(s string) string { return s[:len(s)] }
10 | func after(s string) string { return s }
11 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/C1.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package C1
4 |
5 | import "strings"
6 |
7 | func example() {
8 | x := "foo"
9 | println(x[:len(x)])
10 |
11 | // Match, but the transformation is not sound w.r.t. possible side effects.
12 | println(strings.Repeat("*", 3)[:len(strings.Repeat("*", 3))])
13 |
14 | // No match, since second use of wildcard doesn't match first.
15 | println(strings.Repeat("*", 3)[:len(strings.Repeat("*", 2))])
16 |
17 | // Recursive match demonstrating bottom-up rewrite:
18 | // only after the inner replacement occurs does the outer syntax match.
19 | println((x[:len(x)])[:len(x[:len(x)])])
20 | // -> (x[:len(x)])
21 | // -> x
22 | }
23 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/C1.golden:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package C1
4 |
5 | import "strings"
6 |
7 | func example() {
8 | x := "foo"
9 | println(x)
10 |
11 | // Match, but the transformation is not sound w.r.t. possible side effects.
12 | println(strings.Repeat("*", 3))
13 |
14 | // No match, since second use of wildcard doesn't match first.
15 | println(strings.Repeat("*", 3)[:len(strings.Repeat("*", 2))])
16 |
17 | // Recursive match demonstrating bottom-up rewrite:
18 | // only after the inner replacement occurs does the outer syntax match.
19 | println(x)
20 | // -> (x[:len(x)])
21 | // -> x
22 | }
23 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/D.template:
--------------------------------------------------------------------------------
1 | package template
2 |
3 | import "fmt"
4 |
5 | // Test of semantic (not syntactic) matching of basic literals.
6 |
7 | func before() (int, error) { return fmt.Println(123, "a") }
8 | func after() (int, error) { return fmt.Println(456, "!") }
9 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/D1.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package D1
4 |
5 | import "fmt"
6 |
7 | func example() {
8 | fmt.Println(123, "a") // match
9 | fmt.Println(0x7b, `a`) // match
10 | fmt.Println(0173, "\x61") // match
11 | fmt.Println(100+20+3, "a"+"") // no match: constant expressions, but not basic literals
12 | }
13 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/D1.golden:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package D1
4 |
5 | import "fmt"
6 |
7 | func example() {
8 | fmt.Println(456, "!") // match
9 | fmt.Println(456, "!") // match
10 | fmt.Println(456, "!") // match
11 | fmt.Println(100+20+3, "a"+"") // no match: constant expressions, but not basic literals
12 | }
13 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/E.template:
--------------------------------------------------------------------------------
1 | package template
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | "os"
7 | )
8 |
9 | // Replace call to void function by call to non-void function.
10 |
11 | func before(x interface{}) { log.Fatal(x) }
12 | func after(x interface{}) { fmt.Fprintf(os.Stderr, "warning: %v", x) }
13 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/E1.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package E1
4 |
5 | import "log"
6 |
7 | func example() {
8 | log.Fatal("oops") // match
9 | }
10 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/E1.golden:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package E1
4 |
5 | import (
6 | "fmt"
7 | "log"
8 | "os"
9 | )
10 |
11 | func example() {
12 | fmt.Fprintf(os.Stderr, "warning: %v", "oops") // match
13 | }
14 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/F.template:
--------------------------------------------------------------------------------
1 | package templates
2 |
3 | // Test
4 |
5 | import "sync"
6 |
7 | func before(s sync.RWMutex) { s.Lock() }
8 | func after(s sync.RWMutex) { s.RLock() }
--------------------------------------------------------------------------------
/refactor/eg/testdata/F1.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package F1
4 |
5 | import "sync"
6 |
7 | func example(n int) {
8 | var x struct {
9 | mutex sync.RWMutex
10 | }
11 |
12 | var y struct {
13 | sync.RWMutex
14 | }
15 |
16 | type l struct {
17 | sync.RWMutex
18 | }
19 |
20 | var z struct {
21 | l
22 | }
23 |
24 | var a struct {
25 | *l
26 | }
27 |
28 | var b struct{ Lock func() }
29 |
30 | // Match
31 | x.mutex.Lock()
32 |
33 | // Match
34 | y.Lock()
35 |
36 | // Match indirect
37 | z.Lock()
38 |
39 | // Should be no match however currently matches due to:
40 | // https://golang.org/issue/8584
41 | // Will start failing when this is fixed then just change golden to
42 | // No match pointer indirect
43 | // a.Lock()
44 | a.Lock()
45 |
46 | // No match
47 | b.Lock()
48 | }
49 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/F1.golden:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package F1
4 |
5 | import "sync"
6 |
7 | func example(n int) {
8 | var x struct {
9 | mutex sync.RWMutex
10 | }
11 |
12 | var y struct {
13 | sync.RWMutex
14 | }
15 |
16 | type l struct {
17 | sync.RWMutex
18 | }
19 |
20 | var z struct {
21 | l
22 | }
23 |
24 | var a struct {
25 | *l
26 | }
27 |
28 | var b struct{ Lock func() }
29 |
30 | // Match
31 | x.mutex.RLock()
32 |
33 | // Match
34 | y.RLock()
35 |
36 | // Match indirect
37 | z.RLock()
38 |
39 | // Should be no match however currently matches due to:
40 | // https://golang.org/issue/8584
41 | // Will start failing when this is fixed then just change golden to
42 | // No match pointer indirect
43 | // a.Lock()
44 | a.RLock()
45 |
46 | // No match
47 | b.Lock()
48 | }
49 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/G.template:
--------------------------------------------------------------------------------
1 | package templates
2 |
3 | import (
4 | "go/ast" // defines many unencapsulated structs
5 | "go/token"
6 | )
7 |
8 | func before(from, to token.Pos) ast.BadExpr { return ast.BadExpr{From: from, To: to} }
9 | func after(from, to token.Pos) ast.BadExpr { return ast.BadExpr{from, to} }
10 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/G1.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package G1
4 |
5 | import "go/ast"
6 |
7 | func example() {
8 | _ = ast.BadExpr{From: 123, To: 456} // match
9 | _ = ast.BadExpr{123, 456} // no match
10 | _ = ast.BadExpr{From: 123} // no match
11 | _ = ast.BadExpr{To: 456} // no match
12 | }
13 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/G1.golden:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package G1
4 |
5 | import "go/ast"
6 |
7 | func example() {
8 | _ = ast.BadExpr{123, 456} // match
9 | _ = ast.BadExpr{123, 456} // no match
10 | _ = ast.BadExpr{From: 123} // no match
11 | _ = ast.BadExpr{To: 456} // no match
12 | }
13 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/H.template:
--------------------------------------------------------------------------------
1 | package templates
2 |
3 | import (
4 | "go/ast" // defines many unencapsulated structs
5 | "go/token"
6 | )
7 |
8 | func before(from, to token.Pos) ast.BadExpr { return ast.BadExpr{from, to} }
9 | func after(from, to token.Pos) ast.BadExpr { return ast.BadExpr{From: from, To: to} }
10 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/H1.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package H1
4 |
5 | import "go/ast"
6 |
7 | func example() {
8 | _ = ast.BadExpr{From: 123, To: 456} // no match
9 | _ = ast.BadExpr{123, 456} // match
10 | _ = ast.BadExpr{From: 123} // no match
11 | _ = ast.BadExpr{To: 456} // no match
12 | }
13 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/H1.golden:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package H1
4 |
5 | import "go/ast"
6 |
7 | func example() {
8 | _ = ast.BadExpr{From: 123, To: 456} // no match
9 | _ = ast.BadExpr{From: 123, To: 456} // match
10 | _ = ast.BadExpr{From: 123} // no match
11 | _ = ast.BadExpr{To: 456} // no match
12 | }
13 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/bad_type.template:
--------------------------------------------------------------------------------
1 | package template
2 |
3 | // Test in which replacement has a different type.
4 |
5 | const shouldFail = "int is not a safe replacement for string"
6 |
7 | func before() interface{} { return "three" }
8 | func after() interface{} { return 3 }
9 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/expr_type_mismatch.template:
--------------------------------------------------------------------------------
1 | package template
2 |
3 | import (
4 | "crypto/x509"
5 | "fmt"
6 | )
7 |
8 | // This test demonstrates a false negative: according to the language
9 | // rules this replacement should be ok, but types.Assignable doesn't work
10 | // in the expected way (elementwise assignability) for tuples.
11 | // Perhaps that's even a type-checker bug?
12 | const shouldFail = "(n int, err error) is not a safe replacement for (key interface{}, err error)"
13 |
14 | func before() (interface{}, error) { return x509.ParsePKCS8PrivateKey(nil) }
15 | func after() (interface{}, error) { return fmt.Print() }
16 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/no_after_return.template:
--------------------------------------------------------------------------------
1 | package template
2 |
3 | const shouldFail = "after: must contain a single statement"
4 |
5 | func before() int { return 0 }
6 | func after() int { println(); return 0 }
7 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/no_before.template:
--------------------------------------------------------------------------------
1 | package template
2 |
3 | const shouldFail = "no 'before' func found in template"
4 |
5 | func Before() {}
6 |
--------------------------------------------------------------------------------
/refactor/eg/testdata/type_mismatch.template:
--------------------------------------------------------------------------------
1 | package template
2 |
3 | const shouldFail = "different signatures"
4 |
5 | func before() int { return 0 }
6 | func after() string { return "" }
7 |
--------------------------------------------------------------------------------