TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_Constraint_Interpreter::TAO_Constraint_Interpreter ( const CosTradingRepos::ServiceTypeRepository::TypeStruct& ts, const char* constraints ) : TAO_Interpreter () { // @@ Throwing Exception from constructor is very nasty situation to // deal with. TAO_Trader_Constraint_Validator type_checker (ts); if (TAO_Interpreter::is_empty_string (constraints)) { ACE_NEW_THROW_EX (this->root_, TAO_Literal_Constraint ((CORBA::Boolean) 1), CORBA::NO_MEMORY ()); } else { if (this->build_tree (constraints) != 0) throw CosTrading::IllegalConstraint (constraints); if (type_checker.validate (this->root_) == -1) throw CosTrading::IllegalConstraint (constraints); } }
bool operator() (ti_tuple_t tv) const { if (!is_vector(v_)) return false; vector<var_t> vec = boost::get<vector<var_t> >(v_); if (vec.size() != tv.size()) return false; for (unsigned int i = 0; i < tv.size(); i++) { if (!apply_visitor(type_checker(vec[i]), tv[i])) return false; } return true; }
bool operator() (ti_vect_t tp) const { if (!is_vector(v_)) return false; vector<var_t> vec = boost::get<vector<var_t> >(v_); if (tp.first >= 0 && tp.first != static_cast<int>(vec.size())) return false; for (unsigned int i = 0; i < vec.size(); i++) { if (!apply_visitor(type_checker(vec[i]), tp.second)) return false; } return true; }
static bool convertible_impl( const python::object& py_sequence, mpl::int_< index >, mpl::int_< length > ){ typedef typename tuples::element< index, TTuple>::type element_type; object element = py_sequence[index]; extract<element_type> type_checker( element ); if( !type_checker.check() ){ return false; } else{ return convertible_impl( py_sequence, details::increment_index<index>(), length_type() ); } }
TAO_Preference_Interpreter::TAO_Preference_Interpreter ( const CosTradingRepos::ServiceTypeRepository::TypeStruct& ts, const char* preference ) : TAO_Interpreter () { TAO_Trader_Constraint_Validator type_checker (ts); if (TAO_Interpreter::is_empty_string (preference)) { ACE_NEW_THROW_EX (this->root_, TAO_Noop_Constraint (TAO_FIRST), CORBA::NO_MEMORY ()); } else { if (this->build_tree (preference) != 0) throw CosTrading::Lookup::IllegalPreference (preference); if (type_checker.validate (this->root_) == -1) throw CosTrading::Lookup::IllegalPreference (preference); } }
/*! Check if the object is convertible */ static void * convertible(PyObject * obj){ // is obj is a sequence if(!PySequence_Check(obj)){ return NULL; } // has the obj a len method if(!PyObject_HasAttrString(obj, "__len__")){ return NULL; } bpl::object py_sequence(bpl::handle<>(bpl::borrowed(obj))); if (len(py_sequence) > 0) { bpl::object element = py_sequence[0]; bpl::extract< GIMLI::Pos< double > > type_checker(element); if (type_checker.check()){ return obj; } else { std::cout << WHERE_AM_I << "element cannot converted to GIMLI::Pos< double > " << std::endl; } } else { std::cout << WHERE_AM_I << " " << std::endl; return NULL; } // check if there is a valid converter // if(convertible_impl(py_sequence, boost::mpl::int_< 0 >(), length_type())){ // return obj; // } else{ return NULL; }
void ensure_uniform_sequence( boost::python::object seq, index_type expected_length=-1 ){ ensure_sequence( seq, expected_length ); index_type length = sequence_len( seq ); for( index_type index = 0; index < length; ++index ){ boost::python::object item = seq[index]; boost::python::extract<ExpectedType> type_checker( item ); if( !type_checker.check() ){ std::string expected_type_name( boost::python::type_id<ExpectedType>().name() ); std::string item_type_name("different"); PyObject* item_impl = item.ptr(); if( item_impl && item_impl->ob_type && item_impl->ob_type->tp_name ){ item_type_name = std::string( item_impl->ob_type->tp_name ); } std::stringstream err; err << "Sequence should contain only items with type \"" << expected_type_name << "\". " << "Item at position " << index << " has \"" << item_type_name << "\" type."; raise_error( PyExc_ValueError, err.str().c_str() ); } } }
int main(int argc, char *argv[]) { int ret; if(argc != 2) { printf("Inappropriate format\n"); printf("\t%s filename\n",argv[0]); return 1; } /*get an empty parse tree*/ t_parse_tree *parse_tree = NULL; parse_tree = create_parse_tree(); if(parse_tree == NULL) { printf("Insufficient memory\n"); return 1; } /*get an empty symbol table*/ symbol_table *table = create_symbol_table(START_SIZE); if(table == NULL) { printf("Insufficient memory\n"); return 2; } char *filename = argv[1]; char pt_out[100]; char ast_out[100]; char lexer_out[100]; sprintf(lexer_out, "%s_temp_lex", filename); sprintf(pt_out, "%s_pt.txt",filename); sprintf(ast_out, "%s_ast.txt",filename); ret = lexer(filename); if(ret) { printf("ERROR in the lexical phase exiting\n"); return 1; } printf("lexer completed\n"); FILE *fp_pt = fopen(pt_out,"w"); FILE *fp_ast = fopen(ast_out, "w"); ret = parser(lexer_out, fp_pt, fp_ast, &parse_tree, &table); if(ret) { printf("Parser ERROR\n"); fclose(fp_pt); return 1; } printf("parser completed\n"); display_parse_tree(parse_tree->root, 0, fp_pt); // t_parse_tree *ast = get_AST(parse_tree); // display_parse_tree(ast->root, 0, fp_ast); // free_parse_tree(parse_tree); // free_parse_tree(ast); fclose(fp_pt); // fclose(fp_ast); /**/ ret = type_checker(parse_tree->root, &table); if(DISPLAY_SCOPE_GRAPH) { char file[100]; sprintf(file,"%s_sg.txt",filename); FILE *fp_sg = fopen(file, "w"); display_scope_graph(table->sg->root, 0,fp_sg); // display_scope_graph(table->sg->root, 0,stdout); fclose(fp_sg); //symbol table sprintf(file,"%s_symbol_table.txt", filename); FILE *fp_st = fopen(file, "w"); display_symbol_table(table, fp_st); // display_symbol_table(table, stdout); // fclose(fp_st); } char file[100]; parse_tree = get_decorated_ast(parse_tree); display_parse_tree(parse_tree->root, 0, fp_ast); fclose(fp_ast); sprintf(file, "%s_deco_ast.txt", filename); parse_tree = get_AST(parse_tree); fp_ast = fopen(file, "w"); display_parse_tree(parse_tree->root, 0, fp_ast); fclose(fp_ast); // symbol_list temp = lookup_symbol_table(table, " j", 2); // debug("in driver"); // printf("id-%s scope(%d) referred_count:- %d\n", temp->identifier, temp->scope, temp->referred_count); // temp = exist_in_scope(" j", 5, table); // printf("id-%s scope(%d) referred_count:- %d\n", temp->identifier, temp->scope, temp->referred_count); return 0; }
static bool type_mismatch(tyinfo_map_t& tm, value_map_t& vm, const string& key) { return !apply_visitor(type_checker(vm[key]), tm[key]); }