Skip to content

Commit

Permalink
Format everything with gofmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
nsf committed Mar 3, 2012
1 parent f738f9d commit ccc1591
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 83 deletions.
39 changes: 20 additions & 19 deletions binding_generator.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
})

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(")")
Expand Down Expand Up @@ -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))
}
}

Expand Down
4 changes: 2 additions & 2 deletions cairo.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -89,4 +89,4 @@ func cairo_cgo_to_go_for_interface(bi *gi.BaseInfo, arg1, arg2 string, flags con
}

return out.String()
}
}
2 changes: 1 addition & 1 deletion comment_skipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions function_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down
64 changes: 14 additions & 50 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
*/
}
8 changes: 4 additions & 4 deletions type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("*")
}

Expand Down Expand Up @@ -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("*")
}

Expand Down Expand Up @@ -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()
Expand All @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion typeconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package main

import (
"bytes"
"io"
"fmt"
"io"
"strings"
"text/template"
)
Expand Down

0 comments on commit ccc1591

Please sign in to comment.