MCPcopy Create free account
hub / github.com/nsf/gocode / process_package_data

Method process_package_data

package.go:96–167  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

94}
95
96func (m *package_file_cache) process_package_data(data []byte) {
97 m.scope = new_named_scope(g_universe_scope, m.name)
98
99 // find import section
100 i := bytes.Index(data, []byte{'\n', '$', '$'})
101 if i == -1 {
102 panic(fmt.Sprintf("Can't find the import section in the package file %s", m.name))
103 }
104 data = data[i+len("\n$$"):]
105
106 // main package
107 m.main = new_decl(m.name, decl_package, nil)
108 // create map for other packages
109 m.others = make(map[string]*decl)
110
111 var pp package_parser
112 if data[0] == 'B' {
113 // binary format, skip 'B\n'
114 data = data[2:]
115 if len(data) > 0 && data[0] == 'i' {
116 var p gc_ibin_parser
117 p.init(data[1:], m)
118 pp = &p
119 } else {
120 var p gc_bin_parser
121 p.init(data, m)
122 pp = &p
123 }
124 } else {
125 // textual format, find the beginning of the package clause
126 i = bytes.Index(data, []byte{'p', 'a', 'c', 'k', 'a', 'g', 'e'})
127 if i == -1 {
128 panic("Can't find the package clause")
129 }
130 data = data[i:]
131
132 var p gc_parser
133 p.init(data, m)
134 pp = &p
135 }
136
137 prefix := "!" + m.name + "!"
138 pp.parse_export(func(pkg string, decl ast.Decl) {
139 anonymify_ast(decl, decl_foreign, m.scope)
140 if pkg == "" || strings.HasPrefix(pkg, prefix) {
141 // main package
142 add_ast_decl_to_package(m.main, decl, m.scope)
143 } else {
144 // others
145 if _, ok := m.others[pkg]; !ok {
146 m.others[pkg] = new_decl(pkg, decl_package, nil)
147 }
148 add_ast_decl_to_package(m.others[pkg], decl, m.scope)
149 }
150 })
151
152 // hack, add ourselves to the package scope
153 mainName := "!" + m.name + "!" + m.defalias

Callers 2

update_cacheMethod · 0.95

Calls 8

initMethod · 0.95
parse_exportMethod · 0.95
add_package_to_scopeMethod · 0.95
new_named_scopeFunction · 0.85
new_declFunction · 0.85
anonymify_astFunction · 0.85
add_ast_decl_to_packageFunction · 0.85
replace_declMethod · 0.80

Tested by

no test coverage detected