TypeSpec ASTternary_expression::typecheck (TypeSpec expected) { // FIXME - closures TypeSpec c = typecheck_list (cond(), TypeDesc::TypeInt); TypeSpec t = typecheck_list (trueexpr(), expected); TypeSpec f = typecheck_list (falseexpr(), expected); if (c.is_closure()) error ("Cannot use a closure as a condition"); if (c.is_structure()) error ("Cannot use a struct as a condition"); if (c.is_array()) error ("Cannot use an array as a condition"); // No arrays if (t.is_array() || t.is_array()) { error ("Not allowed: '%s ? %s : %s'", type_c_str(c), type_c_str(t), type_c_str(f)); return TypeSpec (); } // The true and false clauses need to be equivalent types, or one // needs to be assignable to the other (so one can be upcast). if (assignable (t, f) || assignable (f, t)) m_typespec = higherprecision (t.simpletype(), f.simpletype()); else error ("Not allowed: '%s ? %s : %s'", type_c_str(c), type_c_str(t), type_c_str(f)); return m_typespec; }
TypeSpec ASTconditional_statement::typecheck (TypeSpec expected) { typecheck_list (cond ()); oslcompiler->push_nesting (false); typecheck_list (truestmt ()); typecheck_list (falsestmt ()); oslcompiler->pop_nesting (false); TypeSpec c = cond()->typespec(); if (c.is_closure()) error ("Cannot use a closure as an 'if' condition"); if (c.is_structure()) error ("Cannot use a struct as an 'if' condition"); if (c.is_array()) error ("Cannot use an array as an 'if' condition"); return m_typespec = TypeDesc (TypeDesc::NONE); }
TypeSpec ASTloop_statement::typecheck (TypeSpec expected) { typecheck_list (init ()); oslcompiler->push_nesting (true); typecheck_list (cond ()); typecheck_list (iter ()); typecheck_list (stmt ()); oslcompiler->pop_nesting (true); TypeSpec c = cond()->typespec(); if (c.is_closure()) error ("Cannot use a closure as an '%s' condition", opname()); if (c.is_structure()) error ("Cannot use a struct as an '%s' condition", opname()); if (c.is_array()) error ("Cannot use an array as an '%s' condition", opname()); return m_typespec = TypeDesc (TypeDesc::NONE); }
BOOST_FOREACH (ref &c, m_children) { typecheck_list (c, expected); }