comparison gcc/go/gofrontend/import.h @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
27 class Stream 27 class Stream
28 { 28 {
29 public: 29 public:
30 Stream(); 30 Stream();
31 virtual ~Stream(); 31 virtual ~Stream();
32
33 // Set the position, for error messages.
34 void
35 set_pos(int pos)
36 { this->pos_ = pos; }
32 37
33 // Return whether we have seen an error. 38 // Return whether we have seen an error.
34 bool 39 bool
35 saw_error() const 40 saw_error() const
36 { return this->saw_error_; } 41 { return this->saw_error_; }
182 // Advance the stream SKIP bytes. 187 // Advance the stream SKIP bytes.
183 void 188 void
184 advance(size_t skip) 189 advance(size_t skip)
185 { this->stream_->advance(skip); } 190 { this->stream_->advance(skip); }
186 191
192 // Skip a semicolon if using an older version.
193 void
194 require_semicolon_if_old_version()
195 {
196 if (this->version_ == EXPORT_FORMAT_V1
197 || this->version_ == EXPORT_FORMAT_V2)
198 this->require_c_string(";");
199 }
200
187 // Read an identifier. 201 // Read an identifier.
188 std::string 202 std::string
189 read_identifier(); 203 read_identifier();
190 204
191 // Read a name. This is like read_identifier, except that a "?" is 205 // Read a name. This is like read_identifier, except that a "?" is
230 244
231 // Read an import line. 245 // Read an import line.
232 void 246 void
233 read_one_import(); 247 read_one_import();
234 248
249 // Read an indirectimport line.
250 void
251 read_one_indirect_import();
252
235 // Read the import control functions and init graph. 253 // Read the import control functions and init graph.
236 void 254 void
237 read_import_init_fns(Gogo*); 255 read_import_init_fns(Gogo*);
256
257 // Read the types.
258 bool
259 read_types();
238 260
239 // Import a constant. 261 // Import a constant.
240 void 262 void
241 import_const(); 263 import_const();
242 264
249 import_var(); 271 import_var();
250 272
251 // Import a function. 273 // Import a function.
252 Named_object* 274 Named_object*
253 import_func(Package*); 275 import_func(Package*);
276
277 // Parse a type definition.
278 bool
279 parse_type(int index);
280
281 // Read a named type and store it at this->type_[index].
282 Type*
283 read_named_type(int index);
254 284
255 // Register a single builtin type. 285 // Register a single builtin type.
256 void 286 void
257 register_builtin_type(Gogo*, const char* name, Builtin_code); 287 register_builtin_type(Gogo*, const char* name, Builtin_code);
258 288
284 // The package we are importing. 314 // The package we are importing.
285 Package* package_; 315 Package* package_;
286 // Whether to add new objects to the global scope, rather than to a 316 // Whether to add new objects to the global scope, rather than to a
287 // package scope. 317 // package scope.
288 bool add_to_globals_; 318 bool add_to_globals_;
319 // All type data.
320 std::string type_data_;
321 // Position of type data in the stream.
322 int type_pos_;
323 // Mapping from type code to offset/length in type_data_.
324 std::vector<std::pair<size_t, size_t> > type_offsets_;
289 // Mapping from negated builtin type codes to Type structures. 325 // Mapping from negated builtin type codes to Type structures.
290 std::vector<Named_type*> builtin_types_; 326 std::vector<Named_type*> builtin_types_;
291 // Mapping from exported type codes to Type structures. 327 // Mapping from exported type codes to Type structures.
292 std::vector<Type*> types_; 328 std::vector<Type*> types_;
293 // Version of export data we're reading. 329 // Version of export data we're reading.
384 int fd_; 420 int fd_;
385 // Data read from the file. 421 // Data read from the file.
386 std::string data_; 422 std::string data_;
387 }; 423 };
388 424
425 // Read import data from an offset into a std::string. This uses a
426 // reference to the string, to avoid copying, so the string must be
427 // kept alive through some other mechanism.
428
429 class Stream_from_string_ref : public Import::Stream
430 {
431 public:
432 Stream_from_string_ref(const std::string& str, size_t offset, size_t length)
433 : str_(str), pos_(offset), end_(offset + length)
434 { }
435
436 ~Stream_from_string_ref()
437 {}
438
439 protected:
440 bool
441 do_peek(size_t length, const char** bytes)
442 {
443 if (this->pos_ + length > this->end_)
444 return false;
445 *bytes = &this->str_[this->pos_];
446 return true;
447 }
448
449 void
450 do_advance(size_t length)
451 { this->pos_ += length; }
452
453 private:
454 // A reference to the string we are reading from.
455 const std::string& str_;
456 // The current offset into the string.
457 size_t pos_;
458 // The index after the last byte we can read.
459 size_t end_;
460 };
461
389 #endif // !defined(GO_IMPORT_H) 462 #endif // !defined(GO_IMPORT_H)