compiler: tweaks for importing inline function bodies

Track whether we've seen an error when importing a function; we will
use error tracking to avoid knock-on errors.

Stop importing identifiers at a ')'.

Provide a way to adjust the indentation level while importing.

Change-Id: I9cb1bbd999a9d414609ffc14a7eaae6af93fd862
Reviewed-on: https://go-review.googlesource.com/c/150072
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/go/import.cc b/go/import.cc
index eefee7c..d783043 100644
--- a/go/import.cc
+++ b/go/import.cc
@@ -1225,7 +1225,7 @@
   while (true)
     {
       c = stream->peek_char();
-      if (c == -1 || c == ' ' || c == '\n' || c == ';')
+      if (c == -1 || c == ' ' || c == '\n' || c == ';' || c == ')')
 	break;
       ret += c;
       stream->advance(1);
@@ -1450,7 +1450,7 @@
   for (size_t i = start; i < this->body_.length(); i++)
     {
       int c = static_cast<unsigned char>(this->body_[i]);
-      if (c == ' ' || c == '\n' || c == ';')
+      if (c == ' ' || c == '\n' || c == ';' || c == ')')
 	{
 	  this->off_ = i;
 	  return this->body_.substr(start, i - start);
diff --git a/go/import.h b/go/import.h
index e2f4e50..c46a37e 100644
--- a/go/import.h
+++ b/go/import.h
@@ -554,7 +554,7 @@
 		       const std::string& body, size_t off, Block* block,
 		       int indent)
     : gogo_(gogo), imp_(imp), named_object_(named_object), body_(body),
-      off_(off), block_(block), indent_(indent)
+      off_(off), block_(block), indent_(indent), saw_error_(false)
   { }
 
   // The IR.
@@ -597,6 +597,16 @@
   indent() const
   { return this->indent_; }
 
+  // Increment the indentation level.
+  void
+  increment_indent()
+  { ++this->indent_; }
+
+  // Decrement the indentation level.
+  void
+  decrement_indent()
+  { --this->indent_; }
+
   // The name of the function we are parsing.
   const std::string&
   name() const;
@@ -652,6 +662,16 @@
   ifb()
   { return this; }
 
+  // Return whether we have seen an error.
+  bool
+  saw_error() const
+  { return this->saw_error_; }
+
+  // Record that we have seen an error.
+  void
+  set_saw_error()
+  { this->saw_error_ = true; }
+
  private:
   // The IR.
   Gogo* gogo_;