本文整理汇总了C++中TypeSpec::is_float方法的典型用法代码示例。如果您正苦于以下问题:C++ TypeSpec::is_float方法的具体用法?C++ TypeSpec::is_float怎么用?C++ TypeSpec::is_float使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeSpec
的用法示例。
在下文中一共展示了TypeSpec::is_float方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: expr
TypeSpec
ASTtypecast_expression::typecheck (TypeSpec expected)
{
// FIXME - closures
typecheck_children (m_typespec);
TypeSpec t = expr()->typespec();
if (! assignable (m_typespec, t) &&
! (m_typespec.is_int() && t.is_float()) && // (int)float is ok
! (m_typespec.is_triple() && t.is_triple()))
error ("Cannot cast '%s' to '%s'", type_c_str(t),
type_c_str(m_typespec));
return m_typespec;
}
示例2: TypeSpec
TypeSpec
ASTassign_expression::typecheck (TypeSpec expected)
{
TypeSpec vt = var()->typecheck ();
TypeSpec et = expr()->typecheck (vt);
if (! var()->is_lvalue()) {
error ("Can't assign via %s to something that isn't an lvalue", opname());
return TypeSpec();
}
ASSERT (m_op == Assign); // all else handled by binary_op
// We don't currently support assignment of whole arrays
if (vt.is_array() || et.is_array()) {
error ("Can't assign entire arrays");
return TypeSpec();
}
// Special case: ok to assign a literal 0 to a closure to
// initialize it.
if (vt.is_closure() && ! et.is_closure() &&
(et.is_float() || et.is_int()) &&
expr()->nodetype() == literal_node &&
((ASTliteral *)&(*expr()))->floatval() == 0.0f) {
return TypeSpec(); // it's ok
}
// If either argument is a structure, they better both be the same
// exact kind of structure.
if (vt.is_structure() || et.is_structure()) {
int vts = vt.structure(), ets = et.structure();
if (vts == ets)
return m_typespec = vt;
// Otherwise, a structure mismatch
error ("Cannot assign '%s' to '%s'", type_c_str(et), type_c_str(vt));
return TypeSpec();
}
// Expression must be of a type assignable to the lvalue
if (! assignable (vt, et)) {
error ("Cannot assign '%s' to '%s'", type_c_str(et), type_c_str(vt));
// FIXME - can we print the variable in question?
return TypeSpec();
}
return m_typespec = vt;
}
示例3: if
//.........这里部分代码省略.........
track_variable_lifetimes ();
check_for_illegal_writes ();
// if (m_optimizelevel >= 1)
// coalesce_temporaries ();
}
if (! error_encountered()) {
if (m_output_filename.size() == 0)
m_output_filename = default_output_filename ();
write_oso_file (m_output_filename);
}
oslcompiler = NULL;
}
return ! error_encountered();
}
struct GlobalTable {
const char *name;
TypeSpec type;
};
static GlobalTable globals[] = {
{ "P", TypeDesc::TypePoint },
{ "I", TypeDesc::TypeVector },
{ "N", TypeDesc::TypeNormal },
{ "Ng", TypeDesc::TypeNormal },
{ "u", TypeDesc::TypeFloat },
{ "v", TypeDesc::TypeFloat },
{ "dPdu", TypeDesc::TypeVector },
{ "dPdv", TypeDesc::TypeVector },
#if 0
// Light variables -- we don't seem to be on a route to support this
// kind of light shader, so comment these out for now.
{ "L", TypeDesc::TypeVector },
{ "Cl", TypeDesc::TypeColor },
{ "Ns", TypeDesc::TypeNormal },
{ "Pl", TypeDesc::TypePoint },
{ "Nl", TypeDesc::TypeNormal },
#endif
{ "Ps", TypeDesc::TypePoint },
{ "Ci", TypeSpec (TypeDesc::TypeColor, true) },
{ "time", TypeDesc::TypeFloat },
{ "dtime", TypeDesc::TypeFloat },
{ "dPdtime", TypeDesc::TypeVector },
{ NULL }
};
void
OSLCompilerImpl::initialize_globals ()
{
for (int i = 0; globals[i].name; ++i) {
Symbol *s = new Symbol (ustring(globals[i].name), globals[i].type,
SymTypeGlobal);
symtab().insert (s);
}
}
std::string
OSLCompilerImpl::default_output_filename ()
{
if (m_shader && shader_decl())
return shader_decl()->shadername().string() + ".oso";
return std::string();
}
void
OSLCompilerImpl::write_oso_metadata (const ASTNode *metanode) const
{
ASSERT (metanode->nodetype() == ASTNode::variable_declaration_node);
const ASTvariable_declaration *metavar = static_cast<const ASTvariable_declaration *>(metanode);
Symbol *metasym = metavar->sym();
ASSERT (metasym);
TypeSpec ts = metasym->typespec();
oso ("%%meta{%s,%s,", ts.string().c_str(), metasym->name().c_str());
const ASTNode *init = metavar->init().get();
ASSERT (init);
if (ts.is_string() && init->nodetype() == ASTNode::literal_node)
oso ("\"%s\"", ((const ASTliteral *)init)->strval());
else if (ts.is_int() && init->nodetype() == ASTNode::literal_node)
oso ("%d", ((const ASTliteral *)init)->intval());
else if (ts.is_float() && init->nodetype() == ASTNode::literal_node)
oso ("%.8g", ((const ASTliteral *)init)->floatval());
// FIXME -- what about type constructors?
else {
std::cout << "Error, don't know how to print metadata "
<< ts.string() << " with node type "
<< init->nodetypename() << "\n";
ASSERT (0); // FIXME
}
oso ("} ");
}