/** * osl_body_clone function: * this functions builds and returns a "hard copy" (not a pointer copy) of an * osl_body_t data structure provided as parameter. However, let us * recall here that non-string elements are untouched by the OpenScop Library. * \param[in] body The pointer to the body we want to copy. * \return A pointer to the full copy of the body provided as parameter. */ osl_body_p osl_body_clone(osl_body_p body) { osl_body_p copy = NULL; if (body != NULL) { copy = osl_body_malloc(); copy->iterators = osl_strings_clone(body->iterators); copy->expression = osl_strings_clone(body->expression); } return copy; }
/** * @brief Fusion two osl_body into a third one. * The two osl_body must have the same iterators or the program will fail. * * @param body1 The first osl_body. * @param body2 The second osl_body. * * @return An osl_body with the same iteratar as the parameters, but with * their "code" fusionned. */ struct osl_body * substrate_osl_body_fusion( struct osl_body * body1, struct osl_body * body2) { struct osl_body * res = NULL; size_t body1_size = 0, body2_size = 0; body1_size = osl_strings_size(body1->iterators); body2_size = osl_strings_size(body2->iterators); res = osl_body_malloc(); if((osl_strings_equal(body1->iterators, body2->iterators)) || (body1_size==0) || (body2_size==0)) { res->iterators = osl_strings_clone(body1->iterators); substrate_osl_strings_concat( &res->expression, body1->expression, body2->expression); } else { //TODO Maybe fuse when iterators don't match ? (I'm not really sure). OSL_error("Can't fusion body"); } return res; }
/** * osl_scatnames_clone function: * This function builds and returns a "hard copy" (not a pointer copy) of an * osl_scatnames_t data structure. * \param[in] scatnames The pointer to the scatnames structure to clone. * \return A pointer to the clone of the scatnames structure. */ osl_scatnames_p osl_scatnames_clone(osl_scatnames_p scatnames) { osl_scatnames_p clone; if (scatnames == NULL) return NULL; clone = osl_scatnames_malloc(); clone->names = osl_strings_clone(scatnames->names); return clone; }