summaryrefslogtreecommitdiff
path: root/src/cmd/gofmt/gofmt.go
AgeCommit message (Collapse)AuthorFilesLines
2011-01-17Imported Upstream version 2011.01.12upstream/2011.01.12Ondřej Surý1-9/+16
2010-04-09rename os.Dir to os.FileInfoRob Pike1-5/+5
R=rsc CC=golang-dev http://codereview.appspot.com/902042
2010-02-19- removed exp/parser (support for old semicolon syntax)Robert Griesemer1-13/+5
- go/ast: removed StringList (not needed anymore) - go/ast: changed import path and field list tag to a single string - updated all dependencies R=rsc CC=golang-dev http://codereview.appspot.com/217056
2010-01-27More steps towards tracking of identifier scopes.Robert Griesemer1-5/+6
- provide scope to parse functions; if non-nil, parser uses the scope to declare and lookup identifiers - resolve forward references where possible R=rsc CC=golang-dev http://codereview.appspot.com/194098
2010-01-15 Steps towards tracking scopes for identifiers.Robert Griesemer1-0/+4
- Identifiers refer now to the language entity (Object) that they denote. At the moment this is at best an approximation. - Initial data structures for language entities (Objects) and expression types (Type) independent of the actual type notations. - Initial support for declaring and looking up identifiers. - Updated various dependent files and added support functions. - Extensively tested to avoid breakage. This is an AST change. R=rsc CC=golang-dev, rog http://codereview.appspot.com/189080
2010-01-11Remove -oldprinter flag from gofmt; all code isRobert Griesemer1-5/+1
now printed using the semicolon-free style. Removed NoSemis flag and mechanism dealing with optional semicolons from go/printer. Updated all go/printer output files using the semi-colon free style. Changes have no formatting impact on checked in go code under src and misc. R=rsc, r CC=golang-dev http://codereview.appspot.com/184068
2009-12-15 1) Change default gofmt default settings forRobert Griesemer1-59/+59
parsing and printing to new syntax. Use -oldparser to parse the old syntax, use -oldprinter to print the old syntax. 2) Change default gofmt formatting settings to use tabs for indentation only and to use spaces for alignment. This will make the code alignment insensitive to an editor's tabwidth. Use -spaces=false to use tabs for alignment. 3) Manually changed src/exp/parser/parser_test.go so that it doesn't try to parse the parser's source files using the old syntax (they have new syntax now). 4) gofmt -w src misc test/bench 1st set of files. R=rsc CC=agl, golang-dev, iant, ken2, r http://codereview.appspot.com/180047
2009-12-11Various cleanups:Robert Griesemer1-1/+1
- no need to replace comments for stand-alone blocks - always print string concatenations with interspersed "+" (remove option) - minor cleanups R=rsc http://codereview.appspot.com/174076
2009-12-10New flags for gofmt:Robert Griesemer1-10/+23
- oldparser parse old syntax (required semicolons) - oldprinter print old syntax (required semicolons) By default, these flags are enabled for now. Setting -oldparser=false has no effect until go/parser is changed to accept the new syntax. Enabled exp/parser in Makefile; update dependent exp/eval. R=rsc http://codereview.appspot.com/174051
2009-12-02move ReadFile, WriteFile, and ReadDir into a separate io/ioutil package.Rob Pike1-3/+3
this breaks the dependency of package io on package bytes. R=rsc CC=golang-dev http://codereview.appspot.com/163085
2009-12-02Add flag -tabindent to gofmt: forces use ofRobert Griesemer1-13/+21
tabs for indentation even if -spaces is set. Changes to gofmt: - added -tabindent flag - don't recompute parser and printer mode repeatedly Changes to go/printer: - provide new printing mode TabIndent Changes to tabwriter: - implement new mode TabIndent to use tabs independent of the actual padding character for leading empty columns - distinguish between minimal cell width and tab width (tabwidth is only used if the output contains tabs, minwidth and padding are always considered) - fixed and added more comments - some additional factoring By default, -tabindent is disabled and the default gofmt behavior is unchanged. By setting -spaces and -tabindent, gofmt will use tabs for indentation but do any other alignment with spaces. This permits a user to change the visible indentation by simply changing the editor's tab width and the code will remain properly aligned without the need to rerun gofmt. R=rsc http://codereview.appspot.com/163068
2009-12-02gofmt: race condition in error reporting and setting exit codeFazlul Shahriar1-1/+4
How to reproduce: $ mkdir /tmp/foo $ cp /dev/null /tmp/foo/bar.go $ chmod -r /tmp/foo/bar.go $ gofmt /tmp/foo open /tmp/foo/bar.go: permission denied $ echo $? # should echo 2 0 $ Maybe you need to put a call to time.Sleep at the beginning of report(). R=gri CC=golang-dev http://codereview.appspot.com/164073 Committer: Robert Griesemer <gri@golang.org>
2009-12-01gofmt: use os.Stdin instead of opening /dev/stdinFazlul Shahriar1-8/+18
Opening /dev/stdin can sometimes fail. For example, in the acme editor, executing "Edit ,|gofmt" fails with: open /dev/stdin: no such device or address Executing "Edit ,|ls -l /dev/stdin /proc/self/fd/0" gives: lrwxrwxrwx 1 root root 15 2009-09-07 02:17 /dev/stdin -> /proc/self/fd/0 lrwx------ 1 fhs users 64 2009-11-26 22:05 /proc/self/fd/0 -> socket:[5528230] (This is my first change, and I've signed the individual contributor license agreement.) R=rsc, gri CC=golang-dev http://codereview.appspot.com/162041 Committer: Robert Griesemer <gri@golang.org>
2009-11-20gofmt: add -r flag to rewrite source code according to patternRuss Cox1-2/+12
a little slow, but usable (speed unchanged when not using -r) tweak go/printer to handle nodes without line numbers more gracefully in a couple cases. R=gri http://codereview.appspot.com/156103
2009-11-12Remove -align flag from gofmt.Robert Griesemer1-4/+0
(Making it work correctly with -spaces is a bit of work and the output won't make much sense as it is intended as input to tabwriter.) Fixes issue 100. R=rsc http://codereview.appspot.com/154102
2009-11-09remove semis after statements in one-statement statement listsRobert Griesemer1-18/+18
R=rsc, r http://go/go-review/1025029
2009-11-07- avoid division-by-zero crash in tabwriterRobert Griesemer1-0/+4
- correct tabwidth argument for some tabwriter test cases - catch negative tabwidth flag in gofmt w/o crashing R=rsc http://go/go-review/1026022
2009-10-22- make printer interface easily extensible w/o breaking clients (in the future)Robert Griesemer1-1/+1
- replacement for p4 CL 35999 (abandoned) R=rsc http://go/go-review/1012010
2009-10-22go/printer:Robert Griesemer1-1/+1
- handle HTML tagging via (client-installable) Stylers go/doc: - basic styler support - some factoring - ready to contain the search code (but for now excluded) doc/style.css: - updated doc/go_spec.css: - cleanup: replace deprecated uses of <font> tag with <span> tag R=rsc DELTA=302 (160 added, 62 deleted, 80 changed) OCL=35973 CL=35996
2009-10-20remove superfluous tracing supportRobert Griesemer1-5/+1
R=rsc DELTA=5 (0 added, 4 deleted, 1 changed) OCL=35930 CL=35930
2009-10-20Updated and simplified gofmt.Robert Griesemer1-88/+119
- operates on stdin, a single file, or all files in a file tree - setting -w flag writes to (source) file instead of stdout - setting -l flag lists files whose formatting has changed R=rsc DELTA=201 (102 added, 71 deleted, 28 changed) OCL=35890 CL=35926
2009-10-06apply gofmt to the LGTM-marked files from 34501Russ Cox1-19/+19
that have not changed since I applied gofmt. R=gri DELTA=456 (77 added, 3 deleted, 376 changed) OCL=35378 CL=35383
2009-09-17unused importsRuss Cox1-2/+0
R=r OCL=34731 CL=34731
2009-09-10better gofmt formatting:Robert Griesemer1-12/+0
- first cut a better line breaks in expr lists - trailing commas and semis printed where we tend to write them - fixed a couple of minor spacing issues (interface{}, chan<-, map[x]y, x: y) - removed some formatting flags from gofmt: no need to change default - removed option to reverse declaration order when printing - excluded files from test that cause trouble with idempotency test for now R=rsc DELTA=497 (364 added, 83 deleted, 50 changed) OCL=34539 CL=34544
2009-08-06- allow more general type switch syntaxRobert Griesemer1-0/+4
- support for reverse printing of AST (for compiler testing) - added -reverse flag to gofmt R=rsc DELTA=163 (125 added, 11 deleted, 27 changed) OCL=32808 CL=32853
2009-07-31printer:Robert Griesemer1-16/+19
- prepare for generation of HTML id tags and links - do HTML-escaping in central print routine - move tabwriter setup into printer - fixed various TODOs godoc: - removed tabwriter setup, need for various HTML-escaping R=rsc DELTA=210 (107 added, 36 deleted, 67 changed) OCL=32612 CL=32616
2009-07-30go/ast/filter.go:Robert Griesemer1-2/+2
- more orthogonal functionality of filter functions for better re-use go/doc/doc.go: - simplified interface - collect filenames of packages so that they can be shown godoc: - removed TODO, show list of package (linked) files used to create documentation R=rsc DELTA=130 (68 added, 24 deleted, 38 changed) OCL=32549 CL=32552
2009-07-29parser:Robert Griesemer1-4/+4
- Changed filter function for parser.ParsePackage to take an *os.Dir instead of a filename for more powerful filters - Removed TODO in ast.PackageInterface: Now collect package comments from all package files - Cleanups in godoc: Use the new ParsePackage and PackageInterface functions; as a result computing package information is much simpler now. R=rsc DELTA=285 (80 added, 110 deleted, 95 changed) OCL=32473 CL=32486
2009-07-28Intersperse comments nicely when printing an AST.Robert Griesemer1-2/+6
gofmt formatted source code looks pretty good already; with a bit more fine-tuning it should be great. printer.go: - Implemented comment intersperse algorithm. The approach is a result of many trial-and-error experiments but at this point reasonably simple and open to arbitrary fine-tuning. parser.go: - Simplified handling of lead and line comments (formerly called leading and trailing comments). - Use a comments list instead of an array (I may change this back - this is not obviously better and uses more space). doc.go: - Remove comments from AST nodes that have been 'consumed' in the documentation to avoid duplicate printing of them. Allows for better control of what is printed w/o use of printing control flags (which are hard to use and not fine-grained enough). Corresponding adjustments to various clients of these files. R=rsc DELTA=478 (275 added, 108 deleted, 95 changed) OCL=32185 CL=32380
2009-07-16ast:Robert Griesemer1-16/+68
- renamed Program -> SourceFile - added Package node representing the AST for an entire package - added filter function to create a source file mimicking the interface of an entire package parser: - parser entry to parse entire packages - unified naming of parser entry points - factored out entry points into new file (interface.go) gofmt: - extended to accept single .go files, and package paths: gofmt file.go // formatting of a single file gofmt -x file.go // interface of a single file gofmt -x ./MyPackage // interface of a local package gofmt -x math // interface of a $GOROOT relative package Various adjustments in dependent files, documentation. R=rsc DELTA=634 (369 added, 153 deleted, 112 changed) OCL=31743 CL=31748
2009-07-14update remaining files to match new scanner/parser interfaceRobert Griesemer1-10/+4
and use shared error handling infrastructure R=rsc DELTA=109 (3 added, 86 deleted, 20 changed) OCL=31600 CL=31605
2009-07-10mention file name only once in error messageRobert Griesemer1-1/+1
R=r DELTA=1 (0 added, 0 deleted, 1 changed) OCL=31450 CL=31452
2009-07-09Show BUG comments in godoc:Robert Griesemer1-1/+1
ast.go: - rename Comments -> CommentGroup (less confusion) - change all comments/docs to be *CommentGroup filter.go: - do not remove unassociated comments from program as part of export filtering (they are needed by doc.go for BUG comments) scanner.go: - exclude '\n' from //-style comments parser.go: - rewrote collection of comments: now all collected comments are *ast.CommentGroups - clarified distinction between leading and trailing comments - fixed a bug in comment collection (parseGenDecl); corresponding test case is in printer/testdata - extra documentation doc.go: - collect BUG comments - corresponding fix for parser bug in comment collection comment.go: - simplified regex printer.go: - adjust comment printing to new representation printer_test.go, testdata/*: - enable printing of doc comments - extended tests package.html, package.txt: - added Bugs section gofmt: - enable printing of doc comments R=rsc DELTA=339 (126 added, 38 deleted, 175 changed) OCL=31403 CL=31416
2009-07-06- ast.FilterExports: strips all non-exported nodes from an ASTRobert Griesemer1-3/+4
- use FilterExports instead of the various predicates in printer.go and doc.go which simplifies a lot of code and makes it easier to deal with complex cases R=rsc DELTA=445 (197 added, 190 deleted, 58 changed) OCL=31110 CL=31196
2009-06-16- install gofmt in src/cmd/gofmtRobert Griesemer1-0/+107
- remove some left-over files R=rsc DELTA=1465 (281 added, 1181 deleted, 3 changed) OCL=30350 CL=30353