├── README.md ├── sleep ├── go.mod └── sleep.go ├── benchlab ├── go.mod ├── main.go ├── build.go ├── git.go ├── doc.go ├── lab.go ├── bench.go └── machine.go ├── rdate ├── go.mod └── rdate.go ├── c2gofmt ├── testdata │ ├── basic.txt │ ├── comment3.txt │ ├── comment4.txt │ ├── init.txt │ ├── func2.txt │ ├── comment.txt │ ├── slice.txt │ ├── ptr.txt │ ├── basic2.txt │ ├── addr.txt │ ├── rewrite.txt │ ├── basic3.txt │ ├── side2.txt │ ├── func.txt │ ├── static.txt │ ├── rewrite2.txt │ ├── comment2.txt │ ├── bool.txt │ ├── extern.txt │ ├── decl3.txt │ ├── enum.txt │ ├── struct.txt │ ├── struct2.txt │ ├── switch.txt │ ├── switch2.txt │ ├── if.txt │ ├── decl2.txt │ ├── switch3.txt │ ├── decl.txt │ ├── stmt.txt │ ├── side.txt │ └── init2.txt ├── go.mod ├── internal │ └── cc │ │ ├── doc.go │ │ ├── stmt.go │ │ ├── stmtop_string.go │ │ ├── print_test.go │ │ ├── exprop_string.go │ │ ├── parse.go │ │ ├── expr.go │ │ ├── type.go │ │ ├── print.go │ │ └── lex.go ├── fmt_test.go ├── go.sum ├── rename.go ├── main.go ├── decls.go ├── rewrite.go ├── syntax.go └── printer.go ├── gofixerr ├── go.mod ├── go.sum ├── edit.go └── main.go ├── git-foreach ├── go.mod ├── go.sum └── main.go ├── mdweb ├── go.mod ├── go.sum └── main.go └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | Commands. 2 | -------------------------------------------------------------------------------- /sleep/go.mod: -------------------------------------------------------------------------------- 1 | module rsc.io/cmd/sleep 2 | 3 | go 1.21.0 4 | -------------------------------------------------------------------------------- /benchlab/go.mod: -------------------------------------------------------------------------------- 1 | module rsc.io/cmd/benchlab 2 | 3 | go 1.24.0 4 | -------------------------------------------------------------------------------- /rdate/go.mod: -------------------------------------------------------------------------------- 1 | module rsc.io/cmd/rdate 2 | 3 | go 1.21.0 4 | 5 | -------------------------------------------------------------------------------- /c2gofmt/testdata/basic.txt: -------------------------------------------------------------------------------- 1 | int f; 2 | --- 3 | package pkg 4 | 5 | var f int 6 | -------------------------------------------------------------------------------- /c2gofmt/testdata/comment3.txt: -------------------------------------------------------------------------------- 1 | // comment 2 | --- 3 | // comment 4 | 5 | package pkg 6 | -------------------------------------------------------------------------------- /c2gofmt/testdata/comment4.txt: -------------------------------------------------------------------------------- 1 | #include 2 | --- 3 | package pkg 4 | 5 | // #include 6 | -------------------------------------------------------------------------------- /c2gofmt/go.mod: -------------------------------------------------------------------------------- 1 | module rsc.io/cmd/c2gofmt 2 | 3 | go 1.16 4 | 5 | require rsc.io/rf v0.0.0-20201229043002-4f177a6cd303 6 | -------------------------------------------------------------------------------- /c2gofmt/testdata/init.txt: -------------------------------------------------------------------------------- 1 | int x[] = {1, 2, 3, 4, 5}; 2 | --- 3 | package pkg 4 | 5 | var x = [5]int{1, 2, 3, 4, 5} 6 | -------------------------------------------------------------------------------- /c2gofmt/testdata/func2.txt: -------------------------------------------------------------------------------- 1 | void f(void) { 2 | (*g)(); 3 | } 4 | --- 5 | package pkg 6 | 7 | func f() { 8 | g() 9 | } 10 | -------------------------------------------------------------------------------- /gofixerr/go.mod: -------------------------------------------------------------------------------- 1 | module rsc.io/cmd/gofixerr 2 | 3 | go 1.16 4 | 5 | require rsc.io/rf v0.0.0-20210102024717-be19e66fb52d // indirect 6 | -------------------------------------------------------------------------------- /git-foreach/go.mod: -------------------------------------------------------------------------------- 1 | module rsc.io/cmd/git-foreach 2 | 3 | go 1.16 4 | 5 | require golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 6 | -------------------------------------------------------------------------------- /c2gofmt/testdata/comment.txt: -------------------------------------------------------------------------------- 1 | void 2 | f(void) 3 | { /* comment */ 4 | g(); 5 | } 6 | --- 7 | package pkg 8 | 9 | func f() { /* comment */ 10 | g() 11 | } 12 | -------------------------------------------------------------------------------- /c2gofmt/testdata/slice.txt: -------------------------------------------------------------------------------- 1 | int f(char **p) { 2 | return p[1][2]; 3 | } 4 | --- 5 | package pkg 6 | 7 | func f(p [][]C.char) int { 8 | return p[1][2] 9 | } 10 | -------------------------------------------------------------------------------- /c2gofmt/testdata/ptr.txt: -------------------------------------------------------------------------------- 1 | int *f(int *p) { 2 | p = 0; 3 | return p; 4 | } 5 | --- 6 | package pkg 7 | 8 | func f(p *int) *int { 9 | p = nil 10 | return p 11 | } 12 | -------------------------------------------------------------------------------- /c2gofmt/testdata/basic2.txt: -------------------------------------------------------------------------------- 1 | int f; /* comment */ 2 | int g; 3 | 4 | int h; 5 | --- 6 | package pkg 7 | 8 | var f int /* comment */ 9 | var g int 10 | 11 | var h int 12 | -------------------------------------------------------------------------------- /mdweb/go.mod: -------------------------------------------------------------------------------- 1 | module rsc.io/cmd/mdweb 2 | 3 | go 1.24.0 4 | 5 | require rsc.io/markdown v0.0.0-20241212154241-6bf72452917f 6 | 7 | require golang.org/x/text v0.30.0 // indirect 8 | -------------------------------------------------------------------------------- /c2gofmt/testdata/addr.txt: -------------------------------------------------------------------------------- 1 | void f(void) { 2 | XMethod(&x, y); 3 | XMethod(*x, y); 4 | } 5 | --- 6 | package pkg 7 | 8 | func f() { 9 | x.Method(y) 10 | x.Method(y) 11 | } 12 | -------------------------------------------------------------------------------- /c2gofmt/testdata/rewrite.txt: -------------------------------------------------------------------------------- 1 | void f(void) { 2 | int x; 3 | 4 | XMethod(x, 2); 5 | } 6 | --- 7 | package pkg 8 | 9 | func f() { 10 | var x int 11 | x.Method(2) 12 | } 13 | -------------------------------------------------------------------------------- /c2gofmt/testdata/basic3.txt: -------------------------------------------------------------------------------- 1 | #pragma 1 2 | #pragma 2 3 | 4 | int f; /* comment */ 5 | --- 6 | // #pragma 1 7 | // #pragma 2 8 | 9 | package pkg 10 | 11 | var f int /* comment */ 12 | -------------------------------------------------------------------------------- /c2gofmt/testdata/side2.txt: -------------------------------------------------------------------------------- 1 | void f(void) { 2 | c = *p++; 3 | int d = *p++; 4 | } 5 | --- 6 | package pkg 7 | 8 | func f() { 9 | c = *p 10 | p++ 11 | d := *p 12 | p++ 13 | } 14 | -------------------------------------------------------------------------------- /c2gofmt/testdata/func.txt: -------------------------------------------------------------------------------- 1 | int f(void) { return 1; } 2 | int g(void) { return 2; } 3 | --- 4 | package pkg 5 | 6 | func f() int { 7 | return 1 8 | } 9 | 10 | func g() int { 11 | return 2 12 | } 13 | -------------------------------------------------------------------------------- /c2gofmt/testdata/static.txt: -------------------------------------------------------------------------------- 1 | int 2 | f(void) 3 | { 4 | static int x; 5 | x++; 6 | return x; 7 | } 8 | --- 9 | package pkg 10 | 11 | var f_x int 12 | 13 | func f() int { 14 | f_x++ 15 | return f_x 16 | } 17 | -------------------------------------------------------------------------------- /c2gofmt/testdata/rewrite2.txt: -------------------------------------------------------------------------------- 1 | int f(Rectangle r) { 2 | return r.min.x + r.min.y + r.something; 3 | } 4 | --- 5 | package pkg 6 | 7 | func f(r Rectangle) int { 8 | return r.Min.X + r.Min.Y + r.something 9 | } 10 | -------------------------------------------------------------------------------- /c2gofmt/testdata/comment2.txt: -------------------------------------------------------------------------------- 1 | void 2 | f(void) 3 | { 4 | if(x) 5 | g(); 6 | else /* comment */ 7 | h(); 8 | } 9 | --- 10 | package pkg 11 | 12 | func f() { 13 | if x != 0 { 14 | g() 15 | } else { /* comment */ 16 | h() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /c2gofmt/testdata/bool.txt: -------------------------------------------------------------------------------- 1 | int f(int *p) { 2 | if(x); 3 | while(p); 4 | return !p && x || !!y; 5 | } 6 | --- 7 | package pkg 8 | 9 | func f(p *int) int { 10 | if x != 0 { 11 | } 12 | for p != nil { 13 | } 14 | return p == nil && x != 0 || y != 0 15 | } 16 | -------------------------------------------------------------------------------- /c2gofmt/testdata/extern.txt: -------------------------------------------------------------------------------- 1 | extern int a; 2 | 3 | // comment 4 | #define X Y 5 | 6 | // more comment 7 | extern int b; 8 | --- 9 | package pkg 10 | 11 | /* extern var a int */ 12 | 13 | // comment 14 | // #define X Y 15 | 16 | // more comment 17 | /* extern var b int */ 18 | -------------------------------------------------------------------------------- /c2gofmt/testdata/decl3.txt: -------------------------------------------------------------------------------- 1 | int f(void) { 2 | int x, y; 3 | 4 | y = 0; 5 | for(x=0; x<10; x++) { 6 | y += x; 7 | } 8 | return y; 9 | } 10 | --- 11 | package pkg 12 | 13 | func f() int { 14 | y := 0 15 | for x := 0; x < 10; x++ { 16 | y += x 17 | } 18 | return y 19 | } 20 | -------------------------------------------------------------------------------- /c2gofmt/internal/cc/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 | // Package cc implements parsing, type checking, and printing of C programs. 6 | package cc 7 | -------------------------------------------------------------------------------- /c2gofmt/testdata/enum.txt: -------------------------------------------------------------------------------- 1 | enum { 2 | X = 1, 3 | Y, 4 | Z, 5 | }; 6 | enum E { 7 | E0, 8 | E1, 9 | E2, 10 | }; 11 | --- 12 | package pkg 13 | 14 | const ( 15 | X = 1 + iota 16 | Y 17 | Z 18 | ) 19 | 20 | type E int 21 | 22 | const ( 23 | E0 E = iota 24 | E1 25 | E2 26 | ) 27 | -------------------------------------------------------------------------------- /c2gofmt/testdata/struct.txt: -------------------------------------------------------------------------------- 1 | typedef struct S S; 2 | typedef struct T T; 3 | 4 | struct S { 5 | int x; 6 | }; 7 | 8 | int z; 9 | 10 | struct T { 11 | int y; 12 | }; 13 | --- 14 | package pkg 15 | 16 | type S struct { 17 | x int 18 | } 19 | 20 | var z int 21 | 22 | type T struct { 23 | y int 24 | } 25 | -------------------------------------------------------------------------------- /c2gofmt/testdata/struct2.txt: -------------------------------------------------------------------------------- 1 | typedef struct S S; 2 | typedef struct T T; 3 | 4 | struct S { 5 | int x; 6 | }; 7 | 8 | #define Z 1 9 | 10 | struct T { 11 | int y; 12 | }; 13 | --- 14 | package pkg 15 | 16 | type S struct { 17 | x int 18 | } 19 | 20 | // #define Z 1 21 | 22 | type T struct { 23 | y int 24 | } 25 | -------------------------------------------------------------------------------- /c2gofmt/testdata/switch.txt: -------------------------------------------------------------------------------- 1 | void 2 | f(void) 3 | { 4 | switch(1){ 5 | case 1: 6 | f(); 7 | break; 8 | 9 | case 2: 10 | g(); 11 | 12 | case 3: 13 | h(); 14 | } 15 | } 16 | --- 17 | package pkg 18 | 19 | func f() { 20 | switch 1 { 21 | case 1: 22 | f() 23 | 24 | case 2: 25 | g() 26 | fallthrough 27 | 28 | case 3: 29 | h() 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /c2gofmt/testdata/switch2.txt: -------------------------------------------------------------------------------- 1 | void 2 | f(void) 3 | { 4 | switch(1){ 5 | case 1: 6 | f(); 7 | break; 8 | 9 | case 2: 10 | g(); 11 | 12 | case 3: 13 | h(); 14 | break; 15 | } 16 | } 17 | --- 18 | package pkg 19 | 20 | func f() { 21 | switch 1 { 22 | case 1: 23 | f() 24 | 25 | case 2: 26 | g() 27 | fallthrough 28 | 29 | case 3: 30 | h() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /rdate/rdate.go: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 | // Rdate prints the current time in RFC3339 format. 6 | package main 7 | 8 | import ( 9 | "fmt" 10 | "time" 11 | ) 12 | 13 | func main() { 14 | fmt.Printf("%s\n", time.Now().Format(time.RFC3339)) 15 | } 16 | -------------------------------------------------------------------------------- /c2gofmt/testdata/if.txt: -------------------------------------------------------------------------------- 1 | void f(void) { 2 | int z; 3 | if(x == 0) 4 | g(); 5 | else if(x == 1) 6 | h(); 7 | else if(x == 2) 8 | i(); 9 | else if(x == 3) 10 | j(); 11 | else 12 | z = k(); 13 | } 14 | --- 15 | package pkg 16 | 17 | func f() { 18 | if x == 0 { 19 | g() 20 | } else if x == 1 { 21 | h() 22 | } else if x == 2 { 23 | i() 24 | } else if x == 3 { 25 | j() 26 | } else { 27 | z := k() 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /git-foreach/go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= 2 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 3 | golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= 4 | golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= 5 | -------------------------------------------------------------------------------- /c2gofmt/testdata/decl2.txt: -------------------------------------------------------------------------------- 1 | Rune* 2 | rload(Rasp *r, ulong p0, ulong p1, ulong *nrp) 3 | { 4 | Section *s; 5 | long p; 6 | int n, nb; 7 | 8 | nb = 0; 9 | for(p=0,s=r->sect; s && p+s->nrunes<=p0; s=s->next) 10 | p += s->nrunes; 11 | return 0; 12 | } 13 | --- 14 | package pkg 15 | 16 | func rload(r *Rasp, p0 ulong, p1 ulong, nrp *ulong) *Rune { 17 | nb := 0 18 | p := 0 19 | s := r.sect 20 | for ; s != nil && p+s.nrunes <= p0; s = s.next { 21 | p += s.nrunes 22 | } 23 | return 0 24 | } 25 | -------------------------------------------------------------------------------- /c2gofmt/testdata/switch3.txt: -------------------------------------------------------------------------------- 1 | void 2 | f(void) 3 | { 4 | switch(1){ 5 | case 1: 6 | if((c = f()) != 0) 7 | g(); 8 | break; 9 | 10 | case 2: 11 | if((c = g()) != 0) 12 | h(); 13 | 14 | case 3: 15 | if((c = h()) != 0) 16 | i(); 17 | break; 18 | } 19 | } 20 | --- 21 | package pkg 22 | 23 | func f() { 24 | switch 1 { 25 | case 1: 26 | c = f() 27 | if c != 0 { 28 | g() 29 | } 30 | 31 | case 2: 32 | c = g() 33 | if c != 0 { 34 | h() 35 | } 36 | fallthrough 37 | 38 | case 3: 39 | c = h() 40 | if c != 0 { 41 | i() 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /c2gofmt/testdata/decl.txt: -------------------------------------------------------------------------------- 1 | int f(void) { 2 | int x, y; 3 | 4 | x = 1; 5 | y = 2; 6 | return x + y; 7 | } 8 | 9 | int g(void) { 10 | int x, y; 11 | int z = 3; 12 | 13 | y = 1; 14 | if(y) { 15 | x = f(); 16 | return x; 17 | } else { 18 | x = f() + f(); 19 | return x; 20 | } 21 | return 2 + z; 22 | } 23 | --- 24 | package pkg 25 | 26 | func f() int { 27 | x := 1 28 | y := 2 29 | return x + y 30 | } 31 | 32 | func g() int { 33 | z := 3 34 | 35 | y := 1 36 | if y != 0 { 37 | x := f() 38 | return x 39 | } else { 40 | x := f() + f() 41 | return x 42 | } 43 | return 2 + z 44 | } 45 | -------------------------------------------------------------------------------- /c2gofmt/testdata/stmt.txt: -------------------------------------------------------------------------------- 1 | void 2 | f(void) 3 | { 4 | /* c1 */ 5 | 6 | /* c2 */ 7 | int i; /* c3 */ 8 | /* c4 */ 9 | 10 | /* c5 */ 11 | g(i); /* c6 */ 12 | /* c7 */ 13 | 14 | /* c8 */ 15 | g(i); /* c9 */ 16 | /* c10 */ 17 | 18 | /* c11 */ 19 | } 20 | 21 | void 22 | ff(void) 23 | { 24 | g(1); 25 | } 26 | --- 27 | package pkg 28 | 29 | func f() { 30 | /* c1 */ 31 | 32 | /* c2 */ 33 | var i int /* c3 */ 34 | /* c4 */ 35 | 36 | /* c5 */ 37 | g(i) /* c6 */ 38 | /* c7 */ 39 | 40 | /* c8 */ 41 | g(i) /* c9 */ 42 | /* c10 */ 43 | 44 | /* c11 */ 45 | } 46 | 47 | func ff() { 48 | g(1) 49 | } 50 | -------------------------------------------------------------------------------- /mdweb/go.sum: -------------------------------------------------------------------------------- 1 | github.com/yuin/goldmark v1.6.0 h1:boZcn2GTjpsynOsC0iJHnBWa4Bi0qzfJjthwauItG68= 2 | github.com/yuin/goldmark v1.6.0/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 3 | golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k= 4 | golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM= 5 | golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE= 6 | golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w= 7 | rsc.io/markdown v0.0.0-20241212154241-6bf72452917f h1:zQHn9vNRGvg+k5NdSMZ5jdSQcuz7k5niNMO0f0XkwKc= 8 | rsc.io/markdown v0.0.0-20241212154241-6bf72452917f/go.mod h1:dTYI7HoCsVAs6SKPMgkC2TV2xRFJB9WqcVydnnZby2Y= 9 | -------------------------------------------------------------------------------- /c2gofmt/testdata/side.txt: -------------------------------------------------------------------------------- 1 | void f(void) { 2 | if((c = g()) != 0) { 3 | z(); 4 | } 5 | 6 | if(x && (c = g()) != 0) { 7 | z(); 8 | } 9 | 10 | if(x && (c = g()) != 0) { 11 | z(); 12 | } else { 13 | y(); 14 | } 15 | 16 | while((c = g()) != 0) { 17 | z(); 18 | } 19 | 20 | for(x = 1; x && (c = g()) != 0 && (d = h()) > 0; x++) { 21 | z(); 22 | } 23 | } 24 | --- 25 | package pkg 26 | 27 | func f() { 28 | c = g() 29 | if c != 0 { 30 | z() 31 | } 32 | 33 | if x != 0 { 34 | c = g() 35 | if c != 0 { 36 | z() 37 | } 38 | } 39 | 40 | if x != 0 && func() bool { c = g(); return c != 0 }() { 41 | z() 42 | } else { 43 | y() 44 | } 45 | 46 | for { 47 | c = g() 48 | if c == 0 { 49 | break 50 | } 51 | z() 52 | } 53 | 54 | for x = 1; x != 0; x++ { 55 | c = g() 56 | if c == 0 { 57 | break 58 | } 59 | d = h() 60 | if d <= 0 { 61 | break 62 | } 63 | z() 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /benchlab/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2025 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 | "flag" 9 | "fmt" 10 | "log" 11 | "os" 12 | ) 13 | 14 | func usage() { 15 | fmt.Fprintf(os.Stderr, "Usage: benchlab [options]\n") 16 | flag.PrintDefaults() 17 | os.Exit(2) 18 | } 19 | 20 | func main() { 21 | log.SetPrefix("benchlab: ") 22 | log.SetFlags(0) 23 | 24 | var chdir string 25 | var lab Lab 26 | lab.Init(flag.CommandLine) 27 | flag.StringVar(&chdir, "C", "", "change to `dir` immediately at startup") 28 | flag.Usage = usage 29 | flag.Parse() 30 | if flag.NArg() != 0 { 31 | usage() 32 | } 33 | if chdir != "" { 34 | if err := os.Chdir(chdir); err != nil { 35 | log.Fatal(err) 36 | } 37 | } 38 | if err := lab.Run(); err != nil { 39 | log.Fatal(err) 40 | } 41 | os.Stdout.WriteString(lab.Stats()) 42 | } 43 | -------------------------------------------------------------------------------- /c2gofmt/internal/cc/stmt.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 cc 6 | 7 | type Stmt struct { 8 | SyntaxInfo 9 | Op StmtOp 10 | Pre *Expr 11 | Expr *Expr 12 | Post *Expr 13 | Decl *Decl 14 | Body *Stmt 15 | Else *Stmt 16 | Block []*Stmt 17 | Labels []*Label 18 | Text string 19 | Type *Type 20 | } 21 | 22 | //go:generate stringer -type StmtOp 23 | type StmtOp int 24 | 25 | const ( 26 | _ StmtOp = iota 27 | StmtDecl 28 | StmtExpr 29 | Empty 30 | Block 31 | ARGBEGIN 32 | Break 33 | Continue 34 | Do 35 | For 36 | If 37 | Goto 38 | Return 39 | Switch 40 | While 41 | ) 42 | 43 | type Label struct { 44 | SyntaxInfo 45 | Op LabelOp 46 | Expr *Expr 47 | Name string 48 | } 49 | 50 | type LabelOp int 51 | 52 | const ( 53 | _ LabelOp = iota 54 | Case 55 | Default 56 | LabelName 57 | ) 58 | -------------------------------------------------------------------------------- /c2gofmt/testdata/init2.txt: -------------------------------------------------------------------------------- 1 | Cursor bullseye={ 2 | {-7, -7}, 3 | {0x1F, 0xF8, 0x3F, 0xFC, 0x7F, 0xFE, 0xFB, 0xDF, 4 | 0xF3, 0xCF, 0xE3, 0xC7, 0xFF, 0xFF, 0xFF, 0xFF, 5 | 0xFF, 0xFF, 0xFF, 0xFF, 0xE3, 0xC7, 0xF3, 0xCF, 6 | 0x7B, 0xDF, 0x7F, 0xFE, 0x3F, 0xFC, 0x1F, 0xF8,}, 7 | {0x00, 0x00, 0x0F, 0xF0, 0x31, 0x8C, 0x21, 0x84, 8 | 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 0x7F, 0xFE, 9 | 0x7F, 0xFE, 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 10 | 0x21, 0x84, 0x31, 0x8C, 0x0F, 0xF0, 0x00, 0x00,} 11 | }; 12 | --- 13 | package pkg 14 | 15 | var bullseye = Cursor{ 16 | {-7, -7}, 17 | { 18 | 0x1F, 0xF8, 0x3F, 0xFC, 0x7F, 0xFE, 0xFB, 0xDF, 19 | 0xF3, 0xCF, 0xE3, 0xC7, 0xFF, 0xFF, 0xFF, 0xFF, 20 | 0xFF, 0xFF, 0xFF, 0xFF, 0xE3, 0xC7, 0xF3, 0xCF, 21 | 0x7B, 0xDF, 0x7F, 0xFE, 0x3F, 0xFC, 0x1F, 0xF8, 22 | }, 23 | { 24 | 0x00, 0x00, 0x0F, 0xF0, 0x31, 0x8C, 0x21, 0x84, 25 | 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 0x7F, 0xFE, 26 | 0x7F, 0xFE, 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 27 | 0x21, 0x84, 0x31, 0x8C, 0x0F, 0xF0, 0x00, 0x00, 28 | }, 29 | } 30 | -------------------------------------------------------------------------------- /c2gofmt/internal/cc/stmtop_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type StmtOp"; DO NOT EDIT. 2 | 3 | package cc 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[StmtDecl-1] 12 | _ = x[StmtExpr-2] 13 | _ = x[Empty-3] 14 | _ = x[Block-4] 15 | _ = x[ARGBEGIN-5] 16 | _ = x[Break-6] 17 | _ = x[Continue-7] 18 | _ = x[Do-8] 19 | _ = x[For-9] 20 | _ = x[If-10] 21 | _ = x[Goto-11] 22 | _ = x[Return-12] 23 | _ = x[Switch-13] 24 | _ = x[While-14] 25 | } 26 | 27 | const _StmtOp_name = "StmtDeclStmtExprEmptyBlockARGBEGINBreakContinueDoForIfGotoReturnSwitchWhile" 28 | 29 | var _StmtOp_index = [...]uint8{0, 8, 16, 21, 26, 34, 39, 47, 49, 52, 54, 58, 64, 70, 75} 30 | 31 | func (i StmtOp) String() string { 32 | i -= 1 33 | if i < 0 || i >= StmtOp(len(_StmtOp_index)-1) { 34 | return "StmtOp(" + strconv.FormatInt(int64(i+1), 10) + ")" 35 | } 36 | return _StmtOp_name[_StmtOp_index[i]:_StmtOp_index[i+1]] 37 | } 38 | -------------------------------------------------------------------------------- /c2gofmt/fmt_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 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 | "io/ioutil" 10 | "path/filepath" 11 | "testing" 12 | 13 | "rsc.io/rf/diff" 14 | ) 15 | 16 | func Test(t *testing.T) { 17 | parseRules("builtin rules", ` 18 | XMethod(x, y) -> x.Method(y) 19 | r.min -> r.Min 20 | r.max -> r.Max 21 | p.x -> p.X 22 | p.y -> p.Y 23 | `) 24 | 25 | files, _ := filepath.Glob("testdata/*.txt") 26 | if len(files) == 0 { 27 | t.Fatalf("no testdata") 28 | } 29 | for _, file := range files { 30 | t.Run(filepath.Base(file), func(t *testing.T) { 31 | data, err := ioutil.ReadFile(file) 32 | if err != nil { 33 | t.Fatal(err) 34 | } 35 | i := bytes.Index(data, []byte("\n---\n")) 36 | if i < 0 { 37 | t.Fatalf("cannot find --- marker") 38 | } 39 | cdata, want := data[:i+1], data[i+5:] 40 | have := do(file, cdata) 41 | if !bytes.Equal(have, want) { 42 | t.Errorf("%s:\n%s", file, have) 43 | t.Errorf("want:\n%s", want) 44 | d, err := diff.Diff("want", want, "have", have) 45 | if err == nil { 46 | t.Errorf("diff:\n%s", d) 47 | } 48 | } 49 | }) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /c2gofmt/internal/cc/print_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 cc 6 | 7 | import "testing" 8 | 9 | var exprTests = []string{ 10 | "x", 11 | "123", 12 | "1.4", 13 | "'z'", 14 | `"abc" "def"`, 15 | "x + y", 16 | "x * y", 17 | "x / y", 18 | "x % y", 19 | "x << y", 20 | "x >> y", 21 | "x < y", 22 | "x > y", 23 | "x <= y", 24 | "x >= y", 25 | "x == y", 26 | "x != y", 27 | "x & y", 28 | "x ^ y", 29 | "x | y", 30 | "x && y", 31 | "x || y", 32 | "x ? y : z", 33 | "x = y", 34 | "x += y", 35 | "x -= y", 36 | "x *= y", 37 | "x /= y", 38 | "x %= y", 39 | "x <<= y", 40 | "x >>= y", 41 | "x &= y", 42 | "x ^= y", 43 | "x |= y", 44 | "*x", 45 | "&x", 46 | "+x", 47 | "-x", 48 | "!x", 49 | "~x", 50 | "++x", 51 | "--x", 52 | "sizeof x", 53 | "sizeof(int)", 54 | "offsetof(int, x)", 55 | "(int)x", 56 | "(int){}", 57 | "(int){x}", 58 | "(x, y, z)", 59 | "x, y, z", 60 | "f(x, y, z)", 61 | "x[y]", 62 | "x++", 63 | "x--", 64 | "va_arg(x, int)", 65 | } 66 | 67 | func TestPrintExpr(t *testing.T) { 68 | for _, str := range exprTests { 69 | x, err := ParseExpr(str) 70 | if err != nil { 71 | t.Errorf("%v", err) 72 | continue 73 | } 74 | out := x.String() 75 | if out != str { 76 | t.Errorf("ParseExpr(%#q).String() = %#q, want original input", str, out) 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /sleep/sleep.go: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 | // Sleep sleeps for a specified duration and then wakes up and exits. 6 | // It is backwards-compatible with the standard Unix sleep(1) command 7 | // but accepts additional duration syntaxes. 8 | // 9 | // Usage: 10 | // 11 | // sleep 12 | // sleep