Commit 26409c52 by Ian Lance Taylor Committed by Ian Lance Taylor

Define go_assert to replace gcc_assert

This is defined in go-system.h in the backend.

	* go-system.h (go_assert, go_unreachable): Define.

From-SVN: r172846
parent 3a6448ea
2011-04-21 Ian Lance Taylor <iant@google.com>
* go-system.h (go_assert, go_unreachable): Define.
2011-04-19 Ian Lance Taylor <iant@google.com>
* go-system.h: Include "intl.h".
......
......@@ -151,4 +151,10 @@ extern "C"
} // End extern "C"
#endif
// When using gcc, go_assert is just gcc_assert.
#define go_assert(EXPR) gcc_assert(EXPR)
// When using gcc, go_unreachable is just gcc_unreachable.
#define go_unreachable() gcc_unreachable()
#endif // !defined(GO_SYSTEM_H)
......@@ -24,7 +24,7 @@ Issues to be faced in this transition:
features such as %<%> for appropriate quoting.
+ Localization may be an issue.
* Use of gcc_assert and gcc_unreachable.
* Use of gcc_unreachable.
This compiler works, but the code is a work in progress. Notably, the
support for garbage collection is ineffective and needs a complete
......
......@@ -49,7 +49,7 @@ get_var(Expression* expr)
if (ve == NULL)
return NULL;
Named_object* no = ve->named_object();
gcc_assert(no->is_variable() || no->is_result_variable());
go_assert(no->is_variable() || no->is_result_variable());
if (no->is_variable() && no->var_value()->is_global())
return NULL;
return no;
......@@ -103,7 +103,7 @@ Dataflow_traverse_assignment::initialize_variable(Named_object* var)
{
Expression* e = init;
this->value(&e, true, true);
gcc_assert(e == init);
go_assert(e == init);
}
}
......
......@@ -266,7 +266,7 @@ Export::write_type(const Type* type)
{
// This type was already in the table.
int index = p->second;
gcc_assert(index != 0);
go_assert(index != 0);
char buf[30];
snprintf(buf, sizeof buf, "<type %d>", index);
this->write_c_string(buf);
......@@ -289,7 +289,7 @@ Export::write_type(const Type* type)
if (named_type != NULL)
{
// The builtin types should have been predefined.
gcc_assert(named_type->location() != BUILTINS_LOCATION
go_assert(named_type->location() != BUILTINS_LOCATION
|| (named_type->named_object()->package()->name()
== "unsafe"));
named_object = named_type->named_object();
......@@ -355,16 +355,16 @@ void
Export::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());
std::pair<Type_refs::iterator, bool> ins =
this->type_refs_.insert(std::make_pair(named_object->type_value(), code));
gcc_assert(ins.second);
go_assert(ins.second);
// We also insert the underlying type. We can see the underlying
// type at least for string and bool.
Type* real_type = named_object->type_value()->real_type();
ins = this->type_refs_.insert(std::make_pair(real_type, code));
gcc_assert(ins.second);
go_assert(ins.second);
}
// Class Export::Stream.
......@@ -428,7 +428,7 @@ Stream_to_section::do_write(const char* bytes, size_t length)
section* sec = (section*) this->section_;
if (sec == NULL)
{
gcc_assert(targetm.have_named_sections);
go_assert(targetm.have_named_sections);
sec = get_section(".go_export", SECTION_DEBUG, NULL);
this->section_ = (void*) sec;
......
......@@ -1641,7 +1641,7 @@ class Field_reference_expression : public Expression
void
set_struct_expression(Expression* expr)
{
gcc_assert(this->expr_ == NULL);
go_assert(this->expr_ == NULL);
this->expr_ = expr;
}
......
......@@ -27,7 +27,7 @@ GO_EXTERN_C
void
go_create_gogo(int int_type_size, int pointer_size)
{
gcc_assert(::gogo == NULL);
go_assert(::gogo == NULL);
::gogo = new Gogo(go_get_backend(), int_type_size, pointer_size);
if (!unique_prefix.empty())
::gogo->set_unique_prefix(unique_prefix);
......@@ -60,7 +60,7 @@ void
go_parse_input_files(const char** filenames, unsigned int filename_count,
bool only_check_syntax, bool require_return_statement)
{
gcc_assert(filename_count > 0);
go_assert(filename_count > 0);
for (unsigned int i = 0; i < filename_count; ++i)
{
if (i > 0)
......
......@@ -156,7 +156,7 @@ class Gogo
static std::string
hidden_name_prefix(const std::string& name)
{
gcc_assert(Gogo::is_hidden_name(name));
go_assert(Gogo::is_hidden_name(name));
return name.substr(1, name.rfind('.') - 1);
}
......@@ -819,7 +819,7 @@ class Function
void
set_enclosing(Function* enclosing)
{
gcc_assert(this->enclosing_ == NULL);
go_assert(this->enclosing_ == NULL);
this->enclosing_ = enclosing;
}
......@@ -865,7 +865,7 @@ class Function
void
set_closure_var(Named_object* v)
{
gcc_assert(this->closure_var_ == NULL);
go_assert(this->closure_var_ == NULL);
this->closure_var_ = v;
}
......@@ -874,7 +874,7 @@ class Function
Named_object*
enclosing_var(unsigned int index)
{
gcc_assert(index < this->closure_fields_.size());
go_assert(index < this->closure_fields_.size());
return closure_fields_[index].first;
}
......@@ -961,7 +961,7 @@ class Function
tree
get_decl() const
{
gcc_assert(this->fndecl_ != NULL);
go_assert(this->fndecl_ != NULL);
return this->fndecl_;
}
......@@ -1147,7 +1147,7 @@ class Variable
void
set_is_receiver()
{
gcc_assert(this->is_parameter_);
go_assert(this->is_parameter_);
this->is_receiver_ = true;
}
......@@ -1156,7 +1156,7 @@ class Variable
void
set_is_not_receiver()
{
gcc_assert(this->is_parameter_);
go_assert(this->is_parameter_);
this->is_receiver_ = false;
}
......@@ -1184,7 +1184,7 @@ class Variable
void
set_is_varargs_parameter()
{
gcc_assert(this->is_parameter_);
go_assert(this->is_parameter_);
this->is_varargs_parameter_ = true;
}
......@@ -1250,7 +1250,7 @@ class Variable
void
clear_type_from_chan_element()
{
gcc_assert(this->type_from_chan_element_);
go_assert(this->type_from_chan_element_);
this->type_from_chan_element_ = false;
}
......@@ -1722,126 +1722,126 @@ class Named_object
Unknown_name*
unknown_value()
{
gcc_assert(this->classification_ == NAMED_OBJECT_UNKNOWN);
go_assert(this->classification_ == NAMED_OBJECT_UNKNOWN);
return this->u_.unknown_value;
}
const Unknown_name*
unknown_value() const
{
gcc_assert(this->classification_ == NAMED_OBJECT_UNKNOWN);
go_assert(this->classification_ == NAMED_OBJECT_UNKNOWN);
return this->u_.unknown_value;
}
Named_constant*
const_value()
{
gcc_assert(this->classification_ == NAMED_OBJECT_CONST);
go_assert(this->classification_ == NAMED_OBJECT_CONST);
return this->u_.const_value;
}
const Named_constant*
const_value() const
{
gcc_assert(this->classification_ == NAMED_OBJECT_CONST);
go_assert(this->classification_ == NAMED_OBJECT_CONST);
return this->u_.const_value;
}
Named_type*
type_value()
{
gcc_assert(this->classification_ == NAMED_OBJECT_TYPE);
go_assert(this->classification_ == NAMED_OBJECT_TYPE);
return this->u_.type_value;
}
const Named_type*
type_value() const
{
gcc_assert(this->classification_ == NAMED_OBJECT_TYPE);
go_assert(this->classification_ == NAMED_OBJECT_TYPE);
return this->u_.type_value;
}
Type_declaration*
type_declaration_value()
{
gcc_assert(this->classification_ == NAMED_OBJECT_TYPE_DECLARATION);
go_assert(this->classification_ == NAMED_OBJECT_TYPE_DECLARATION);
return this->u_.type_declaration;
}
const Type_declaration*
type_declaration_value() const
{
gcc_assert(this->classification_ == NAMED_OBJECT_TYPE_DECLARATION);
go_assert(this->classification_ == NAMED_OBJECT_TYPE_DECLARATION);
return this->u_.type_declaration;
}
Variable*
var_value()
{
gcc_assert(this->classification_ == NAMED_OBJECT_VAR);
go_assert(this->classification_ == NAMED_OBJECT_VAR);
return this->u_.var_value;
}
const Variable*
var_value() const
{
gcc_assert(this->classification_ == NAMED_OBJECT_VAR);
go_assert(this->classification_ == NAMED_OBJECT_VAR);
return this->u_.var_value;
}
Result_variable*
result_var_value()
{
gcc_assert(this->classification_ == NAMED_OBJECT_RESULT_VAR);
go_assert(this->classification_ == NAMED_OBJECT_RESULT_VAR);
return this->u_.result_var_value;
}
const Result_variable*
result_var_value() const
{
gcc_assert(this->classification_ == NAMED_OBJECT_RESULT_VAR);
go_assert(this->classification_ == NAMED_OBJECT_RESULT_VAR);
return this->u_.result_var_value;
}
Function*
func_value()
{
gcc_assert(this->classification_ == NAMED_OBJECT_FUNC);
go_assert(this->classification_ == NAMED_OBJECT_FUNC);
return this->u_.func_value;
}
const Function*
func_value() const
{
gcc_assert(this->classification_ == NAMED_OBJECT_FUNC);
go_assert(this->classification_ == NAMED_OBJECT_FUNC);
return this->u_.func_value;
}
Function_declaration*
func_declaration_value()
{
gcc_assert(this->classification_ == NAMED_OBJECT_FUNC_DECLARATION);
go_assert(this->classification_ == NAMED_OBJECT_FUNC_DECLARATION);
return this->u_.func_declaration_value;
}
const Function_declaration*
func_declaration_value() const
{
gcc_assert(this->classification_ == NAMED_OBJECT_FUNC_DECLARATION);
go_assert(this->classification_ == NAMED_OBJECT_FUNC_DECLARATION);
return this->u_.func_declaration_value;
}
Package*
package_value()
{
gcc_assert(this->classification_ == NAMED_OBJECT_PACKAGE);
go_assert(this->classification_ == NAMED_OBJECT_PACKAGE);
return this->u_.package_value;
}
const Package*
package_value() const
{
gcc_assert(this->classification_ == NAMED_OBJECT_PACKAGE);
go_assert(this->classification_ == NAMED_OBJECT_PACKAGE);
return this->u_.package_value;
}
......@@ -2174,7 +2174,7 @@ class Label
void
define(source_location location)
{
gcc_assert(this->location_ == 0);
go_assert(this->location_ == 0);
this->location_ = location;
}
......@@ -2263,7 +2263,7 @@ class Package
const std::string&
unique_prefix() const
{
gcc_assert(!this->unique_prefix_.empty());
go_assert(!this->unique_prefix_.empty());
return this->unique_prefix_;
}
......
......@@ -456,7 +456,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
......@@ -617,7 +617,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 +628,7 @@ Import::read_type()
}
else
{
gcc_assert(no->is_type());
go_assert(no->is_type());
this->types_[index] = no->type_value();
}
}
......@@ -714,9 +714,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();
}
......@@ -842,7 +842,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);
......
......@@ -132,9 +132,9 @@ Keywords::keyword_to_code(const char* keyword, size_t len) const
const char*
Keywords::keyword_to_string(Keyword code) const
{
gcc_assert(code > KEYWORD_INVALID && code < this->count_);
go_assert(code > KEYWORD_INVALID && code < this->count_);
const Mapping* map = &this->mapping_[code];
gcc_assert(map->keycode == code);
go_assert(map->keycode == code);
return map->keystring;
}
......@@ -1005,7 +1005,7 @@ Lex::gather_number()
std::string s(pnum, p - pnum);
mpz_t val;
int r = mpz_init_set_str(val, s.c_str(), base);
gcc_assert(r == 0);
go_assert(r == 0);
if (neg)
mpz_neg(val, val);
......@@ -1029,7 +1029,7 @@ Lex::gather_number()
std::string s(pnum, p - pnum);
mpz_t val;
int r = mpz_init_set_str(val, s.c_str(), 10);
gcc_assert(r == 0);
go_assert(r == 0);
if (neg)
mpz_neg(val, val);
......@@ -1076,7 +1076,7 @@ Lex::gather_number()
std::string s(pnum, p - pnum);
mpfr_t val;
int r = mpfr_init_set_str(val, s.c_str(), 10, GMP_RNDN);
gcc_assert(r == 0);
go_assert(r == 0);
if (neg)
mpfr_neg(val, val, GMP_RNDN);
......
......@@ -183,7 +183,7 @@ class Token
Keyword
keyword() const
{
gcc_assert(this->classification_ == TOKEN_KEYWORD);
go_assert(this->classification_ == TOKEN_KEYWORD);
return this->u_.keyword;
}
......@@ -196,7 +196,7 @@ class Token
const std::string&
identifier() const
{
gcc_assert(this->classification_ == TOKEN_IDENTIFIER);
go_assert(this->classification_ == TOKEN_IDENTIFIER);
return *this->u_.identifier_value.name;
}
......@@ -204,7 +204,7 @@ class Token
bool
is_identifier_exported() const
{
gcc_assert(this->classification_ == TOKEN_IDENTIFIER);
go_assert(this->classification_ == TOKEN_IDENTIFIER);
return this->u_.identifier_value.is_exported;
}
......@@ -220,7 +220,7 @@ class Token
std::string
string_value() const
{
gcc_assert(this->classification_ == TOKEN_STRING);
go_assert(this->classification_ == TOKEN_STRING);
return *this->u_.string_value;
}
......@@ -228,7 +228,7 @@ class Token
const mpz_t*
integer_value() const
{
gcc_assert(this->classification_ == TOKEN_INTEGER);
go_assert(this->classification_ == TOKEN_INTEGER);
return &this->u_.integer_value;
}
......@@ -236,7 +236,7 @@ class Token
const mpfr_t*
float_value() const
{
gcc_assert(this->classification_ == TOKEN_FLOAT);
go_assert(this->classification_ == TOKEN_FLOAT);
return &this->u_.float_value;
}
......@@ -244,7 +244,7 @@ class Token
const mpfr_t*
imaginary_value() const
{
gcc_assert(this->classification_ == TOKEN_IMAGINARY);
go_assert(this->classification_ == TOKEN_IMAGINARY);
return &this->u_.float_value;
}
......@@ -252,7 +252,7 @@ class Token
Operator
op() const
{
gcc_assert(this->classification_ == TOKEN_OPERATOR);
go_assert(this->classification_ == TOKEN_OPERATOR);
return this->u_.op;
}
......
......@@ -77,7 +77,7 @@ static Type* runtime_function_types[NUMBER_OF_RUNTIME_FUNCTION_TYPES];
static Type*
runtime_function_type(Runtime_function_type bft)
{
gcc_assert(bft < NUMBER_OF_RUNTIME_FUNCTION_TYPES);
go_assert(bft < NUMBER_OF_RUNTIME_FUNCTION_TYPES);
if (runtime_function_types[bft] == NULL)
{
const source_location bloc = BUILTINS_LOCATION;
......@@ -223,7 +223,7 @@ convert_to_runtime_function_type(Runtime_function_type bft, Expression* e,
return Expression::make_unsafe_cast(runtime_function_type(bft), e, loc);
case RFT_TYPE:
gcc_assert(e->type() == Type::make_type_descriptor_ptr_type());
go_assert(e->type() == Type::make_type_descriptor_ptr_type());
return e;
}
}
......@@ -240,7 +240,7 @@ Runtime::convert_types(Gogo* gogo)
if (t != NULL && t->named_type() != NULL)
{
bool r = t->verify();
gcc_assert(r);
go_assert(r);
t->named_type()->convert(gogo);
}
}
......@@ -279,7 +279,7 @@ runtime_function_declarations[Runtime::NUMBER_OF_FUNCTIONS];
Named_object*
Runtime::runtime_declaration(Function code)
{
gcc_assert(code < Runtime::NUMBER_OF_FUNCTIONS);
go_assert(code < Runtime::NUMBER_OF_FUNCTIONS);
if (runtime_function_declarations[code] == NULL)
{
const Runtime_function* pb = &runtime_functions[code];
......@@ -339,11 +339,11 @@ Call_expression*
Runtime::make_call(Runtime::Function code, source_location loc,
int param_count, ...)
{
gcc_assert(code < Runtime::NUMBER_OF_FUNCTIONS);
go_assert(code < Runtime::NUMBER_OF_FUNCTIONS);
const Runtime_function* pb = &runtime_functions[code];
gcc_assert(static_cast<size_t>(param_count)
go_assert(static_cast<size_t>(param_count)
<= sizeof(pb->parameter_types) / sizeof(pb->parameter_types[0]));
Named_object* no = runtime_declaration(code);
......
......@@ -690,7 +690,7 @@ class Select_clauses
: channel_(channel), val_(val), closed_(closed), var_(var),
closedvar_(closedvar), statements_(statements), location_(location),
is_send_(is_send), is_default_(is_default), is_lowered_(false)
{ gcc_assert(is_default ? channel == NULL : channel != NULL); }
{ go_assert(is_default ? channel == NULL : channel != NULL); }
// Traverse the select clause.
int
......@@ -719,7 +719,7 @@ class Select_clauses
bool
is_send() const
{
gcc_assert(!this->is_default_);
go_assert(!this->is_default_);
return this->is_send_;
}
......@@ -792,7 +792,7 @@ class Select_statement : public Statement
void
add_clauses(Select_clauses* clauses)
{
gcc_assert(this->clauses_ == NULL);
go_assert(this->clauses_ == NULL);
this->clauses_ = clauses;
}
......@@ -967,7 +967,7 @@ class For_statement : public Statement
void
add_statements(Block* statements)
{
gcc_assert(this->statements_ == NULL);
go_assert(this->statements_ == NULL);
this->statements_ = statements;
}
......@@ -1030,7 +1030,7 @@ class For_range_statement : public Statement
void
add_statements(Block* statements)
{
gcc_assert(this->statements_ == NULL);
go_assert(this->statements_ == NULL);
this->statements_ = statements;
}
......@@ -1267,7 +1267,7 @@ class Switch_statement : public Statement
void
add_clauses(Case_clauses* clauses)
{
gcc_assert(this->clauses_ == NULL);
go_assert(this->clauses_ == NULL);
this->clauses_ = clauses;
}
......@@ -1407,13 +1407,13 @@ class Type_switch_statement : public Statement
source_location location)
: Statement(STATEMENT_TYPE_SWITCH, location),
var_(var), expr_(expr), clauses_(NULL), break_label_(NULL)
{ gcc_assert(var == NULL || expr == NULL); }
{ go_assert(var == NULL || expr == NULL); }
// Add the clauses.
void
add_clauses(Type_case_clauses* clauses)
{
gcc_assert(this->clauses_ == NULL);
go_assert(this->clauses_ == NULL);
this->clauses_ = clauses;
}
......
......@@ -160,7 +160,7 @@ class Method
Named_object*
stub_object() const
{
gcc_assert(this->stub_ != NULL);
go_assert(this->stub_ != NULL);
return this->stub_;
}
......@@ -168,7 +168,7 @@ class Method
void
set_stub_object(Named_object* no)
{
gcc_assert(this->stub_ == NULL);
go_assert(this->stub_ == NULL);
this->stub_ = no;
}
......@@ -1167,7 +1167,7 @@ class Typed_identifier
void
set_type(Type* type)
{
gcc_assert(this->type_ == NULL || type->is_error_type());
go_assert(this->type_ == NULL || type->is_error_type());
this->type_ = type;
}
......@@ -1213,7 +1213,7 @@ class Typed_identifier_list
void
set_type(size_t i, Type* type)
{
gcc_assert(i < this->entries_.size());
go_assert(i < this->entries_.size());
this->entries_[i].set_type(type);
}
......@@ -1253,7 +1253,7 @@ class Typed_identifier_list
void
resize(size_t c)
{
gcc_assert(c <= this->entries_.size());
go_assert(c <= this->entries_.size());
this->entries_.resize(c, Typed_identifier("", NULL, UNKNOWN_LOCATION));
}
......@@ -1777,7 +1777,7 @@ class Struct_field
const std::string&
tag() const
{
gcc_assert(this->tag_ != NULL);
go_assert(this->tag_ != NULL);
return *this->tag_;
}
......@@ -2228,7 +2228,7 @@ class Channel_type : public Type
: Type(TYPE_CHANNEL),
may_send_(may_send), may_receive_(may_receive),
element_type_(element_type)
{ gcc_assert(may_send || may_receive); }
{ go_assert(may_send || may_receive); }
// Whether this channel can send data.
bool
......@@ -2312,7 +2312,7 @@ class Interface_type : public Type
Interface_type(Typed_identifier_list* methods, source_location location)
: Type(TYPE_INTERFACE),
methods_(methods), location_(location)
{ gcc_assert(methods == NULL || !methods->empty()); }
{ go_assert(methods == NULL || !methods->empty()); }
// The location where the interface type was defined.
source_location
......
......@@ -27,7 +27,7 @@ Gogo::import_unsafe(const std::string& local_name, bool is_local_name_exported,
if (package == NULL)
{
gcc_assert(saw_errors());
go_assert(saw_errors());
return;
}
......@@ -44,9 +44,9 @@ Gogo::import_unsafe(const std::string& local_name, bool is_local_name_exported,
}
else
{
gcc_assert(no->package() == package);
gcc_assert(no->is_type());
gcc_assert(no->type_value()->is_unsafe_pointer_type());
go_assert(no->package() == package);
go_assert(no->is_type());
go_assert(no->type_value()->is_unsafe_pointer_type());
no->type_value()->set_is_visible();
}
Named_type* pointer_type = no->type_value();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment