(data []byte)
| 94 | } |
| 95 | |
| 96 | func (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 |
no test coverage detected