]> Cypherpunks repositories - gostls13.git/commitdiff
- simplify "needsBlanks" logic for identifiers and strings
authorRobert Griesemer <gri@golang.org>
Tue, 6 Oct 2009 22:22:03 +0000 (15:22 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 6 Oct 2009 22:22:03 +0000 (15:22 -0700)
TBR=rsc
DELTA=16  (10 added, 4 deleted, 2 changed)
OCL=35379
CL=35403

src/pkg/go/printer/printer.go
src/pkg/go/printer/testdata/expressions.go
src/pkg/go/printer/testdata/expressions.golden

index 443546cd43182057c742dff0f79716e16b91da82..73ac64d4ae3274d193e22104f4bf7c2ed316ffd2 100644 (file)
@@ -684,10 +684,10 @@ func needsBlanks(expr ast.Expr) bool {
        switch x := expr.(type) {
        case *ast.Ident:
                // "long" identifiers look better with blanks around them
-               return len(x.Value) > 12;  // adjust as looks best
+               return len(x.Value) > 8;
        case *ast.BasicLit:
                // "long" literals look better with blanks around them
-               return len(x.Value) > 6;  // adjust as looks best
+               return len(x.Value) > 8;
        case *ast.ParenExpr:
                // parenthesized expressions don't need blanks around them
                return false;
index aa43a3b1551774323b7d601db771eea6bb7d626f..d335496f0aadcb47b4d1421414906870be51e9ef 100644 (file)
@@ -10,6 +10,7 @@ type T struct {
 
 var (
        a, b, c, d, e int;
+       under_bar int;
        longIdentifier1, longIdentifier2, longIdentifier3 int;
        t0, t1, t2 T;
        s string;
@@ -29,14 +30,15 @@ func _() {
        _ = 1+a;
        _ = a+1;
        _ = a+b+1;
-       _ = "foo"+s;
-       _ = s+"foo";
        _ = s[1:2];
        _ = s[a:b];
        _ = s[0:len(s)];
        _ = s[0]<<1;
        _ = (s[0]<<1)&0xf;
        _ = s[0] << 2 | s[1] >> 4;
+       _ = "foo"+s;
+       _ = s+"foo";
+       _ = 'a'+'b';
 
        // spaces around expressions of different precedence or expressions containing spaces
        _ = a + -b;
@@ -77,6 +79,7 @@ func _() {
        _ = a + b + c + 2*3 + d + e;
        _ = (a+b+c)*2;
        _ = a - b + c - d + (a+b+c) + d&e;
+       _ = under_bar-1;
 }
 
 
index 5b2cfca28d3265954c9048b49b789f1892ceb4b8..b8fca425737db051f004592cd4bd95f9645dbca5 100644 (file)
@@ -10,6 +10,7 @@ type T struct {
 
 var (
        a, b, c, d, e                                           int;
+       under_bar                                               int;
        longIdentifier1, longIdentifier2, longIdentifier3       int;
        t0, t1, t2                                              T;
        s                                                       string;
@@ -29,14 +30,15 @@ func _() {
        _ = 1+a;
        _ = a+1;
        _ = a+b+1;
-       _ = "foo"+s;
-       _ = s+"foo";
        _ = s[1:2];
        _ = s[a:b];
        _ = s[0:len(s)];
        _ = s[0]<<1;
        _ = (s[0]<<1)&0xf;
        _ = s[0]<<2 | s[1]>>4;
+       _ = "foo"+s;
+       _ = s+"foo";
+       _ = 'a'+'b';
 
        // spaces around expressions of different precedence or expressions containing spaces
        _ = a + -b;
@@ -77,6 +79,7 @@ func _() {
        _ = a + b + c + 2*3 + d + e;
        _ = (a+b+c)*2;
        _ = a - b + c - d + (a+b+c) + d&e;
+       _ = under_bar - 1;
 }