diff 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
line wrap: on
line diff
--- a/gcc/go/gofrontend/import.h	Fri Oct 27 22:46:09 2017 +0900
+++ b/gcc/go/gofrontend/import.h	Thu Oct 25 07:37:49 2018 +0900
@@ -30,6 +30,11 @@
     Stream();
     virtual ~Stream();
 
+    // Set the position, for error messages.
+    void
+    set_pos(int pos)
+    { this->pos_ = pos; }
+
     // Return whether we have seen an error.
     bool
     saw_error() const
@@ -184,6 +189,15 @@
   advance(size_t skip)
   { this->stream_->advance(skip); }
 
+  // Skip a semicolon if using an older version.
+  void
+  require_semicolon_if_old_version()
+  {
+    if (this->version_ == EXPORT_FORMAT_V1
+	|| this->version_ == EXPORT_FORMAT_V2)
+      this->require_c_string(";");
+  }
+
   // Read an identifier.
   std::string
   read_identifier();
@@ -232,10 +246,18 @@
   void
   read_one_import();
 
+  // Read an indirectimport line.
+  void
+  read_one_indirect_import();
+
   // Read the import control functions and init graph.
   void
   read_import_init_fns(Gogo*);
 
+  // Read the types.
+  bool
+  read_types();
+
   // Import a constant.
   void
   import_const();
@@ -252,6 +274,14 @@
   Named_object*
   import_func(Package*);
 
+  // Parse a type definition.
+  bool
+  parse_type(int index);
+
+  // Read a named type and store it at this->type_[index].
+  Type*
+  read_named_type(int index);
+
   // Register a single builtin type.
   void
   register_builtin_type(Gogo*, const char* name, Builtin_code);
@@ -286,6 +316,12 @@
   // Whether to add new objects to the global scope, rather than to a
   // package scope.
   bool add_to_globals_;
+  // All type data.
+  std::string type_data_;
+  // Position of type data in the stream.
+  int type_pos_;
+  // Mapping from type code to offset/length in type_data_.
+  std::vector<std::pair<size_t, size_t> > type_offsets_;
   // Mapping from negated builtin type codes to Type structures.
   std::vector<Named_type*> builtin_types_;
   // Mapping from exported type codes to Type structures.
@@ -386,4 +422,41 @@
   std::string data_;
 };
 
+// Read import data from an offset into a std::string.  This uses a
+// reference to the string, to avoid copying, so the string must be
+// kept alive through some other mechanism.
+
+class Stream_from_string_ref : public Import::Stream
+{
+ public:
+  Stream_from_string_ref(const std::string& str, size_t offset, size_t length)
+    : str_(str), pos_(offset), end_(offset + length)
+  { }
+
+  ~Stream_from_string_ref()
+  {}
+
+ protected:
+  bool
+  do_peek(size_t length, const char** bytes)
+  {
+    if (this->pos_ + length > this->end_)
+      return false;
+    *bytes = &this->str_[this->pos_];
+    return true;
+  }
+
+  void
+  do_advance(size_t length)
+  { this->pos_ += length; }
+
+ private:
+  // A reference to the string we are reading from.
+  const std::string& str_;
+  // The current offset into the string.
+  size_t pos_;
+  // The index after the last byte we can read.
+  size_t end_;
+};
+
 #endif // !defined(GO_IMPORT_H)