// Class Import_function_body.
+Import_function_body::Import_function_body(Gogo* gogo,
+ Import* imp,
+ Named_object* named_object,
+ const std::string& body,
+ size_t off,
+ Block* block,
+ int indent)
+ : gogo_(gogo), imp_(imp), named_object_(named_object), body_(body),
+ off_(off), indent_(indent), temporaries_(), labels_(),
+ saw_error_(false)
+{
+ this->blocks_.push_back(block);
+}
+
+Import_function_body::~Import_function_body()
+{
+ // At this point we should be left with the original outer block only.
+ go_assert(saw_errors() || this->blocks_.size() == 1);
+}
+
// The name of the function we are parsing.
const std::string&
public:
Import_function_body(Gogo* gogo, Import* imp, Named_object* named_object,
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), temporaries_(), labels_(),
- saw_error_(false)
- { }
+ int indent);
+ ~Import_function_body();
// The IR.
Gogo*
// The current block.
Block*
block()
- { return this->block_; }
+ { return this->blocks_.back(); }
+
+ // Begin importing a new block BLOCK nested within the current block.
+ void
+ begin_block(Block *block)
+ { this->blocks_.push_back(block); }
+
+ // Record the fact that we're done importing the current block.
+ void
+ finish_block()
+ { this->blocks_.pop_back(); }
// The current indentation.
int
const std::string& body_;
// The current offset into body_.
size_t off_;
- // Current block.
- Block* block_;
+ // Stack to record nesting of blocks being imported.
+ std::vector<Block *> blocks_;
// Current expected indentation level.
int indent_;
// Temporary statements by index.