OSDN Git Service

compiler: Change alias handling, change rune alias to int32.
[pf3gnuchains/gcc-fork.git] / gcc / go / gofrontend / import.cc
index ec27aba..de7edc9 100644 (file)
@@ -42,8 +42,8 @@ const char* const Import::import_marker = "*imported*";
 // returns a pointer to a Stream object to read the data that it
 // exports.  If the file is not found, it returns NULL.
 
-// When FILENAME is not an absolute path, we use the search path
-// provided by -I and -L options.
+// When FILENAME is not an absolute path and does not start with ./ or
+// ../, we use the search path provided by -I and -L options.
 
 // When FILENAME does not exist, we try modifying FILENAME to find the
 // file.  We use the first of these which exists:
@@ -59,9 +59,20 @@ const char* const Import::import_marker = "*imported*";
 // later in the search path.
 
 Import::Stream*
-Import::open_package(const std::string& filename, source_location location)
+Import::open_package(const std::string& filename, Location location)
 {
-  if (!IS_ABSOLUTE_PATH(filename))
+  bool is_local;
+  if (IS_ABSOLUTE_PATH(filename))
+    is_local = true;
+  else if (filename[0] == '.' && IS_DIR_SEPARATOR(filename[1]))
+    is_local = true;
+  else if (filename[0] == '.'
+          && filename[1] == '.'
+          && IS_DIR_SEPARATOR(filename[2]))
+    is_local = true;
+  else
+    is_local = false;
+  if (!is_local)
     {
       for (std::vector<std::string>::const_iterator p = search_path.begin();
           p != search_path.end();
@@ -88,7 +99,7 @@ Import::open_package(const std::string& filename, source_location location)
 
 Import::Stream*
 Import::try_package_in_directory(const std::string& filename,
-                                source_location location)
+                                Location location)
 {
   std::string found_filename = filename;
   int fd = open(found_filename.c_str(), O_RDONLY | O_BINARY);
@@ -175,7 +186,7 @@ Import::try_suffixes(std::string* pfilename)
 
 Import::Stream*
 Import::find_export_data(const std::string& filename, int fd,
-                        source_location location)
+                        Location location)
 {
   // See if we can read this as an object file.
   Import::Stream* stream = Import::find_object_export_data(filename, fd, 0,
@@ -213,48 +224,26 @@ Import::Stream*
 Import::find_object_export_data(const std::string& filename,
                                int fd,
                                off_t offset,
-                               source_location location)
+                               Location location)
 {
-  const char* errmsg;
+  char *buf;
+  size_t len;
   int err;
-  simple_object_read* sobj = simple_object_start_read(fd, offset,
-                                                     "__GNU_GO",
-                                                     &errmsg, &err);
-  if (sobj == NULL)
-    return NULL;
-
-  off_t sec_offset;
-  off_t sec_length;
-  int found = simple_object_find_section(sobj, ".go_export", &sec_offset,
-                                        &sec_length, &errmsg, &err);
-
-  simple_object_release_read(sobj);
-
-  if (!found)
-    return NULL;
-
-  if (lseek(fd, offset + sec_offset, SEEK_SET) < 0)
+  const char *errmsg = go_read_export_data(fd, offset, &buf, &len, &err);
+  if (errmsg != NULL)
     {
-      error_at(location, "lseek %s failed: %m", filename.c_str());
+      if (err == 0)
+       error_at(location, "%s: %s", filename.c_str(), errmsg);
+      else
+       error_at(location, "%s: %s: %s", filename.c_str(), errmsg,
+                xstrerror(err));
       return NULL;
     }
 
-  char* buf = new char[sec_length];
-  ssize_t c = read(fd, buf, sec_length);
-  if (c < 0)
-    {
-      error_at(location, "read %s failed: %m", filename.c_str());
-      delete[] buf;
-      return NULL;
-    }
-  if (c < sec_length)
-    {
-      error_at(location, "%s: short read", filename.c_str());
-      delete[] buf;
-      return NULL;
-    }
+  if (buf == NULL)
+    return NULL;
 
-  return new Stream_from_buffer(buf, sec_length);
+  return new Stream_from_buffer(buf, len);
 }
 
 // Class Import.
@@ -262,7 +251,7 @@ Import::find_object_export_data(const std::string& filename,
 // Construct an Import object.  We make the builtin_types_ vector
 // large enough to hold all the builtin types.
 
-Import::Import(Stream* stream, source_location location)
+Import::Import(Stream* stream, Location location)
   : gogo_(NULL), stream_(stream), location_(location), package_(NULL),
     add_to_globals_(false),
     builtin_types_((- SMALLEST_BUILTIN_CODE) + 1),
@@ -448,7 +437,7 @@ Import::import_func(Package* package)
   if (is_varargs)
     fntype->set_is_varargs();
 
-  source_location loc = this->location_;
+  Location loc = this->location_;
   Named_object* no;
   if (fntype->is_method())
     {
@@ -456,7 +445,7 @@ Import::import_func(Package* package)
       if (rtype->is_error_type())
        return NULL;
       Named_type* named_rtype = rtype->named_type();
-      gcc_assert(named_rtype != NULL);
+      go_assert(named_rtype != NULL);
       no = named_rtype->add_method_declaration(name, package, fntype, loc);
     }
   else
@@ -603,7 +592,7 @@ Import::read_type()
     package = this->package_;
   else
     package = this->gogo_->register_package(package_name, unique_prefix,
-                                           UNKNOWN_LOCATION);
+                                           Linemap::unknown_location());
 
   Named_object* no = package->bindings()->lookup(type_name);
   if (no == NULL)
@@ -617,7 +606,7 @@ Import::read_type()
       return Type::make_error_type();
     }
   else
-    gcc_assert(no->package() == package);
+    go_assert(no->package() == package);
 
   if (this->types_[index] == NULL)
     {
@@ -628,7 +617,7 @@ Import::read_type()
        }
       else
        {
-         gcc_assert(no->is_type());
+         go_assert(no->is_type());
          this->types_[index] = no->type_value();
        }
     }
@@ -704,10 +693,11 @@ Import::register_builtin_types(Gogo* gogo)
   this->register_builtin_type(gogo, "int", BUILTIN_INT);
   this->register_builtin_type(gogo, "uint", BUILTIN_UINT);
   this->register_builtin_type(gogo, "uintptr", BUILTIN_UINTPTR);
-  this->register_builtin_type(gogo, "float", BUILTIN_FLOAT);
-  this->register_builtin_type(gogo, "complex", BUILTIN_COMPLEX);
   this->register_builtin_type(gogo, "bool", BUILTIN_BOOL);
   this->register_builtin_type(gogo, "string", BUILTIN_STRING);
+  this->register_builtin_type(gogo, "error", BUILTIN_ERROR);
+  this->register_builtin_type(gogo, "byte", BUILTIN_BYTE);
+  this->register_builtin_type(gogo, "rune", BUILTIN_RUNE);
 }
 
 // Register a single builtin type.
@@ -716,9 +706,9 @@ void
 Import::register_builtin_type(Gogo* gogo, const char* name, Builtin_code code)
 {
   Named_object* named_object = gogo->lookup_global(name);
-  gcc_assert(named_object != NULL && named_object->is_type());
+  go_assert(named_object != NULL && named_object->is_type());
   int index = - static_cast<int>(code);
-  gcc_assert(index > 0
+  go_assert(index > 0
             && static_cast<size_t>(index) < this->builtin_types_.size());
   this->builtin_types_[index] = named_object->type_value();
 }
@@ -800,7 +790,7 @@ Import::Stream::match_bytes(const char* bytes, size_t length)
 // Require that the next LENGTH bytes from the stream match BYTES.
 
 void
-Import::Stream::require_bytes(source_location location, const char* bytes,
+Import::Stream::require_bytes(Location location, const char* bytes,
                              size_t length)
 {
   const char* read;
@@ -844,7 +834,7 @@ Stream_from_file::do_peek(size_t length, const char** bytes)
       return true;
     }
   // Don't bother to handle the general case, since we don't need it.
-  gcc_assert(length < 64);
+  go_assert(length < 64);
   char buf[64];
   ssize_t got = read(this->fd_, buf, length);