bool SuifValidater::is_valid_SymbolTable(SymbolTable* symtab) { if (symtab == NULL) SUIF_THROW(SuifException(String("Cannot validate a NULL SymbolTable."))); bool ok_stat = true; {for (Iter<SymbolTable::lookup_table_pair> it = symtab->get_lookup_table_iterator(); it.is_valid(); it.next()) { if (!symtab->has_symbol_table_object_member(it.current().second)) { ok_stat = false; add_error(to_id_string(symtab) + " has a lookup pair <" + it.current().first + ", " + to_id_string(it.current().second) + "> with dangling object."); } }} {for (Iter<SymbolTableObject*> it = symtab->get_symbol_table_object_iterator(); it.is_valid(); it.next()) { SymbolTableObject *sobj = it.current(); if ((sobj->get_name().length() > 0) && !is_in_lookup_list(it.current(), symtab)) { ok_stat = false; add_error(to_id_string(symtab) + " has " + to_id_string(it.current()) + " not in lookup list."); } }} return ok_stat; }
static void check_numptr_types(DataType* t1, DataType* t2) { if (!is_kind_of<NumericType>(t1) && !is_kind_of<PointerType>(t1)) SUIF_THROW(SuifDevException(__FILE__, __LINE__, String("Expection either numeric or pointer " "type - ") + to_id_string(t1))); if (!is_kind_of<NumericType>(t2) && !is_kind_of<PointerType>(t2)) SUIF_THROW(SuifDevException(__FILE__, __LINE__, String("Expection either numeric or pointer " "type - ") + to_id_string(t2))); }
LoadVariableExpression* NodeBuilder::load_var(VariableSymbol* var) { Type* rtype = get_unqualified_type(var->get_type()); if (!is_kind_of<DataType>(rtype)) { trash(var); SUIF_THROW(SuifException(String("Cannot make a LoadVariableExpression out of ") + to_id_string(var) + " whose type " + to_id_string(rtype) + " is not a data type.")); } return create_load_variable_expression(_suif_env, to<DataType>(rtype), var); }
StoreStatement* NodeBuilder::store(Expression* dst_addr, Expression* src_addr) { if (!is_same_type(get_pointed_to_type(dst_addr->get_result_type()), src_addr->get_result_type())) { trash(dst_addr); trash(src_addr); SUIF_THROW(SuifException(String("Type error in StoreStatement from ") + to_id_string(src_addr) + " to " + to_id_string(dst_addr))); } return create_store_statement(_suif_env, src_addr, dst_addr); }
StoreVariableStatement* NodeBuilder::store_var(VariableSymbol* dst, Expression* src) { if (!is_same_type(dst->get_type(), src->get_result_type())) { trash(dst); trash(src); SUIF_THROW(SuifException(String("Type mismatch in StoreVariableStatement for ") + to_id_string(dst) + " from expression " + to_id_string(src))); } return create_store_variable_statement(_suif_env, dst, src); }
Walker::ApplyStatus SuifValidater::OwnChecker::operator()(SuifObject *obj) { _validater->add_ownee(obj); if (obj == _owner) return Walker::Continue; if (_owner != obj->get_parent()) { _is_ok = false; _validater->add_error(to_id_string(obj) + " owned by " + to_id_string(_owner) + " but has parent " + to_id_string(obj->get_parent())); } _is_ok &= _validater->is_valid_ownership(obj); return Walker::Truncate; }
void SuifValidater::validate( SuifObject* obj) { SuifValidater val; if (!val.is_valid(obj)) { SUIF_THROW(SuifException(String("Validation of ") + to_id_string(obj) + " failed because\n" + val.get_error())); } }
Walker::ApplyStatus SuifValidater::RefChecker::operator()(SuifObject* obj) { if (!_validater->is_ownee(obj)) { _is_ok = false; _validater->add_error(to_id_string(obj) + " is referenced but not in the owners tree."); } return Walker::Continue; }
LoadExpression* NodeBuilder::load(Expression* addr) { Type* ptype = get_unqualified_type(addr->get_result_type()); if (!is_kind_of<PointerType>(ptype)) { trash(addr); SUIF_THROW(SuifException(String("Cannot make a LoadExpression out of ") + to_id_string(addr) + " whose type " + to_id_string(ptype) + " is not a pointer type.")); } Type* btype = get_unqualified_type(to<PointerType>(ptype)->get_reference_type()); if (!is_kind_of<DataType>(btype)) { trash(addr); SUIF_THROW(SuifException(String("Cannot make a LoadExpression out of ") + to_id_string(addr) + " whose type " + to_id_string(ptype) + " is not a pointer to a DataType.")); } DataType *dtype = to<DataType>(btype); return create_load_expression(_suif_env, dtype, addr); }
/** Create an expression for byte offset of a group field. * */ Expression* NodeBuilder::get_field_offset_exp(FieldSymbol* fsym) { Expression *boffset = fsym->get_bit_offset(); if (!is_kind_of<IntConstant>(boffset)) { trash(fsym); SUIF_THROW(SuifException(String("Field offset not in IntConstant ") + to_id_string(fsym))); } IInteger v = to<IntConstant>(boffset)->get_value(); return int_const(v.div(IInteger(BITSPERBYTE))); }
IfStatement* NodeBuilder::new_if(Expression* pred, Statement* then_part, Statement* else_part) { if (!(is_kind_of<IntegerType>(pred->get_result_type()) || is_kind_of<BooleanType>(pred->get_result_type()))) { trash(then_part); trash(else_part); SUIF_THROW(SuifException(String("Expection a boolean or integer expression ") + to_id_string(pred))); } return create_if_statement(_suif_env, pred, then_part, else_part); }
FieldAccessExpression* NodeBuilder::field_addr(Expression* grp_addr, LString field_name) { GroupType* gtype = to_ref_type<GroupType>(this, grp_addr->get_result_type()); if (gtype == 0) { trash(grp_addr); SUIF_THROW(SuifException(String("Type error: expecting an addr to a group ") + to_id_string(grp_addr))); } FieldSymbol *f = find_field(to<GroupType>(gtype), field_name); if (f == 0) { trash(grp_addr); SUIF_THROW(SuifException(String("Cannot find field <") + field_name + "> in group type " + to_id_string(gtype))); } FieldAccessExpression *res = create_field_access_expression(_suif_env, // to<DataType>(fieldtype), get_pointer_type(f->get_type()), grp_addr, f); return res; }
CallExpression* CfeNodeBuilder::call(Expression* callee_addr, suif_vector<Expression*>* args) { CProcedureType* ctype = to_ref_type<CProcedureType>(this, callee_addr->get_result_type()); if (ctype == 0) { trash(callee_addr); for (unsigned i = 0; i<args->length(); i++) { trash(args->at(i)); } SUIF_THROW(SuifException(String("Type error in CallExpression ") + to_id_string(callee_addr))); } DataType* rtype = to<CProcedureType>(ctype)->get_result_type(); CallExpression* exp = create_call_expression(get_suif_env(), rtype, callee_addr); for (unsigned i = 0; i<args->length(); i++) { exp->append_argument(args->at(i)); } return exp; }