Example #1
0
/**
 * @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;
}
Example #2
0
/**
 * osl_body_read function:
 * this function reads a body structure from a string complying to the
 * OpenScop textual format and returns a pointer to this body structure.
 * The input string should only contain the body this function
 * has to read (comments at the end of the line are accepted). The input
 * parameter is updated to the position in the input string this function
 * reach right after reading the strings structure.
 * \param[in,out] input The input string where to find a body structure.
 *                      Updated to the position after what has been read.
 * \return A pointer to the body structure that has been read.
 */
osl_body_p osl_body_sread(char ** input) {
  osl_body_p body = NULL;
  char * expression;
  int nb_iterators;

  if (input) {
    body = osl_body_malloc();
    
    // Read the number of iterators.
    nb_iterators = osl_util_read_int(NULL, input);
    
    // Read the iterator strings if any.
    if (nb_iterators > 0) {
      body->iterators = osl_strings_sread(input);
    }
    else {
      body->iterators = osl_strings_malloc();
      OSL_malloc(body->iterators->string, char **, sizeof(char *));
      body->iterators->string[0] = NULL;
    }

    // Read the body:
    expression = osl_util_read_line(NULL, input);

    // Insert the body.
    body->expression = osl_strings_encapsulate(expression);
  }

  return body;
}
Example #3
0
/**
 * 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;
}
Example #4
0
/**
 * osl_body_read function:
 * this function reads a body structure from a string complying to the
 * OpenScop textual format and returns a pointer to this body structure.
 * The input string should only contain the body this function
 * has to read (comments at the end of the line are accepted). The input
 * parameter is updated to the position in the input string this function
 * reach right after reading the strings structure.
 * \param[in,out] input The input string where to find a body structure.
 *                      Updated to the position after what has been read.
 * \return A pointer to the body structure that has been read.
 */
osl_body_p osl_body_sread(char ** input) {
  osl_body_p body = NULL;
  char * expression;
  int nb_iterators;

  if (input) {
    body = osl_body_malloc();
    
    // Read the number of iterators.
    nb_iterators = osl_util_read_int(NULL, input);
    
    // Read the iterator strings if any.
    if (nb_iterators > 0)
      body->iterators = osl_strings_sread(input);

    // Read the body:
    // - Skip blank/commented lines and spaces before the body.
    osl_util_sskip_blank_and_comments(input);
      
    // - Remove the comments after the body.
    expression = *input;
    while (*input && **input != '#' && **input != '\n')
      (*input)++;
    
    if (*input && **input == '#') {
      **input = '\0';
      while (**input != '\n')
        (*input)++;
    }
    else {
      if (*input && **input == '\n') {
        **input = '\0';
        (*input)++;
      }
    }

    // - Copy the body.
    body->expression = osl_strings_encapsulate(strdup(expression));
  }

  return body;
}