Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Big refactoring, CamelCase -> words_with_underscores.

Also some minor code reorganizations.
  • Loading branch information...
commit fff16d190ba5ea4eff9c364402e150377a09ee5a 1 parent 956f4c2
nsf authored
Showing with 1,371 additions and 1,417 deletions.
  1. +30 −30 apropos.go
  2. +188 −190 autocompletecontext.go
  3. +132 −132 autocompletefile.go
  4. +53 −74 config.go
  5. +386 −398 decl.go
  6. +72 −72 declcache.go
  7. +96 −97 gocode.go
  8. +32 −32 goremote/goremote.go
  9. +3 −3 os_posix.go
  10. +2 −2 os_windows.go
  11. +197 −195 package.go
  12. +33 −30 ripper.go
  13. +46 −46 rpc.go
  14. +20 −20 scope.go
  15. +81 −96 server.go
  16. 0  {testing → testdata}/DESC
  17. 0  {testing → testdata}/README
  18. 0  {testing → testdata}/all.bash
  19. 0  {testing → testdata}/run.py
  20. 0  {testing → testdata}/run.rb
  21. 0  {testing → testdata}/test.0001/cursor.47
  22. 0  {testing/test.0023 → testdata/test.0001}/out.expected
  23. 0  {testing → testdata}/test.0001/test.go
  24. 0  {testing → testdata}/test.0002/cursor.105
  25. 0  {testing → testdata}/test.0002/out.expected
  26. 0  {testing → testdata}/test.0002/test.go
  27. 0  {testing → testdata}/test.0003/cursor.552
  28. 0  {testing/test.0021 → testdata/test.0003}/out.expected
  29. 0  {testing → testdata}/test.0003/test.go
  30. 0  {testing → testdata}/test.0004/cursor.1348
  31. 0  {testing → testdata}/test.0004/out.expected
  32. 0  {testing → testdata}/test.0004/test.go
  33. 0  {testing/test.0006 → testdata/test.0005}/b.go
  34. 0  {testing → testdata}/test.0005/cursor.327
  35. 0  {testing → testdata}/test.0005/out.expected
  36. 0  {testing → testdata}/test.0005/test.go
  37. 0  {testing/test.0005 → testdata/test.0006}/b.go
  38. 0  {testing → testdata}/test.0006/cursor.286
  39. 0  {testing → testdata}/test.0006/out.expected
  40. 0  {testing → testdata}/test.0006/test.go
  41. 0  {testing → testdata}/test.0007/cursor.58
  42. 0  {testing → testdata}/test.0007/out.expected
  43. 0  {testing → testdata}/test.0007/test.go
  44. 0  {testing → testdata}/test.0008/cursor.120
  45. 0  {testing → testdata}/test.0008/out.expected
  46. 0  {testing → testdata}/test.0008/test.go
  47. 0  {testing → testdata}/test.0009/cursor.126
  48. 0  {testing/test.0020 → testdata/test.0009}/out.expected
  49. 0  {testing → testdata}/test.0009/test.go
  50. 0  {testing → testdata}/test.0010/cursor.104
  51. 0  {testing → testdata}/test.0010/out.expected
  52. 0  {testing → testdata}/test.0010/test.go
  53. 0  {testing → testdata}/test.0011/cursor.76
  54. 0  {testing → testdata}/test.0011/out.expected
  55. 0  {testing → testdata}/test.0011/test.go
  56. 0  {testing → testdata}/test.0012/cursor.114
  57. 0  {testing → testdata}/test.0012/out.expected
  58. 0  {testing → testdata}/test.0012/test.go
  59. 0  {testing → testdata}/test.0013/cursor.359
  60. 0  {testing → testdata}/test.0013/out.expected
  61. 0  {testing → testdata}/test.0013/test.go
  62. 0  {testing → testdata}/test.0014/cursor.191
  63. 0  {testing → testdata}/test.0014/out.expected
  64. 0  {testing → testdata}/test.0014/test.go
  65. 0  {testing → testdata}/test.0015/cursor.130
  66. 0  {testing → testdata}/test.0015/out.expected
  67. 0  {testing → testdata}/test.0015/test.go
  68. 0  {testing → testdata}/test.0016/cursor.122
  69. 0  {testing → testdata}/test.0016/out.expected
  70. 0  {testing → testdata}/test.0016/test.go
  71. 0  {testing → testdata}/test.0017/cursor.70
  72. 0  {testing → testdata}/test.0017/out.expected
  73. 0  {testing → testdata}/test.0017/test.go
  74. 0  {testing → testdata}/test.0018/cursor.355
  75. 0  {testing → testdata}/test.0018/out.expected
  76. 0  {testing → testdata}/test.0018/test.go
  77. 0  {testing → testdata}/test.0019/cursor.72
  78. 0  {testing → testdata}/test.0019/out.expected
  79. 0  {testing → testdata}/test.0019/test.go
  80. 0  {testing → testdata}/test.0020/cursor.174
  81. 0  {testing/test.0009 → testdata/test.0020}/out.expected
  82. 0  {testing → testdata}/test.0020/test.go
  83. 0  {testing/test.0034 → testdata/test.0021}/cursor.82
  84. 0  {testing/test.0003 → testdata/test.0021}/out.expected
  85. 0  {testing → testdata}/test.0021/test.go
  86. 0  {testing → testdata}/test.0022/cursor.79
  87. 0  {testing → testdata}/test.0022/out.expected
  88. 0  {testing → testdata}/test.0022/test.go
  89. 0  {testing → testdata}/test.0023/cursor.88
  90. 0  {testing/test.0001 → testdata/test.0023}/out.expected
  91. 0  {testing → testdata}/test.0023/test.go
  92. 0  {testing → testdata}/test.0024/cursor.71
  93. 0  {testing → testdata}/test.0024/out.expected
  94. 0  {testing → testdata}/test.0024/test.go
  95. 0  {testing → testdata}/test.0025/cursor.53
  96. 0  {testing → testdata}/test.0025/out.expected
  97. 0  {testing → testdata}/test.0025/test.go
  98. 0  {testing → testdata}/test.0026/cursor.164
  99. 0  {testing → testdata}/test.0026/out.expected
  100. 0  {testing → testdata}/test.0026/test.go
  101. 0  {testing → testdata}/test.0027/cursor.84
  102. 0  {testing → testdata}/test.0027/out.expected
  103. 0  {testing → testdata}/test.0027/test.go
  104. 0  {testing → testdata}/test.0028/cursor.129
  105. 0  {testing → testdata}/test.0028/out.expected
  106. 0  {testing → testdata}/test.0028/test.go
  107. 0  {testing → testdata}/test.0029/cursor.62
  108. 0  {testing → testdata}/test.0029/out.expected
  109. 0  {testing → testdata}/test.0029/test.go
  110. 0  {testing → testdata}/test.0030/cursor.85
  111. 0  {testing → testdata}/test.0030/out.expected
  112. 0  {testing → testdata}/test.0030/test.go
  113. 0  {testing → testdata}/test.0031/cursor.80
  114. 0  {testing → testdata}/test.0031/out.expected
  115. 0  {testing → testdata}/test.0031/test.go
  116. 0  {testing → testdata}/test.0032/cursor.1991
  117. 0  {testing → testdata}/test.0032/out.expected
  118. 0  {testing → testdata}/test.0032/test.go
  119. 0  {testing → testdata}/test.0033/cursor.138
  120. 0  {testing → testdata}/test.0033/out.expected
  121. 0  {testing → testdata}/test.0033/test.go
  122. 0  {testing/test.0021 → testdata/test.0034}/cursor.82
  123. 0  {testing → testdata}/test.0034/out.expected
  124. 0  {testing → testdata}/test.0034/test.go
  125. 0  {testing → testdata}/test.0035/cursor.91
  126. 0  {testing → testdata}/test.0035/out.expected
  127. 0  {testing → testdata}/test.0035/test.go
60 apropos.go
View
@@ -6,12 +6,12 @@ import (
"unicode/utf8"
)
-type DeclApropos struct {
- Decl *Decl
- Partial string
+type decl_apropos struct {
+ decl *decl
+ partial string
}
-func utf8MoveBackwards(file []byte, cursor int) int {
+func utf8_move_backwards(file []byte, cursor int) int {
for {
cursor--
if cursor <= 0 {
@@ -24,17 +24,17 @@ func utf8MoveBackwards(file []byte, cursor int) int {
return 0
}
-func isIdent(r rune) bool {
+func is_ident(r rune) bool {
return unicode.IsDigit(r) || unicode.IsLetter(r) || r == '_'
}
-func skipIdent(file []byte, cursor int) int {
+func skip_ident(file []byte, cursor int) int {
for {
letter, _ := utf8.DecodeRune(file[cursor:])
- if !isIdent(letter) {
+ if !is_ident(letter) {
return cursor
}
- cursor = utf8MoveBackwards(file, cursor)
+ cursor = utf8_move_backwards(file, cursor)
if cursor <= 0 {
return 0
}
@@ -42,14 +42,14 @@ func skipIdent(file []byte, cursor int) int {
return 0
}
-var pairs = map[byte]byte{
+var g_bracket_pairs = map[byte]byte{
')': '(',
']': '[',
}
-func skipToPair(file []byte, cursor int) int {
+func skip_to_pair(file []byte, cursor int) int {
right := file[cursor]
- left := pairs[file[cursor]]
+ left := g_bracket_pairs[file[cursor]]
balance := 1
for balance != 0 {
cursor--
@@ -66,7 +66,7 @@ func skipToPair(file []byte, cursor int) int {
return cursor
}
-func findExpr(file []byte) []byte {
+func find_expr(file []byte) []byte {
const (
LAST_NONE = iota
LAST_DOT
@@ -75,24 +75,24 @@ func findExpr(file []byte) []byte {
)
last := LAST_NONE
cursor := len(file)
- cursor = utf8MoveBackwards(file, cursor)
+ cursor = utf8_move_backwards(file, cursor)
loop:
for {
c := file[cursor]
letter, _ := utf8.DecodeRune(file[cursor:])
switch c {
case '.':
- cursor = utf8MoveBackwards(file, cursor)
+ cursor = utf8_move_backwards(file, cursor)
last = LAST_DOT
case ')', ']':
if last == LAST_IDENT {
break loop
}
- cursor = utf8MoveBackwards(file, skipToPair(file, cursor))
+ cursor = utf8_move_backwards(file, skip_to_pair(file, cursor))
last = LAST_PAREN
default:
- if isIdent(letter) {
- cursor = skipIdent(file, cursor)
+ if is_ident(letter) {
+ cursor = skip_ident(file, cursor)
last = LAST_IDENT
} else {
break loop
@@ -102,49 +102,49 @@ loop:
return file[cursor+1:]
}
-func (c *AutoCompleteContext) deduceExpr(file []byte, partial string) *DeclApropos {
- e := string(findExpr(file))
+func (c *auto_complete_context) deduce_expr(file []byte, partial string) *decl_apropos {
+ e := string(find_expr(file))
expr, err := parser.ParseExpr(e)
if err != nil {
return nil
}
- typedecl := exprToDecl(expr, c.current.scope)
+ typedecl := expr_to_decl(expr, c.current.scope)
if typedecl != nil {
- return &DeclApropos{typedecl, partial}
+ return &decl_apropos{typedecl, partial}
}
return nil
}
-func (c *AutoCompleteContext) deduceDecl(file []byte, cursor int) *DeclApropos {
+func (c *auto_complete_context) deduce_decl(file []byte, cursor int) *decl_apropos {
orig := cursor
if cursor < 0 {
return nil
}
if cursor == 0 {
- return &DeclApropos{nil, ""}
+ return &decl_apropos{nil, ""}
}
// figure out what is just before the cursor
- cursor = utf8MoveBackwards(file, cursor)
+ cursor = utf8_move_backwards(file, cursor)
if file[cursor] == '.' {
// we're '<whatever>.'
// figure out decl, Parital is ""
- return c.deduceExpr(file[:cursor], "")
+ return c.deduce_expr(file[:cursor], "")
} else {
letter, _ := utf8.DecodeRune(file[cursor:])
- if isIdent(letter) {
+ if is_ident(letter) {
// we're '<whatever>.<ident>'
// parse <ident> as Partial and figure out decl
- cursor = skipIdent(file, cursor)
+ cursor = skip_ident(file, cursor)
partial := string(file[cursor+1 : orig])
if file[cursor] == '.' {
- return c.deduceExpr(file[:cursor], partial)
+ return c.deduce_expr(file[:cursor], partial)
} else {
- return &DeclApropos{nil, partial}
+ return &decl_apropos{nil, partial}
}
}
}
- return &DeclApropos{nil, ""}
+ return &decl_apropos{nil, ""}
}
378 autocompletecontext.go
View
@@ -16,22 +16,22 @@ import (
)
//-------------------------------------------------------------------------
-// OutBuffers
+// out_buffers
//
// Temporary structure for writing autocomplete response.
//-------------------------------------------------------------------------
-type OutBuffers struct {
+type out_buffers struct {
tmpbuf *bytes.Buffer
names []string
types []string
classes []string
- ctx *AutoCompleteContext
+ ctx *auto_complete_context
tmpns map[string]bool
}
-func NewOutBuffers(ctx *AutoCompleteContext) *OutBuffers {
- b := new(OutBuffers)
+func new_out_buffers(ctx *auto_complete_context) *out_buffers {
+ b := new(out_buffers)
b.tmpbuf = bytes.NewBuffer(make([]byte, 0, 1024))
b.names = make([]string, 0, 1024)
b.types = make([]string, 0, 1024)
@@ -40,29 +40,29 @@ func NewOutBuffers(ctx *AutoCompleteContext) *OutBuffers {
return b
}
-func (b *OutBuffers) Len() int {
+func (b *out_buffers) Len() int {
return len(b.names)
}
-func (b *OutBuffers) Less(i, j int) bool {
+func (b *out_buffers) Less(i, j int) bool {
if b.classes[i][0] == b.classes[j][0] {
return b.names[i] < b.names[j]
}
return b.classes[i] < b.classes[j]
}
-func (b *OutBuffers) Swap(i, j int) {
+func (b *out_buffers) Swap(i, j int) {
b.names[i], b.names[j] = b.names[j], b.names[i]
b.types[i], b.types[j] = b.types[j], b.types[i]
b.classes[i], b.classes[j] = b.classes[j], b.classes[i]
}
-func (b *OutBuffers) appendDecl(p, name string, decl *Decl, class int) {
- c1 := !Config.ProposeBuiltins && decl.Scope == universeScope && decl.Name != "Error"
- c2 := class != -1 && !matchClass(int(decl.Class), class)
+func (b *out_buffers) append_decl(p, name string, decl *decl, class int) {
+ c1 := !g_config.ProposeBuiltins && decl.scope == g_universe_scope && decl.name != "Error"
+ c2 := class != -1 && !match_class(int(decl.class), class)
c3 := class == -1 && !strings.HasPrefix(name, p)
- c4 := !decl.Matches()
- c5 := !checkTypeExpr(decl.Type)
+ c4 := !decl.matches()
+ c5 := !check_type_expr(decl.typ)
if c1 || c2 || c3 || c4 || c5 {
return
@@ -70,51 +70,51 @@ func (b *OutBuffers) appendDecl(p, name string, decl *Decl, class int) {
b.names = append(b.names, name)
- decl.PrettyPrintType(b.tmpbuf)
+ decl.pretty_print_type(b.tmpbuf)
b.types = append(b.types, b.tmpbuf.String())
b.tmpbuf.Reset()
- b.classes = append(b.classes, decl.ClassName())
+ b.classes = append(b.classes, decl.class_name())
}
-func (b *OutBuffers) appendEmbedded(p string, decl *Decl, class int) {
- if decl.Embedded == nil {
+func (b *out_buffers) append_embedded(p string, decl *decl, class int) {
+ if decl.embedded == nil {
return
}
- firstLevel := false
+ first_level := false
if b.tmpns == nil {
// first level, create tmp namespace
b.tmpns = make(map[string]bool)
- firstLevel = true
+ first_level = true
// add all children of the current decl to the namespace
- for _, c := range decl.Children {
- b.tmpns[c.Name] = true
+ for _, c := range decl.children {
+ b.tmpns[c.name] = true
}
}
- for _, emb := range decl.Embedded {
- typedecl := typeToDecl(emb, decl.Scope)
+ for _, emb := range decl.embedded {
+ typedecl := type_to_decl(emb, decl.scope)
if typedecl != nil {
- for _, c := range typedecl.Children {
- if _, has := b.tmpns[c.Name]; has {
+ for _, c := range typedecl.children {
+ if _, has := b.tmpns[c.name]; has {
continue
}
- b.appendDecl(p, c.Name, c, class)
- b.tmpns[c.Name] = true
+ b.append_decl(p, c.name, c, class)
+ b.tmpns[c.name] = true
}
- b.appendEmbedded(p, typedecl, class)
+ b.append_embedded(p, typedecl, class)
}
}
- if firstLevel {
+ if first_level {
// remove tmp namespace
b.tmpns = nil
}
}
-func matchClass(declclass int, class int) bool {
+func match_class(declclass int, class int) bool {
if class == declclass {
return true
}
@@ -122,67 +122,67 @@ func matchClass(declclass int, class int) bool {
}
//-------------------------------------------------------------------------
-// AutoCompleteContext
+// auto_complete_context
//
// Context that holds cache structures for autocompletion needs. It
// includes cache for packages and for main package files.
//-------------------------------------------------------------------------
-type AutoCompleteContext struct {
- current *AutoCompleteFile // currently editted file
- others []*DeclFileCache // other files of the current package
- pkg *Scope
+type auto_complete_context struct {
+ current *auto_complete_file // currently editted file
+ others []*decl_file_cache // other files of the current package
+ pkg *scope
- pcache PackageCache // packages cache
- declcache *DeclCache // top-level declarations cache
+ pcache package_cache // packages cache
+ declcache *decl_cache // top-level declarations cache
}
-func NewAutoCompleteContext(pcache PackageCache, declcache *DeclCache) *AutoCompleteContext {
- c := new(AutoCompleteContext)
- c.current = NewAutoCompleteFile("")
+func new_auto_complete_context(pcache package_cache, declcache *decl_cache) *auto_complete_context {
+ c := new(auto_complete_context)
+ c.current = new_auto_complete_file("")
c.pcache = pcache
c.declcache = declcache
return c
}
-func (c *AutoCompleteContext) updateCaches() {
+func (c *auto_complete_context) update_caches() {
// temporary map for packages that we need to check for a cache expiration
// map is used as a set of unique items to prevent double checks
- ps := make(map[string]*PackageFileCache)
+ ps := make(map[string]*package_file_cache)
// collect import information from all of the files
- c.pcache.AppendPackages(ps, c.current.packages)
- c.others = getOtherPackageFiles(c.current.name, c.current.packageName, c.declcache)
+ c.pcache.append_packages(ps, c.current.packages)
+ c.others = get_other_package_files(c.current.name, c.current.package_name, c.declcache)
for _, other := range c.others {
- c.pcache.AppendPackages(ps, other.Packages)
+ c.pcache.append_packages(ps, other.packages)
}
- updatePackages(ps)
+ update_packages(ps)
// fix imports for all files
- fixupPackages(c.current.filescope, c.current.packages, c.pcache)
+ fixup_packages(c.current.filescope, c.current.packages, c.pcache)
for _, f := range c.others {
- fixupPackages(f.FileScope, f.Packages, c.pcache)
+ fixup_packages(f.filescope, f.packages, c.pcache)
}
// At this point we have collected all top level declarations, now we need to
// merge them in the common package block.
- c.mergeDecls()
+ c.merge_decls()
}
-func (c *AutoCompleteContext) mergeDecls() {
- c.pkg = NewScope(universeScope)
- mergeDecls(c.current.filescope, c.pkg, c.current.decls)
- mergeDeclsFromPackages(c.pkg, c.current.packages, c.pcache)
+func (c *auto_complete_context) merge_decls() {
+ c.pkg = new_scope(g_universe_scope)
+ merge_decls(c.current.filescope, c.pkg, c.current.decls)
+ merge_decls_from_packages(c.pkg, c.current.packages, c.pcache)
for _, f := range c.others {
- mergeDecls(f.FileScope, c.pkg, f.Decls)
- mergeDeclsFromPackages(c.pkg, f.Packages, c.pcache)
+ merge_decls(f.filescope, c.pkg, f.decls)
+ merge_decls_from_packages(c.pkg, f.packages, c.pcache)
}
}
-func (c *AutoCompleteContext) makeDeclSet(scope *Scope) map[string]*Decl {
- set := make(map[string]*Decl, len(c.pkg.entities)*2)
- makeDeclSetRecursive(set, scope)
+func (c *auto_complete_context) make_decl_set(scope *scope) map[string]*decl {
+ set := make(map[string]*decl, len(c.pkg.entities)*2)
+ make_decl_set_recursive(set, scope)
return set
}
@@ -191,7 +191,7 @@ func (c *AutoCompleteContext) makeDeclSet(scope *Scope) map[string]*Decl {
// 2. apropos types (pretty-printed)
// 3. apropos classes
// and length of the part that should be replaced (if any)
-func (c *AutoCompleteContext) Apropos(file []byte, filename string, cursor int) ([]string, []string, []string, int) {
+func (c *auto_complete_context) apropos(file []byte, filename string, cursor int) ([]string, []string, []string, int) {
c.current.cursor = cursor
c.current.name = filename
@@ -202,64 +202,64 @@ func (c *AutoCompleteContext) Apropos(file []byte, filename string, cursor int)
// Does full processing of the currently editted file (top-level declarations plus
// active function).
- c.current.processData(file)
+ c.current.process_data(file)
// Updates cache of other files and packages. See the function for details of
// the process. At the end merges all the top-level declarations into the package
// block.
- c.updateCaches()
+ c.update_caches()
// And we're ready to Go. ;)
- b := NewOutBuffers(c)
+ b := new_out_buffers(c)
partial := 0
- da := c.deduceDecl(file, cursor)
+ da := c.deduce_decl(file, cursor)
if da != nil {
class := -1
- switch da.Partial {
+ switch da.partial {
case "const":
- class = DECL_CONST
+ class = decl_const
case "var":
- class = DECL_VAR
+ class = decl_var
case "type":
- class = DECL_TYPE
+ class = decl_type
case "func":
- class = DECL_FUNC
+ class = decl_func
case "package":
- class = DECL_PACKAGE
+ class = decl_package
}
- if da.Decl == nil {
+ if da.decl == nil {
// In case if no declaraion is a subject of completion, propose all:
- set := c.makeDeclSet(c.current.scope)
+ set := c.make_decl_set(c.current.scope)
for key, value := range set {
if value == nil {
continue
}
- value.InferType()
- b.appendDecl(da.Partial, key, value, class)
+ value.infer_type()
+ b.append_decl(da.partial, key, value, class)
}
} else {
// propose all children of a subject declaration and
- for _, decl := range da.Decl.Children {
- if da.Decl.Class == DECL_PACKAGE && !ast.IsExported(decl.Name) {
+ for _, decl := range da.decl.children {
+ if da.decl.class == decl_package && !ast.IsExported(decl.name) {
continue
}
- b.appendDecl(da.Partial, decl.Name, decl, class)
+ b.append_decl(da.partial, decl.name, decl, class)
}
// propose all children of an underlying struct/interface type
- adecl := advanceToStructOrInterface(da.Decl)
- if adecl != nil && adecl != da.Decl {
- for _, decl := range adecl.Children {
- if decl.Class == DECL_VAR {
- b.appendDecl(da.Partial, decl.Name, decl, class)
+ adecl := advance_to_struct_or_interface(da.decl)
+ if adecl != nil && adecl != da.decl {
+ for _, decl := range adecl.children {
+ if decl.class == decl_var {
+ b.append_decl(da.partial, decl.name, decl, class)
}
}
}
// propose all children of its embedded types
- b.appendEmbedded(da.Partial, da.Decl, class)
+ b.append_embedded(da.partial, da.decl, class)
}
- partial = len(da.Partial)
+ partial = len(da.partial)
}
if len(b.names) == 0 || len(b.types) == 0 || len(b.classes) == 0 {
@@ -270,18 +270,18 @@ func (c *AutoCompleteContext) Apropos(file []byte, filename string, cursor int)
return b.names, b.types, b.classes, partial
}
-func updatePackages(ps map[string]*PackageFileCache) {
+func update_packages(ps map[string]*package_file_cache) {
// initiate package cache update
done := make(chan bool)
for _, p := range ps {
- go func(p *PackageFileCache) {
+ go func(p *package_file_cache) {
defer func() {
if err := recover(); err != nil {
- printBacktrace(err)
+ print_backtrace(err)
done <- false
}
}()
- p.updateCache()
+ p.update_cache()
done <- true
}(p)
}
@@ -294,16 +294,16 @@ func updatePackages(ps map[string]*PackageFileCache) {
}
}
-func mergeDecls(filescope *Scope, pkg *Scope, decls map[string]*Decl) {
+func merge_decls(filescope *scope, pkg *scope, decls map[string]*decl) {
for _, d := range decls {
- pkg.mergeDecl(d)
+ pkg.merge_decl(d)
}
filescope.parent = pkg
}
-func mergeDeclsFromPackages(pkgscope *Scope, pkgs PackageImports, pcache PackageCache) {
+func merge_decls_from_packages(pkgscope *scope, pkgs package_imports, pcache package_cache) {
for _, p := range pkgs {
- path, alias := p.Path, p.Alias
+ path, alias := p.path, p.alias
if alias != "." {
continue
}
@@ -311,17 +311,17 @@ func mergeDeclsFromPackages(pkgscope *Scope, pkgs PackageImports, pcache Package
if p == nil {
continue
}
- for _, d := range p.Children {
- if ast.IsExported(d.Name) {
- pkgscope.mergeDecl(d)
+ for _, d := range p.children {
+ if ast.IsExported(d.name) {
+ pkgscope.merge_decl(d)
}
}
}
}
-func fixupPackages(filescope *Scope, pkgs PackageImports, pcache PackageCache) {
+func fixup_packages(filescope *scope, pkgs package_imports, pcache package_cache) {
for _, p := range pkgs {
- path, alias := p.Path, p.Alias
+ path, alias := p.path, p.alias
if alias == "" {
alias = pcache[path].defalias
}
@@ -329,25 +329,25 @@ func fixupPackages(filescope *Scope, pkgs PackageImports, pcache PackageCache) {
if alias == "." {
continue
}
- filescope.replaceDecl(alias, pcache[path].main)
+ filescope.replace_decl(alias, pcache[path].main)
}
}
-func getOtherPackageFiles(filename, packageName string, declcache *DeclCache) []*DeclFileCache {
- others := findOtherPackageFiles(filename, packageName)
+func get_other_package_files(filename, packageName string, declcache *decl_cache) []*decl_file_cache {
+ others := find_other_package_files(filename, packageName)
- ret := make([]*DeclFileCache, len(others))
- done := make(chan *DeclFileCache)
+ ret := make([]*decl_file_cache, len(others))
+ done := make(chan *decl_file_cache)
for _, nm := range others {
go func(name string) {
defer func() {
if err := recover(); err != nil {
- printBacktrace(err)
+ print_backtrace(err)
done <- nil
}
}()
- done <- declcache.Get(name)
+ done <- declcache.get_and_update(name)
}(nm)
}
@@ -361,19 +361,19 @@ func getOtherPackageFiles(filename, packageName string, declcache *DeclCache) []
return ret
}
-func findOtherPackageFiles(filename, packageName string) []string {
+func find_other_package_files(filename, package_name string) []string {
if filename == "" {
return nil
}
dir, file := filepath.Split(filename)
- filesInDir, err := ioutil.ReadDir(dir)
+ files_in_dir, err := ioutil.ReadDir(dir)
if err != nil {
panic(err)
}
count := 0
- for _, stat := range filesInDir {
+ for _, stat := range files_in_dir {
ok, _ := filepath.Match("*.go", stat.Name())
if !ok || stat.Name() == file {
continue
@@ -382,17 +382,17 @@ func findOtherPackageFiles(filename, packageName string) []string {
}
out := make([]string, 0, count)
- for _, stat := range filesInDir {
- const NonRegular = os.ModeDir | os.ModeSymlink |
+ for _, stat := range files_in_dir {
+ const non_regular = os.ModeDir | os.ModeSymlink |
os.ModeDevice | os.ModeNamedPipe | os.ModeSocket
ok, _ := filepath.Match("*.go", stat.Name())
- if !ok || stat.Name() == file || stat.Mode()&NonRegular != 0 {
+ if !ok || stat.Name() == file || stat.Mode()&non_regular != 0 {
continue
}
abspath := filepath.Join(dir, stat.Name())
- if filePackageName(abspath) == packageName {
+ if file_package_name(abspath) == package_name {
n := len(out)
out = out[:n+1]
out[n] = abspath
@@ -402,29 +402,29 @@ func findOtherPackageFiles(filename, packageName string) []string {
return out
}
-func filePackageName(filename string) string {
+func file_package_name(filename string) string {
file, _ := parser.ParseFile(token.NewFileSet(), filename, nil, parser.PackageClauseOnly)
return file.Name.Name
}
-func makeDeclSetRecursive(set map[string]*Decl, scope *Scope) {
+func make_decl_set_recursive(set map[string]*decl, scope *scope) {
for name, ent := range scope.entities {
if _, ok := set[name]; !ok {
set[name] = ent
}
}
if scope.parent != nil {
- makeDeclSetRecursive(set, scope.parent)
+ make_decl_set_recursive(set, scope.parent)
}
}
-func checkFuncFieldList(f *ast.FieldList) bool {
+func check_func_field_list(f *ast.FieldList) bool {
if f == nil {
return true
}
for _, field := range f.List {
- if !checkTypeExpr(field.Type) {
+ if !check_type_expr(field.Type) {
return false
}
}
@@ -433,26 +433,26 @@ func checkFuncFieldList(f *ast.FieldList) bool {
// checks for a type expression correctness, it the type expression has
// ast.BadExpr somewhere, returns false, otherwise true
-func checkTypeExpr(e ast.Expr) bool {
+func check_type_expr(e ast.Expr) bool {
switch t := e.(type) {
case *ast.StarExpr:
- return checkTypeExpr(t.X)
+ return check_type_expr(t.X)
case *ast.ArrayType:
- return checkTypeExpr(t.Elt)
+ return check_type_expr(t.Elt)
case *ast.SelectorExpr:
- return checkTypeExpr(t.X)
+ return check_type_expr(t.X)
case *ast.FuncType:
- a := checkFuncFieldList(t.Params)
- b := checkFuncFieldList(t.Results)
+ a := check_func_field_list(t.Params)
+ b := check_func_field_list(t.Results)
return a && b
case *ast.MapType:
- a := checkTypeExpr(t.Key)
- b := checkTypeExpr(t.Value)
+ a := check_type_expr(t.Key)
+ b := check_type_expr(t.Value)
return a && b
case *ast.Ellipsis:
- return checkTypeExpr(t.Elt)
+ return check_type_expr(t.Elt)
case *ast.ChanType:
- return checkTypeExpr(t.Value)
+ return check_type_expr(t.Value)
case *ast.BadExpr:
return false
default:
@@ -465,54 +465,54 @@ func checkTypeExpr(e ast.Expr) bool {
// Status output
//-------------------------------------------------------------------------
-type DeclSlice []*Decl
+type decl_slice []*decl
-func (s DeclSlice) Less(i, j int) bool {
- if s[i].ClassName()[0] == s[j].ClassName()[0] {
- return s[i].Name < s[j].Name
+func (s decl_slice) Less(i, j int) bool {
+ if s[i].class_name()[0] == s[j].class_name()[0] {
+ return s[i].name < s[j].name
}
- return s[i].ClassName() < s[j].ClassName()
+ return s[i].class_name() < s[j].class_name()
}
-func (s DeclSlice) Len() int { return len(s) }
-func (s DeclSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
+func (s decl_slice) Len() int { return len(s) }
+func (s decl_slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
const (
- COLOR_red = "\033[0;31m"
- COLOR_RED = "\033[1;31m"
- COLOR_green = "\033[0;32m"
- COLOR_GREEN = "\033[1;32m"
- COLOR_yellow = "\033[0;33m"
- COLOR_YELLOW = "\033[1;33m"
- COLOR_blue = "\033[0;34m"
- COLOR_BLUE = "\033[1;34m"
- COLOR_magenta = "\033[0;35m"
- COLOR_MAGENTA = "\033[1;35m"
- COLOR_cyan = "\033[0;36m"
- COLOR_CYAN = "\033[1;36m"
- COLOR_white = "\033[0;37m"
- COLOR_WHITE = "\033[1;37m"
- NC = "\033[0m"
+ color_red = "\033[0;31m"
+ color_red_bold = "\033[1;31m"
+ color_green = "\033[0;32m"
+ color_green_bold = "\033[1;32m"
+ color_yellow = "\033[0;33m"
+ color_yellow_bold = "\033[1;33m"
+ color_blue = "\033[0;34m"
+ color_blue_bold = "\033[1;34m"
+ color_magenta = "\033[0;35m"
+ color_magenta_bold = "\033[1;35m"
+ color_cyan = "\033[0;36m"
+ color_cyan_bold = "\033[1;36m"
+ color_white = "\033[0;37m"
+ color_white_bold = "\033[1;37m"
+ color_none = "\033[0m"
)
-var declClassToColor = [...]string{
- DECL_CONST: COLOR_WHITE,
- DECL_VAR: COLOR_magenta,
- DECL_TYPE: COLOR_cyan,
- DECL_FUNC: COLOR_green,
- DECL_PACKAGE: COLOR_red,
- DECL_METHODS_STUB: COLOR_red,
+var g_decl_class_to_color = [...]string{
+ decl_const: color_white_bold,
+ decl_var: color_magenta,
+ decl_type: color_cyan,
+ decl_func: color_green,
+ decl_package: color_red,
+ decl_methods_stub: color_red,
}
-var declClassToStringStatus = [...]string{
- DECL_CONST: " const",
- DECL_VAR: " var",
- DECL_TYPE: " type",
- DECL_FUNC: " func",
- DECL_PACKAGE: "package",
- DECL_METHODS_STUB: " stub",
+var g_decl_class_to_string_status = [...]string{
+ decl_const: " const",
+ decl_var: " var",
+ decl_type: " type",
+ decl_func: " func",
+ decl_package: "package",
+ decl_methods_stub: " stub",
}
-func (c *AutoCompleteContext) Status() string {
+func (c *auto_complete_context) status() string {
buf := bytes.NewBuffer(make([]byte, 0, 4096))
fmt.Fprintf(buf, "Server's GOMAXPROCS == %d\n", runtime.GOMAXPROCS(0))
@@ -520,7 +520,7 @@ func (c *AutoCompleteContext) Status() string {
fmt.Fprintf(buf, "\nListing these entries:\n")
for _, mod := range c.pcache {
fmt.Fprintf(buf, "\tname: %s (default alias: %s)\n", mod.name, mod.defalias)
- fmt.Fprintf(buf, "\timports %d declarations and %d packages\n", len(mod.main.Children), len(mod.others))
+ fmt.Fprintf(buf, "\timports %d declarations and %d packages\n", len(mod.main.children), len(mod.others))
if mod.mtime == -1 {
fmt.Fprintf(buf, "\tthis package stays in cache forever (built-in package)\n")
} else {
@@ -530,7 +530,7 @@ func (c *AutoCompleteContext) Status() string {
fmt.Fprintf(buf, "\n")
}
if c.current.name != "" {
- fmt.Fprintf(buf, "Last editted file: %s (package: %s)\n", c.current.name, c.current.packageName)
+ fmt.Fprintf(buf, "Last editted file: %s (package: %s)\n", c.current.name, c.current.package_name)
if len(c.others) > 0 {
fmt.Fprintf(buf, "\nOther files from the current package:\n")
}
@@ -539,53 +539,51 @@ func (c *AutoCompleteContext) Status() string {
}
fmt.Fprintf(buf, "\nListing declarations from files:\n")
- const STATUS_DECLS = "\t%s%s" + NC + " " + COLOR_yellow + "%s" + NC + "\n"
- const STATUS_DECLS_CHILDREN = "\t%s%s" + NC + " " + COLOR_yellow + "%s" + NC + " (%d)\n"
- var ds DeclSlice
- var i int
+ const status_decls = "\t%s%s" + color_none + " " + color_yellow + "%s" + color_none + "\n"
+ const status_decls_children = "\t%s%s" + color_none + " " + color_yellow + "%s" + color_none + " (%d)\n"
fmt.Fprintf(buf, "\n%s:\n", c.current.name)
- ds = make(DeclSlice, len(c.current.decls))
- i = 0
+ ds := make(decl_slice, len(c.current.decls))
+ i := 0
for _, d := range c.current.decls {
ds[i] = d
i++
}
sort.Sort(ds)
for _, d := range ds {
- if len(d.Children) > 0 {
- fmt.Fprintf(buf, STATUS_DECLS_CHILDREN,
- declClassToColor[d.Class],
- declClassToStringStatus[d.Class],
- d.Name, len(d.Children))
+ if len(d.children) > 0 {
+ fmt.Fprintf(buf, status_decls_children,
+ g_decl_class_to_color[d.class],
+ g_decl_class_to_string_status[d.class],
+ d.name, len(d.children))
} else {
- fmt.Fprintf(buf, STATUS_DECLS,
- declClassToColor[d.Class],
- declClassToStringStatus[d.Class],
- d.Name)
+ fmt.Fprintf(buf, status_decls,
+ g_decl_class_to_color[d.class],
+ g_decl_class_to_string_status[d.class],
+ d.name)
}
}
for _, f := range c.others {
fmt.Fprintf(buf, "\n%s:\n", f.name)
- ds = make(DeclSlice, len(f.Decls))
+ ds = make(decl_slice, len(f.decls))
i = 0
- for _, d := range f.Decls {
+ for _, d := range f.decls {
ds[i] = d
i++
}
sort.Sort(ds)
for _, d := range ds {
- if len(d.Children) > 0 {
- fmt.Fprintf(buf, STATUS_DECLS_CHILDREN,
- declClassToColor[d.Class],
- declClassToStringStatus[d.Class],
- d.Name, len(d.Children))
+ if len(d.children) > 0 {
+ fmt.Fprintf(buf, status_decls_children,
+ g_decl_class_to_color[d.class],
+ g_decl_class_to_string_status[d.class],
+ d.name, len(d.children))
} else {
- fmt.Fprintf(buf, STATUS_DECLS,
- declClassToColor[d.Class],
- declClassToStringStatus[d.Class],
- d.Name)
+ fmt.Fprintf(buf, status_decls,
+ g_decl_class_to_color[d.class],
+ g_decl_class_to_string_status[d.class],
+ d.name)
}
}
}
264 autocompletefile.go
View
@@ -1,13 +1,13 @@
package main
import (
+ "bytes"
"go/ast"
"go/parser"
"go/token"
- "bytes"
)
-func parseDeclList(fset *token.FileSet, data []byte) ([]ast.Decl, error) {
+func parse_decl_list(fset *token.FileSet, data []byte) ([]ast.Decl, error) {
var buf bytes.Buffer
buf.WriteString("package p;")
buf.Write(data)
@@ -19,303 +19,303 @@ func parseDeclList(fset *token.FileSet, data []byte) ([]ast.Decl, error) {
}
//-------------------------------------------------------------------------
-// AutoCompleteFile
+// auto_complete_file
//-------------------------------------------------------------------------
-type AutoCompleteFile struct {
- name string
- packageName string
+type auto_complete_file struct {
+ name string
+ package_name string
- decls map[string]*Decl
- packages PackageImports
- filescope *Scope
- scope *Scope
+ decls map[string]*decl
+ packages package_imports
+ filescope *scope
+ scope *scope
cursor int // for current file buffer only
fset *token.FileSet
}
-func NewAutoCompleteFile(name string) *AutoCompleteFile {
- p := new(AutoCompleteFile)
+func new_auto_complete_file(name string) *auto_complete_file {
+ p := new(auto_complete_file)
p.name = name
p.cursor = -1
p.fset = token.NewFileSet()
return p
}
-func (f *AutoCompleteFile) offset(p token.Pos) int {
+func (f *auto_complete_file) offset(p token.Pos) int {
const fixlen = len("package p;")
return f.fset.Position(p).Offset - fixlen
}
// this one is used for current file buffer exclusively
-func (f *AutoCompleteFile) processData(data []byte) {
- cur, filedata, block := RipOffDecl(data, f.cursor)
+func (f *auto_complete_file) process_data(data []byte) {
+ cur, filedata, block := rip_off_decl(data, f.cursor)
file, _ := parser.ParseFile(f.fset, "", filedata, 0)
- f.packageName = packageName(file)
+ f.package_name = package_name(file)
- f.decls = make(map[string]*Decl)
- f.packages = NewPackageImports(f.name, file.Decls)
- f.filescope = NewScope(nil)
+ f.decls = make(map[string]*decl)
+ f.packages = new_package_imports(f.name, file.Decls)
+ f.filescope = new_scope(nil)
f.scope = f.filescope
for _, d := range file.Decls {
- anonymifyAst(d, 0, f.filescope)
+ anonymify_ast(d, 0, f.filescope)
}
// process all top-level declarations
for _, decl := range file.Decls {
- appendToTopDecls(f.decls, decl, f.scope)
+ append_to_top_decls(f.decls, decl, f.scope)
}
if block != nil {
// process local function as top-level declaration
- decls, _ := parseDeclList(f.fset, block)
+ decls, _ := parse_decl_list(f.fset, block)
for _, d := range decls {
- anonymifyAst(d, 0, f.filescope)
+ anonymify_ast(d, 0, f.filescope)
}
for _, decl := range decls {
- appendToTopDecls(f.decls, decl, f.scope)
+ append_to_top_decls(f.decls, decl, f.scope)
}
// process function internals
f.cursor = cur
for _, decl := range decls {
- f.processDeclLocals(decl)
+ f.process_decl_locals(decl)
}
}
}
-func (f *AutoCompleteFile) processDeclLocals(decl ast.Decl) {
+func (f *auto_complete_file) process_decl_locals(decl ast.Decl) {
switch t := decl.(type) {
case *ast.FuncDecl:
- if f.cursorIn(t.Body) {
+ if f.cursor_in(t.Body) {
s := f.scope
- f.scope = NewScope(f.scope)
+ f.scope = new_scope(f.scope)
- f.processFieldList(t.Recv, s)
- f.processFieldList(t.Type.Params, s)
- f.processFieldList(t.Type.Results, s)
- f.processBlockStmt(t.Body)
+ f.process_field_list(t.Recv, s)
+ f.process_field_list(t.Type.Params, s)
+ f.process_field_list(t.Type.Results, s)
+ f.process_block_stmt(t.Body)
}
}
}
-func (f *AutoCompleteFile) processDecl(decl ast.Decl) {
+func (f *auto_complete_file) process_decl(decl ast.Decl) {
if t, ok := decl.(*ast.GenDecl); ok && f.offset(t.TokPos) > f.cursor {
return
}
prevscope := f.scope
- foreachDecl(decl, func(data *foreachDeclStruct) {
- class := astDeclClass(data.decl)
- if class != DECL_TYPE {
- f.scope, prevscope = AdvanceScope(f.scope)
+ foreach_decl(decl, func(data *foreach_decl_struct) {
+ class := ast_decl_class(data.decl)
+ if class != decl_type {
+ f.scope, prevscope = advance_scope(f.scope)
}
for i, name := range data.names {
- typ, v, vi := data.typeValueIndex(i, 0)
+ typ, v, vi := data.type_value_index(i, 0)
- d := NewDecl2(name.Name, class, 0, typ, v, vi, prevscope)
+ d := new_decl_full(name.Name, class, 0, typ, v, vi, prevscope)
if d == nil {
return
}
- f.scope.addNamedDecl(d)
+ f.scope.add_named_decl(d)
}
})
}
-func (f *AutoCompleteFile) processBlockStmt(block *ast.BlockStmt) {
- if block != nil && f.cursorIn(block) {
- f.scope, _ = AdvanceScope(f.scope)
+func (f *auto_complete_file) process_block_stmt(block *ast.BlockStmt) {
+ if block != nil && f.cursor_in(block) {
+ f.scope, _ = advance_scope(f.scope)
for _, stmt := range block.List {
- f.processStmt(stmt)
+ f.process_stmt(stmt)
}
// hack to process all func literals
- v := new(funcLitVisitor)
+ v := new(func_lit_visitor)
v.ctx = f
ast.Walk(v, block)
}
}
-type funcLitVisitor struct {
- ctx *AutoCompleteFile
+type func_lit_visitor struct {
+ ctx *auto_complete_file
}
-func (v *funcLitVisitor) Visit(node ast.Node) ast.Visitor {
- if t, ok := node.(*ast.FuncLit); ok && v.ctx.cursorIn(t.Body) {
+func (v *func_lit_visitor) Visit(node ast.Node) ast.Visitor {
+ if t, ok := node.(*ast.FuncLit); ok && v.ctx.cursor_in(t.Body) {
s := v.ctx.scope
- v.ctx.scope, _ = AdvanceScope(v.ctx.scope)
+ v.ctx.scope, _ = advance_scope(v.ctx.scope)
- v.ctx.processFieldList(t.Type.Params, s)
- v.ctx.processFieldList(t.Type.Results, s)
- v.ctx.processBlockStmt(t.Body)
+ v.ctx.process_field_list(t.Type.Params, s)
+ v.ctx.process_field_list(t.Type.Results, s)
+ v.ctx.process_block_stmt(t.Body)
return nil
}
return v
}
-func (f *AutoCompleteFile) processStmt(stmt ast.Stmt) {
+func (f *auto_complete_file) process_stmt(stmt ast.Stmt) {
switch t := stmt.(type) {
case *ast.DeclStmt:
- f.processDecl(t.Decl)
+ f.process_decl(t.Decl)
case *ast.AssignStmt:
- f.processAssignStmt(t)
+ f.process_assign_stmt(t)
case *ast.IfStmt:
- if f.cursorIn(t.Body) {
- f.scope, _ = AdvanceScope(f.scope)
+ if f.cursor_in(t.Body) {
+ f.scope, _ = advance_scope(f.scope)
- f.processStmt(t.Init)
- f.processBlockStmt(t.Body)
+ f.process_stmt(t.Init)
+ f.process_block_stmt(t.Body)
}
- f.processStmt(t.Else)
+ f.process_stmt(t.Else)
case *ast.BlockStmt:
- f.processBlockStmt(t)
+ f.process_block_stmt(t)
case *ast.RangeStmt:
- f.processRangeStmt(t)
+ f.process_range_stmt(t)
case *ast.ForStmt:
- if f.cursorIn(t.Body) {
- f.scope, _ = AdvanceScope(f.scope)
+ if f.cursor_in(t.Body) {
+ f.scope, _ = advance_scope(f.scope)
- f.processStmt(t.Init)
- f.processBlockStmt(t.Body)
+ f.process_stmt(t.Init)
+ f.process_block_stmt(t.Body)
}
case *ast.SwitchStmt:
- f.processSwitchStmt(t)
+ f.process_switch_stmt(t)
case *ast.TypeSwitchStmt:
- f.processTypeSwitchStmt(t)
+ f.process_type_switch_stmt(t)
case *ast.SelectStmt:
- f.processSelectStmt(t)
+ f.process_select_stmt(t)
case *ast.LabeledStmt:
- f.processStmt(t.Stmt)
+ f.process_stmt(t.Stmt)
}
}
-func (f *AutoCompleteFile) processSelectStmt(a *ast.SelectStmt) {
- if !f.cursorIn(a.Body) {
+func (f *auto_complete_file) process_select_stmt(a *ast.SelectStmt) {
+ if !f.cursor_in(a.Body) {
return
}
- var prevscope *Scope
- f.scope, prevscope = AdvanceScope(f.scope)
+ var prevscope *scope
+ f.scope, prevscope = advance_scope(f.scope)
- var lastCursorAfter *ast.CommClause
+ var last_cursor_after *ast.CommClause
for _, s := range a.Body.List {
if cc := s.(*ast.CommClause); f.cursor > f.offset(cc.Colon) {
- lastCursorAfter = cc
+ last_cursor_after = cc
}
}
- if lastCursorAfter != nil {
- if lastCursorAfter.Comm != nil {
+ if last_cursor_after != nil {
+ if last_cursor_after.Comm != nil {
//if lastCursorAfter.Lhs != nil && lastCursorAfter.Tok == token.DEFINE {
- if astmt, ok := lastCursorAfter.Comm.(*ast.AssignStmt); ok && astmt.Tok == token.DEFINE {
+ if astmt, ok := last_cursor_after.Comm.(*ast.AssignStmt); ok && astmt.Tok == token.DEFINE {
vname := astmt.Lhs[0].(*ast.Ident).Name
- v := NewDeclVar(vname, nil, astmt.Rhs[0], -1, prevscope)
- f.scope.addNamedDecl(v)
+ v := new_decl_var(vname, nil, astmt.Rhs[0], -1, prevscope)
+ f.scope.add_named_decl(v)
}
}
- for _, s := range lastCursorAfter.Body {
- f.processStmt(s)
+ for _, s := range last_cursor_after.Body {
+ f.process_stmt(s)
}
}
}
-func (f *AutoCompleteFile) processTypeSwitchStmt(a *ast.TypeSwitchStmt) {
- if !f.cursorIn(a.Body) {
+func (f *auto_complete_file) process_type_switch_stmt(a *ast.TypeSwitchStmt) {
+ if !f.cursor_in(a.Body) {
return
}
- var prevscope *Scope
- f.scope, prevscope = AdvanceScope(f.scope)
+ var prevscope *scope
+ f.scope, prevscope = advance_scope(f.scope)
- f.processStmt(a.Init)
+ f.process_stmt(a.Init)
// type var
- var tv *Decl
+ var tv *decl
if a, ok := a.Assign.(*ast.AssignStmt); ok {
lhs := a.Lhs
rhs := a.Rhs
if lhs != nil && len(lhs) == 1 {
tvname := lhs[0].(*ast.Ident).Name
- tv = NewDeclVar(tvname, nil, rhs[0], -1, prevscope)
+ tv = new_decl_var(tvname, nil, rhs[0], -1, prevscope)
}
}
- var lastCursorAfter *ast.CaseClause
+ var last_cursor_after *ast.CaseClause
for _, s := range a.Body.List {
if cc := s.(*ast.CaseClause); f.cursor > f.offset(cc.Colon) {
- lastCursorAfter = cc
+ last_cursor_after = cc
}
}
- if lastCursorAfter != nil {
+ if last_cursor_after != nil {
if tv != nil {
- if lastCursorAfter.List != nil && len(lastCursorAfter.List) == 1 {
- tv.Type = lastCursorAfter.List[0]
- tv.Value = nil
+ if last_cursor_after.List != nil && len(last_cursor_after.List) == 1 {
+ tv.typ = last_cursor_after.List[0]
+ tv.value = nil
}
- f.scope.addNamedDecl(tv)
+ f.scope.add_named_decl(tv)
}
- for _, s := range lastCursorAfter.Body {
- f.processStmt(s)
+ for _, s := range last_cursor_after.Body {
+ f.process_stmt(s)
}
}
}
-func (f *AutoCompleteFile) processSwitchStmt(a *ast.SwitchStmt) {
- if !f.cursorIn(a.Body) {
+func (f *auto_complete_file) process_switch_stmt(a *ast.SwitchStmt) {
+ if !f.cursor_in(a.Body) {
return
}
- f.scope, _ = AdvanceScope(f.scope)
+ f.scope, _ = advance_scope(f.scope)
- f.processStmt(a.Init)
- var lastCursorAfter *ast.CaseClause
+ f.process_stmt(a.Init)
+ var last_cursor_after *ast.CaseClause
for _, s := range a.Body.List {
if cc := s.(*ast.CaseClause); f.cursor > f.offset(cc.Colon) {
- lastCursorAfter = cc
+ last_cursor_after = cc
}
}
- if lastCursorAfter != nil {
- for _, s := range lastCursorAfter.Body {
- f.processStmt(s)
+ if last_cursor_after != nil {
+ for _, s := range last_cursor_after.Body {
+ f.process_stmt(s)
}
}
}
-func (f *AutoCompleteFile) processRangeStmt(a *ast.RangeStmt) {
- if !f.cursorIn(a.Body) {
+func (f *auto_complete_file) process_range_stmt(a *ast.RangeStmt) {
+ if !f.cursor_in(a.Body) {
return
}
- var prevscope *Scope
- f.scope, prevscope = AdvanceScope(f.scope)
+ var prevscope *scope
+ f.scope, prevscope = advance_scope(f.scope)
if a.Tok == token.DEFINE {
if t, ok := a.Key.(*ast.Ident); ok {
- d := NewDeclVar(t.Name, nil, a.X, 0, prevscope)
+ d := new_decl_var(t.Name, nil, a.X, 0, prevscope)
if d != nil {
- d.Flags |= DECL_RANGEVAR
- f.scope.addNamedDecl(d)
+ d.flags |= decl_rangevar
+ f.scope.add_named_decl(d)
}
}
if a.Value != nil {
if t, ok := a.Value.(*ast.Ident); ok {
- d := NewDeclVar(t.Name, nil, a.X, 1, prevscope)
+ d := new_decl_var(t.Name, nil, a.X, 1, prevscope)
if d != nil {
- d.Flags |= DECL_RANGEVAR
- f.scope.addNamedDecl(d)
+ d.flags |= decl_rangevar
+ f.scope.add_named_decl(d)
}
}
}
}
- f.processBlockStmt(a.Body)
+ f.process_block_stmt(a.Body)
}
-func (f *AutoCompleteFile) processAssignStmt(a *ast.AssignStmt) {
+func (f *auto_complete_file) process_assign_stmt(a *ast.AssignStmt) {
if a.Tok != token.DEFINE || f.offset(a.TokPos) > f.cursor {
return
}
@@ -330,31 +330,31 @@ func (f *AutoCompleteFile) processAssignStmt(a *ast.AssignStmt) {
names[i] = id
}
- var prevscope *Scope
- f.scope, prevscope = AdvanceScope(f.scope)
+ var prevscope *scope
+ f.scope, prevscope = advance_scope(f.scope)
- pack := declPack{names, nil, a.Rhs}
+ pack := decl_pack{names, nil, a.Rhs}
for i, name := range pack.names {
- typ, v, vi := pack.typeValueIndex(i, 0)
- d := NewDeclVar(name.Name, typ, v, vi, prevscope)
+ typ, v, vi := pack.type_value_index(i, 0)
+ d := new_decl_var(name.Name, typ, v, vi, prevscope)
if d == nil {
continue
}
- f.scope.addNamedDecl(d)
+ f.scope.add_named_decl(d)
}
}
-func (f *AutoCompleteFile) processFieldList(fieldList *ast.FieldList, s *Scope) {
- if fieldList != nil {
- decls := astFieldListToDecls(fieldList, DECL_VAR, 0, s)
+func (f *auto_complete_file) process_field_list(field_list *ast.FieldList, s *scope) {
+ if field_list != nil {
+ decls := ast_field_list_to_decls(field_list, decl_var, 0, s)
for _, d := range decls {
- f.scope.addNamedDecl(d)
+ f.scope.add_named_decl(d)
}
}
}
-func (f *AutoCompleteFile) cursorIn(block *ast.BlockStmt) bool {
+func (f *auto_complete_file) cursor_in(block *ast.BlockStmt) bool {
if f.cursor == -1 || block == nil {
return false
}
127 config.go
View
@@ -2,6 +2,7 @@ package main
import (
"bytes"
+ "encoding/json"
"fmt"
"io"
"io/ioutil"
@@ -9,25 +10,38 @@ import (
"path/filepath"
"reflect"
"strconv"
- "encoding/json"
)
+func xdg_home_dir() string {
+ xdghome := os.Getenv("XDG_CONFIG_HOME")
+ if xdghome == "" {
+ xdghome = filepath.Join(os.Getenv("HOME"), ".config")
+ }
+ return xdghome
+}
+
+func config_file() string {
+ return filepath.Join(xdg_home_dir(), "gocode", "config.json")
+}
+
//-------------------------------------------------------------------------
-// Config
+// config
//
// Structure represents persistent config storage of the gocode daemon. Usually
// the config is located somewhere in ~/.config/gocode directory.
//-------------------------------------------------------------------------
-var Config = struct {
+type config struct {
ProposeBuiltins bool `json:"propose-builtins"`
LibPath string `json:"lib-path"`
-}{
+}
+
+var g_config = config{
false,
"",
}
-var boolStrings = map[string]bool{
+var g_string_to_bool = map[string]bool{
"t": true,
"true": true,
"y": true,
@@ -42,10 +56,10 @@ var boolStrings = map[string]bool{
"0": false,
}
-func setValue(v reflect.Value, name, value string) {
+func set_value(v reflect.Value, value string) {
switch t := v; t.Kind() {
case reflect.Bool:
- v, ok := boolStrings[value]
+ v, ok := g_string_to_bool[value]
if ok {
t.SetBool(v)
}
@@ -64,93 +78,77 @@ func setValue(v reflect.Value, name, value string) {
}
}
-func listValue(v reflect.Value, name string, w io.Writer) {
+func list_value(v reflect.Value, name string, w io.Writer) {
switch t := v; t.Kind() {
case reflect.Bool:
- fmt.Fprintf(w, "%s = %v\n", name, t.Bool())
+ fmt.Fprintf(w, "%s %v\n", name, t.Bool())
case reflect.String:
- fmt.Fprintf(w, "%s = \"%v\"\n", name, t.String())
+ fmt.Fprintf(w, "%s \"%v\"\n", name, t.String())
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- fmt.Fprintf(w, "%s = %v\n", name, t.Int())
+ fmt.Fprintf(w, "%s %v\n", name, t.Int())
case reflect.Float32, reflect.Float64:
- fmt.Fprintf(w, "%s = %v\n", name, t.Float())
+ fmt.Fprintf(w, "%s %v\n", name, t.Float())
}
}
-func listConfig(v interface{}) string {
- str, typ, ok := interfaceIsPtrStruct(v)
- if !ok {
- return ""
- }
-
+func (this *config) list() string {
+ str, typ := this.value_and_type()
buf := bytes.NewBuffer(make([]byte, 0, 256))
for i := 0; i < str.NumField(); i++ {
v := str.Field(i)
name := typ.Field(i).Tag.Get("json")
- listValue(v, name, buf)
+ list_value(v, name, buf)
}
return buf.String()
}
-func listOption(v interface{}, name string) string {
- str, typ, ok := interfaceIsPtrStruct(v)
- if !ok {
- return ""
- }
-
+func (this *config) list_option(name string) string {
+ str, typ := this.value_and_type()
buf := bytes.NewBuffer(make([]byte, 0, 256))
for i := 0; i < str.NumField(); i++ {
v := str.Field(i)
nm := typ.Field(i).Tag.Get("json")
if nm == name {
- listValue(v, name, buf)
+ list_value(v, name, buf)
}
}
return buf.String()
}
-func setOption(v interface{}, name, value string) string {
- str, typ, ok := interfaceIsPtrStruct(v)
- if !ok {
- return ""
- }
-
+func (this *config) set_option(name, value string) string {
+ str, typ := this.value_and_type()
buf := bytes.NewBuffer(make([]byte, 0, 256))
for i := 0; i < str.NumField(); i++ {
v := str.Field(i)
nm := typ.Field(i).Tag.Get("json")
if nm == name {
- setValue(v, name, value)
- listValue(v, name, buf)
+ set_value(v, value)
+ list_value(v, name, buf)
}
}
- writeConfig(v)
+ this.write()
return buf.String()
-}
-func interfaceIsPtrStruct(v interface{}) (reflect.Value, reflect.Type, bool) {
- ptr := reflect.ValueOf(v)
- ok := ptr.Kind() == reflect.Ptr
- if !ok {
- return reflect.Value{}, nil, false
- }
+}
- str := ptr.Elem()
- if str.Kind() != reflect.Struct {
- return reflect.Value{}, nil, false
- }
- typ := str.Type()
- return str, typ, true
+func (this *config) value_and_type() (reflect.Value, reflect.Type) {
+ v := reflect.ValueOf(this).Elem()
+ return v, v.Type()
}
-func writeConfig(v interface{}) error {
- data, err := json.Marshal(v)
+func (this *config) write() error {
+ data, err := json.Marshal(this)
if err != nil {
return err
}
- makeSureConfigDirExists()
- f, err := os.Create(configFile())
+ // make sure config dir exists
+ dir := filepath.Join(xdg_home_dir(), "gocode")
+ if !file_exists(dir) {
+ os.MkdirAll(dir, 0755)
+ }
+
+ f, err := os.Create(config_file())
if err != nil {
return err
}
@@ -164,35 +162,16 @@ func writeConfig(v interface{}) error {
return nil
}
-func readConfig(v interface{}) error {
- data, err := ioutil.ReadFile(configFile())
+func (this *config) read() error {
+ data, err := ioutil.ReadFile(config_file())
if err != nil {
return err
}
- err = json.Unmarshal(data, v)
+ err = json.Unmarshal(data, this)
if err != nil {
return err
}
return nil
}
-
-func xdgHomeDir() string {
- xdghome := os.Getenv("XDG_CONFIG_HOME")
- if xdghome == "" {
- xdghome = filepath.Join(os.Getenv("HOME"), ".config")
- }
- return xdghome
-}
-
-func makeSureConfigDirExists() {
- dir := filepath.Join(xdgHomeDir(), "gocode")
- if !fileExists(dir) {
- os.MkdirAll(dir, 0755)
- }
-}
-
-func configFile() string {
- return filepath.Join(xdgHomeDir(), "gocode", "config.json")
-}
784 decl.go
View
@@ -11,72 +11,72 @@ import (
"sync"
)
-// Decl.Class
+// decl.class
const (
- DECL_CONST = iota
- DECL_VAR
- DECL_TYPE
- DECL_FUNC
- DECL_PACKAGE
+ decl_const = iota
+ decl_var
+ decl_type
+ decl_func
+ decl_package
// this one serves as a temporary type for those methods that were
// declared before their actual owner
- DECL_METHODS_STUB
+ decl_methods_stub
)
-// Decl.Flags
+// decl.flags
const (
- DECL_FOREIGN = 1 << iota // imported from another package
+ decl_foreign = 1 << iota // imported from another package
// means that the decl is a part of the range statement
// its type is inferred in a special way
- DECL_RANGEVAR
+ decl_rangevar
)
-var declClassToString = [...]string{
- DECL_CONST: "const",
- DECL_VAR: "var",
- DECL_TYPE: "type",
- DECL_FUNC: "func",
- DECL_PACKAGE: "package",
- DECL_METHODS_STUB: "IF YOU SEE THIS, REPORT A BUG", // :D
+var g_decl_class_to_string = [...]string{
+ decl_const: "const",
+ decl_var: "var",
+ decl_type: "type",
+ decl_func: "func",
+ decl_package: "package",
+ decl_methods_stub: "IF YOU SEE THIS, REPORT A BUG", // :D
}
//-------------------------------------------------------------------------
-// Decl
+// decl
//
// The most important data structure of the whole gocode project. It
// describes a single declaration and its children.
//-------------------------------------------------------------------------
-type Decl struct {
+type decl struct {
// Name starts with '$' if the declaration describes an anonymous type.
// '$s_%d' for anonymous struct types
// '$i_%d' for anonymous interface types
- Name string
- Type ast.Expr
- Class int16
- Flags int16
+ name string
+ typ ast.Expr
+ class int16
+ flags int16
// functions for interface type, fields+methods for struct type
- Children map[string]*Decl
+ children map[string]*decl
// embedded types
- Embedded []ast.Expr
+ embedded []ast.Expr
// if the type is unknown at AST building time, I'm using these
- Value ast.Expr
+ value ast.Expr
// if it's a multiassignment and the Value is a CallExpr, it is being set
// to an index into the return value tuple, otherwise it's a -1
- ValueIndex int
+ value_index int
// scope where this Decl was declared in (not its visibilty scope!)
// Decl uses it for type inference
- Scope *Scope
+ scope *scope
}
-func astDeclType(d ast.Decl) ast.Expr {
+func ast_decl_type(d ast.Decl) ast.Expr {
switch t := d.(type) {
case *ast.GenDecl:
switch t.Tok {
@@ -94,25 +94,25 @@ func astDeclType(d ast.Decl) ast.Expr {
return nil
}
-func astDeclClass(d ast.Decl) int {
+func ast_decl_class(d ast.Decl) int {
switch t := d.(type) {
case *ast.GenDecl:
switch t.Tok {
case token.VAR:
- return DECL_VAR
+ return decl_var
case token.CONST:
- return DECL_CONST
+ return decl_const
case token.TYPE:
- return DECL_TYPE
+ return decl_type
}
case *ast.FuncDecl:
- return DECL_FUNC
+ return decl_func
}
panic("unreachable")
return 0
}
-func astDeclConvertable(d ast.Decl) bool {
+func ast_decl_convertable(d ast.Decl) bool {
switch t := d.(type) {
case *ast.GenDecl:
switch t.Tok {
@@ -125,7 +125,7 @@ func astDeclConvertable(d ast.Decl) bool {
return false
}
-func astFieldListToDecls(f *ast.FieldList, class int, flags int, scope *Scope) map[string]*Decl {
+func ast_field_list_to_decls(f *ast.FieldList, class int, flags int, scope *scope) map[string]*decl {
count := 0
for _, field := range f.List {
count += len(field.Names)
@@ -135,44 +135,44 @@ func astFieldListToDecls(f *ast.FieldList, class int, flags int, scope *Scope) m
return nil
}
- decls := make(map[string]*Decl, count)
+ decls := make(map[string]*decl, count)
for _, field := range f.List {
for _, name := range field.Names {
- if flags&DECL_FOREIGN != 0 && !ast.IsExported(name.Name) {
+ if flags&decl_foreign != 0 && !ast.IsExported(name.Name) {
continue
}
- d := &Decl{
- Name: name.Name,
- Type: field.Type,
- Class: int16(class),
- Flags: int16(flags),
- Scope: scope,
- ValueIndex: -1,
+ d := &decl{
+ name: name.Name,
+ typ: field.Type,
+ class: int16(class),
+ flags: int16(flags),
+ scope: scope,
+ value_index: -1,
}
- decls[d.Name] = d
+ decls[d.name] = d
}
// add anonymous field as a child (type embedding)
- if class == DECL_VAR && field.Names == nil {
- tp := typePath(field.Type)
- if flags&DECL_FOREIGN != 0 && !ast.IsExported(tp.name) {
+ if class == decl_var && field.Names == nil {
+ tp := get_type_path(field.Type)
+ if flags&decl_foreign != 0 && !ast.IsExported(tp.name) {
continue
}
- d := &Decl{
- Name: tp.name,
- Type: field.Type,
- Class: int16(class),
- Flags: int16(flags),
- Scope: scope,
- ValueIndex: -1,
+ d := &decl{
+ name: tp.name,
+ typ: field.Type,
+ class: int16(class),
+ flags: int16(flags),
+ scope: scope,
+ value_index: -1,
}
- decls[d.Name] = d
+ decls[d.name] = d
}
}
return decls
}
-func astFieldListToEmbedded(f *ast.FieldList) []ast.Expr {
+func ast_field_list_to_embedded(f *ast.FieldList) []ast.Expr {
count := 0
for _, field := range f.List {
if field.Names == nil || field.Names[0].Name == "?" {
@@ -196,37 +196,38 @@ func astFieldListToEmbedded(f *ast.FieldList) []ast.Expr {
return embedded
}
-func astTypeToEmbedded(ty ast.Expr) []ast.Expr {
+func ast_type_to_embedded(ty ast.Expr) []ast.Expr {
switch t := ty.(type) {
case *ast.StructType:
- return astFieldListToEmbedded(t.Fields)
+ return ast_field_list_to_embedded(t.Fields)
case *ast.InterfaceType:
- return astFieldListToEmbedded(t.Methods)
+ return ast_field_list_to_embedded(t.Methods)
}
return nil
}
-func astTypeToChildren(ty ast.Expr, flags int, scope *Scope) map[string]*Decl {
+func ast_type_to_children(ty ast.Expr, flags int, scope *scope) map[string]*decl {
switch t := ty.(type) {
case *ast.StructType:
- return astFieldListToDecls(t.Fields, DECL_VAR, flags, scope)
+ return ast_field_list_to_decls(t.Fields, decl_var, flags, scope)
case *ast.InterfaceType:
- return astFieldListToDecls(t.Methods, DECL_FUNC, flags, scope)
+ return ast_field_list_to_decls(t.Methods, decl_func, flags, scope)
}
return nil
}
//-------------------------------------------------------------------------
-// AnonymousIDGen
+// anonymous_id_gen
+//
// ID generator for anonymous types (thread-safe)
//-------------------------------------------------------------------------
-type AnonymousIDGen struct {
+type anonymous_id_gen struct {
sync.Mutex
i int
}
-func (a *AnonymousIDGen) Gen() (id int) {
+func (a *anonymous_id_gen) gen() (id int) {
a.Lock()
defer a.Unlock()
id = a.i
@@ -234,11 +235,11 @@ func (a *AnonymousIDGen) Gen() (id int) {
return
}
-var anonGen AnonymousIDGen
+var g_anon_gen anonymous_id_gen
//-------------------------------------------------------------------------
-func checkForAnonType(t ast.Expr, flags int, s *Scope) ast.Expr {
+func check_for_anon_type(t ast.Expr, flags int, s *scope) ast.Expr {
if t == nil {
return nil
}
@@ -246,15 +247,15 @@ func checkForAnonType(t ast.Expr, flags int, s *Scope) ast.Expr {
switch t.(type) {
case *ast.StructType:
- name = fmt.Sprintf("$s_%d", anonGen.Gen())
+ name = fmt.Sprintf("$s_%d", g_anon_gen.gen())
case *ast.InterfaceType:
- name = fmt.Sprintf("$i_%d", anonGen.Gen())
+ name = fmt.Sprintf("$i_%d", g_anon_gen.gen())
}
if name != "" {
- anonymifyAst(t, flags, s)
- d := NewDeclAnonType(name, flags, t, s)
- s.addNamedDecl(d)
+ anonymify_ast(t, flags, s)
+ d := new_decl_full(name, decl_type, flags, t, nil, -1, s)
+ s.add_named_decl(d)
return ast.NewIdent(name)
}
return t
@@ -262,87 +263,44 @@ func checkForAnonType(t ast.Expr, flags int, s *Scope) ast.Expr {
//-------------------------------------------------------------------------
-func NewDecl2(name string, class, flags int, typ, v ast.Expr, vi int, s *Scope) *Decl {
- d := new(Decl)
- d.Name = name
- d.Class = int16(class)
- d.Flags = int16(flags)
- d.Type = typ
- d.Value = v
- d.ValueIndex = vi
- d.Scope = s
- d.Children = astTypeToChildren(d.Type, flags, s)
- d.Embedded = astTypeToEmbedded(d.Type)
- return d
-}
-
-func NewDeclAnonType(name string, flags int, typ ast.Expr, s *Scope) *Decl {
- d := NewDecl(name, DECL_TYPE, s)
- d.Type = typ
- d.Flags = int16(flags)
- d.Children = astTypeToChildren(d.Type, flags, s)
- d.Embedded = astTypeToEmbedded(d.Type)
+func new_decl_full(name string, class, flags int, typ, v ast.Expr, vi int, s *scope) *decl {
+ d := new(decl)
+ d.name = name
+ d.class = int16(class)
+ d.flags = int16(flags)
+ d.typ = typ
+ d.value = v
+ d.value_index = vi
+ d.scope = s
+ d.children = ast_type_to_children(d.typ, flags, s)
+ d.embedded = ast_type_to_embedded(d.typ)
return d
}
-func NewDeclTyped(name string, class int, typ ast.Expr, scope *Scope) *Decl {
- d := NewDecl(name, class, scope)
- d.Type = typ
- return d
-}
-
-func NewDeclTypedNamed(name string, class int, typ string, scope *Scope) *Decl {
- d := NewDecl(name, class, scope)
- d.Type = ast.NewIdent(typ)
- return d
-}
-
-func NewDecl(name string, class int, scope *Scope) *Decl {
- decl := new(Decl)
- decl.Name = name
- decl.Class = int16(class)
- decl.ValueIndex = -1
- decl.Scope = scope
+func new_decl(name string, class int, scope *scope) *decl {
+ decl := new(decl)
+ decl.name = name
+ decl.class = int16(class)
+ decl.value_index = -1
+ decl.scope = scope
return decl
}
-func NewDeclVar(name string, typ ast.Expr, value ast.Expr, vindex int, scope *Scope) *Decl {
+func new_decl_var(name string, typ ast.Expr, value ast.Expr, vindex int, scope *scope) *decl {
if name == "_" {
return nil
}
- decl := new(Decl)
- decl.Name = name
- decl.Class = DECL_VAR
- decl.Type = typ
- decl.Value = value
- decl.ValueIndex = vindex
- decl.Scope = scope
+ decl := new(decl)
+ decl.name = name
+ decl.class = decl_var
+ decl.typ = typ
+ decl.value = value
+ decl.value_index = vindex
+ decl.scope = scope
return decl
}
-func NewDeclBuiltinError(scope *Scope) *Decl {
- d := NewDecl("error", DECL_TYPE, scope)
- d.Type = &ast.InterfaceType{}
- d.Children = make(map[string]*Decl)
- d.Children["Error"] = NewDeclTyped(
- "Error",
- DECL_FUNC,
- &ast.FuncType{
- Results: &ast.FieldList{
- List: []*ast.Field{
- {
- Type: ast.NewIdent("string"),
- },
- },
- },
- },
- scope,
- )
-
- return d
-}
-
-func MethodOf(d ast.Decl) string {
+func method_of(d ast.Decl) string {
if t, ok := d.(*ast.FuncDecl); ok {
if t.Recv != nil {
switch t := t.Recv.List[0].Type.(type) {
@@ -359,101 +317,102 @@ func MethodOf(d ast.Decl) string {
}
// complete copy
-func (d *Decl) Copy(other *Decl) {
- d.Name = other.Name
- d.Class = other.Class
- d.Type = other.Type
- d.Value = other.Value
- d.ValueIndex = other.ValueIndex
- d.Children = other.Children
- d.Embedded = other.Embedded
- d.Scope = other.Scope
-}
-
-func (other *Decl) DeepCopy() *Decl {
- d := new(Decl)
- d.Name = other.Name
- d.Class = other.Class
- d.Type = other.Type
- d.Value = other.Value
- d.ValueIndex = other.ValueIndex
- d.Children = make(map[string]*Decl, len(other.Children))
- for key, value := range other.Children {
- d.Children[key] = value
- }
- if other.Embedded != nil {
- d.Embedded = make([]ast.Expr, len(other.Embedded))
- copy(d.Embedded, other.Embedded)
- }
- d.Scope = other.Scope
+func (d *decl) copy(other *decl) {
+ // TODO: Go has struct assignment now, remove this
+ d.name = other.name
+ d.class = other.class
+ d.typ = other.typ
+ d.value = other.value
+ d.value_index = other.value_index
+ d.children = other.children
+ d.embedded = other.embedded
+ d.scope = other.scope
+}
+
+func (other *decl) deep_copy() *decl {
+ d := new(decl)
+ d.name = other.name
+ d.class = other.class
+ d.typ = other.typ
+ d.value = other.value
+ d.value_index = other.value_index
+ d.children = make(map[string]*decl, len(other.children))
+ for key, value := range other.children {
+ d.children[key] = value
+ }
+ if other.embedded != nil {
+ d.embedded = make([]ast.Expr, len(other.embedded))
+ copy(d.embedded, other.embedded)
+ }
+ d.scope = other.scope
return d
}
-func (d *Decl) ClassName() string {
- return declClassToString[d.Class]
+func (d *decl) class_name() string {
+ return g_decl_class_to_string[d.class]
}
-func (d *Decl) ExpandOrReplace(other *Decl) {
+func (d *decl) expand_or_replace(other *decl) {
// expand only if it's a methods stub, otherwise simply copy
- if d.Class != DECL_METHODS_STUB && other.Class != DECL_METHODS_STUB {
- d.Copy(other)
+ if d.class != decl_methods_stub && other.class != decl_methods_stub {
+ d.copy(other)
return
}
- if d.Class == DECL_METHODS_STUB {
- d.Type = other.Type
- d.Class = other.Class
+ if d.class == decl_methods_stub {
+ d.typ = other.typ
+ d.class = other.class
}
- if other.Children != nil {
- for _, c := range other.Children {
- d.AddChild(c)
+ if other.children != nil {
+ for _, c := range other.children {
+ d.add_child(c)
}
}