From 115ca468995eb29dc9a2dbf4ea89c36e8023354d Mon Sep 17 00:00:00 2001 From: Cedric Bastoul Date: Thu, 2 Jun 2011 15:18:47 +0200 Subject: [PATCH] Switch to Google coding style --- include/openscop/arrays.h | 3 +- include/openscop/comment.h | 3 +- include/openscop/extension.h | 3 +- include/openscop/names.h | 3 +- include/openscop/relation.h | 3 +- include/openscop/relation_list.h | 3 +- include/openscop/scop.h.in | 3 +- include/openscop/statement.h | 3 +- include/openscop/util.h | 1 + include/openscop/vector.h | 3 +- source/extension.c.in | 135 ++++------- source/extension.sh | 18 +- source/extensions/arrays.c | 111 +++------ source/extensions/comment.c | 58 ++--- source/names.c | 117 +++------ source/relation.c | 500 +++++++++++++++------------------------ source/relation_list.c | 121 ++++------ source/scop.c | 227 ++++++------------ source/statement.c | 132 ++++------- source/util.c | 188 +++++---------- source/vector.c | 89 +++---- 21 files changed, 595 insertions(+), 1129 deletions(-) diff --git a/include/openscop/arrays.h b/include/openscop/arrays.h index 751ba4f..f31256c 100644 --- a/include/openscop/arrays.h +++ b/include/openscop/arrays.h @@ -83,8 +83,7 @@ extern "C" * has a name string and an identifier: the ith name as name * string names[i] and identifier id[i]. */ -struct openscop_arrays -{ +struct openscop_arrays { int nb_names; /**< Number of names. */ int * id; /**< Array of nb_names identifiers. */ char ** names; /**< Array of nb_names names. */ diff --git a/include/openscop/comment.h b/include/openscop/comment.h index 4419791..cf1508e 100644 --- a/include/openscop/comment.h +++ b/include/openscop/comment.h @@ -81,8 +81,7 @@ extern "C" * The openscop_comment_t structure stores a comment extention to the core * OpenScop representation. It is simply a 0-terminated string. */ -struct openscop_comment -{ +struct openscop_comment { char * comment; /**< A comment message as a 0-terminated string. */ }; typedef struct openscop_comment openscop_comment_t; diff --git a/include/openscop/extension.h b/include/openscop/extension.h index 8449ec0..d9ac3f2 100644 --- a/include/openscop/extension.h +++ b/include/openscop/extension.h @@ -84,8 +84,7 @@ extern "C" * OpenScop representation. It is a node of a NULL-terminated linked list of * extensions. */ -struct openscop_extension -{ +struct openscop_extension { int type; /**< This extension's type. */ void * extension; /**< Pointer to the extension itself. */ struct openscop_extension * next; /**< Pointer to the next extension. */ diff --git a/include/openscop/names.h b/include/openscop/names.h index 428ba4d..7646045 100644 --- a/include/openscop/names.h +++ b/include/openscop/names.h @@ -82,8 +82,7 @@ extern "C" * convenience, the default type is (char *), but it may be casted to your * preferred type iff the "textual" field is 0. */ -struct openscop_names -{ +struct openscop_names { int textual; /**< 1 if names are character strings, 0 otherwise. */ int nb_parameters; /**< Number of parameters names. */ int nb_iterators; /**< Number of iterators names. */ diff --git a/include/openscop/relation.h b/include/openscop/relation.h index ecf4833..4cfa1d3 100644 --- a/include/openscop/relation.h +++ b/include/openscop/relation.h @@ -97,8 +97,7 @@ extern "C" * - The first output dimension of any access relations corresponds to * the name of the array. */ -struct openscop_relation -{ +struct openscop_relation { int nb_rows; /**< The number of rows */ int nb_columns; /**< The number of columns */ int nb_output_dims; /**< The number of output dimensions */ diff --git a/include/openscop/relation_list.h b/include/openscop/relation_list.h index a90546f..1f75f0f 100644 --- a/include/openscop/relation_list.h +++ b/include/openscop/relation_list.h @@ -81,8 +81,7 @@ extern "C" * The openscop_relation_list_t structure describes a (NULL-terminated * linked) list of relations. */ -struct openscop_relation_list -{ +struct openscop_relation_list { openscop_relation_p elt; /**< An element of the list. */ struct openscop_relation_list * next; /**< Pointer to the next element of the list.*/ diff --git a/include/openscop/scop.h.in b/include/openscop/scop.h.in index 822d6fe..135c1f7 100644 --- a/include/openscop/scop.h.in +++ b/include/openscop/scop.h.in @@ -96,8 +96,7 @@ extern "C" * The scop_t structure stores the useful information of a static * control part of a program to process it within a polyhedral framework. */ -struct openscop_scop -{ +struct openscop_scop { int version; /**< Version of the data structure */ char * language; /**< Target language (backend) */ openscop_relation_p context; /**< Constraints on the SCoP parameters */ diff --git a/include/openscop/statement.h b/include/openscop/statement.h index c3e174d..5902edd 100644 --- a/include/openscop/statement.h +++ b/include/openscop/statement.h @@ -83,8 +83,7 @@ extern "C" * within a polyhedral framework. The order in the list may matter for naming * conventions (e.g. "S1" for the first statement in the list). */ -struct openscop_statement -{ +struct openscop_statement { int version; /**< Version of the data structure */ openscop_relation_p domain; /**< Iteration domain of the statement */ openscop_relation_p scattering; /**< Scattering function for the statement */ diff --git a/include/openscop/util.h b/include/openscop/util.h index a4755e9..89fddfc 100644 --- a/include/openscop/util.h +++ b/include/openscop/util.h @@ -93,6 +93,7 @@ char * openscop_util_read_tail(FILE *); char * openscop_util_tag_content(char *, char *, char *); void openscop_util_safe_strcat(char **, char *, int *); + # if defined(__cplusplus) } # endif diff --git a/include/openscop/vector.h b/include/openscop/vector.h index 2f38cdf..6b27a6a 100644 --- a/include/openscop/vector.h +++ b/include/openscop/vector.h @@ -81,8 +81,7 @@ extern "C" * an inequality >= 0. When the vector describes an array access, a number * different than 0 is the array identifier. */ -struct openscop_vector -{ +struct openscop_vector { unsigned size; /**< The number of vector entries */ openscop_int_t * v; /**< An array of values */ }; diff --git a/source/extension.c.in b/source/extension.c.in index aae83e3..7af3712 100644 --- a/source/extension.c.in +++ b/source/extension.c.in @@ -95,11 +95,9 @@ * \param extensions The extensions whose information have to be printed. * \param level Number of spaces before printing, for each line. */ -void -openscop_extension_print_structure(FILE * file, - openscop_extension_p extension, - int level) -{ +void openscop_extension_print_structure(FILE * file, + openscop_extension_p extension, + int level) { int j, first = 1; // Go to the right level. @@ -111,10 +109,8 @@ openscop_extension_print_structure(FILE * file, else fprintf(file, "+-- NULL extension\n"); - while (extension != NULL) - { - if (!first) - { + while (extension != NULL) { + if (!first) { // Go to the right level. for (j = 0; j < level; j++) fprintf(file, "|\t"); @@ -131,10 +127,8 @@ openscop_extension_print_structure(FILE * file, // Go to the right level. for (j = 0; j < level; j++) fprintf(file, "|\t"); - switch (extension->type) - { @PRINT_STRUCTURE1@ - default: - { + switch (extension->type) { @PRINT_STRUCTURE1@ + default: { fprintf(file, "|\ttype = unsupported (%d)\n", extension->type); } } @@ -144,10 +138,8 @@ openscop_extension_print_structure(FILE * file, fprintf(file, "|\t"); fprintf(file, "\n"); - switch (extension->type) - { @PRINT_STRUCTURE2@ - default: - { + switch (extension->type) { @PRINT_STRUCTURE2@ + default: { // A blank line. for (j = 0; j <= level+1; j++) fprintf(file, "|\t"); @@ -158,8 +150,7 @@ openscop_extension_print_structure(FILE * file, extension = extension->next; // Next line. - if (extension != NULL) - { + if (extension != NULL) { for (j = 0; j <= level; j++) fprintf(file, "|\t"); fprintf(file, "V\n"); @@ -175,9 +166,7 @@ openscop_extension_print_structure(FILE * file, * \param file File where informations are printed. * \param extension The extension structure to print. */ -void -openscop_extension_print(FILE * file, openscop_extension_p extension) -{ +void openscop_extension_print(FILE * file, openscop_extension_p extension) { openscop_extension_print_structure(file, extension, 0); } @@ -189,30 +178,25 @@ openscop_extension_print(FILE * file, openscop_extension_p extension) * \param extension The extension structure to print. * \return A string containing the OpenScop dump of the extension structure. */ -void -openscop_extension_print_openscop(FILE * file, openscop_extension_p extension) -{ +void openscop_extension_print_openscop(FILE * file, + openscop_extension_p extension) { char * string; int ignored; if (extension == NULL) return; - while (extension != NULL) - { + while (extension != NULL) { ignored = 0; - switch (extension->type) - { @PRINT_OPENSCOP@ - default: - { + switch (extension->type) { @PRINT_OPENSCOP@ + default: { ignored = 1; fprintf(stderr, "[OpenScop] Warning: unsupported extension, " "printing it has been ignored.\n"); } } - if (!ignored) - { + if (!ignored) { fprintf(file, "%s\n", string); free(string); } @@ -235,9 +219,7 @@ openscop_extension_print_openscop(FILE * file, openscop_extension_p extension) * \param file The input file where to read a list of extension fields. * \return A pointer to the extension structure that has been read. */ -openscop_extension_p -openscop_extension_read(FILE * file) -{ +openscop_extension_p openscop_extension_read(FILE * file) { char * extension_string; openscop_extension_p extension = NULL; void * x; @@ -265,13 +247,11 @@ openscop_extension_read(FILE * file) * \param type The type of the new extension to add. * \param x The new extension to add. */ -void -openscop_extension_add(openscop_extension_p * extension, int type, void * x) -{ +void openscop_extension_add(openscop_extension_p * extension, int type, + void * x) { openscop_extension_p new; - if (x != NULL) - { + if (x != NULL) { new = openscop_extension_malloc(); new->type = type; new->extension = x; @@ -289,14 +269,11 @@ openscop_extension_add(openscop_extension_p * extension, int type, void * x) * \return A pointer to an empty extension structure with fields set to * default values. */ -openscop_extension_p -openscop_extension_malloc() -{ +openscop_extension_p openscop_extension_malloc() { openscop_extension_p extension; extension = (openscop_extension_p)malloc(sizeof(openscop_extension_t)); - if (extension == NULL) - { + if (extension == NULL) { fprintf(stderr, "[OpenScop] Error: memory Overflow.\n"); exit(1); } @@ -314,18 +291,13 @@ openscop_extension_malloc() * This function frees the allocated memory for an extension structure. * \param extension The pointer to the extension structure we want to free. */ -void -openscop_extension_free(openscop_extension_p extension) -{ +void openscop_extension_free(openscop_extension_p extension) { openscop_extension_p next; - while (extension != NULL) - { + while (extension != NULL) { next = extension->next; - switch (extension->type) - { @FREE@ - default: - { + switch (extension->type) { @FREE@ + default: { fprintf(stderr, "[OpenScop] Warning: unsupported extension, " "memory leaks are possible.\n"); @@ -350,18 +322,13 @@ openscop_extension_free(openscop_extension_p extension) * \param extension The pointer to the extension structure we want to copy. * \return A pointer to the copy of the extension structure. */ -openscop_extension_p -openscop_extension_copy(openscop_extension_p extension) -{ +openscop_extension_p openscop_extension_copy(openscop_extension_p extension) { openscop_extension_p copy = NULL; void * x; - while (extension != NULL) - { - switch (extension->type) - { @COPY@ - default: - { + while (extension != NULL) { + switch (extension->type) { @COPY@ + default: { fprintf(stderr, "[OpenScop] Warning: unsupported extension, " "copy ignored.\n"); @@ -384,13 +351,10 @@ openscop_extension_copy(openscop_extension_p extension) * \param x The list of extensions. * \return The number of elements in the list. */ -int -openscop_extension_count(openscop_extension_p x) -{ +int openscop_extension_count(openscop_extension_p x) { int extension_number = 0; - while (x != NULL) - { + while (x != NULL) { extension_number++; x = x->next; } @@ -401,17 +365,16 @@ openscop_extension_count(openscop_extension_p x) /** * openscop_extension_equal function: - * this function returns true if the two extension structures are the same, false - * otherwise. This functions considers two extension structures as equal if - * the order of the array names differ, however the identifiers and names + * this function returns true if the two extension structures are the same, + * false otherwise. This functions considers two extension structures as equal + * if the order of the array names differ, however the identifiers and names * must be the same. * \param a1 The first extension structure. * \param a2 The second extension structure. * \return 1 if a1 and a2 are the same (content-wise), 0 otherwise. */ -int -openscop_extension_equal(openscop_extension_p x1, openscop_extension_p x2) -{ +int openscop_extension_equal(openscop_extension_p x1, + openscop_extension_p x2) { int x1_extension_number, x2_extension_number; int found, equal; openscop_extension_p backup_x2 = x2; @@ -423,18 +386,13 @@ openscop_extension_equal(openscop_extension_p x1, openscop_extension_p x2) return 0; // Check that for each extension in x1 a similar extension is in x2. - while (x1 != NULL) - { + while (x1 != NULL) { x2 = backup_x2; found = 0; - while ((x2 != NULL) && (found != 1)) - { - if (x1->type == x2->type) - { - switch (x1->type) - { @EQUAL@ - default: - { + while ((x2 != NULL) && (found != 1)) { + if (x1->type == x2->type) { + switch (x1->type) { @EQUAL@ + default: { fprintf(stderr, "[OpenScop] Warning: unsupported extension, " "cannot state extension equality.\n"); @@ -470,11 +428,8 @@ openscop_extension_equal(openscop_extension_p x1, openscop_extension_p x2) * \param type The type of the extension we are looking for. * \return The first extension of the requested type in the list. */ -void * -openscop_extension_lookup(openscop_extension_p x, int type) -{ - while (x != NULL) - { +void * openscop_extension_lookup(openscop_extension_p x, int type) { + while (x != NULL) { if (x->type == type) return x->extension; diff --git a/source/extension.sh b/source/extension.sh index 16f56ad..ab250ec 100755 --- a/source/extension.sh +++ b/source/extension.sh @@ -72,8 +72,7 @@ EXTENSIONS_OUT='./source/extension.c' TEMPLATE_STRING[0]= TEMPLATE_SUBSTITUTION[0]='@PRINT_STRUCTURE1@' TEMPLATE[0]='\ - case OPENSCOP_EXTENSION_TEMPLATE:\ - {\ + case OPENSCOP_EXTENSION_TEMPLATE: {\ fprintf(file, "|\\\\ttype = OPENSCOP_EXTENSION_TEMPLATE\\\\n");\ break;\ }' @@ -83,8 +82,7 @@ TEMPLATE[0]='\ TEMPLATE_STRING[1]= TEMPLATE_SUBSTITUTION[1]='@PRINT_STRUCTURE2@' TEMPLATE[1]='\ - case OPENSCOP_EXTENSION_TEMPLATE:\ - {\ + case OPENSCOP_EXTENSION_TEMPLATE: {\ openscop_template_print_structure(\ file,\ (openscop_template_p)extension->extension,\ @@ -97,8 +95,7 @@ TEMPLATE[1]='\ TEMPLATE_STRING[2]= TEMPLATE_SUBSTITUTION[2]='@PRINT_OPENSCOP@' TEMPLATE[2]='\ - case OPENSCOP_EXTENSION_TEMPLATE:\ - {\ + case OPENSCOP_EXTENSION_TEMPLATE: {\ string = openscop_template_print_openscop(\ (openscop_template_p)extension->extension);\ break;\ @@ -117,8 +114,7 @@ TEMPLATE[3]='\ TEMPLATE_STRING[4]= TEMPLATE_SUBSTITUTION[4]='@FREE@' TEMPLATE[4]='\ - case OPENSCOP_EXTENSION_TEMPLATE:\ - {\ + case OPENSCOP_EXTENSION_TEMPLATE: {\ openscop_template_free(extension->extension);\ break;\ }' @@ -128,8 +124,7 @@ TEMPLATE[4]='\ TEMPLATE_STRING[5]= TEMPLATE_SUBSTITUTION[5]='@COPY@' TEMPLATE[5]='\ - case OPENSCOP_EXTENSION_TEMPLATE:\ - {\ + case OPENSCOP_EXTENSION_TEMPLATE: {\ x = (void *)openscop_template_copy(extension->extension);\ break;\ }' @@ -139,8 +134,7 @@ TEMPLATE[5]='\ TEMPLATE_STRING[6]= TEMPLATE_SUBSTITUTION[6]='@EQUAL@' TEMPLATE[6]='\ - case OPENSCOP_EXTENSION_TEMPLATE:\ - {\ + case OPENSCOP_EXTENSION_TEMPLATE: {\ equal = openscop_template_equal(x1->extension, x2->extension);\ break;\ }' diff --git a/source/extensions/arrays.c b/source/extensions/arrays.c index 5f4d22e..6fb8491 100644 --- a/source/extensions/arrays.c +++ b/source/extensions/arrays.c @@ -82,10 +82,8 @@ * \param arrays The arrays structure whose information has to be printed. * \param level Number of spaces before printing, for each line. */ -void -openscop_arrays_print_structure(FILE * file, openscop_arrays_p arrays, - int level) -{ +void openscop_arrays_print_structure(FILE * file, openscop_arrays_p arrays, + int level) { int i, j; // Go to the right level. @@ -97,8 +95,7 @@ openscop_arrays_print_structure(FILE * file, openscop_arrays_p arrays, else fprintf(file, "+-- NULL arrays\n"); - if (arrays != NULL) - { + if (arrays != NULL) { // Go to the right level. for(j = 0; j <= level; j++) fprintf(file, "|\t"); @@ -107,8 +104,7 @@ openscop_arrays_print_structure(FILE * file, openscop_arrays_p arrays, fprintf(file, "nb_names: %d\n", arrays->nb_names); // Display the id/name. - for(i = 0; i < arrays->nb_names; i++) - { + for(i = 0; i < arrays->nb_names; i++) { // Go to the right level. for(j = 0; j <= level; j++) fprintf(file, "|\t"); @@ -131,9 +127,7 @@ openscop_arrays_print_structure(FILE * file, openscop_arrays_p arrays, * \param file The file where the information has to be printed. * \param arrays The arrays structure whose information has to be printed. */ -void -openscop_arrays_print(FILE * file, openscop_arrays_p arrays) -{ +void openscop_arrays_print(FILE * file, openscop_arrays_p arrays) { openscop_arrays_print_structure(file, arrays, 0); } @@ -145,20 +139,16 @@ openscop_arrays_print(FILE * file, openscop_arrays_p arrays) * \param arrays The arrays structure whose information has to be printed. * \return A string containing the OpenScop dump of the arrays structure. */ -char * -openscop_arrays_print_openscop(openscop_arrays_p arrays) -{ +char * openscop_arrays_print_openscop(openscop_arrays_p arrays) { int i; int high_water_mark = OPENSCOP_MAX_STRING; char * string = NULL; char * buffer; - if (arrays != NULL) - { + if (arrays != NULL) { string = (char *)malloc(high_water_mark * sizeof(char)); buffer = (char *)malloc(OPENSCOP_MAX_STRING * sizeof(char)); - if ((string == NULL) || (buffer == NULL)) - { + if ((string == NULL) || (buffer == NULL)) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -170,8 +160,7 @@ openscop_arrays_print_openscop(openscop_arrays_p arrays) sprintf(buffer, "\n%d\n", arrays->nb_names); openscop_util_safe_strcat(&string, buffer, &high_water_mark); - for (i = 0; i < arrays->nb_names; i++) - { + for (i = 0; i < arrays->nb_names; i++) { sprintf(buffer, "%d %s\n", arrays->id[i], arrays->names[i]); openscop_util_safe_strcat(&string, buffer, &high_water_mark); } @@ -199,9 +188,7 @@ openscop_arrays_print_openscop(openscop_arrays_p arrays) * \param extensions The input string where to find an arrays structure. * \return A pointer to the arrays structure that has been read. */ -openscop_arrays_p -openscop_arrays_read(char * extensions) -{ +openscop_arrays_p openscop_arrays_read(char * extensions) { int i, k, array_id; int nb_names; int * id; @@ -213,8 +200,7 @@ openscop_arrays_read(char * extensions) content = openscop_util_tag_content(extensions, OPENSCOP_TAG_ARRAY_START, OPENSCOP_TAG_ARRAY_STOP); - if (content == NULL) - { + if (content == NULL) { fprintf(stderr, "[OpenScop] Info: no array optional tag.\n"); return NULL; } @@ -230,11 +216,9 @@ openscop_arrays_read(char * extensions) names[i] = NULL; // Get each array name. - for (k = 0; k < nb_names; k++) - { + for (k = 0; k < nb_names; k++) { // Skip blank or commented lines. - while (*content == '#' || *content == '\n') - { + while (*content == '#' || *content == '\n') { for (; *content != '\n'; ++content) continue; ++content; @@ -245,8 +229,7 @@ openscop_arrays_read(char * extensions) buff[i] = *content; buff[i] = '\0'; sscanf(buff, "%d", &array_id); - if (array_id <= 0) - { + if (array_id <= 0) { fprintf(stderr, "[OpenScop] Error: array id must be > 0.\n"); exit(1); } @@ -288,14 +271,11 @@ openscop_arrays_read(char * extensions) * \return A pointer to an empty arrays structure with fields set to * default values. */ -openscop_arrays_p -openscop_arrays_malloc() -{ +openscop_arrays_p openscop_arrays_malloc() { openscop_arrays_p arrays; arrays = (openscop_arrays_p)malloc(sizeof(openscop_arrays_t)); - if (arrays == NULL) - { + if (arrays == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -313,15 +293,11 @@ openscop_arrays_malloc() * This function frees the allocated memory for an arrays structure. * \param arrays The pointer to the arrays structure we want to free. */ -void -openscop_arrays_free(openscop_arrays_p arrays) -{ +void openscop_arrays_free(openscop_arrays_p arrays) { int i; - if (arrays != NULL) - { - if (arrays->names != NULL) - { + if (arrays != NULL) { + if (arrays->names != NULL) { free(arrays->id); for (i = 0; i < arrays->nb_names; i++) free(arrays->names[i]); @@ -345,9 +321,7 @@ openscop_arrays_free(openscop_arrays_p arrays) * \param arrays The pointer to the arrays structure we want to copy. * \return A pointer to the copy of the arrays structure. */ -openscop_arrays_p -openscop_arrays_copy(openscop_arrays_p arrays) -{ +openscop_arrays_p openscop_arrays_copy(openscop_arrays_p arrays) { openscop_arrays_p copy; int i; @@ -355,22 +329,18 @@ openscop_arrays_copy(openscop_arrays_p arrays) return NULL; copy = openscop_arrays_malloc(); - if (copy != NULL) - { + if (copy != NULL) { copy->nb_names = arrays->nb_names; copy->id = (int *)malloc(arrays->nb_names * sizeof(int)); copy->names = (char **)malloc(arrays->nb_names * sizeof(char*)); - if ((copy->id == NULL) || (copy->names == NULL)) - { + if ((copy->id == NULL) || (copy->names == NULL)) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } - for (i = 0; i < arrays->nb_names; i++) - { + for (i = 0; i < arrays->nb_names; i++) { copy->id[i] = arrays->id[i]; copy->names[i] = strdup(arrays->names[i]); - if ((copy->names[i] == NULL) && (arrays->names[i] != NULL)) - { + if ((copy->names[i] == NULL) && (arrays->names[i] != NULL)) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -391,9 +361,7 @@ openscop_arrays_copy(openscop_arrays_p arrays) * \param a2 The second arrays structure. * \return 1 if a1 and a2 are the same (content-wise), 0 otherwise. */ -int -openscop_arrays_equal(openscop_arrays_p a1, openscop_arrays_p a2) -{ +int openscop_arrays_equal(openscop_arrays_p a1, openscop_arrays_p a2) { int i, j, found; if ((a1 == NULL) && (a2 == NULL)) @@ -408,13 +376,10 @@ openscop_arrays_equal(openscop_arrays_p a1, openscop_arrays_p a2) // We accept a different order of the names, as long as the identifiers // are the same. - for (i = 0; i < a1->nb_names; i++) - { + for (i = 0; i < a1->nb_names; i++) { found = 0; - for (j = 0; j < a2->nb_names; j++) - { - if ((a1->id[i] == a2->id[j]) && (!strcmp(a1->names[i], a2->names[j]))) - { + for (j = 0; j < a2->nb_names; j++) { + if ((a1->id[i] == a2->id[j]) && (!strcmp(a1->names[i], a2->names[j]))) { found = 1; break; } @@ -438,17 +403,15 @@ openscop_arrays_equal(openscop_arrays_p a1, openscop_arrays_p a2) * \param nb_names Pointer to the location to store the number of names. * \return An array of strings corresponding to the array names. */ -char ** -openscop_arrays_generate_names(openscop_arrays_p arrays, int * nb_names) -{ +char ** openscop_arrays_generate_names(openscop_arrays_p arrays, + int * nb_names) { char ** names = NULL; char ** tmpnames; int i; *nb_names = 0; - if (arrays != NULL) - { + if (arrays != NULL) { // Get the maximum id (it will be nb_names). for (i = 0; i < arrays->nb_names; i++) if (arrays->id[i] > *nb_names) @@ -456,16 +419,13 @@ openscop_arrays_generate_names(openscop_arrays_p arrays, int * nb_names) // Allocate the array of names and store the existing names. names = (char **)malloc(*nb_names * sizeof(char *)); - if (names == NULL) - { + if (names == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } - for (i = 0; i < arrays->nb_names; i++) - { + for (i = 0; i < arrays->nb_names; i++) { names[arrays->id[i] - 1] = strdup(arrays->names[i]); - if (names[arrays->id[i] - 1] == NULL) - { + if (names[arrays->id[i] - 1] == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -473,8 +433,7 @@ openscop_arrays_generate_names(openscop_arrays_p arrays, int * nb_names) // Fill the missing names. tmpnames = openscop_util_strings_generate("A_", *nb_names); - for (i = 0; i < *nb_names; i++) - { + for (i = 0; i < *nb_names; i++) { if (names[i] == NULL || names[i][0] == '\0') names[i] = tmpnames[i]; // Use a generated name. else diff --git a/source/extensions/comment.c b/source/extensions/comment.c index 145dd74..23f2124 100644 --- a/source/extensions/comment.c +++ b/source/extensions/comment.c @@ -81,10 +81,8 @@ * \param comment The comment structure whose information has to be printed. * \param level Number of spaces before printing, for each line. */ -void -openscop_comment_print_structure(FILE * file, openscop_comment_p comment, - int level) -{ +void openscop_comment_print_structure(FILE * file, openscop_comment_p comment, + int level) { int j; char * tmp; @@ -97,8 +95,7 @@ openscop_comment_print_structure(FILE * file, openscop_comment_p comment, else fprintf(file, "+-- NULL comment\n"); - if (comment != NULL) - { + if (comment != NULL) { // Go to the right level. for(j = 0; j <= level; j++) fprintf(file, "|\t"); @@ -126,9 +123,7 @@ openscop_comment_print_structure(FILE * file, openscop_comment_p comment, * \param file The file where the information has to be printed. * \param comment The comment structure whose information has to be printed. */ -void -openscop_comment_print(FILE * file, openscop_comment_p comment) -{ +void openscop_comment_print(FILE * file, openscop_comment_p comment) { openscop_comment_print_structure(file, comment, 0); } @@ -140,19 +135,15 @@ openscop_comment_print(FILE * file, openscop_comment_p comment) * \param comment The comment structure whose information has to be printed. * \return A string containing the OpenScop dump of the comment structure. */ -char * -openscop_comment_print_openscop(openscop_comment_p comment) -{ +char * openscop_comment_print_openscop(openscop_comment_p comment) { int high_water_mark = OPENSCOP_MAX_STRING; char * string = NULL; char * buffer; - if (comment != NULL) - { + if (comment != NULL) { string = (char *)malloc(high_water_mark * sizeof(char)); buffer = (char *)malloc(OPENSCOP_MAX_STRING * sizeof(char)); - if ((string == NULL) || (buffer == NULL)) - { + if ((string == NULL) || (buffer == NULL)) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -191,22 +182,18 @@ openscop_comment_print_openscop(openscop_comment_p comment) * \param extensions The input string where to find a comment structure. * \return A pointer to the comment structure that has been read. */ -openscop_comment_p -openscop_comment_read(char * extensions) -{ +openscop_comment_p openscop_comment_read(char * extensions) { char * content; openscop_comment_p comment; content = openscop_util_tag_content(extensions, OPENSCOP_TAG_COMMENT_START, OPENSCOP_TAG_COMMENT_STOP); - if (content == NULL) - { + if (content == NULL) { fprintf(stderr, "[OpenScop] Info: no comment optional tag.\n"); return NULL; } - if (strlen(content) > OPENSCOP_MAX_STRING) - { + if (strlen(content) > OPENSCOP_MAX_STRING) { fprintf(stderr, "[OpenScop] Error: comment too long.\n"); exit(1); } @@ -231,14 +218,11 @@ openscop_comment_read(char * extensions) * \return A pointer to an empty comment structure with fields set to * default values. */ -openscop_comment_p -openscop_comment_malloc() -{ +openscop_comment_p openscop_comment_malloc() { openscop_comment_p comment; comment = (openscop_comment_p)malloc(sizeof(openscop_comment_t)); - if (comment == NULL) - { + if (comment == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -255,11 +239,8 @@ openscop_comment_malloc() * structure. * \param comment The pointer to the comment structure we want to free. */ -void -openscop_comment_free(openscop_comment_p comment) -{ - if (comment != NULL) - { +void openscop_comment_free(openscop_comment_p comment) { + if (comment != NULL) { if(comment->comment != NULL) free(comment->comment); free(comment); @@ -279,9 +260,7 @@ openscop_comment_free(openscop_comment_p comment) * \param comment The pointer to the comment structure we want to copy. * \return A pointer to the copy of the comment structure. */ -openscop_comment_p -openscop_comment_copy(openscop_comment_p comment) -{ +openscop_comment_p openscop_comment_copy(openscop_comment_p comment) { openscop_comment_p copy; if (comment == NULL) @@ -289,8 +268,7 @@ openscop_comment_copy(openscop_comment_p comment) copy = openscop_comment_malloc(); copy->comment = strdup(comment->comment); - if ((copy->comment == NULL) && (comment->comment != NULL)) - { + if ((copy->comment == NULL) && (comment->comment != NULL)) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -307,9 +285,7 @@ openscop_comment_copy(openscop_comment_p comment) * \param c2 The second comment structure. * \return 1 if c1 and c2 are the same (content-wise), 0 otherwise. */ -int -openscop_comment_equal(openscop_comment_p c1, openscop_comment_p c2) -{ +int openscop_comment_equal(openscop_comment_p c1, openscop_comment_p c2) { if ((c1 == NULL) && (c2 == NULL)) return 1; diff --git a/source/names.c b/source/names.c index b479a63..0e37d1b 100644 --- a/source/names.c +++ b/source/names.c @@ -81,29 +81,25 @@ * \param names The names structure whose information has to be printed. * \param level Number of spaces before printing, for each line. */ -void -openscop_names_print_structure(FILE * file, openscop_names_p names, int level) -{ +void openscop_names_print_structure(FILE * file, openscop_names_p names, + int level) { int j; // Go to the right level. for (j = 0; j < level; j++) fprintf(file, "|\t"); - if (names != NULL) - { + if (names != NULL) { if (names->textual == 1) fprintf(file, "+-- openscop_names_t\n"); else fprintf(file, "+-- openscop_names_t (non textual)\n"); } - else - { + else { fprintf(file, "+-- NULL names\n"); } - if ((names != NULL) && (names->textual == 1)) - { + if ((names != NULL) && (names->textual == 1)) { // A blank line. for (j = 0; j <= level+1; j++) fprintf(file, "|\t"); @@ -149,9 +145,7 @@ openscop_names_print_structure(FILE * file, openscop_names_p names, int level) * \param file The file where the information has to be printed. * \param names The names structure whose information has to be printed. */ -void -openscop_names_print(FILE * file, openscop_names_p names) -{ +void openscop_names_print(FILE * file, openscop_names_p names) { openscop_names_print_structure(file, names, 0); } @@ -163,9 +157,7 @@ openscop_names_print(FILE * file, openscop_names_p names) * \param file The file where the information has to be printed. * \param names The names structure whose information has to be printed. */ -void -openscop_names_print_openscop(FILE * file, openscop_names_p names) -{ +void openscop_names_print_openscop(FILE * file, openscop_names_p names) { int print = ((names != NULL) && (names->textual == 1)); openscop_util_strings_print_openscop(file, @@ -195,41 +187,32 @@ openscop_names_print_openscop(FILE * file, openscop_names_p names) * \param file The file where the names has to be read. * \return A pointer to the names structure that has been read. */ -openscop_names_p -openscop_names_read(FILE * file) -{ - openscop_names_p names; - - names = openscop_names_malloc(); - if (openscop_util_read_int(file, NULL) > 0) - { +openscop_names_p openscop_names_read(FILE * file) { + openscop_names_p names = openscop_names_malloc(); + + if (openscop_util_read_int(file, NULL) > 0) { names->parameters = openscop_util_strings_read(file, &(names->nb_parameters)); } - else - { + else { names->nb_parameters = 0; names->parameters = NULL; } - if (openscop_util_read_int(file, NULL) > 0) - { + if (openscop_util_read_int(file, NULL) > 0) { names->iterators = openscop_util_strings_read(file, &(names->nb_iterators)); } - else - { + else { names->nb_iterators = 0; names->iterators = NULL; } - if (openscop_util_read_int(file, NULL) > 0) - { + if (openscop_util_read_int(file, NULL) > 0) { names->scattdims = openscop_util_strings_read(file, &(names->nb_scattdims)); } - else - { + else { names->nb_scattdims = 0; names->scattdims = NULL; } @@ -251,14 +234,10 @@ openscop_names_read(FILE * file) * \return A pointer to an empty names structure with fields set to * default values. */ -openscop_names_p -openscop_names_malloc() -{ - openscop_names_p names; - - names = (openscop_names_p)malloc(sizeof(openscop_names_t)); - if (names == NULL) - { +openscop_names_p openscop_names_malloc() { + openscop_names_p names = (openscop_names_p)malloc(sizeof(openscop_names_t)); + + if (names == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -288,13 +267,9 @@ openscop_names_malloc() * the array itself), this function will only free the openscop_names_t shell. * \param names The pointer to the names structure we want to free. */ -void -openscop_names_free(openscop_names_p names) -{ - if (names != NULL) - { - if (names->textual == 1) - { +void openscop_names_free(openscop_names_p names) { + if (names != NULL) { + if (names->textual == 1) { openscop_util_strings_free(names->parameters, names->nb_parameters); openscop_util_strings_free(names->iterators, names->nb_iterators); openscop_util_strings_free(names->scattdims, names->nb_scattdims); @@ -320,12 +295,9 @@ openscop_names_free(openscop_names_p names) * \param names The pointer to the names structure we want to copy. * \return A pointer to the copy of the names structure provided as parameter. */ -openscop_names_p -openscop_names_copy(openscop_names_p names) -{ - openscop_names_p copy; +openscop_names_p openscop_names_copy(openscop_names_p names) { + openscop_names_p copy = openscop_names_malloc(); - copy = openscop_names_malloc(); copy->textual = names->textual; copy->nb_parameters = names->nb_parameters; copy->nb_iterators = names->nb_iterators; @@ -356,47 +328,39 @@ openscop_names_copy(openscop_names_p names) * \param n2 The second names structure. * \return 1 if n1 and n2 are the same (content-wise), 0 otherwise. */ -int -openscop_names_equal(openscop_names_p n1, openscop_names_p n2) -{ +int openscop_names_equal(openscop_names_p n1, openscop_names_p n2) { if ((n1 == NULL) && (n2 == NULL)) return 1; if (((n1 == NULL) && (n2 != NULL)) || ((n1 != NULL) && (n2 == NULL))) return 0; - if (!openscop_util_strings_equal(n1->parameters, n1->nb_parameters, - n2->parameters, n1->nb_parameters)) - { + n2->parameters, n1->nb_parameters)) { fprintf(stderr, "[OpenScop] info: parameters are not the same.\n"); return 0; } if (!openscop_util_strings_equal(n1->iterators, n1->nb_iterators, - n2->iterators, n1->nb_iterators)) - { + n2->iterators, n1->nb_iterators)) { fprintf(stderr, "[OpenScop] info: iterators are not the same.\n"); return 0; } if (!openscop_util_strings_equal(n1->scattdims, n1->nb_scattdims, - n2->scattdims, n1->nb_scattdims)) - { + n2->scattdims, n1->nb_scattdims)) { fprintf(stderr, "[OpenScop] info: scattdims are not the same.\n"); return 0; } if (!openscop_util_strings_equal(n1->localdims, n1->nb_localdims, - n2->localdims, n1->nb_localdims)) - { + n2->localdims, n1->nb_localdims)) { fprintf(stderr, "[OpenScop] info: localdims are not the same.\n"); return 0; } if (!openscop_util_strings_equal(n1->arrays, n1->nb_arrays, - n2->arrays, n1->nb_arrays)) - { + n2->arrays, n1->nb_arrays)) { fprintf(stderr, "[OpenScop] info: arrays are not the same.\n"); return 0; } @@ -415,29 +379,24 @@ openscop_names_equal(openscop_names_p n1, openscop_names_p n2) * \param min_nb_scattdims The minimum acceptable number of scattdims. * \return 0 if the integrity check fails, 1 otherwise. */ -int -openscop_names_integrity_check(openscop_names_p names, - int min_nb_parameters, - int min_nb_iterators, - int min_nb_scattdims) -{ +int openscop_names_integrity_check(openscop_names_p names, + int min_nb_parameters, + int min_nb_iterators, + int min_nb_scattdims) { if ((names->nb_parameters > 0) && - (names->nb_parameters < min_nb_parameters)) - { + (names->nb_parameters < min_nb_parameters)) { fprintf(stderr, "[OpenScop] Warning: not enough parameter names.\n"); return 0; } if ((names->nb_iterators > 0) && - (names->nb_iterators < min_nb_iterators)) - { + (names->nb_iterators < min_nb_iterators)) { fprintf(stderr, "[OpenScop] Warning: not enough iterator names.\n"); return 0; } if ((names->nb_scattdims > 0) && - (names->nb_scattdims < min_nb_scattdims)) - { + (names->nb_scattdims < min_nb_scattdims)) { fprintf(stderr, "[OpenScop] Warning: not enough scattering " "dimension names.\n"); return 0; diff --git a/source/relation.c b/source/relation.c index 830824d..fc6094d 100644 --- a/source/relation.c +++ b/source/relation.c @@ -83,10 +83,9 @@ * \param[in] relation The relation whose information have to be printed. * \param[in] level Number of spaces before printing, for each line. */ -void -openscop_relation_print_structure(FILE * file, openscop_relation_p relation, - int level) -{ +void openscop_relation_print_structure(FILE * file, + openscop_relation_p relation, + int level) { int i, j, first = 1; // Go to the right level. @@ -98,10 +97,8 @@ openscop_relation_print_structure(FILE * file, openscop_relation_p relation, else fprintf(file, "+-- NULL relation\n"); - while (relation != NULL) - { - if (! first) - { + while (relation != NULL) { + if (! first) { // Go to the right level. for (j = 0; j < level; j++) fprintf(file, "|\t"); @@ -119,15 +116,13 @@ openscop_relation_print_structure(FILE * file, openscop_relation_p relation, relation->nb_local_dims, relation->nb_parameters); // Display the relation. - for (i = 0; i < relation->nb_rows; i++) - { + for (i = 0; i < relation->nb_rows; i++) { for (j = 0; j <= level; j++) fprintf(file, "|\t"); fprintf(file, "[ "); - for (j = 0; j < relation->nb_columns; j++) - { + for (j = 0; j < relation->nb_columns; j++) { SCOPINT_print(file, OPENSCOP_FMT, relation->m[i][j]); fprintf(file, " "); } @@ -138,8 +133,7 @@ openscop_relation_print_structure(FILE * file, openscop_relation_p relation, relation = relation->next; // Next line. - if (relation != NULL) - { + if (relation != NULL) { for (j = 0; j <= level; j++) fprintf(file, "|\t"); fprintf(file, "|\n"); @@ -163,9 +157,7 @@ openscop_relation_print_structure(FILE * file, openscop_relation_p relation, * \param[in] file File where informations are printed. * \param[in] relation The relation whose information have to be printed. */ -void -openscop_relation_print(FILE * file, openscop_relation_p relation) -{ +void openscop_relation_print(FILE * file, openscop_relation_p relation) { openscop_relation_print_structure(file, relation, 0); } @@ -184,31 +176,26 @@ openscop_relation_print(FILE * file, openscop_relation_p relation) * \return A string that contains the printing of a value. */ static -char * -openscop_relation_expression_element(openscop_int_t val, int * first, int cst, - char * name) -{ - char * sval, * body, * temp; - - temp = (char *)malloc(OPENSCOP_MAX_STRING * sizeof(char)); - body = (char *)malloc(OPENSCOP_MAX_STRING * sizeof(char)); - sval = (char *)malloc(OPENSCOP_MAX_STRING * sizeof(char)); +char * openscop_relation_expression_element(openscop_int_t val, int * first, + int cst, char * name) { + char * temp = (char *)malloc(OPENSCOP_MAX_STRING * sizeof(char)); + char * body = (char *)malloc(OPENSCOP_MAX_STRING * sizeof(char)); + char * sval = (char *)malloc(OPENSCOP_MAX_STRING * sizeof(char)); + body[0] = '\0'; sval[0] = '\0'; // statements for the 'normal' processing. - if (SCOPINT_notzero_p(val) && (!cst)) - { - if ((*first) || SCOPINT_neg_p(val)) - { - if (SCOPINT_one_p(val)) // case 1 + if (SCOPINT_notzero_p(val) && (!cst)) { + if ((*first) || SCOPINT_neg_p(val)) { + if (SCOPINT_one_p(val)) { // case 1 sprintf(sval, "%s", name); - else - { - if (SCOPINT_mone_p(val)) // case -1 + } + else { + if (SCOPINT_mone_p(val)) { // case -1 sprintf(sval, "-%s", name); - else // default case - { + } + else { // default case SCOPINT_sprint(sval, OPENSCOP_FMT_TXT, val); sprintf(temp, "*%s", name); strcat(sval, temp); @@ -216,12 +203,11 @@ openscop_relation_expression_element(openscop_int_t val, int * first, int cst, } *first = 0; } - else - { - if (SCOPINT_one_p(val)) + else { + if (SCOPINT_one_p(val)) { sprintf(sval, "+%s", name); - else - { + } + else { sprintf(sval, "+"); SCOPINT_sprint(temp, OPENSCOP_FMT_TXT, val); strcat(sval, temp); @@ -230,20 +216,17 @@ openscop_relation_expression_element(openscop_int_t val, int * first, int cst, } } } - else - { - if (cst) - { + else { + if (cst) { if ((SCOPINT_zero_p(val) && (*first)) || SCOPINT_neg_p(val)) SCOPINT_sprint(sval, OPENSCOP_FMT_TXT, val); - if (SCOPINT_pos_p(val)) - { - if (!(*first)) - { + if (SCOPINT_pos_p(val)) { + if (!(*first)) { SCOPINT_sprint(sval, "+"OPENSCOP_FMT_TXT, val); // Block macro ! } - else + else { SCOPINT_sprint(sval, OPENSCOP_FMT_TXT, val); + } } } } @@ -266,32 +249,27 @@ openscop_relation_expression_element(openscop_int_t val, int * first, int cst, * printing comments is not needed. * \return A string that contains the printing of an affine expression. */ -static -char * -openscop_relation_expression(openscop_relation_p relation, int row, - openscop_names_p names) -{ +static char * openscop_relation_expression(openscop_relation_p relation, + int row, openscop_names_p names) { int i, first = 1; - char * sline, * sval; - - sline = (char *)malloc(OPENSCOP_MAX_STRING * sizeof(char)) ; - sline[0] = '\0' ; + char * sval; + char * sline = (char *)malloc(OPENSCOP_MAX_STRING * sizeof(char)); + sline[0] = '\0'; // First the iterator part. - for (i = 1; i <= names->nb_iterators; i++) - { - sval = openscop_relation_expression_element(relation->m[row][i], - &first, 0, names->iterators[i-1]); + for (i = 1; i <= names->nb_iterators; i++) { + sval = openscop_relation_expression_element( + relation->m[row][i], &first, 0, names->iterators[i-1]); strcat(sline, sval); free(sval); } // Next the local dims part. for (i = names->nb_iterators + 1; - i <= names->nb_iterators + names->nb_localdims; i++) - { - sval = openscop_relation_expression_element(relation->m[row][i], &first, 0, - names->localdims[i - names->nb_iterators - 1]); + i <= names->nb_iterators + names->nb_localdims; i++) { + sval = openscop_relation_expression_element( + relation->m[row][i], &first, 0, + names->localdims[i - names->nb_iterators - 1]); strcat(sline, sval); free(sval); } @@ -299,9 +277,9 @@ openscop_relation_expression(openscop_relation_p relation, int row, // Next the parameter part. for (i = names->nb_iterators + names->nb_localdims + 1; i <= names->nb_iterators + names->nb_localdims + names->nb_parameters; - i++) - { - sval = openscop_relation_expression_element(relation->m[row][i], &first, 0, + i++) { + sval = openscop_relation_expression_element( + relation->m[row][i], &first, 0, names->parameters[i - names->nb_iterators - names->nb_localdims - 1]); strcat(sline, sval); free(sval); @@ -325,32 +303,25 @@ openscop_relation_expression(openscop_relation_p relation, int row, * \return The accessed array identifier. */ static -int -openscop_relation_get_array_id(openscop_relation_p relation) -{ - if (relation == NULL) - { +int openscop_relation_get_array_id(openscop_relation_p relation) { + if (relation == NULL) { fprintf(stderr, "[OpenScop] Error: cannot find nb_arrays " "in a NULL relation.\n"); exit(1); } - if (relation->nb_local_dims == OPENSCOP_UNDEFINED) - { + if (relation->nb_local_dims == OPENSCOP_UNDEFINED) { // Matrix representation case. - if ((relation->nb_rows < 1) || (relation->nb_columns < 1)) - { + if ((relation->nb_rows < 1) || (relation->nb_columns < 1)) { fprintf(stderr, "[OpenScop] Error: not enough rows or columns " "to extract nb_arrays.\n"); exit(1); } return SCOPINT_get_si(relation->m[0][0]); } - else - { + else { // Relation representation case. - if ((relation->nb_rows < 1) || (relation->nb_columns < 2)) - { + if ((relation->nb_rows < 1) || (relation->nb_columns < 2)) { fprintf(stderr, "[OpenScop] Error: not enough rows or columns " "to extract nb_arrays.\n"); exit(1); @@ -373,17 +344,15 @@ openscop_relation_get_array_id(openscop_relation_p relation) * matrix representation is used. Set to NULL if printing * comments is not needed. */ -void -openscop_relation_print_openscop(FILE * file, openscop_relation_p relation, - int type, openscop_names_p names) -{ +void openscop_relation_print_openscop(FILE * file, + openscop_relation_p relation, + int type, openscop_names_p names) { int i, j, k; int part, nb_parts; char * expression; openscop_relation_p r; - if (relation == NULL) - { + if (relation == NULL) { fprintf(stderr, "[OpenScop] Warning: asked to print a NULL relation.\n"); fprintf(file, "# NULL relation\n"); return; @@ -398,8 +367,7 @@ openscop_relation_print_openscop(FILE * file, openscop_relation_p relation, // Count the number of parts in the union and print it if it is not 1. r = relation; nb_parts = 0; - while (r != NULL) - { + while (r != NULL) { nb_parts++; r = r->next; } @@ -407,8 +375,7 @@ openscop_relation_print_openscop(FILE * file, openscop_relation_p relation, fprintf(file, "# Union with %d parts\n%d\n", nb_parts, nb_parts); // Print each part of the union. - for (part = 1; part <= nb_parts; part++) - { + for (part = 1; part <= nb_parts; part++) { if (nb_parts > 1) fprintf(file, "# Union part No.%d\n", part); if ((relation->nb_output_dims == OPENSCOP_UNDEFINED) && @@ -422,16 +389,13 @@ openscop_relation_print_openscop(FILE * file, openscop_relation_p relation, relation->nb_output_dims, relation->nb_input_dims, relation->nb_local_dims, relation->nb_parameters); - for (i = 0; i < relation->nb_rows; i++) - { - for (j = 0; j < relation->nb_columns; j++) - { + for (i = 0; i < relation->nb_rows; i++) { + for (j = 0; j < relation->nb_columns; j++) { SCOPINT_print(file, OPENSCOP_FMT, relation->m[i][j]); fprintf(file, " "); } - if (type == OPENSCOP_TYPE_DOMAIN) - { + if (type == OPENSCOP_TYPE_DOMAIN) { expression = openscop_relation_expression(relation, i, names); fprintf(file, " ## %s", expression); free(expression); @@ -441,25 +405,21 @@ openscop_relation_print_openscop(FILE * file, openscop_relation_p relation, fprintf(file, " >= 0"); } - if (type == OPENSCOP_TYPE_SCATTERING) - { + if (type == OPENSCOP_TYPE_SCATTERING) { expression = openscop_relation_expression(relation, i, names); fprintf(file, " ## %s", expression); free(expression); } - if (type == OPENSCOP_TYPE_ACCESS) - { + if (type == OPENSCOP_TYPE_ACCESS) { //TODO: works only for matrix: use openscop_relation_get_array_id - if (SCOPINT_notzero_p(relation->m[i][0])) - { + if (SCOPINT_notzero_p(relation->m[i][0])) { if (strncmp(names->arrays[SCOPINT_get_si(relation->m[i][0]) - 1], OPENSCOP_FAKE_ARRAY, strlen(OPENSCOP_FAKE_ARRAY))) fprintf(file, " ## %s", names->arrays[SCOPINT_get_si(relation->m[i][0]) - 1]); k = i; - do - { + do { expression = openscop_relation_expression(relation, k, names); fprintf(file, "[%s]", expression); free(expression); @@ -468,8 +428,9 @@ openscop_relation_print_openscop(FILE * file, openscop_relation_p relation, while ((k < relation->nb_rows) && SCOPINT_zero_p(relation->m[k][0])); } - else + else { fprintf(file, " ##"); + } } fprintf(file, "\n"); @@ -491,9 +452,7 @@ openscop_relation_print_openscop(FILE * file, openscop_relation_p relation, * \param[in] file The input stream. * \return A pointer to the relation structure that has been read. */ -openscop_relation_p -openscop_relation_read(FILE * foo) -{ +openscop_relation_p openscop_relation_read(FILE * foo) { int i, j, k, n, read = 0; int nb_rows, nb_columns; int nb_output_dims, nb_input_dims, nb_local_dims, nb_parameters; @@ -506,11 +465,9 @@ openscop_relation_read(FILE * foo) openscop_int_t * p = NULL; // Read each part of the union (the number of parts may be updated inside) - for (k = 0; k < nb_union_parts; k++) - { + for (k = 0; k < nb_union_parts; k++) { // Read the number of union parts or the properties of the union part - while (read_properties) - { + while (read_properties) { read_properties = 0; // Read relation properties. @@ -520,25 +477,23 @@ openscop_relation_read(FILE * foo) &nb_local_dims, &nb_parameters); if (((read != 1) && (read != 2) && (read != 6)) || - ((read == 1) && (may_read_nb_union_parts != 1))) - { + ((read == 1) && (may_read_nb_union_parts != 1))) { fprintf(stderr, "[OpenScop] Error:: badly formated relation.\n"); exit(1); } - if (read == 1) - { + + if (read == 1) { // Only one number means a union and is the number of parts. nb_union_parts = nb_rows; - if (nb_union_parts < 1) - { + if (nb_union_parts < 1) { fprintf(stderr, "[OpenScop] Error: negative nb of union parts.\n"); exit(1); } // Allow to read the properties of the first part of the union. read_properties = 1; } - if (read == 2) - { + + if (read == 2) { nb_output_dims = OPENSCOP_UNDEFINED; nb_input_dims = OPENSCOP_UNDEFINED; nb_local_dims = OPENSCOP_UNDEFINED; @@ -559,38 +514,31 @@ openscop_relation_read(FILE * foo) if ((relation->nb_rows != 0) && (relation->nb_columns != 0)) p = relation->m[0]; - for (i = 0; i < relation->nb_rows; i++) - { + for (i = 0; i < relation->nb_rows; i++) { c = openscop_util_skip_blank_and_comments(foo, s); - if (c == NULL) - { + if (c == NULL) { fprintf(stderr, "[OpenScop] Error: not enough rows.\n"); exit(1); } - for (j = 0; j < relation->nb_columns; j++) - { - if (c == NULL || *c == '#' || *c == '\n') - { + for (j = 0; j < relation->nb_columns; j++) { + if (c == NULL || *c == '#' || *c == '\n') { fprintf(stderr, "[OpenScop] Error: not enough columns.\n"); exit(1); } - if (sscanf(c, "%s%n", str, &n) == 0) - { + if (sscanf(c, "%s%n", str, &n) == 0) { fprintf(stderr, "[OpenScop] Error: not enough rows.\n"); exit(1); } #if defined(OPENSCOP_INT_T_IS_MP) long long val; - if (sscanf(str, "%lld", &val) == 0) - { + if (sscanf(str, "%lld", &val) == 0) { fprintf(stderr, "[OpenScop] Error: failed to read an integer.\n"); exit(1); } mpz_set_si(*p++, val); #else - if (sscanf(str, OPENSCOP_FMT_TXT, p++) == 0) - { + if (sscanf(str, OPENSCOP_FMT_TXT, p++) == 0) { fprintf(stderr, "[OpenScop] Error: failed to read an integer.\n"); exit(1); } @@ -600,13 +548,13 @@ openscop_relation_read(FILE * foo) } // Build the linked list of union parts. - if (first == 1) - { + if (first == 1) { relation_union = relation; first = 0; } - else + else { previous->next = relation; + } previous = relation; read_properties = 1; @@ -631,16 +579,13 @@ openscop_relation_read(FILE * foo) * \return A pointer to an empty relation with fields set to default values * and a ready-to-use constraint matrix. */ -openscop_relation_p -openscop_relation_malloc(int nb_rows, int nb_columns) -{ +openscop_relation_p openscop_relation_malloc(int nb_rows, int nb_columns) { openscop_relation_p relation; openscop_int_t ** p, * q; int i, j; relation = (openscop_relation_p)malloc(sizeof(openscop_relation_t)); - if (relation == NULL) - { + if (relation == NULL) { fprintf(stderr, "[OpenScop] Error: memory Overflow.\n"); exit(1); } @@ -653,25 +598,22 @@ openscop_relation_malloc(int nb_rows, int nb_columns) relation->nb_local_dims = OPENSCOP_UNDEFINED; if ((nb_rows == 0) || (nb_columns == 0) || - (nb_rows == OPENSCOP_UNDEFINED) || (nb_columns == OPENSCOP_UNDEFINED)) + (nb_rows == OPENSCOP_UNDEFINED) || (nb_columns == OPENSCOP_UNDEFINED)) { relation->m = NULL; - else - { + } + else { p = (openscop_int_t **)malloc(nb_rows * sizeof(openscop_int_t *)); - if (p == NULL) - { + if (p == NULL) { fprintf(stderr, "[OpenScop] Error: memory Overflow.\n"); exit(1); } q = (openscop_int_t *)malloc(nb_rows*nb_columns*sizeof(openscop_int_t)); - if (q == NULL) - { + if (q == NULL) { fprintf(stderr, "[OpenScop] Error: memory Overflow.\n"); exit(1); } relation->m = p; - for (i = 0; i < nb_rows; i++) - { + for (i = 0; i < nb_rows; i++) { *p++ = q; for (j = 0; j < nb_columns; j++) SCOPINT_init_set_si(*(q+j),0); @@ -691,9 +633,7 @@ openscop_relation_malloc(int nb_rows, int nb_columns) * openscop_relation_t structure, i.e. only m. * \param[in] relation The pointer to the relation we want to free internals. */ -void -openscop_relation_free_inside(openscop_relation_p relation) -{ +void openscop_relation_free_inside(openscop_relation_p relation) { int i, nb_elements; openscop_int_t * p; @@ -708,8 +648,7 @@ openscop_relation_free_inside(openscop_relation_p relation) for (i = 0; i < nb_elements; i++) SCOPINT_clear(*p++); - if (relation->m != NULL) - { + if (relation->m != NULL) { if (nb_elements > 0) free(relation->m[0]); free(relation->m); @@ -723,16 +662,13 @@ openscop_relation_free_inside(openscop_relation_p relation) * structure. * \param[in] relation The pointer to the relation we want to free. */ -void -openscop_relation_free(openscop_relation_p relation) -{ +void openscop_relation_free(openscop_relation_p relation) { openscop_relation_p tmp; if (relation == NULL) return; - while (relation != NULL) - { + while (relation != NULL) { tmp = relation->next; openscop_relation_free_inside(relation); free(relation); @@ -755,16 +691,13 @@ openscop_relation_free(openscop_relation_p relation) * \return 1 if the relation has "matrix" representation, -1 if it is NULL, * 0 in all other cases. */ -int -openscop_relation_is_matrix(openscop_relation_p relation) -{ +int openscop_relation_is_matrix(openscop_relation_p relation) { if (relation == NULL) return -1; // A relation has matrix representation if all nb_local_dims fields // of all parts of the union is OPENSCOP_UNDEFINED. - while (relation != NULL) - { + while (relation != NULL) { if (relation->nb_local_dims != OPENSCOP_UNDEFINED) return 0; @@ -787,9 +720,8 @@ openscop_relation_is_matrix(openscop_relation_p relation) * \return A pointer to the full copy of the relation union restricted to the * first n rows of constraint matrix for each part of the union. */ -openscop_relation_p -openscop_relation_ncopy(openscop_relation_p relation, int n) -{ +openscop_relation_p openscop_relation_ncopy(openscop_relation_p relation, + int n) { int i, j; int first = 1, all_rows = 0; openscop_relation_p copy = NULL, node, previous = NULL; @@ -797,13 +729,11 @@ openscop_relation_ncopy(openscop_relation_p relation, int n) if (n == -1) all_rows = 1; - while (relation != NULL) - { + while (relation != NULL) { if (all_rows) n = relation->nb_rows; - if (n > relation->nb_rows) - { + if (n > relation->nb_rows) { fprintf(stderr,"[OpenScop] Error: not enough rows in the relation\n"); exit(1); } @@ -818,14 +748,12 @@ openscop_relation_ncopy(openscop_relation_p relation, int n) for (j = 0; j < relation->nb_columns; j++) SCOPINT_assign(node->m[i][j], relation->m[i][j]); - if (first) - { + if (first) { first = 0; copy = node; previous = node; } - else - { + else { previous->next = node; previous = previous->next; } @@ -844,9 +772,7 @@ openscop_relation_ncopy(openscop_relation_p relation, int n) * \param[in] relation The pointer to the relation we want to copy. * \return A pointer to the copy of the union of relations. */ -openscop_relation_p -openscop_relation_copy(openscop_relation_p relation) -{ +openscop_relation_p openscop_relation_copy(openscop_relation_p relation) { if (relation == NULL) return NULL; @@ -863,16 +789,13 @@ openscop_relation_copy(openscop_relation_p relation) * \param[in] vector The vector that will replace a row of the relation. * \param[in] row The row of the relation to be replaced. */ -void -openscop_relation_replace_vector(openscop_relation_p relation, - openscop_vector_p vector, int row) -{ +void openscop_relation_replace_vector(openscop_relation_p relation, + openscop_vector_p vector, int row) { int i; if ((relation == NULL) || (vector == NULL) || (relation->nb_columns != vector->size) || - (row >= relation->nb_rows) || (row < 0)) - { + (row >= relation->nb_rows) || (row < 0)) { fprintf(stderr,"[OpenScop] Error: vector cannot replace relation row.\n"); exit(1); } @@ -891,23 +814,20 @@ openscop_relation_replace_vector(openscop_relation_p relation, * \param[in] vector The vector that will replace a row of the relation. * \param[in] row The row of the relation to be replaced. */ -void -openscop_relation_add_vector(openscop_relation_p relation, - openscop_vector_p vector, - int row) -{ +void openscop_relation_add_vector(openscop_relation_p relation, + openscop_vector_p vector, int row) { int i; if ((relation == NULL) || (vector == NULL) || (relation->nb_columns != vector->size) || - (row >= relation->nb_rows) || (row < 0)) - { + (row >= relation->nb_rows) || (row < 0)) { fprintf(stderr,"[OpenScop] Error: vector cannot be added to relation.\n"); exit(1); } if (SCOPINT_get_si(relation->m[row][0]) == 0) SCOPINT_assign(relation->m[row][0], vector->v[0]); + for (i = 1; i < vector->size; i++) SCOPINT_addto(relation->m[row][i], relation->m[row][i], vector->v[i]); } @@ -922,23 +842,20 @@ openscop_relation_add_vector(openscop_relation_p relation, * \param[in] vector The vector to subtract to a relation row. * \param[in] row The row of the relation to subtract the vector. */ -void -openscop_relation_sub_vector(openscop_relation_p relation, - openscop_vector_p vector, - int row) -{ +void openscop_relation_sub_vector(openscop_relation_p relation, + openscop_vector_p vector, int row) { int i; if ((relation == NULL) || (vector == NULL) || (relation->nb_columns != vector->size) || - (row >= relation->nb_rows) || (row < 0)) - { + (row >= relation->nb_rows) || (row < 0)) { fprintf(stderr,"[OpenScop] Error: vector cannot be subtracted to row.\n"); exit(1); } if (SCOPINT_get_si(relation->m[row][0]) == 0) SCOPINT_assign(relation->m[row][0], vector->v[0]); + for (i = 1; i < vector->size; i++) SCOPINT_subtract(relation->m[row][i], relation->m[row][i], vector->v[i]); } @@ -954,11 +871,8 @@ openscop_relation_sub_vector(openscop_relation_p relation, * \param[in] vector The vector that will be added relation. * \param[in] row The row where to insert the vector. */ -void -openscop_relation_insert_vector(openscop_relation_p relation, - openscop_vector_p vector, - int row) -{ +void openscop_relation_insert_vector(openscop_relation_p relation, + openscop_vector_p vector, int row) { openscop_relation_p temp; temp = openscop_relation_from_vector(vector); @@ -974,9 +888,7 @@ openscop_relation_insert_vector(openscop_relation_p relation, * \param[in] vector The vector to convert to a relation. * \return A pointer to a relation resulting from the vector conversion. */ -openscop_relation_p -openscop_relation_from_vector(openscop_vector_p vector) -{ +openscop_relation_p openscop_relation_from_vector(openscop_vector_p vector) { openscop_relation_p relation; if (vector == NULL) @@ -997,16 +909,13 @@ openscop_relation_from_vector(openscop_vector_p vector) * \param[in] r2 The relation containing the new rows. * \param[in] row The first row of the relation r1 to be replaced. */ -void -openscop_relation_replace_relation(openscop_relation_p r1, - openscop_relation_p r2, int row) -{ +void openscop_relation_replace_relation(openscop_relation_p r1, + openscop_relation_p r2, int row) { int i, j; if ((r1 == NULL) || (r2 == NULL) || (r1->nb_columns != r1->nb_columns) || - ((row + r2->nb_rows) > r1->nb_rows) || (row < 0)) - { + ((row + r2->nb_rows) > r1->nb_rows) || (row < 0)) { fprintf(stderr,"[OpenScop] Error: relation rows could not be replaced.\n"); exit(1); } @@ -1027,10 +936,8 @@ openscop_relation_replace_relation(openscop_relation_p r1, * \param[in] r2 The relation to be inserted. * \param[in] row The row where to insert the relation */ -void -openscop_relation_insert_relation(openscop_relation_p r1, - openscop_relation_p r2, int row) -{ +void openscop_relation_insert_relation(openscop_relation_p r1, + openscop_relation_p r2, int row) { int i, j; openscop_relation_p temp; @@ -1038,8 +945,7 @@ openscop_relation_insert_relation(openscop_relation_p r1, return; if ((r1->nb_columns != r2->nb_columns) || - (row > r1->nb_rows) || (row < 0)) - { + (row > r1->nb_rows) || (row < 0)) { fprintf(stderr,"[OpenScop] Error: constraints cannot be inserted.\n"); exit(1); } @@ -1079,9 +985,8 @@ openscop_relation_insert_relation(openscop_relation_p r1, * \return A pointer to the relation resulting from the concatenation of * the first elements of r1 and r2. */ -openscop_relation_p -openscop_relation_concat(openscop_relation_p r1, openscop_relation_p r2) -{ +openscop_relation_p openscop_relation_concat(openscop_relation_p r1, + openscop_relation_p r2) { openscop_relation_p new; if (r1 == NULL) @@ -1090,14 +995,12 @@ openscop_relation_concat(openscop_relation_p r1, openscop_relation_p r2) if (r2 == NULL) return openscop_relation_copy(r1); - if (r1->nb_columns != r2->nb_columns) - { + if (r1->nb_columns != r2->nb_columns) { fprintf(stderr, "[OpenScop] Error: incompatible sizes " "for concatenation.\n"); exit(1); } - if (r1->next || r2->next) - { + if (r1->next || r2->next) { fprintf(stderr, "[OpenScop] Warning: relation concatenation is done " "on the first elements only.\n"); } @@ -1118,13 +1021,10 @@ openscop_relation_concat(openscop_relation_p r1, openscop_relation_p r2) * \param[in] r2 The second relation. * \return 1 if r1 and r2 are the same (content-wise), 0 otherwise. */ -int -openscop_relation_equal(openscop_relation_p r1, openscop_relation_p r2) -{ +int openscop_relation_equal(openscop_relation_p r1, openscop_relation_p r2) { int i, j; - while ((r1 != NULL) && (r2 != NULL)) - { + while ((r1 != NULL) && (r2 != NULL)) { if (r1 == r2) return 1; @@ -1166,20 +1066,15 @@ openscop_relation_equal(openscop_relation_p r1, openscop_relation_p r2) * not OPENSCOP_UNDEFINED, 1 otherwise. */ static -int -openscop_relation_check_property(int * expected, int actual) -{ - if (*expected != OPENSCOP_UNDEFINED) - { +int openscop_relation_check_property(int * expected, int actual) { + if (*expected != OPENSCOP_UNDEFINED) { if ((actual != OPENSCOP_UNDEFINED) && - (actual != *expected)) - { + (actual != *expected)) { fprintf(stderr, "[OpenScop] Warning: unexpected property.\n"); return 0; } } - else - { + else { *expected = actual; } @@ -1201,18 +1096,16 @@ openscop_relation_check_property(int * expected, int actual) * \return 0 if the number of columns seems incorrect, 1 otherwise. */ static -int -openscop_relation_check_nb_columns(openscop_relation_p relation, - int expected_nb_output_dims, - int expected_nb_input_dims, - int expected_nb_parameters) -{ +int openscop_relation_check_nb_columns(openscop_relation_p relation, + int expected_nb_output_dims, + int expected_nb_input_dims, + int expected_nb_parameters) { int expected_nb_local_dims, expected_nb_columns; if ((expected_nb_output_dims != OPENSCOP_UNDEFINED) && (expected_nb_input_dims != OPENSCOP_UNDEFINED) && - (expected_nb_parameters != OPENSCOP_UNDEFINED)) - { + (expected_nb_parameters != OPENSCOP_UNDEFINED)) { + if (relation->nb_local_dims == OPENSCOP_UNDEFINED) expected_nb_local_dims = 0; else @@ -1224,8 +1117,7 @@ openscop_relation_check_nb_columns(openscop_relation_p relation, expected_nb_parameters + 2; - if (expected_nb_columns != relation->nb_columns) - { + if (expected_nb_columns != relation->nb_columns) { fprintf(stderr, "[OpenScop] Warning: unexpected number of columns.\n"); return 0; } @@ -1244,14 +1136,11 @@ openscop_relation_check_nb_columns(openscop_relation_p relation, * \return 0 if the representation consistency check fails, 1 if it succeeds. */ static -int -openscop_relation_consistency_check(openscop_relation_p r) -{ +int openscop_relation_consistency_check(openscop_relation_p r) { int matrix = 0; int relation = 0; - while (r != NULL) - { + while (r != NULL) { if (r->nb_local_dims == OPENSCOP_UNDEFINED) matrix = 1; else @@ -1278,36 +1167,30 @@ openscop_relation_consistency_check(openscop_relation_p r) * \param[in] expected_nb_parameters Expected number of parameters. * \return 0 if the integrity check fails, 1 otherwise. */ -int -openscop_relation_integrity_check(openscop_relation_p relation, - int type, - int expected_nb_output_dims, - int expected_nb_input_dims, - int expected_nb_parameters) -{ +int openscop_relation_integrity_check(openscop_relation_p relation, + int type, + int expected_nb_output_dims, + int expected_nb_input_dims, + int expected_nb_parameters) { int i, start; // Check the NULL case. - if (relation == NULL) - { + if (relation == NULL) { if ((expected_nb_output_dims != OPENSCOP_UNDEFINED) && (expected_nb_input_dims != OPENSCOP_UNDEFINED) && - (expected_nb_parameters != OPENSCOP_UNDEFINED)) - { + (expected_nb_parameters != OPENSCOP_UNDEFINED)) { fprintf(stderr, "[OpenScop] Warning: NULL relation with " "some expected properties.\n"); return 0; } - else - { + else { fprintf(stderr, "[OpenScop] Warning: NULL relation.\n"); return 1; } } // Check the relation is using either matrix or relation representation. - if (!openscop_relation_consistency_check(relation)) - { + if (!openscop_relation_consistency_check(relation)) { fprintf(stderr, "[OpenScop] Warning: inconsistent representation " "(both matrix and relation).\n"); return 0; @@ -1316,8 +1199,7 @@ openscop_relation_integrity_check(openscop_relation_p relation, // Check that a context has actually 0 or an undefined #output dimensions. if ((type == OPENSCOP_TYPE_CONTEXT) && ((relation->nb_output_dims != 0) && - (relation->nb_output_dims != OPENSCOP_UNDEFINED))) - { + (relation->nb_output_dims != OPENSCOP_UNDEFINED))) { fprintf(stderr, "[OpenScop] Warning: context without 0 " "as number of output dimensions.\n"); return 0; @@ -1327,8 +1209,7 @@ openscop_relation_integrity_check(openscop_relation_p relation, if (((type == OPENSCOP_TYPE_DOMAIN) || (type == OPENSCOP_TYPE_CONTEXT)) && ((relation->nb_input_dims != 0) && - (relation->nb_input_dims != OPENSCOP_UNDEFINED))) - { + (relation->nb_input_dims != OPENSCOP_UNDEFINED))) { fprintf(stderr, "[OpenScop] Warning: domain or context without 0 " "as number of input dimensions.\n"); return 0; @@ -1344,14 +1225,12 @@ openscop_relation_integrity_check(openscop_relation_p relation, relation->nb_parameters)) return 0; - while (relation != NULL) - { + while (relation != NULL) { // Properties (except the number of local dimensions) should be the same // in all parts. if ((expected_nb_output_dims != relation->nb_output_dims) || (expected_nb_input_dims != relation->nb_input_dims) || - (expected_nb_parameters != relation->nb_parameters)) - { + (expected_nb_parameters != relation->nb_parameters)) { fprintf(stderr, "[OpenScop] Warning: inconsistent properties.\n"); return 0; } @@ -1370,51 +1249,43 @@ openscop_relation_integrity_check(openscop_relation_p relation, // and all other elements are 0. // - for scattering functions in "matrix" representation, the // first column is made only of 0. - if ((relation->nb_rows > 0) && (relation->nb_columns > 0)) - { + if ((relation->nb_rows > 0) && (relation->nb_columns > 0)) { start = 0; if ((relation->nb_local_dims == OPENSCOP_UNDEFINED) && - (type == OPENSCOP_TYPE_ACCESS)) - { + (type == OPENSCOP_TYPE_ACCESS)) { start = 1; - if (SCOPINT_get_si(relation->m[0][0]) <= 0) - { + if (SCOPINT_get_si(relation->m[0][0]) <= 0) { fprintf(stderr, "[OpenScop] Warning: bad array identifier " "in access function.\n"); return 0; } } - for (i = start; i < relation->nb_rows; i++) - { + for (i = start; i < relation->nb_rows; i++) { if ((type == OPENSCOP_TYPE_ACCESS) && - (openscop_relation_is_matrix(relation))) - { - if (!SCOPINT_zero_p(relation->m[i][0])) - { + (openscop_relation_is_matrix(relation))) { + if (!SCOPINT_zero_p(relation->m[i][0])) { fprintf(stderr, "[OpenScop] Warning: non-first element of the " - "first column of an access function is not 0.\n"); + "first column of an access function is not 0.\n"); return 0; } } - else if ((type == OPENSCOP_TYPE_SCATTERING) && - (openscop_relation_is_matrix(relation))) - { - if (!SCOPINT_zero_p(relation->m[i][0])) - { - fprintf(stderr, "[OpenScop] Warning: first column of a " - "scattering function not made of 0s.\n"); - return 0; + else { + if ((type == OPENSCOP_TYPE_SCATTERING) && + (openscop_relation_is_matrix(relation))) { + if (!SCOPINT_zero_p(relation->m[i][0])) { + fprintf(stderr, "[OpenScop] Warning: first column of a " + "scattering function not made of 0s.\n"); + return 0; + } } - } - else - { - if (!SCOPINT_zero_p(relation->m[i][0]) && - !SCOPINT_one_p(relation->m[i][0])) - { - fprintf(stderr, "[OpenScop] Warning: first column of a relation " - "is not made of 0 or 1 only.\n"); - return 0; + else { + if (!SCOPINT_zero_p(relation->m[i][0]) && + !SCOPINT_one_p(relation->m[i][0])) { + fprintf(stderr, "[OpenScop] Warning: first column of a " + "relation is not made of 0 or 1 only.\n"); + return 0; + } } } } @@ -1442,9 +1313,8 @@ openscop_relation_integrity_check(openscop_relation_p relation, * \param[in] r2 The second relation. * \return A new relation corresponding to the union of r1 and r2. */ -openscop_relation_p -openscop_relation_union(openscop_relation_p r1, openscop_relation_p r2) -{ +openscop_relation_p openscop_relation_union(openscop_relation_p r1, + openscop_relation_p r2) { openscop_relation_p copy1, copy2, tmp; if ((r1 == NULL) && (r2 == NULL)) diff --git a/source/relation_list.c b/source/relation_list.c index 5f72104..9b62945 100644 --- a/source/relation_list.c +++ b/source/relation_list.c @@ -82,10 +82,9 @@ * \param l The list of relations whose information have to be printed. * \param level Number of spaces before printing, for each line. */ -void -openscop_relation_list_print_structure(FILE * file, openscop_relation_list_p l, - int level) -{ +void openscop_relation_list_print_structure(FILE * file, + openscop_relation_list_p l, + int level) { int j, first = 1; // Go to the right level. @@ -97,10 +96,8 @@ openscop_relation_list_print_structure(FILE * file, openscop_relation_list_p l, else fprintf(file, "+-- NULL relation list\n"); - while (l != NULL) - { - if (!first) - { + while (l != NULL) { + if (!first) { // Go to the right level. for (j = 0; j < level; j++) fprintf(file, "|\t"); @@ -120,8 +117,7 @@ openscop_relation_list_print_structure(FILE * file, openscop_relation_list_p l, l = l->next; // Next line. - if (l != NULL) - { + if (l != NULL) { for (j = 0; j <= level; j++) fprintf(file, "|\t"); fprintf(file, "V\n"); @@ -142,9 +138,7 @@ openscop_relation_list_print_structure(FILE * file, openscop_relation_list_p l, * \param file File where informations are printed. * \param list The relation whose information have to be printed. */ -void -openscop_relation_list_print(FILE * file, openscop_relation_list_p list) -{ +void openscop_relation_list_print(FILE * file, openscop_relation_list_p list) { openscop_relation_list_print_structure(file, list, 0); } @@ -161,11 +155,9 @@ openscop_relation_list_print(FILE * file, openscop_relation_list_p list) * representation is used. Set to NULL if printing comments * is not needed. */ -void -openscop_relation_list_print_openscop(FILE * file, - openscop_relation_list_p list, - int type, openscop_names_p names) -{ +void openscop_relation_list_print_openscop(FILE * file, + openscop_relation_list_p list, + int type, openscop_names_p names) { int i; openscop_relation_list_p head = list; @@ -181,8 +173,7 @@ openscop_relation_list_print_openscop(FILE * file, // Print each element of the relation list. i = 0; - while (head) - { + while (head) { fprintf(file, "# List element No.%d\n", i); openscop_relation_print_openscop(file, head->elt, type, names); head = head->next; @@ -203,9 +194,7 @@ openscop_relation_list_print_openscop(FILE * file, * \param file The input stream. * \return A pointer to the relation list structure that has been read. */ -openscop_relation_list_p -openscop_relation_list_read(FILE* file) -{ +openscop_relation_list_p openscop_relation_list_read(FILE* file) { char s[OPENSCOP_MAX_STRING]; int i; openscop_relation_list_p list; @@ -222,8 +211,7 @@ openscop_relation_list_read(FILE* file) // Allocate the header of the list and start reading each element. res = list = openscop_relation_list_malloc(); - for (i = 0; i < nb_mat; ++i) - { + for (i = 0; i < nb_mat; ++i) { list->elt = openscop_relation_read(file); if (i < nb_mat - 1) list->next = openscop_relation_list_malloc(); @@ -247,14 +235,11 @@ openscop_relation_list_read(FILE* file) * \return A pointer to an empty relation list with fields set to default * values. */ -openscop_relation_list_p -openscop_relation_list_malloc() -{ - openscop_relation_list_p res = - (openscop_relation_list_p) malloc(sizeof(openscop_relation_list_t)); - - if (res == NULL) - { +openscop_relation_list_p openscop_relation_list_malloc() { + openscop_relation_list_p res; + res = (openscop_relation_list_p)malloc(sizeof(openscop_relation_list_t)); + + if (res == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -273,16 +258,13 @@ openscop_relation_list_malloc() * structure, and all the relations stored in the list. * \param list The pointer to the relation list we want to free. */ -void -openscop_relation_list_free(openscop_relation_list_p list) -{ +void openscop_relation_list_free(openscop_relation_list_p list) { openscop_relation_list_p tmp; if (list == NULL) return; - while (list) - { + while (list) { if (list->elt) openscop_relation_free(list->elt); tmp = list->next; @@ -301,17 +283,12 @@ openscop_relation_list_free(openscop_relation_list_p list) * openscop_relation_list_node function: * This function builds an openscop_relation_list_t node and sets its * relation element as a copy of the one provided as parameter. - * \param relation The pointer to the relation to copy/paste in a list node. + * \param r The pointer to the relation to copy/paste in a list node. * \return A pointer to a relation list node containing a copy of "relation". */ -openscop_relation_list_p -openscop_relation_list_node(openscop_relation_p relation) -{ - openscop_relation_list_p new; - - new = openscop_relation_list_malloc(); - new->elt = openscop_relation_copy(relation); - +openscop_relation_list_p openscop_relation_list_node(openscop_relation_p r) { + openscop_relation_list_p new = openscop_relation_list_malloc(); + new->elt = openscop_relation_copy(r); return new; } @@ -323,25 +300,22 @@ openscop_relation_list_node(openscop_relation_p relation) * \param list The pointer to the relation list we want to copy. * \return A pointer to the full copy of the relation list in parameter. */ -openscop_relation_list_p -openscop_relation_list_copy(openscop_relation_list_p list) -{ +openscop_relation_list_p openscop_relation_list_copy( + openscop_relation_list_p list) { + int first = 1; openscop_relation_list_p copy = NULL, node, previous = NULL; - while (list != NULL) - { + while (list != NULL) { node = openscop_relation_list_malloc(); node->elt = openscop_relation_copy(list->elt); - if (first) - { + if (first) { first = 0; copy = node; previous = node; } - else - { + else { previous->next = node; previous = previous->next; } @@ -362,10 +336,10 @@ openscop_relation_list_copy(openscop_relation_list_p list) * \return A pointer to the relation list resulting from the concatenation of * l1 and l2. */ -openscop_relation_list_p -openscop_relation_list_concat(openscop_relation_list_p l1, - openscop_relation_list_p l2) -{ +openscop_relation_list_p openscop_relation_list_concat( + openscop_relation_list_p l1, + openscop_relation_list_p l2) { + openscop_relation_list_p new, end; if (l1 == NULL) @@ -392,12 +366,9 @@ openscop_relation_list_concat(openscop_relation_list_p l1, * \param l2 The second relation list. * \return 1 if l1 and l2 are the same (content-wise), 0 otherwise. */ -int -openscop_relation_list_equal(openscop_relation_list_p l1, - openscop_relation_list_p l2) -{ - while ((l1 != NULL) && (l2 != NULL)) - { +int openscop_relation_list_equal(openscop_relation_list_p l1, + openscop_relation_list_p l2) { + while ((l1 != NULL) && (l2 != NULL)) { if (!openscop_relation_equal(l1->elt, l2->elt)) return 0; @@ -427,15 +398,12 @@ openscop_relation_list_equal(openscop_relation_list_p l1, * \param expected_nb_parameters Expected number of parameters. * \return 0 if the integrity check fails, 1 otherwise. */ -int -openscop_relation_list_integrity_check(openscop_relation_list_p list, - int type, - int expected_nb_output_dims, - int expected_nb_input_dims, - int expected_nb_parameters) -{ - while (list != NULL) - { +int openscop_relation_list_integrity_check(openscop_relation_list_p list, + int type, + int expected_nb_output_dims, + int expected_nb_input_dims, + int expected_nb_parameters) { + while (list != NULL) { // Check the access function. if (( openscop_relation_is_matrix(list->elt) && !openscop_relation_integrity_check(list->elt, @@ -448,8 +416,7 @@ openscop_relation_list_integrity_check(openscop_relation_list_p list, type, expected_nb_output_dims, expected_nb_input_dims, - expected_nb_parameters))) - { + expected_nb_parameters))) { return 0; } diff --git a/source/scop.c b/source/scop.c index f6aef69..f8fb1eb 100644 --- a/source/scop.c +++ b/source/scop.c @@ -82,17 +82,15 @@ * \param scop The scop structure whose information has to be printed. * \param level Number of spaces before printing, for each line. */ -void -openscop_scop_print_structure(FILE * file, openscop_scop_p scop, int level) -{ +void openscop_scop_print_structure(FILE * file, openscop_scop_p scop, + int level) { int j; // Go to the right level. for (j = 0; j < level; j++) fprintf(file, "|\t"); - if (scop != NULL) - { + if (scop != NULL) { fprintf(file, "+-- openscop_scop_t\n"); // A blank line. @@ -127,8 +125,7 @@ openscop_scop_print_structure(FILE * file, openscop_scop_p scop, int level) fprintf(file, "|\t"); fprintf(file, "\n"); } - else - { + else { fprintf(file, "+-- NULL scop\n"); } @@ -146,9 +143,7 @@ openscop_scop_print_structure(FILE * file, openscop_scop_p scop, int level) * \param file The file where the information has to be printed. * \param scop The scop structure whose information has to be printed. */ -void -openscop_scop_print(FILE * file, openscop_scop_p scop) -{ +void openscop_scop_print(FILE * file, openscop_scop_p scop) { openscop_scop_print_structure(file, scop, 0); } @@ -167,14 +162,12 @@ openscop_scop_print(FILE * file, openscop_scop_p scop) * \parem nb_arrays The number of arrays in the scop (output). */ static -void -openscop_scop_name_limits(openscop_scop_p scop, - int * nb_parameters, - int * nb_iterators, - int * nb_scattdims, - int * nb_localdims, - int * nb_arrays) -{ +void openscop_scop_name_limits(openscop_scop_p scop, + int * nb_parameters, + int * nb_iterators, + int * nb_scattdims, + int * nb_localdims, + int * nb_arrays) { int i, k, tmp, coef, id; openscop_statement_p statement; openscop_relation_list_p list; @@ -186,14 +179,11 @@ openscop_scop_name_limits(openscop_scop_p scop, // in the corresponding field, it is 0 for matrix format. *nb_parameters = 0; *nb_localdims = 0; - if (scop->context != NULL) - { - if (openscop_relation_is_matrix(scop->context)) - { + if (scop->context != NULL) { + if (openscop_relation_is_matrix(scop->context)) { *nb_parameters = scop->context->nb_columns - 2; } - else - { + else { *nb_parameters = scop->context->nb_parameters; *nb_localdims = scop->context->nb_local_dims; } @@ -203,21 +193,17 @@ openscop_scop_name_limits(openscop_scop_p scop, *nb_scattdims = 0; *nb_arrays = 0; statement = scop->statement; - while (statement != NULL) - { + while (statement != NULL) { // * The number of iterators are defined by iteration domains, // - in matrix format we compute it using #columns and #parameters, // - in relation format it corresponds to the #output_dims. - if (statement->domain != NULL) - { - if (openscop_relation_is_matrix(statement->domain)) - { + if (statement->domain != NULL) { + if (openscop_relation_is_matrix(statement->domain)) { tmp = statement->domain->nb_columns - *nb_parameters - 2; if (tmp > *nb_iterators) *nb_iterators = tmp; } - else - { + else { if (statement->domain->nb_output_dims > *nb_iterators) *nb_iterators = statement->domain->nb_output_dims; @@ -229,15 +215,12 @@ openscop_scop_name_limits(openscop_scop_p scop, // * The number of scattdims are defined by scattering, // - in matrix format it corresponds to the number of rows, // - in relation format it corresponds to the #input_dims. - if (statement->scattering != NULL) - { - if (openscop_relation_is_matrix(statement->scattering)) - { + if (statement->scattering != NULL) { + if (openscop_relation_is_matrix(statement->scattering)) { if (statement->domain->nb_rows > *nb_scattdims) *nb_scattdims = statement->scattering->nb_rows; } - else - { + else { if (statement->scattering->nb_input_dims > *nb_scattdims) *nb_scattdims = statement->scattering->nb_input_dims; @@ -251,29 +234,22 @@ openscop_scop_name_limits(openscop_scop_p scop, // - in relation format, array identifiers are // m[i][#columns -1] / m[i][1], with i the (supposedly only) row // where m[i][1] is not 0. - for (k = 0; k < 2; k++) - { + for (k = 0; k < 2; k++) { if (k == 0) list = statement->read; else list = statement->write; - while (list != NULL) - { - if (list->elt != NULL) - { - if (openscop_relation_is_matrix(list->elt)) - { + while (list != NULL) { + if (list->elt != NULL) { + if (openscop_relation_is_matrix(list->elt)) { if (SCOPINT_get_si(list->elt->m[0][0]) > *nb_arrays) *nb_arrays = SCOPINT_get_si(list->elt->m[0][0]); } - else - { - for (i = 0; i < list->elt->nb_rows; i++) - { + else { + for (i = 0; i < list->elt->nb_rows; i++) { coef = SCOPINT_get_si(list->elt->m[i][1]); - if (coef != 0) - { + if (coef != 0) { id = SCOPINT_get_si(list->elt->m[0][list->elt->nb_columns-1]); if (abs(id / coef) > *nb_arrays) *nb_arrays = abs(id / coef); @@ -304,9 +280,7 @@ openscop_scop_name_limits(openscop_scop_p scop, * \return A set of names for the scop. */ static -openscop_names_p -openscop_scop_full_names(openscop_scop_p scop) -{ +openscop_names_p openscop_scop_full_names(openscop_scop_p scop) { int nb_parameters; int nb_iterators; int nb_scattdims; @@ -357,15 +331,12 @@ openscop_scop_full_names(openscop_scop_p scop) * \param file The file where the information has to be printed. * \param scop The scop structure whose information has to be printed. */ -void -openscop_scop_print_openscop(FILE * file, openscop_scop_p scop) -{ +void openscop_scop_print_openscop(FILE * file, openscop_scop_p scop) { openscop_names_p names; int tmp_nb_iterators = 0; char ** tmp_iterators = NULL; - if (openscop_scop_integrity_check(scop) == 0) - { + if (openscop_scop_integrity_check(scop) == 0) { fprintf(stderr, "[OpenScop] Error: OpenScop integrity check failed.\n"); exit(1); } @@ -373,8 +344,7 @@ openscop_scop_print_openscop(FILE * file, openscop_scop_p scop) // Build a name structure for pretty printing of relations. names = openscop_scop_full_names(scop); - if (0) - { + if (0) { fprintf(file, "# \n"); fprintf(file, "# <| \n"); fprintf(file, "# A \n"); @@ -407,8 +377,7 @@ openscop_scop_print_openscop(FILE * file, openscop_scop_p scop) fprintf(file, "- --_ --- __ --- __--\n"); fprintf(file, "#.:: :::::::::::::::::::Y88as88a...s88aa.\n"); } - else - { + else { fprintf(file, "# [File generated by the OpenScop Library %s %s bits]\n", OPENSCOP_RELEASE,OPENSCOP_VERSION); } @@ -439,8 +408,7 @@ openscop_scop_print_openscop(FILE * file, openscop_scop_p scop) openscop_statement_print_openscop(file, scop->statement, names); - if (scop->extension) - { + if (scop->extension) { fprintf(file, "# ===============================================" " Extensions\n"); openscop_extension_print_openscop(file, scop->extension); @@ -456,9 +424,7 @@ openscop_scop_print_openscop(FILE * file, openscop_scop_p scop) static -void -openscop_scop_update_val(int * variable, int value) -{ +void openscop_scop_update_val(int * variable, int value) { if ((*variable == OPENSCOP_UNDEFINED) || (*variable == value)) *variable = value; else @@ -467,13 +433,10 @@ openscop_scop_update_val(int * variable, int value) } static -void -openscop_scop_update_properties(openscop_relation_p relation, - int nb_output_dims, int nb_input_dims, - int nb_parameters) -{ - if (relation != NULL) - { +void openscop_scop_update_properties(openscop_relation_p relation, + int nb_output_dims, int nb_input_dims, + int nb_parameters) { + if (relation != NULL) { openscop_scop_update_val(&(relation->nb_output_dims), nb_output_dims); openscop_scop_update_val(&(relation->nb_input_dims), nb_input_dims); openscop_scop_update_val(&(relation->nb_parameters), nb_parameters); @@ -492,9 +455,7 @@ openscop_scop_update_properties(openscop_relation_p relation, * \param scop The SCoP we want to propagate properties. */ static -void -openscop_scop_propagate_properties(openscop_scop_p scop) -{ +void openscop_scop_propagate_properties(openscop_scop_p scop) { int i, nb_parameters; openscop_statement_p statement; openscop_relation_p relation; @@ -502,59 +463,51 @@ openscop_scop_propagate_properties(openscop_scop_p scop) // Context part: get the number of parameters. if ((scop->context != NULL) && - (openscop_relation_is_matrix(scop->context))) - { + (openscop_relation_is_matrix(scop->context))) { nb_parameters = scop->context->nb_columns - 2; openscop_scop_update_properties(scop->context, 0, 0, nb_parameters); } - else + else { return; + } // For each statement: statement = scop->statement; - while (statement != NULL) - { + while (statement != NULL) { // - Domain part, relation = statement->domain; - if (openscop_relation_is_matrix(relation)) - { - while (relation != NULL) - { - openscop_scop_update_properties(relation, - relation->nb_columns - nb_parameters - 2, 0, nb_parameters); + if (openscop_relation_is_matrix(relation)) { + while (relation != NULL) { + openscop_scop_update_properties( + relation, relation->nb_columns-nb_parameters-2, 0, nb_parameters); relation = relation->next; } } // - Scattering part, relation = statement->scattering; - if (openscop_relation_is_matrix(relation)) - { - while (relation != NULL) - { - openscop_scop_update_properties(relation, - 0, relation->nb_columns - nb_parameters - 2, nb_parameters); + if (openscop_relation_is_matrix(relation)) { + while (relation != NULL) { + openscop_scop_update_properties( + relation, 0, relation->nb_columns-nb_parameters-2, nb_parameters); relation = relation->next; } } // - Access part. - for (i = 0; i < 2; i++) - { + for (i = 0; i < 2; i++) { if (i == 0) list = statement->read; else list = statement->write; - while (list != NULL) - { + while (list != NULL) { relation = list->elt; - if (openscop_relation_is_matrix(relation)) - { - while (relation != NULL) - { - openscop_scop_update_properties(relation, - 0, relation->nb_columns - nb_parameters - 2, nb_parameters); + if (openscop_relation_is_matrix(relation)) { + while (relation != NULL) { + openscop_scop_update_properties( + relation, 0, relation->nb_columns - nb_parameters - 2, + nb_parameters); relation = relation->next; } } @@ -578,9 +531,7 @@ openscop_scop_propagate_properties(openscop_scop_p scop) * \param file The file where the scop has to be read. * \return A pointer to the scop structure that has been read. */ -openscop_scop_p -openscop_scop_read(FILE * file) -{ +openscop_scop_p openscop_scop_read(FILE * file) { openscop_scop_p scop = NULL; openscop_statement_p stmt = NULL; openscop_statement_p prev = NULL; @@ -600,8 +551,7 @@ openscop_scop_read(FILE * file) // Ensure the file is a .scop. tmp = openscop_util_strings_read(file, &max); - if ((max == 0) || (strcmp(*tmp, "OpenScop"))) - { + if ((max == 0) || (strcmp(*tmp, "OpenScop"))) { fprintf(stderr, "[OpenScop] Error: not an OpenScop file " "(type \"%s\".\n", *tmp); exit (1); @@ -614,8 +564,7 @@ openscop_scop_read(FILE * file) // Read the language. char ** language = openscop_util_strings_read(file, &max); - if (max == 0) - { + if (max == 0) { fprintf(stderr, "[OpenScop] Error: no language (backend) specified.\n"); exit (1); } @@ -636,8 +585,7 @@ openscop_scop_read(FILE * file) // Read the number of statements. nb_statements = openscop_util_read_int(file, NULL); - for (i = 0; i < nb_statements; ++i) - { + for (i = 0; i < nb_statements; ++i) { // Read each statement. stmt = openscop_statement_read(file); if (scop->statement == NULL) @@ -678,14 +626,11 @@ openscop_scop_read(FILE * file) * allocated space. * \return A pointer to an empty scop with fields set to default values. */ -openscop_scop_p -openscop_scop_malloc() -{ +openscop_scop_p openscop_scop_malloc() { openscop_scop_p scop; scop = (openscop_scop_p)malloc(sizeof(openscop_scop_t)); - if (scop == NULL) - { + if (scop == NULL) { fprintf(stderr, "[OpenScop] Memory Overflow.\n"); exit(1); } @@ -707,11 +652,8 @@ openscop_scop_malloc() * This function frees the allocated memory for a openscop_scop_t structure. * \param scop The pointer to the scop we want to free. */ -void -openscop_scop_free(openscop_scop_p scop) -{ - if (scop != NULL) - { +void openscop_scop_free(openscop_scop_p scop) { + if (scop != NULL) { if (scop->language != NULL) free(scop->language); @@ -738,9 +680,7 @@ openscop_scop_free(openscop_scop_p scop) * \param statement The pointer to the scop we want to copy. * \return A pointer to the full copy of the scop provided as parameter. */ -openscop_scop_p -openscop_scop_copy(openscop_scop_p scop) -{ +openscop_scop_p openscop_scop_copy(openscop_scop_p scop) { openscop_scop_p copy; copy = openscop_scop_malloc(); @@ -764,41 +704,33 @@ openscop_scop_copy(openscop_scop_p scop) * \param s2 The second scop. * \return 1 if s1 and s2 are the same (content-wise), 0 otherwise. */ -int -openscop_scop_equal(openscop_scop_p s1, openscop_scop_p s2) -{ - if (s1->version != s2->version) - { +int openscop_scop_equal(openscop_scop_p s1, openscop_scop_p s2) { + if (s1->version != s2->version) { fprintf(stderr, "[OpenScop] info: versions are not the same.\n"); //return 0; } - if (strcmp(s1->language, s2->language) != 0) - { + if (strcmp(s1->language, s2->language) != 0) { fprintf(stderr, "[OpenScop] info: languages are not the same.\n"); return 0; } - if (!openscop_relation_equal(s1->context, s2->context)) - { + if (!openscop_relation_equal(s1->context, s2->context)) { fprintf(stderr, "[OpenScop] info: contexts are not the same.\n"); return 0; } - if (!openscop_names_equal(s1->names, s2->names)) - { + if (!openscop_names_equal(s1->names, s2->names)) { fprintf(stderr, "[OpenScop] info: names are not the same.\n"); return 0; } - if (!openscop_statement_equal(s1->statement, s2->statement)) - { + if (!openscop_statement_equal(s1->statement, s2->statement)) { fprintf(stderr, "[OpenScop] info: statements are not the same.\n"); return 0; } - if (!openscop_extension_equal(s1->extension, s2->extension)) - { + if (!openscop_extension_equal(s1->extension, s2->extension)) { fprintf(stderr, "[OpenScop] info: extensions are not the same.\n"); return 0; } @@ -807,8 +739,6 @@ openscop_scop_equal(openscop_scop_p s1, openscop_scop_p s2) } - - /** * openscop_scop_integrity_check function: * This function checks that a scop is "well formed". It returns 0 if the @@ -816,9 +746,7 @@ openscop_scop_equal(openscop_scop_p s1, openscop_scop_p s2) * \param scop The scop we want to check. * \return 0 if the integrity check fails, 1 otherwise. */ -int -openscop_scop_integrity_check(openscop_scop_p scop) -{ +int openscop_scop_integrity_check(openscop_scop_p scop) { int expected_nb_parameters; int max_nb_parameters; int max_nb_iterators; @@ -843,8 +771,7 @@ openscop_scop_integrity_check(openscop_scop_p scop) return 0; // Get the number of parameters. - if (scop->context != NULL) - { + if (scop->context != NULL) { if (openscop_relation_is_matrix(scop->context)) expected_nb_parameters = scop->context->nb_columns - 2; else diff --git a/source/statement.c b/source/statement.c index 54540f1..9e4947e 100644 --- a/source/statement.c +++ b/source/statement.c @@ -84,10 +84,9 @@ * \param statement The statement whose information have to be printed. * \param level Number of spaces before printing, for each line. */ -void -openscop_statement_print_structure(FILE * file, openscop_statement_p statement, - int level) -{ +void openscop_statement_print_structure(FILE * file, + openscop_statement_p statement, + int level) { int i, j, first = 1, number = 1; // Go to the right level. @@ -99,9 +98,8 @@ openscop_statement_print_structure(FILE * file, openscop_statement_p statement, else fprintf(file, "+-- NULL statement\n"); - while (statement != NULL) - { if (!first) - { + while (statement != NULL) { + if (!first) { // Go to the right level. for (j = 0; j < level; j++) fprintf(file, "|\t"); @@ -130,8 +128,7 @@ openscop_statement_print_structure(FILE * file, openscop_statement_p statement, // Print the original iterator names. for (i = 0; i <= level; i++) fprintf(file, "|\t"); - if (statement->nb_iterators > 0) - { + if (statement->nb_iterators > 0) { fprintf(file, "+-- Original iterator strings:"); for (i = 0; i < statement->nb_iterators; i++) fprintf(file, " %s", statement->iterators[i]); @@ -162,8 +159,7 @@ openscop_statement_print_structure(FILE * file, openscop_statement_p statement, number++; // Next line. - if (statement != NULL) - { + if (statement != NULL) { for (j = 0; j <= level; j++) fprintf(file, "|\t"); fprintf(file, "V\n"); @@ -184,9 +180,7 @@ openscop_statement_print_structure(FILE * file, openscop_statement_p statement, * \param file File where informations are printed. * \param statement The statement whose information have to be printed. */ -void -openscop_statement_print(FILE * file, openscop_statement_p statement) -{ +void openscop_statement_print(FILE * file, openscop_statement_p statement) { openscop_statement_print_structure(file, statement, 0); } @@ -202,20 +196,17 @@ openscop_statement_print(FILE * file, openscop_statement_p statement) * representation is used. Set to NULL if printing comments * is not needed. */ -void -openscop_statement_print_openscop(FILE * file, openscop_statement_p statement, - openscop_names_p names) -{ +void openscop_statement_print_openscop(FILE * file, + openscop_statement_p statement, + openscop_names_p names) { int i, switched, number = 1; int tmp_nb_iterators = 0; char ** tmp_iterators = NULL; - while (statement != NULL) - { + while (statement != NULL) { // Switch iterator names to the current statement names if possible. switched = 0; - if (statement->nb_iterators > 0) - { + if (statement->nb_iterators > 0) { tmp_nb_iterators = names->nb_iterators; tmp_iterators = names->iterators; names->nb_iterators = statement->nb_iterators; @@ -258,8 +249,7 @@ openscop_statement_print_openscop(FILE * file, openscop_statement_p statement, fprintf(file, "%2d.4 Body\n", number); fprintf(file, "# Statement body is provided\n"); fprintf(file, "1\n"); - if (statement->nb_iterators > 0) - { + if (statement->nb_iterators > 0) { fprintf(file, "# Original iterator names\n"); for (i = 0; i < statement->nb_iterators; i++) fprintf(file, "%s ", statement->iterators[i]); @@ -271,8 +261,7 @@ openscop_statement_print_openscop(FILE * file, openscop_statement_p statement, fprintf(file, "%s\n", statement->body); fprintf(file, "\n\n"); - if (switched == 1) - { + if (switched == 1) { statement->nb_iterators = tmp_nb_iterators; statement->iterators = tmp_iterators; } @@ -294,15 +283,12 @@ openscop_statement_print_openscop(FILE * file, openscop_statement_p statement, * \param file The input stream. * \return A pointer to the statement structure that has been read. */ -openscop_statement_p -openscop_statement_read(FILE * file) -{ +openscop_statement_p openscop_statement_read(FILE * file) { openscop_statement_p stmt = openscop_statement_malloc(); char buff[OPENSCOP_MAX_STRING], * start, * end; int nb_iterators; - if (file) - { + if (file) { // Read the domain matrices. stmt->domain = openscop_relation_read(file); @@ -311,15 +297,13 @@ openscop_statement_read(FILE * file) stmt->scattering = openscop_relation_read(file); // Read the access functions, if any. - if (openscop_util_read_int(file, NULL) > 0) - { + if (openscop_util_read_int(file, NULL) > 0) { stmt->read = openscop_relation_list_read(file); stmt->write = openscop_relation_list_read(file); } // Read the body information, if any. - if (openscop_util_read_int(file, NULL) > 0) - { + if (openscop_util_read_int(file, NULL) > 0) { // Read the original iterator names. stmt->iterators = openscop_util_strings_read(file, &nb_iterators); stmt->nb_iterators = nb_iterators; @@ -337,8 +321,7 @@ openscop_statement_read(FILE * file) // - Copy the body. stmt->body = strdup(start); } - else - { + else { stmt->nb_iterators = OPENSCOP_UNDEFINED; stmt->iterators = NULL; stmt->body = strdup("[undefined]"); @@ -361,14 +344,11 @@ openscop_statement_read(FILE * file) * to the allocated space. * \return A pointer to an empty statement with fields set to default values. */ -openscop_statement_p -openscop_statement_malloc() -{ +openscop_statement_p openscop_statement_malloc() { openscop_statement_p statement; statement = (openscop_statement_p)malloc(sizeof(openscop_statement_t)); - if (statement == NULL) - { + if (statement == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -392,21 +372,17 @@ openscop_statement_malloc() * structure. * \param statement The pointer to the statement we want to free. */ -void -openscop_statement_free(openscop_statement_p statement) -{ +void openscop_statement_free(openscop_statement_p statement) { int i; openscop_statement_p next; - while (statement != NULL) - { + while (statement != NULL) { next = statement->next; openscop_relation_free(statement->domain); openscop_relation_free(statement->scattering); openscop_relation_list_free(statement->read); openscop_relation_list_free(statement->write); - if (statement->iterators != NULL) - { + if (statement->iterators != NULL) { for (i = 0; i < statement->nb_iterators; i++) free(statement->iterators[i]); free(statement->iterators); @@ -432,10 +408,8 @@ openscop_statement_free(openscop_statement_p statement) * \param location Address of the first element of the statement list. * \param statement The statement to add to the list. */ -void -openscop_statement_add(openscop_statement_p * location, - openscop_statement_p statement) -{ +void openscop_statement_add(openscop_statement_p * location, + openscop_statement_p statement) { while (*location != NULL) location = &((*location)->next); @@ -450,13 +424,10 @@ openscop_statement_add(openscop_statement_p * location, * \param statement The first element of the statement list. * \return The number of statements in the statement list. */ -int -openscop_statement_number(openscop_statement_p statement) -{ +int openscop_statement_number(openscop_statement_p statement) { int number = 0; - while (statement != NULL) - { + while (statement != NULL) { number++; statement = statement->next; } @@ -471,14 +442,11 @@ openscop_statement_number(openscop_statement_p statement) * \param statement The pointer to the statement we want to copy. * \return A pointer to the full copy of the statement provided as parameter. */ -openscop_statement_p -openscop_statement_copy(openscop_statement_p statement) -{ +openscop_statement_p openscop_statement_copy(openscop_statement_p statement) { int first = 1; openscop_statement_p copy = NULL, node, previous = NULL; - while (statement != NULL) - { + while (statement != NULL) { node = openscop_statement_malloc(); node->version = statement->version; node->domain = openscop_relation_copy(statement->domain); @@ -491,14 +459,12 @@ openscop_statement_copy(openscop_statement_p statement) node->body = strdup(statement->body); node->next = NULL; - if (first) - { + if (first) { first = 0; copy = node; previous = node; } - else - { + else { previous->next = node; previous = previous->next; } @@ -518,9 +484,8 @@ openscop_statement_copy(openscop_statement_p statement) * \param s2 The second statement. * \return 1 if s1 and s2 are the same (content-wise), 0 otherwise. */ -int -openscop_statement_equal(openscop_statement_p s1, openscop_statement_p s2) -{ +int openscop_statement_equal(openscop_statement_p s1, + openscop_statement_p s2) { int i; if (((s1->next != NULL) && (s2->next == NULL)) || @@ -558,14 +523,11 @@ openscop_statement_equal(openscop_statement_p s1, openscop_statement_p s2) * \param expected_nb_parameters Expected number of parameters. * \return 0 if the integrity check fails, 1 otherwise. */ -int -openscop_statement_integrity_check(openscop_statement_p statement, - int expected_nb_parameters) -{ +int openscop_statement_integrity_check(openscop_statement_p statement, + int expected_nb_parameters) { int expected_nb_iterators = OPENSCOP_UNDEFINED; - while (statement != NULL) - { + while (statement != NULL) { // Check the domain. if ((openscop_relation_is_matrix(statement->domain) && !openscop_relation_integrity_check(statement->domain, @@ -578,16 +540,13 @@ openscop_statement_integrity_check(openscop_statement_p statement, OPENSCOP_TYPE_DOMAIN, OPENSCOP_UNDEFINED, 0, - expected_nb_parameters))) - { + expected_nb_parameters))) { return 0; } // Get the number of iterators. - if (statement->domain != NULL) - { - if (openscop_relation_is_matrix(statement->domain)) - { + if (statement->domain != NULL) { + if (openscop_relation_is_matrix(statement->domain)) { if (expected_nb_parameters != OPENSCOP_UNDEFINED) expected_nb_iterators = statement->domain->nb_columns - expected_nb_parameters - 2; @@ -610,8 +569,7 @@ openscop_statement_integrity_check(openscop_statement_p statement, OPENSCOP_TYPE_SCATTERING, OPENSCOP_UNDEFINED, expected_nb_iterators, - expected_nb_parameters))) - { + expected_nb_parameters))) { return 0; } @@ -625,14 +583,12 @@ openscop_statement_integrity_check(openscop_statement_p statement, OPENSCOP_TYPE_ACCESS, OPENSCOP_UNDEFINED, expected_nb_iterators, - expected_nb_parameters)) - { + expected_nb_parameters)) { return 0; } if ((statement->nb_iterators > 0) && - (statement->nb_iterators < statement->domain->nb_output_dims)) - { + (statement->nb_iterators < statement->domain->nb_output_dims)) { fprintf(stderr, "[OpenScop] Warning: not enough original iterator " "names.\n"); return 0; diff --git a/source/util.c b/source/util.c index 67baab5..20165bc 100644 --- a/source/util.c +++ b/source/util.c @@ -84,19 +84,16 @@ * \param level Number of spaces before printing, for each line. * \param title A string to use as a title for the array of strings. */ -void -openscop_util_strings_print_structure(FILE * file, - char ** strings, int nb_strings, - int level, - char * title) -{ +void openscop_util_strings_print_structure(FILE * file, + char ** strings, int nb_strings, + int level, + char * title) { int i; // Print the original parameter names. for (i = 0; i <= level; i++) fprintf(file, "|\t"); - if (nb_strings > 0) - { + if (nb_strings > 0) { fprintf(file, "+-- %s:", title); for (i = 0; i < nb_strings; i++) fprintf(file, " %s", strings[i]); @@ -122,16 +119,13 @@ openscop_util_strings_print_structure(FILE * file, * \param print Boolean not set to 0 to print the names, 0 otherwise. * \param title A string to use as a title for the array of strings. */ -void -openscop_util_strings_print_openscop(FILE * file, - char ** strings, int nb_strings, - int print, - char * title) -{ +void openscop_util_strings_print_openscop(FILE * file, + char ** strings, int nb_strings, + int print, + char * title) { int i; - if ((print != 0) && (nb_strings > 0)) - { + if ((print != 0) && (nb_strings > 0)) { fprintf(file, "# %s are provided\n", title); fprintf(file, "1\n"); fprintf(file, "# %s\n", title); @@ -139,8 +133,7 @@ openscop_util_strings_print_openscop(FILE * file, fprintf(file, "%s ", strings[i]); fprintf(file, "\n\n"); } - else - { + else { fprintf(file, "# %s are not provided\n", title); fprintf(file, "0\n\n"); } @@ -157,9 +150,7 @@ openscop_util_strings_print_openscop(FILE * file, * \param nb_strings Pointer to where to store the number of strings (output). * \return The array of strings that has been read. */ -char ** -openscop_util_strings_read(FILE * file, int * nb_strings) -{ +char ** openscop_util_strings_read(FILE * file, int * nb_strings) { char str[OPENSCOP_MAX_STRING]; char tmp[OPENSCOP_MAX_STRING]; char * s, * start; @@ -172,8 +163,7 @@ openscop_util_strings_read(FILE * file, int * nb_strings) // Count the actual number of strings. *nb_strings = 0; s = start; - while (1) - { + while (1) { for (count = 0; *s && ! isspace(*s) && *s != '#'; ++count) s++; @@ -186,12 +176,10 @@ openscop_util_strings_read(FILE * file, int * nb_strings) ++s; } - if (*nb_strings > 0) - { + if (*nb_strings > 0) { // Allocate the array of strings. Make it NULL-terminated. strings = (char **) malloc(sizeof(char *) * ((*nb_strings) + 1)); - if (strings == NULL) - { + if (strings == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -199,14 +187,12 @@ openscop_util_strings_read(FILE * file, int * nb_strings) // Read the desired number of strings. s = start; - for (i = 0; i < *nb_strings; ++i) - { + for (i = 0; i < *nb_strings; ++i) { for (count = 0; *s && ! isspace(*s) && *s != '#'; ++count) tmp[count] = *(s++); tmp[count] = '\0'; strings[i] = strdup(tmp); - if (strings[i] == NULL) - { + if (strings[i] == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -227,27 +213,21 @@ openscop_util_strings_read(FILE * file, int * nb_strings) * \param nb_strings The number of strings to generate. * \return An array of 'nb' generated strings. */ -char ** -openscop_util_strings_generate(char * prefix, int nb_strings) -{ +char ** openscop_util_strings_generate(char * prefix, int nb_strings) { char ** strings = NULL; char buff[strlen(prefix) + 16]; // TODO: better (log10(INT_MAX) ?) :-D. int i; - if (nb_strings) - { + if (nb_strings) { strings = (char **)malloc(sizeof(char *) * nb_strings); - if (strings == NULL) - { + if (strings == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } - for (i = 0; i < nb_strings; i++) - { + for (i = 0; i < nb_strings; i++) { sprintf(buff, "%s%d", prefix, i + 1); strings[i] = strdup(buff); - if (strings[i] == NULL) - { + if (strings[i] == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -266,22 +246,18 @@ openscop_util_strings_generate(char * prefix, int nb_strings) * \param prefix The prefix of the generated names. * \param nb_complete The desired number of strings in the new array. */ -void -openscop_util_strings_complete(char *** strings, int * nb_strings, - char * prefix, int nb_complete) -{ +void openscop_util_strings_complete(char *** strings, int * nb_strings, + char * prefix, int nb_complete) { int i, nb_new; char ** completion; nb_new = nb_complete - *nb_strings; - if (nb_new < 0) - { + if (nb_new < 0) { fprintf(stderr, "[OpenScop] Error: completed smaller than original.\n"); exit(1); } - if (nb_new > 0) - { + if (nb_new > 0) { *strings = (char **)realloc(*strings, nb_complete * sizeof(char *)); completion = openscop_util_strings_generate(prefix, nb_new); for (i = 0; i < nb_new; i++) @@ -298,13 +274,10 @@ openscop_util_strings_complete(char *** strings, int * nb_strings, * \param strings The array of strings we want to free. * \param nb_strings The number of strings in the array of strings. */ -void -openscop_util_strings_free(char ** strings, int nb_strings) -{ +void openscop_util_strings_free(char ** strings, int nb_strings) { int i; - if (strings != NULL) - { + if (strings != NULL) { for (i = 0; i < nb_strings; i++) if (strings[i] != NULL) free(strings[i]); @@ -321,9 +294,7 @@ openscop_util_strings_free(char ** strings, int nb_strings) * \param nb_strings The number of strings in the array to copy. * \return The copy of the array of strings. */ -char ** -openscop_util_strings_copy(char ** strings, int nb_strings) -{ +char ** openscop_util_strings_copy(char ** strings, int nb_strings) { int i; char ** copy; @@ -331,16 +302,13 @@ openscop_util_strings_copy(char ** strings, int nb_strings) return NULL; copy = (char **)malloc(nb_strings * sizeof(char *)); - if (copy == NULL) - { + if (copy == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } - for (i = 0; i < nb_strings; i++) - { + for (i = 0; i < nb_strings; i++) { copy[i] = strdup(strings[i]); - if (copy[i] == NULL) - { + if (copy[i] == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -360,9 +328,7 @@ openscop_util_strings_copy(char ** strings, int nb_strings) * \param nb_s2 The number of strings in the second array of string. * \return 1 if s1 and s2 are the same (content-wise), 0 otherwise. */ -int -openscop_util_strings_equal(char ** s1, int nb_s1, char ** s2, int nb_s2) -{ +int openscop_util_strings_equal(char ** s1, int nb_s1, char ** s2, int nb_s2) { int i; if ((s1 == NULL) && (s2 == NULL)) @@ -385,6 +351,7 @@ openscop_util_strings_equal(char ** s1, int nb_s1, char ** s2, int nb_s2) * Utility functions * *****************************************************************************/ + /** * openscop_util_skip_blank_and_comments internal function. * This function reads the open file 'file' line by line and skips @@ -399,12 +366,10 @@ openscop_util_strings_equal(char ** s1, int nb_s1, char ** s2, int nb_s2) * that contains useful information. * \return The address of the the first useful digit in str. */ -char * openscop_util_skip_blank_and_comments(FILE * file, char * str) -{ +char * openscop_util_skip_blank_and_comments(FILE * file, char * str) { char * start; - do - { + do { start = fgets(str, OPENSCOP_MAX_STRING, file); while ((start != NULL) && isspace(*start) && (*start != '\n')) start++; @@ -424,51 +389,42 @@ char * openscop_util_skip_blank_and_comments(FILE * file, char * str) * is updated to reflect the read and points after the int. * \return The int that have been read. */ -int -openscop_util_read_int(FILE * file, char ** str) -{ +int openscop_util_read_int(FILE * file, char ** str) { char s[OPENSCOP_MAX_STRING], * start; int res; int i = 0; int read_int = 0; - if ((file != NULL && str != NULL) || (file == NULL && str == NULL)) - { + if ((file != NULL && str != NULL) || (file == NULL && str == NULL)) { fprintf(stderr, "[OpenScop] Error: one and only one of the two parameters" " of util_read_int can be non-NULL\n"); exit (1); } - if (file != NULL) - { + if (file != NULL) { // Parse from a file. start = openscop_util_skip_blank_and_comments(file, s); sscanf(start, " %d", &res); } - if (str != NULL) - { + if (str != NULL) { // Parse from a string. // Skip blank/commented lines. - do - { + do { while (*str && **str && isspace(**str)) ++(*str); - if (**str == '#') - { + if (**str == '#') { while (**str && **str != '\n') ++(*str); } - else - { + else { // Build the chain to analyze. while (**str && !isspace(**str) && **str != '\n') s[i++] = *((*str)++); s[i] = '\0'; - if (sscanf(s, "%d", &res) != 1) - { - fprintf(stderr, "[OpenScop] Error: an int was expected.\n"); - exit(1); - } + if (sscanf(s, "%d", &res) != 1) { + fprintf(stderr, "[OpenScop] Error: an int was expected.\n"); + exit(1); + } read_int = 1; } } @@ -488,9 +444,7 @@ openscop_util_read_int(FILE * file, char ** str) * \param file The file where to read the tail. * \return The string corresponding to the tail of the input file. */ -char * -openscop_util_read_tail(FILE * file) -{ +char * openscop_util_read_tail(FILE * file) { int high_water_mark = OPENSCOP_MAX_STRING; int nb_chars = 0; char buff[OPENSCOP_MAX_STRING], *c; @@ -502,8 +456,7 @@ openscop_util_read_tail(FILE * file) return NULL; extensions = (char *)malloc(high_water_mark * sizeof(char)); - if (extensions == NULL) - { + if (extensions == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -512,17 +465,14 @@ openscop_util_read_tail(FILE * file) nb_chars = strlen(c); // - Copy everything else to the option tags field. - while (!feof(file)) - { + while (!feof(file)) { extensions[nb_chars] = fgetc(file); nb_chars++; - if (nb_chars >= high_water_mark) - { + if (nb_chars >= high_water_mark) { high_water_mark += high_water_mark; extensions = (char *)realloc(extensions, high_water_mark * sizeof(char)); - if (extensions == NULL) - { + if (extensions == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -547,9 +497,7 @@ openscop_util_read_tail(FILE * file) * \param endtag The string that marks the end of the content. * \return The string between 'tag' and 'endtag' in 'str'. */ -char * -openscop_util_tag_content(char * str, char * tag, char * endtag) -{ +char * openscop_util_tag_content(char * str, char * tag, char * endtag) { int i; char * start; char * stop; @@ -557,12 +505,12 @@ openscop_util_tag_content(char * str, char * tag, char * endtag) int lentag; char * res = NULL; - if (str) - { + if (str) { start = str; lentag = strlen(tag); for (; start && *start && strncmp(start, tag, lentag); ++start) - ; + continue; + // The tag 'tag' was not found. if (! *start) return NULL; @@ -570,16 +518,17 @@ openscop_util_tag_content(char * str, char * tag, char * endtag) stop = start; lentag = strlen(endtag); for (size = 0; *stop && strncmp(stop, endtag, lentag); ++stop, ++size) - ; + continue; + // the tag 'endtag' was not found. if (! *stop) return NULL; res = (char *)malloc((size + 1) * sizeof(char)); - if (res == NULL) - { + if (res == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } + // Copy the chain between the two tags. for (++start, i = 0; start != stop; ++start, ++i) res[i] = *start; @@ -601,22 +550,17 @@ openscop_util_tag_content(char * str, char * tag, char * endtag) * \param hwm pointer to the size of the *dst buffer (may be updated). * TODO: This function is not that safe, improve it ! */ -void -openscop_util_safe_strcat(char ** dst, char * src, int * hwm) -{ +void openscop_util_safe_strcat(char ** dst, char * src, int * hwm) { - if (strlen(src) >= OPENSCOP_MAX_STRING) - { + if (strlen(src) >= OPENSCOP_MAX_STRING) { fprintf(stderr, "[OpenScop] Error: string to concatenate is too long.\n"); exit(1); } - if (strlen(*dst) + strlen(src) >= *hwm) - { + if (strlen(*dst) + strlen(src) >= *hwm) { *hwm += OPENSCOP_MAX_STRING; *dst = (char *)realloc(*dst, *hwm * sizeof(char)); - if (*dst == NULL) - { + if (*dst == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -624,7 +568,3 @@ openscop_util_safe_strcat(char ** dst, char * src, int * hwm) strcat(*dst, src); } - - - - diff --git a/source/vector.c b/source/vector.c index 78da98e..6355c86 100644 --- a/source/vector.c +++ b/source/vector.c @@ -83,14 +83,11 @@ * \param vector The vector whose information have to be printed. * \param level Number of spaces before printing, for each line. */ -void -openscop_vector_print_structure(FILE * file, openscop_vector_p vector, - int level) -{ +void openscop_vector_print_structure(FILE * file, openscop_vector_p vector, + int level) { int j; - if (vector != NULL) - { + if (vector != NULL) { // Go to the right level. for (j = 0; j < level; j++) fprintf(file,"|\t"); @@ -106,16 +103,14 @@ openscop_vector_print_structure(FILE * file, openscop_vector_p vector, fprintf(file,"[ "); - for (j = 0; j < vector->size; j++) - { + for (j = 0; j < vector->size; j++) { SCOPINT_print(file,OPENSCOP_FMT,vector->v[j]); fprintf(file," "); } fprintf(file,"]\n"); } - else - { + else { // Go to the right level. for (j = 0; j < level; j++) fprintf(file,"|\t"); @@ -136,9 +131,7 @@ openscop_vector_print_structure(FILE * file, openscop_vector_p vector, * \param file File where informations are printed. * \param vector The vector whose information have to be printed. */ -void -openscop_vector_print(FILE * file, openscop_vector_p vector) -{ +void openscop_vector_print(FILE * file, openscop_vector_p vector) { openscop_vector_print_structure(file,vector,0); } @@ -156,27 +149,23 @@ openscop_vector_print(FILE * file, openscop_vector_p vector) * \param size The number of entries of the vector to allocate. * \return A pointer to the newly allocated openscop_vector_t structure. */ -openscop_vector_p -openscop_vector_malloc(unsigned size) -{ +openscop_vector_p openscop_vector_malloc(unsigned size) { openscop_vector_p vector; openscop_int_t * p; - int i ; + int i; vector = (openscop_vector_p)malloc(sizeof(openscop_vector_t)); - if (vector == NULL) - { + if (vector == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } vector->size = size; - if (size == 0) + if (size == 0) { vector->v = NULL; - else - { + } + else { p = (openscop_int_t *)malloc(size * sizeof(openscop_int_t)); - if (p == NULL) - { + if (p == NULL) { fprintf(stderr, "[OpenScop] Error: memory overflow.\n"); exit(1); } @@ -193,14 +182,11 @@ openscop_vector_malloc(unsigned size) * This function frees the allocated memory for a openscop_vector_t structure. * \param vector The pointer to the vector we want to free. */ -void -openscop_vector_free(openscop_vector_p vector) -{ +void openscop_vector_free(openscop_vector_p vector) { int i; openscop_int_t * p; - if (vector != NULL) - { + if (vector != NULL) { p = vector->v; for (i = 0; i < vector->size; i++) SCOPINT_clear(*p++); @@ -225,14 +211,12 @@ openscop_vector_free(openscop_vector_p vector) * \param scalar The scalar to add to the vector. * \return A pointer to a new vector, copy of the basis one plus the scalar. */ -openscop_vector_p -openscop_vector_add_scalar(openscop_vector_p vector, int scalar) -{ +openscop_vector_p openscop_vector_add_scalar(openscop_vector_p vector, + int scalar) { int i; openscop_vector_p result; - if ((vector == NULL) || (vector->size < 2)) - { + if ((vector == NULL) || (vector->size < 2)) { fprintf(stderr,"[OpenScop] Error: incompatible vector for addition.\n"); exit(1); } @@ -256,14 +240,12 @@ openscop_vector_add_scalar(openscop_vector_p vector, int scalar) * \param v2 The second vector for the addition. * \return A pointer to a new vector, corresponding to v1 + v2. */ -openscop_vector_p -openscop_vector_add(openscop_vector_p v1, openscop_vector_p v2) -{ +openscop_vector_p openscop_vector_add(openscop_vector_p v1, + openscop_vector_p v2) { int i; openscop_vector_p v3; - if ((v1 == NULL) || (v2 == NULL) || (v1->size != v2->size)) - { + if ((v1 == NULL) || (v2 == NULL) || (v1->size != v2->size)) { fprintf(stderr,"[OpenScop] Error: incompatible vectors for addition.\n"); exit(1); } @@ -285,14 +267,12 @@ openscop_vector_add(openscop_vector_p v1, openscop_vector_p v2) * \param v2 The second vector for the subtraction (result is v1-v2). * \return A pointer to a new vector, corresponding to v1 - v2. */ -openscop_vector_p -openscop_vector_sub(openscop_vector_p v1, openscop_vector_p v2) -{ +openscop_vector_p openscop_vector_sub(openscop_vector_p v1, + openscop_vector_p v2) { int i; openscop_vector_p v3; - if ((v1 == NULL) || (v2 == NULL) || (v1->size != v2->size)) - { + if ((v1 == NULL) || (v2 == NULL) || (v1->size != v2->size)) { fprintf(stderr,"[OpenScop] Error: " "incompatible vectors for subtraction.\n"); exit(1); @@ -314,11 +294,8 @@ openscop_vector_sub(openscop_vector_p v1, openscop_vector_p v2) * an argument. * \param vector The vector to be tagged. */ -void -openscop_vector_tag_inequality(openscop_vector_p vector) -{ - if ((vector == NULL) || (vector->size < 1)) - { +void openscop_vector_tag_inequality(openscop_vector_p vector) { + if ((vector == NULL) || (vector->size < 1)) { fprintf(stderr,"[OpenScop] Error: vector cannot be tagged.\n"); exit(1); } @@ -334,11 +311,8 @@ openscop_vector_tag_inequality(openscop_vector_p vector) * an argument. * \param vector The vector to be tagged. */ -void -openscop_vector_tag_equality(openscop_vector_p vector) -{ - if ((vector == NULL) || (vector->size < 1)) - { +void openscop_vector_tag_equality(openscop_vector_p vector) { + if ((vector == NULL) || (vector->size < 1)) { fprintf(stderr,"[OpenScop] Error: vector cannot be tagged.\n"); exit(1); } @@ -354,9 +328,7 @@ openscop_vector_tag_equality(openscop_vector_p vector) * \param v2 The second vector. * \return 1 if v1 and v2 are the same (content-wise), 0 otherwise. */ -int -openscop_vector_equal(openscop_vector_p v1, openscop_vector_p v2) -{ +int openscop_vector_equal(openscop_vector_p v1, openscop_vector_p v2) { int i; if (v1->size != v2->size) @@ -379,8 +351,7 @@ openscop_vector_equal(openscop_vector_p v1, openscop_vector_p v2) * \return A new vector corresponding to scalar * v. */ openscop_vector_p openscop_vector_mul_scalar(openscop_vector_p v, - int scalar) -{ + int scalar) { int i; openscop_vector_p result = openscop_vector_malloc(v->size); -- 2.11.4.GIT