From ccc15919102b8a278c10628e0c9bfea52ad394ef Mon Sep 17 00:00:00 2001 From: nsf Date: Sat, 3 Mar 2012 10:45:46 +0600 Subject: [PATCH] Format everything with gofmt. --- binding_generator.go | 39 ++++++++++++++------------- cairo.go | 4 +-- comment_skipper.go | 2 +- function_builder.go | 9 +++---- main.go | 64 ++++++++++---------------------------------- type.go | 8 +++--- typeconv.go | 2 +- util.go | 2 +- 8 files changed, 47 insertions(+), 83 deletions(-) diff --git a/binding_generator.go b/binding_generator.go index d3bcf23..99904e9 100644 --- a/binding_generator.go +++ b/binding_generator.go @@ -1,21 +1,21 @@ package main import ( + "bufio" "bytes" "fmt" "gobject/gi" - "strings" "os" - "bufio" + "strings" ) type binding_generator struct { file_go *os.File - file_c *os.File - file_h *os.File - out_go *bufio.Writer - out_c *bufio.Writer - out_h *bufio.Writer + file_c *os.File + file_h *os.File + out_go *bufio.Writer + out_c *bufio.Writer + out_h *bufio.Writer // temporary buffer for 'go_bindings' go_bindings bytes.Buffer @@ -61,11 +61,11 @@ func (this *binding_generator) generate(go_template string) { t := must_template(go_template) t.Execute(this.out_go, map[string]interface{}{ "g_object_ref_unref": g_object_ref_unref, - "go_utils": go_utils(true), - "go_utils_no_cb": go_utils(false), - "go_bindings": this.go_bindings.String(), - "g_error_free": g_error_free, - "g_free": g_free, + "go_utils": go_utils(true), + "go_utils_no_cb": go_utils(false), + "go_bindings": this.go_bindings.String(), + "g_error_free": g_error_free, + "g_free": g_free, }) // write source/header preambles @@ -76,7 +76,7 @@ func (this *binding_generator) generate(go_template string) { // filename c_template.Execute(this.out_c, map[string]interface{}{ "namespace": config.namespace, - "package": config.pkg, + "package": config.pkg, }) p = printer_to(this.out_c) p("\n\n") @@ -266,7 +266,6 @@ func (this *binding_generator) c_func_forward_declaration(fi *gi.FunctionInfo) { pc("}\n") } - // generating forward C declarations properly: // 10 - various typedefs // 20 - functions and methods @@ -399,8 +398,8 @@ func go_utils(cb bool) string { var out bytes.Buffer go_utils_template.Execute(&out, map[string]interface{}{ - "gobjectns": config.gns, - "namespace": config.namespace, + "gobjectns": config.gns, + "namespace": config.namespace, "nocallbacks": !cb, }) @@ -511,7 +510,7 @@ func (this *binding_generator) process_struct_info(si *gi.StructInfo) { offset += type_size(ft, type_exact) } if size != offset { - p("\t_ [%d]byte\n", size - offset) + p("\t_ [%d]byte\n", size-offset) } p("}\n") //printf("type %s struct { data [%d]byte }\n", name, size) @@ -788,7 +787,9 @@ func (this *binding_generator) process_function_info(fi *gi.FunctionInfo) { name = config.rename(fullnm, name) p("%s(", name) for i, arg := range fb.args { - if i != 0 { p(", ") } + if i != 0 { + p(", ") + } p("%s0 %s", arg.arg_info.Name(), go_type(arg.type_info, type_none)) } p(")") @@ -835,7 +836,7 @@ func (this *binding_generator) process_function_info(fi *gi.FunctionInfo) { p("\tvar %s1 %s\n", arg.arg_info.Name(), cgo_type(arg.type_info, type_none)) if al := arg.type_info.ArrayLength(); al != -1 { arg := fb.orig_args[al] - p("\tvar %s1 %s\n", arg.Name(), cgo_type(arg.Type(), type_none)) + p("\tvar %s1 %s\n", arg.Name(), cgo_type(arg.Type(), type_none)) } } diff --git a/cairo.go b/cairo.go index 7b5403c..60df96b 100644 --- a/cairo.go +++ b/cairo.go @@ -1,8 +1,8 @@ package main import ( - "gobject/gi" "bytes" + "gobject/gi" ) func cairo_go_type_for_interface(bi *gi.BaseInfo, flags type_flags) string { @@ -89,4 +89,4 @@ func cairo_cgo_to_go_for_interface(bi *gi.BaseInfo, arg1, arg2 string, flags con } return out.String() -} \ No newline at end of file +} diff --git a/comment_skipper.go b/comment_skipper.go index a7687eb..7d631ed 100644 --- a/comment_skipper.go +++ b/comment_skipper.go @@ -8,7 +8,7 @@ type comment_skipper struct { } func new_comment_skipper(r io.Reader) *comment_skipper { - return &comment_skipper{ bufio.NewReader(r) } + return &comment_skipper{bufio.NewReader(r)} } // advance to str and consume it or return error if it's not possible diff --git a/function_builder.go b/function_builder.go index 575401e..ef73451 100644 --- a/function_builder.go +++ b/function_builder.go @@ -5,14 +5,14 @@ import ( ) type function_builder struct { - function *gi.FunctionInfo - args []function_builder_arg - rets []function_builder_arg + function *gi.FunctionInfo + args []function_builder_arg + rets []function_builder_arg orig_args []*gi.ArgInfo } type function_builder_arg struct { - index int + index int arg_info *gi.ArgInfo type_info *gi.TypeInfo } @@ -30,7 +30,6 @@ func new_function_builder(fi *gi.FunctionInfo) *function_builder { fb := new(function_builder) fb.function = fi - // prepare an array of ArgInfos for i, n := 0, fi.NumArg(); i < n; i++ { arg := fi.Arg(i) diff --git a/main.go b/main.go index 30afc5b..9e3a393 100644 --- a/main.go +++ b/main.go @@ -15,20 +15,20 @@ import ( var config config_type type config_type struct { - out_go *bufio.Writer - out_c *bufio.Writer - out_h *bufio.Writer - namespace string - version string - pkg string - gns string - renames map[string]string - blacklist map[string]map[string]bool - whitelist map[string]map[string]bool + out_go *bufio.Writer + out_c *bufio.Writer + out_h *bufio.Writer + namespace string + version string + pkg string + gns string + renames map[string]string + blacklist map[string]map[string]bool + whitelist map[string]map[string]bool method_blacklist map[string]map[string]bool method_whitelist map[string]map[string]bool - disguised_types map[string]bool - word_subst map[string]string + disguised_types map[string]bool + word_subst map[string]string } func (this *config_type) load(path string) { @@ -63,8 +63,8 @@ func (this *config_type) load(path string) { func (this *config_type) load_sys(path string) { var tmp struct { - DisguisedTypes []string `json:"disguised-types"` - WordSubst map[string]string `json:"word-subst"` + DisguisedTypes []string `json:"disguised-types"` + WordSubst map[string]string `json:"word-subst"` } err := parse_json_with_comments(path, &tmp) @@ -216,40 +216,4 @@ func main() { bg := new_binding_generator(out_base) defer bg.release() bg.generate(string(go_template)) - - /* - // prepare Go output - file_go, err := os.Create(out_path_go) - panic_if_error(err) - defer file_go.Close() - config.out_go = bufio.NewWriter(file_go) - - // prepare C output - file_c, err := os.Create(out_path_c) - panic_if_error(err) - defer file_c.Close() - config.out_c = bufio.NewWriter(file_c) - printf_c = printer_to(config.out_c) - - c_template.Execute(config.out_c, map[string]interface{}{ - "namespace": config.namespace, - }) - printf_c("\n") - - // prepare H output - file_h, err := os.Create(out_path_h) - panic_if_error(err) - defer file_h.Close() - config.out_h = bufio.NewWriter(file_h) - - // load the template and process it - tpl, err := ioutil.ReadFile(in_path) - panic_if_error(err) - process_template(string(tpl)) - - // flush output - config.out_go.Flush() - config.out_c.Flush() - config.out_h.Flush() - */ } diff --git a/type.go b/type.go index f07dc17..79ce593 100644 --- a/type.go +++ b/type.go @@ -108,7 +108,7 @@ func cgo_type_for_tag(tag gi.TypeTag, flags type_flags) string { var out bytes.Buffer p := printer_to(&out) - if flags & type_pointer != 0 { + if flags&type_pointer != 0 { p("*") } @@ -364,7 +364,7 @@ func go_type_for_tag(tag gi.TypeTag, flags type_flags) string { var out bytes.Buffer p := printer_to(&out) - if flags & type_pointer != 0 { + if flags&type_pointer != 0 { p("*") } @@ -460,7 +460,7 @@ func simple_cgo_type(ti *gi.TypeInfo, flags type_flags) string { switch bi.Type() { case gi.INFO_TYPE_ENUM, gi.INFO_TYPE_FLAGS: ei := gi.ToEnumInfo(bi) - return go_type_for_tag(ei.StorageType(), flags | type_exact) + return go_type_for_tag(ei.StorageType(), flags|type_exact) case gi.INFO_TYPE_STRUCT: ns := bi.Namespace() nm := bi.Name() @@ -471,7 +471,7 @@ func simple_cgo_type(ti *gi.TypeInfo, flags type_flags) string { } } if !strings.HasPrefix(cgo_type(ti, flags), "*") { - return go_type_for_tag(tag, flags | type_exact) + return go_type_for_tag(tag, flags|type_exact) } return "unsafe.Pointer" } diff --git a/typeconv.go b/typeconv.go index 3267368..748e189 100644 --- a/typeconv.go +++ b/typeconv.go @@ -155,7 +155,7 @@ func go_to_cgo_for_tag(tag gi.TypeTag, arg0, arg1 string, flags conv_flags) stri case gi.TYPE_TAG_BOOLEAN: return fmt.Sprintf("%s = _GoBoolToCBool(%s)", arg1, arg0) default: - if flags & conv_pointer == 0 { + if flags&conv_pointer == 0 { return fmt.Sprintf("%s = %s(%s)", arg1, cgo_type_for_tag(tag, type_none), arg0) } else { diff --git a/util.go b/util.go index 30e492d..897cffd 100644 --- a/util.go +++ b/util.go @@ -2,8 +2,8 @@ package main import ( "bytes" - "io" "fmt" + "io" "strings" "text/template" )