本文整理汇总了C++中TypeSpec::is_matrix方法的典型用法代码示例。如果您正苦于以下问题:C++ TypeSpec::is_matrix方法的具体用法?C++ TypeSpec::is_matrix怎么用?C++ TypeSpec::is_matrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeSpec
的用法示例。
在下文中一共展示了TypeSpec::is_matrix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TypeSpec
TypeSpec
ASTbinary_expression::typecheck (TypeSpec expected)
{
typecheck_children (expected);
TypeSpec l = left()->typespec();
TypeSpec r = right()->typespec();
// No binary ops work on structs or arrays
if (l.is_structure() || r.is_structure() || l.is_array() || r.is_array()) {
error ("Not allowed: '%s %s %s'",
type_c_str(l), opname(), type_c_str(r));
return TypeSpec ();
}
// Special for closures -- just a few cases to worry about
if (l.is_color_closure() || r.is_color_closure()) {
if (m_op == Add) {
if (l.is_color_closure() && r.is_color_closure())
return m_typespec = l;
}
if (m_op == Mul) {
if (l.is_color_closure() && (r.is_color() || r.is_int_or_float()))
return m_typespec = l;
if (r.is_color_closure() && (l.is_color() || l.is_int_or_float())) {
// N.B. Reorder so that it's always r = closure * k,
// not r = k * closure. See codegen for why this helps.
std::swap (m_children[0], m_children[1]);
return m_typespec = r;
}
}
// If we got this far, it's an op that's not allowed
error ("Not allowed: '%s %s %s'",
type_c_str(l), opname(), type_c_str(r));
return TypeSpec ();
}
switch (m_op) {
case Sub :
case Add :
case Mul :
case Div :
// Add/Sub/Mul/Div work for any equivalent types, and
// combination of int/float and other numeric types, but do not
// work with strings. Add/Sub don't work with matrices, but
// Mul/Div do.
// FIXME -- currently, equivalent types combine to make the
// left type. But maybe we should be more careful, for example
// point-point -> vector, etc.
if (l.is_string() || r.is_string())
break; // Dispense with strings trivially
if ((m_op == Sub || m_op == Add) && (l.is_matrix() || r.is_matrix()))
break; // Matrices don't combine for + and -
if (equivalent (l, r) ||
(l.is_numeric() && r.is_int_or_float()) ||
(l.is_int_or_float() && r.is_numeric()))
return m_typespec = higherprecision (l.simpletype(), r.simpletype());
break;
case Mod :
// Mod only works with ints, and return ints.
if (l.is_int() && r.is_int())
return m_typespec = TypeDesc::TypeInt;
break;
case Equal :
case NotEqual :
// Any equivalent types can be compared with == and !=, also a
// float or int can be compared to any other numeric type.
// Result is always an int.
if (equivalent (l, r) ||
(l.is_numeric() && r.is_int_or_float()) ||
(l.is_int_or_float() && r.is_numeric()))
return m_typespec = TypeDesc::TypeInt;
break;
case Greater :
case Less :
case GreaterEqual :
case LessEqual :
// G/L comparisons only work with floats or ints, and always
// return int.
if (l.is_int_or_float() && r.is_int_or_float())
return m_typespec = TypeDesc::TypeInt;
break;
case BitAnd :
case BitOr :
case Xor :
case ShiftLeft :
case ShiftRight :
// Bitwise ops only work with ints, and return ints.
if (l.is_int() && r.is_int())
return m_typespec = TypeDesc::TypeInt;
break;
case And :
case Or :
// Logical ops work on any simple type (since they test for
// nonzeroness), but always return int.
return m_typespec = TypeDesc::TypeInt;
//.........这里部分代码省略.........