1 // export.h -- Export declarations in Go frontend. -*- C++ -*-
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
10 #include "string-dump.h"
19 // Codes used for the builtin types. These are all negative to make
20 // them easily distinct from the codes assigned by Export::write_type.
21 // Note that these codes may not be changed! Changing them would
22 // break existing export data.
35 BUILTIN_FLOAT64
= -10,
38 BUILTIN_UINTPTR
= -13,
41 BUILTIN_COMPLEX64
= -17,
42 BUILTIN_COMPLEX128
= -18,
47 SMALLEST_BUILTIN_CODE
= -21
50 // This class manages exporting Go declarations. It handles the main
51 // loop of exporting. A pointer to this class is also passed to the
52 // various specific export implementations.
54 class Export
: public String_dump
57 // The Stream class is an interface used to output the exported
58 // information. The caller should instantiate a child of this
66 // Write a string. Implements the String_dump interface.
68 write_string(const std::string
& s
)
69 { this->write_and_sum_bytes(s
.data(), s
.length()); }
71 // Write a nul terminated string. Implements the String_dump interface.
73 write_c_string(const char* s
)
74 { this->write_and_sum_bytes(s
, strlen(s
)); }
78 write_bytes(const char* bytes
, size_t length
)
79 { this->write_and_sum_bytes(bytes
, length
); }
81 // Return the raw bytes of the checksum data.
85 // Write a checksum string to the stream. This will be called at
86 // the end of the other output.
88 write_checksum(const std::string
&);
91 // This function is called with data to export. This data must be
92 // made available as a contiguous stream for the importer.
94 do_write(const char* bytes
, size_t length
) = 0;
98 write_and_sum_bytes(const char*, size_t);
106 // The magic code for version 1 export data.
107 static const int v1_magic_len
= 4;
108 static const char v1_magic
[v1_magic_len
];
110 // The length of the v1 checksum string.
111 static const int v1_checksum_len
= 20;
113 // Register the builtin types.
115 register_builtin_types(Gogo
*);
117 // Export the identifiers in BINDINGS which are marked for export.
118 // The exporting is done via a series of calls to THIS->STREAM_. If
119 // is nothing to export, this->stream_->write will not be called.
120 // PREFIX is the package prefix. PKGPATH is the package path.
121 // Only one of PREFIX and PKGPATH will be non-empty.
122 // PACKAGE_PRIORITY is the priority to use for this package.
123 // PACKAGES is all the packages we have seen.
124 // IMPORTS is the explicitly imported packages.
125 // IMPORT_INIT_FN is the name of the import initialization function
126 // for this package; it will be empty if none is needed.
127 // IMPORTED_INIT_FNS is the list of initialization functions for
128 // imported packages.
130 export_globals(const std::string
& package_name
,
131 const std::string
& prefix
,
132 const std::string
& pkgpath
,
133 int package_priority
,
134 const std::map
<std::string
, Package
*>& packages
,
135 const std::map
<std::string
, Package
*>& imports
,
136 const std::string
& import_init_fn
,
137 const std::set
<Import_init
>& imported_init_fns
,
138 const Bindings
* bindings
);
140 // Write a string to the export stream.
142 write_string(const std::string
& s
)
143 { this->stream_
->write_string(s
); }
145 // Write a nul terminated string to the export stream.
147 write_c_string(const char* s
)
148 { this->stream_
->write_c_string(s
); }
150 // Write some bytes to the export stream.
152 write_bytes(const char* bytes
, size_t length
)
153 { this->stream_
->write_bytes(bytes
, length
); }
155 // Write a name to the export stream. If NAME is empty, write "?".
157 write_name(const std::string
& name
);
159 // Write out a type. This handles references back to previous
162 write_type(const Type
*);
165 Export(const Export
&);
166 Export
& operator=(const Export
&);
168 // Write out all known packages.
170 write_packages(const std::map
<std::string
, Package
*>& packages
);
172 // Write out the imported packages.
174 write_imports(const std::map
<std::string
, Package
*>& imports
);
176 // Write out the imported initialization functions.
178 write_imported_init_fns(const std::string
& package_name
, int priority
,
179 const std::string
&, const std::set
<Import_init
>&);
181 // Register one builtin type.
183 register_builtin_type(Gogo
*, const char* name
, Builtin_code
);
185 // Mapping from Type objects to a constant index.
186 typedef Unordered_map(const Type
*, int) Type_refs
;
188 // The stream to which we are writing data.
191 Type_refs type_refs_
;
192 // Index number of next type.
194 // Packages we have written out.
195 Unordered_set(const Package
*) packages_
;
198 // An export streamer which puts the export stream in a named section.
200 class Stream_to_section
: public Export::Stream
207 do_write(const char*, size_t);
210 #endif // !defined(GO_EXPORT_H)