FAQ
Reviewers: gri,

Message:
Hello gri@golang.org (cc: golang-dev@googlegroups.com),

I'd like you to review this change to
https://code.google.com/p/go.tools


Description:
go.tools/ssa: move AllFunctions to ssautil subpackage

Please review this at https://codereview.appspot.com/37970043/

Affected files (+18, -16 lines):
    M oracle/peers.go
    M ssa/doc.go
    M ssa/ssautil/visit.go
    M ssa/stdlib_test.go


Index: oracle/peers.go
===================================================================
--- a/oracle/peers.go
+++ b/oracle/peers.go
@@ -14,6 +14,7 @@
    "code.google.com/p/go.tools/oracle/serial"
    "code.google.com/p/go.tools/pointer"
    "code.google.com/p/go.tools/ssa"
+ "code.google.com/p/go.tools/ssa/ssautil"
   )

   // peers enumerates, for a given channel send (or receive) operation,
@@ -36,7 +37,7 @@

    // Look at all send/receive instructions in the whole ssa.Program.
    // Build a list of those of same type to query.
- allFuncs := ssa.AllFunctions(o.prog)
+ allFuncs := ssautil.AllFunctions(o.prog)
    for fn := range allFuncs {
     for _, b := range fn.Blocks {
      for _, instr := range b.Instrs {
Index: ssa/doc.go
===================================================================
--- a/ssa/doc.go
+++ b/ssa/doc.go
@@ -114,14 +114,12 @@
   // either accurate or unambiguous. The public API exposes a number of
   // name-based maps for client convenience.
   //
+// The ssa/ssautil package provides various utilities that depend only
+// on the public API of this package.
+//
   // TODO(adonovan): Consider the exceptional control-flow implications
   // of defer and recover().
   //
-// TODO(adonovan): write an example showing how to visit all functions
-// in a Program, including package init functions, methods of named
-// and anon types, and functions used as values but never called
-// directly. See AllFunctions().
-//
   // TODO(adonovan): write a how-to document for all the various cases
   // of trying to determine corresponding elements across the four
   // domains of source locations, ast.Nodes, types.Objects,
Index: ssa/ssautil/visit.go
===================================================================
rename from ssa/visit.go
rename to ssa/ssautil/visit.go
--- a/ssa/visit.go
+++ b/ssa/ssautil/visit.go
@@ -2,7 +2,9 @@
   // Use of this source code is governed by a BSD-style
   // license that can be found in the LICENSE file.

-package ssa
+package ssautil
+
+import "code.google.com/p/go.tools/ssa"

   // This file defines utilities for visiting the SSA representation of
   // a Program.
@@ -17,24 +19,24 @@
   //
   // Precondition: all packages are built.
   //
-func AllFunctions(prog *Program) map[*Function]bool {
+func AllFunctions(prog *ssa.Program) map[*ssa.Function]bool {
    visit := visitor{
     prog: prog,
- seen: make(map[*Function]bool),
+ seen: make(map[*ssa.Function]bool),
    }
    visit.program()
    return visit.seen
   }

   type visitor struct {
- prog *Program
- seen map[*Function]bool
+ prog *ssa.Program
+ seen map[*ssa.Function]bool
   }

   func (visit *visitor) program() {
    for _, pkg := range visit.prog.AllPackages() {
     for _, mem := range pkg.Members {
- if fn, ok := mem.(*Function); ok {
+ if fn, ok := mem.(*ssa.Function); ok {
       visit.function(fn)
      }
     }
@@ -47,14 +49,14 @@
    }
   }

-func (visit *visitor) function(fn *Function) {
+func (visit *visitor) function(fn *ssa.Function) {
    if !visit.seen[fn] {
     visit.seen[fn] = true
+ var buf [10]*ssa.Value // avoid alloc in common case
     for _, b := range fn.Blocks {
      for _, instr := range b.Instrs {
- var buf [10]*Value // avoid alloc in common case
       for _, op := range instr.Operands(buf[:0]) {
- if fn, ok := (*op).(*Function); ok {
+ if fn, ok := (*op).(*ssa.Function); ok {
         visit.function(fn)
        }
       }
Index: ssa/stdlib_test.go
===================================================================
--- a/ssa/stdlib_test.go
+++ b/ssa/stdlib_test.go
@@ -21,6 +21,7 @@

    "code.google.com/p/go.tools/importer"
    "code.google.com/p/go.tools/ssa"
+ "code.google.com/p/go.tools/ssa/ssautil"
   )

   const debugMode = false
@@ -97,7 +98,7 @@
    }

    // Dump some statistics.
- allFuncs := ssa.AllFunctions(prog)
+ allFuncs := ssautil.AllFunctions(prog)
    var numInstrs int
    for fn := range allFuncs {
     for _, b := range fn.Blocks {


--

---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Gri at Dec 5, 2013 at 10:15 pm
    LGTM

    https://codereview.appspot.com/37970043/

    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Adonovan at Dec 5, 2013 at 10:16 pm
    *** Submitted as
    https://code.google.com/p/go/source/detail?r=fa2302314916&repo=tools ***

    go.tools/ssa: move AllFunctions to ssautil subpackage

    R=gri
    CC=golang-dev
    https://codereview.appspot.com/37970043


    https://codereview.appspot.com/37970043/

    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedDec 5, '13 at 10:06p
activeDec 5, '13 at 10:16p
posts3
users2
websitegolang.org

2 users in discussion

Adonovan: 2 posts Gri: 1 post

People

Translate

site design / logo © 2021 Grokbase