do_dump_statement(Ast_dump_context*) const;
};
+//
+// Helper to tack on available source position information
+// at the end of a statement.
+//
+static std::string
+dsuffix(Location location)
+{
+ std::string lstr = Linemap::location_to_string(location);
+ if (lstr == "")
+ return lstr;
+ std::string rval(" // ");
+ rval += lstr;
+ return rval;
+}
+
// Dump the AST representation for an error statement.
void
ast_dump_context->ostream() << "= ";
ast_dump_context->dump_expression(var->init());
}
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make a variable declaration.
ast_dump_context->ostream() << " = ";
ast_dump_context->dump_expression(this->init_);
}
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make and initialize a temporary variable in BLOCK.
ast_dump_context->dump_expression(this->lhs_);
ast_dump_context->ostream() << " = " ;
ast_dump_context->dump_expression(this->rhs_);
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make an assignment statement.
ast_dump_context->dump_expression(this->lhs_);
ast_dump_context->dump_operator(this->op_);
ast_dump_context->dump_expression(this->rhs_);
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make an assignment operation statement.
ast_dump_context->dump_expression_list(this->lhs_);
ast_dump_context->ostream() << " = ";
ast_dump_context->dump_expression_list(this->rhs_);
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make a tuple assignment statement.
ast_dump_context->dump_expression(this->present_);
ast_dump_context->ostream() << " = ";
ast_dump_context->dump_expression(this->map_index_);
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make a map assignment statement which returns a pair of values.
ast_dump_context->dump_expression(this->closed_);
ast_dump_context->ostream() << " <- ";
ast_dump_context->dump_expression(this->channel_);
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make a nonblocking receive statement.
ast_dump_context->dump_expression(this->expr_);
ast_dump_context->ostream() << " . ";
ast_dump_context->dump_type(this->type_);
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make an assignment from a type guard to a pair of variables.
{
ast_dump_context->print_indent();
ast_dump_context->dump_expression(expr_);
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make an expression statement from an Expression.
{
ast_dump_context->print_indent();
ast_dump_context->dump_expression(expr_);
- ast_dump_context->ostream() << (is_inc_? "++": "--") << std::endl;
+ ast_dump_context->ostream() << (is_inc_? "++": "--") << dsuffix(location()) << std::endl;
}
// Make an increment statement.
ast_dump_context->print_indent();
ast_dump_context->ostream() << "go ";
ast_dump_context->dump_expression(this->call());
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make a go statement.
ast_dump_context->print_indent();
ast_dump_context->ostream() << "defer ";
ast_dump_context->dump_expression(this->call());
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make a defer statement.
ast_dump_context->print_indent();
ast_dump_context->ostream() << "return " ;
ast_dump_context->dump_expression_list(this->vals_);
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make a return statement.
ast_dump_context->ostream() << " ";
ast_dump_context->dump_label_name(this->label_);
}
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make a break statement.
Goto_statement::do_dump_statement(Ast_dump_context* ast_dump_context) const
{
ast_dump_context->print_indent();
- ast_dump_context->ostream() << "goto " << this->label_->name() << std::endl;
+ ast_dump_context->ostream() << "goto " << this->label_->name() << dsuffix(location()) << std::endl;
}
// Make a goto statement.
ast_dump_context->print_indent();
ast_dump_context->ostream() << "goto ";
ast_dump_context->dump_label_name(this->label_);
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make a goto statement to an unnamed label.
Label_statement::do_dump_statement(Ast_dump_context* ast_dump_context) const
{
ast_dump_context->print_indent();
- ast_dump_context->ostream() << this->label_->name() << ":" << std::endl;
+ ast_dump_context->ostream() << this->label_->name() << ":" << dsuffix(location()) << std::endl;
}
// Make a label statement.
{
ast_dump_context->print_indent();
ast_dump_context->dump_label_name(this->label_);
- ast_dump_context->ostream() << ":" << std::endl;
+ ast_dump_context->ostream() << ":" << dsuffix(location()) << std::endl;
}
// Make an unnamed label statement.
ast_dump_context->print_indent();
ast_dump_context->ostream() << "if ";
ast_dump_context->dump_expression(this->cond_);
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
if (ast_dump_context->dump_subblocks())
{
ast_dump_context->dump_block(this->then_block_);
if (this->is_fallthrough_)
{
ast_dump_context->print_indent();
- ast_dump_context->ostream() << " (fallthrough)" << std::endl;
+ ast_dump_context->ostream() << " (fallthrough)" << dsuffix(location()) << std::endl;
}
}
}
if (ast_dump_context->dump_subblocks())
{
- ast_dump_context->ostream() << " {" << std::endl;
+ ast_dump_context->ostream() << " {" << dsuffix(location()) << std::endl;
this->clauses_->dump_clauses(ast_dump_context);
ast_dump_context->print_indent();
ast_dump_context->ostream() << "}";
ast_dump_context->ostream() << " .(type)";
if (ast_dump_context->dump_subblocks())
{
- ast_dump_context->ostream() << " {" << std::endl;
+ ast_dump_context->ostream() << " {" << dsuffix(location()) << std::endl;
this->clauses_->dump_clauses(ast_dump_context);
ast_dump_context->ostream() << "}";
}
ast_dump_context->dump_expression(this->channel_);
ast_dump_context->ostream() << " <- ";
ast_dump_context->dump_expression(this->val_);
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make a send statement.
ast_dump_context->ostream() << "select";
if (ast_dump_context->dump_subblocks())
{
- ast_dump_context->ostream() << " {" << std::endl;
+ ast_dump_context->ostream() << " {" << dsuffix(location()) << std::endl;
this->clauses_->dump_clauses(ast_dump_context);
ast_dump_context->ostream() << "}";
}
ast_dump_context->ostream() << "}";
}
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make a for statement.
ast_dump_context->print_indent();
ast_dump_context->ostream() << "}";
}
- ast_dump_context->ostream() << std::endl;
+ ast_dump_context->ostream() << dsuffix(location()) << std::endl;
}
// Make a for statement with a range clause.