/** * Create a supplier for the stem, returning the tail names as * the indexes and the values as the items. * * @return A supplier instance. */ SupplierClass *StemClass::supplier() { // essentially the same logic as allItems(), but both the item and the // tail value are accumulated. size_t count = 0; CompoundTableElement *variable = tails.first(); while (variable != OREF_NULL) { // again, get the variable count if (variable->getVariableValue() != OREF_NULL) { count++; /* count this variable */ } variable = tails.next(variable); } // to create the supplier, we need 2 arrays ArrayClass *tailValues = new_array(count); ArrayClass *values = new_array(count); count = 1; // we fill in using 1-based indexes variable = tails.first(); while (variable != OREF_NULL) { // now grab both the tail and value and put them in the respective arrays if (variable->getVariableValue() != OREF_NULL) { tailValues->put(variable->getName(), count); values->put(variable->getVariableValue(), count++); } variable = tails.next(variable); } // two arrays become one supplier return new_supplier(values, tailValues); }
/** * Extract from the method dictionary all methods defined with * a given scope. * * @param scope The target scope. If null, then all methods * are returned. * * @return A supplier holding the names and methods with the target * scope. This supplier can be empty. */ RexxSupplier *RexxBehaviour::getMethods(RexxObject *scope) { // if asking for everything, just return the supplier. if (scope == OREF_NULL) { return this->methodDictionary->supplier(); } size_t count = 0; HashLink i; // travese the method dictionary, searching for methods with the target scope for (i = this->methodDictionary->first(); this->methodDictionary->index(i) != OREF_NULL; i = this->methodDictionary->next(i)) { if (((RexxMethod *)this->methodDictionary->value(i))->getScope() == scope) { count++; } } RexxArray *names = new_array(count); RexxArray *methods = new_array(count); count = 1; // pass two, copy the entries into the array for (i = this->methodDictionary->first(); this->methodDictionary->index(i) != OREF_NULL; i = this->methodDictionary->next(i)) { if (((RexxMethod *)this->methodDictionary->value(i))->getScope() == scope) { names->put(this->methodDictionary->index(i), count); methods->put(this->methodDictionary->value(i), count); count++; } } return (RexxSupplier *)new_supplier(methods, names); }