mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Simplified @is_comparer
This commit is contained in:
@@ -13,26 +13,10 @@ macro usz @len_from_list(&list)
|
||||
macro bool @is_comparer(#cmp, #list)
|
||||
{
|
||||
var $Type = $typeof(#cmp);
|
||||
$if $and($Type.kindof == FUNC, $Type.returns.kindof == SIGNED_INT):
|
||||
var $params = $Type.params;
|
||||
$if $params.len != 2:
|
||||
return false;
|
||||
$else
|
||||
$if $params[0] != $params[1]:
|
||||
return false;
|
||||
$else
|
||||
var $element = @typeid(#list[0]);
|
||||
$switch
|
||||
$case $element == $params[0]:
|
||||
return true;
|
||||
$case $and($params[0].kindof == POINTER, $params[0].inner == $element):
|
||||
return true;
|
||||
$default:
|
||||
return false;
|
||||
$endswitch
|
||||
$endif
|
||||
$endif
|
||||
$else
|
||||
return false;
|
||||
$endif
|
||||
$switch
|
||||
$case $or($Type.kindof != FUNC, $Type.returns.kindof != SIGNED_INT): return false;
|
||||
$case $defined(#cmp(#list[0], #list[0])): return true;
|
||||
$case $defined(#cmp(&&(#list[0]), &&(#list[0]))): return true;
|
||||
$default: return false;
|
||||
$endswitch
|
||||
}
|
||||
@@ -104,11 +104,8 @@ static bool cast_is_allowed(CastContext *cc, bool is_explicit, bool is_silent)
|
||||
// No rule => no
|
||||
if (!rule)
|
||||
{
|
||||
if (!is_silent)
|
||||
{
|
||||
RETURN_CAST_ERROR(cc->expr, "You cannot cast %s to %s.", type_quoted_error_string(cc->expr->type), type_quoted_error_string(cc->to_type));
|
||||
}
|
||||
return false;
|
||||
if (is_silent) return false;
|
||||
RETURN_CAST_ERROR(cc->expr, "You cannot cast %s to %s.", type_quoted_error_string(cc->expr->type), type_quoted_error_string(cc->to_type));
|
||||
}
|
||||
|
||||
return rule(cc, is_explicit, is_silent);
|
||||
|
||||
Reference in New Issue
Block a user