/* * Derives a new vtbl from the parent's vtbl. * Methods whose is_dispatched field is false are ignored. */ vtbl_t* SingleInheritanceVtbls:: derive_vtbl( vtbl_t* parent_vtbl, SingleInheritanceClassType* current_class ) { suif_assert( current_class ); if( ! current_class->get_methods_are_complete() ) handle_incomplete_class( current_class ); if ( parent_vtbl == NULL ) parent_vtbl = new vtbl_t(); // copy the parent vtbl vtbl_t* current_vtbl = new vtbl_t( *parent_vtbl ); list<InstanceMethodSymbol* > method_list = collect_stos<InstanceMethodSymbol,InstanceMethodSymbol>( current_class->get_instance_method_symbol_table() ); for ( unsigned i = 0 ; i < method_list.size() ; i++ ) { InstanceMethodSymbol* msym = method_list[i]; if ( msym->get_is_dispatched() ) insert_method( msym, current_vtbl ); } // insert vtbl in map _vtbls.enter_value( current_class, current_vtbl ); return current_vtbl; }
/* Parse and insert methods from methods string */ void parse_methods_string(char *str) { char *method, *tmp, *i; int num_methods = 0; #ifdef DEBUG ASSERT(str); #endif if (strlen(str) == 0) LOG_DIE("Empty methods string provided"); /* Make a temporary copy of the string so we don't modify the original */ if ((tmp = malloc(strlen(str) + 1)) == NULL) LOG_DIE("Cannot allocate memory for methods string buffer"); strcpy(tmp, str); for (i = tmp; (method = strtok(i, ",")); i = NULL) { method = str_strip_whitespace(method); method = str_tolower(method); if (strlen(method) == 0) continue; if (insert_method(method)) num_methods++; } free(tmp); if (num_methods == 0) LOG_DIE("No valid methods found in string"); return; }
template <class T> void add_method(T in_method) { insert_method(std::make_shared<T>(in_method)); }