PIPS
newgen_string_buffer.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct __string_buffer_headstring_buffer
 minimal a la java StringBuffer... More...
 

Functions

string_buffer string_buffer_make (bool dup)
 allocate a new string buffer More...
 
void string_buffer_free (string_buffer *)
 free string buffer structure, also free string contents according to the dup field More...
 
void string_buffer_free_all (string_buffer *)
 free string buffer structure and force string freeing More...
 
size_t string_buffer_size (const string_buffer)
 return the size of the string in string_buffer sb More...
 
bool string_buffer_empty_p (const string_buffer)
 return whether string_buffer sb is empty. More...
 
void string_buffer_reset (string_buffer)
 remove stack contents More...
 
void string_buffer_append (string_buffer, const string)
 append string s (if non empty) to string buffer sb, the duplication is done if needed according to the dup field. More...
 
void string_buffer_cat (string_buffer, const string,...)
 append a NULL terminated list of string to sb. More...
 
void string_buffer_append_sb (string_buffer, const string_buffer)
 append the string buffer sb2 to string buffer sb. More...
 
void string_buffer_append_list (string_buffer, const list)
 append a list of string to a string buffer. More...
 
void string_buffer_printf_alist (string_buffer, const string, va_list *)
 formatted alist version More...
 
void string_buffer_printf (string_buffer, const string,...)
 append a formatted string to sb More...
 
string string_buffer_to_string (const string_buffer)
 return malloc'ed string from string buffer sb More...
 
string string_buffer_to_string_reverse (const string_buffer)
 return malloc'ed string from string buffer sb going from bottom to top More...
 
void string_buffer_to_file (const string_buffer, FILE *)
 put string buffer into file. More...
 
void string_buffer_append_c_string_buffer (const string_buffer, string_buffer, int)
 put string buffer as a C-string definition of the string buffer, including external double-quotes. More...
 
void string_buffer_append_xml_text (string_buffer, const string, bool)
 append a string with XML escapes More...
 

Typedef Documentation

◆ string_buffer

minimal a la java StringBuffer...

Definition at line 27 of file newgen_string_buffer.h.

Function Documentation

◆ string_buffer_append()

void string_buffer_append ( string_buffer  sb,
const  string 
)

append string s (if non empty) to string buffer sb, the duplication is done if needed according to the dup field.

Definition at line 260 of file string_buffer.c.

261 {
262  if (*s)
264 }
char * strdup()
static void string_buffer_append_internal(string_buffer sb, const string s)
append, without handling duplication
Definition: statement.c:4047

References strdup(), and string_buffer_append_internal().

Referenced by add_margin(), append_xml_attribute(), close_extensions(), dump_common_layout(), dump_functional(), extensions_to_string(), get_symbol_table(), open_xml_logfile(), pips_stop_xml(), pragma_to_string(), print_call_precondition(), reductions_get_omp_pragma_str(), safe_get_line_interval(), set_to_string_buffer(), step_directive_to_strings(), string_buffer_append_c_string_buffer(), string_buffer_append_list(), string_buffer_append_numeric(), string_buffer_append_sb(), string_buffer_append_symbolic(), string_buffer_append_word(), string_buffer_cat(), string_buffer_printf_alist(), text_to_string_gen(), two_string_buffer_append_symbolic(), xml_Application(), xml_Argument(), xml_Array(), xml_AssignArgument(), xml_Bounds(), xml_Boxes(), xml_Call(), xml_Chain_Graph(), xml_code(), xml_Compute_and_Need(), xml_data(), xml_declarations(), xml_Full_Type(), xml_loop(), xml_Loop(), xml_Matrix(), xml_ParameterUseToArrayBound(), xml_Pattern_Paving(), xml_reference(), xml_references(), xml_Region_Parameter(), xml_Region_Range(), xml_Scalar(), xml_Task(), xml_task(), xml_TaskParameter(), xml_TaskParameters(), xml_TaskReturnParameter(), xml_tasks(), xml_tiling(), xml_Transposition(), and xml_Type_Entity().

+ Here is the call graph for this function:

◆ string_buffer_append_c_string_buffer()

void string_buffer_append_c_string_buffer ( string_buffer  sb,
const string_buffer  src,
int  indent 
)

put string buffer as a C-string definition of the string buffer, including external double-quotes.

It adds escapes for special characters.

Definition at line 165 of file string_buffer.c.

167 {
168  message_assert("distinct string buffers", sb!=src);
169  // internal working buffer...
170  char buffer[BUFFER_SIZE];
171  int i = 0, j;
172  // start string
173  buffer[i++] = '"';
174  bool in_string = true;
175  STACK_MAP_X(s, string,
176  for (char * c = s; *c; c++)
177  {
178  if (i>BUFFER_SIZE-10-indent)
179  {
180  buffer[i++] = '\0';
182  i = 0;
183  }
184  if (!in_string)
185  {
186  buffer[i++] = '\n';
187  for (j=0; j<indent; j++)
188  buffer[i++] = ' ';
189  buffer[i++] = '"';
190  in_string = true;
191  }
192  switch (*c)
193  {
194  case '\n': // New line
195  buffer[i++] = '\\';
196  buffer[i++] = 'n';
197  // the string is closed on newlines anyway
198  buffer[i++] = '"';
199  in_string = false;
200  break;
201  case '\a': // Audible bell
202  buffer[i++] = '\\';
203  buffer[i++] = 'a';
204  break;
205  case '\b': // Backspace
206  buffer[i++] = '\\';
207  buffer[i++] = 'b';
208  break;
209  case '\f': // Form feed
210  buffer[i++] = '\\';
211  buffer[i++] = 'f';
212  break;
213  case '\r': // carriage Return
214  buffer[i++] = '\\';
215  buffer[i++] = 'r';
216  break;
217  case '\t': // horizontal tab
218  buffer[i++] = '\\';
219  buffer[i++] = 't';
220  break;
221  case '\v': // Vertical tab
222  buffer[i++] = '\\';
223  buffer[i++] = 'v';
224  break;
225  case '\0': // null character
226  buffer[i++] = '\\';
227  buffer[i++] = '0';
228  break;
229  case '\\': // backslash
230  buffer[i++] = '\\';
231  buffer[i++] = '\\';
232  break;
233  case '"': // double quote
234  buffer[i++] = '\\';
235  buffer[i++] = '"';
236  break;
237  default:
238  buffer[i++] = *c;
239  }
240  },
241  src->ins, 0);
242  // end string if needed
243  if (in_string)
244  buffer[i++] = '"';
245  buffer[i++] = '\0';
247 }
#define src(name, suf)
HPFC by Fabien Coelho, May 1993 and later...
Definition: compile.c:41
#define message_assert(msg, ex)
Definition: newgen_assert.h:47
#define STACK_MAP_X(_item, _itemtype, _code, _stack, _downwards)
not needed
Definition: newgen_stack.h:104
static string buffer
Definition: string.c:113
#define BUFFER_SIZE
void string_buffer_append(string_buffer sb, const string s)
append string s (if non empty) to string buffer sb, the duplication is done if needed according to th...

References buffer, BUFFER_SIZE, message_assert, src, STACK_MAP_X, and string_buffer_append().

Referenced by opencl_compile_mergeable_dag().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_buffer_append_list()

void string_buffer_append_list ( string_buffer  sb,
const list  l 
)

append a list of string to a string buffer.

Note that each element of the list is duplicated or not according to the dup field.

Returns
void
Parameters
sb,thestring buffer where to append the whole list
l,thelist of string to append to the string buffer

Definition at line 282 of file string_buffer.c.

283 {
284  FOREACH (string, s, l)
286 }
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179

References FOREACH, and string_buffer_append().

Referenced by pragma_to_string().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_buffer_append_sb()

void string_buffer_append_sb ( string_buffer  sb,
const string_buffer  sb2 
)

append the string buffer sb2 to string buffer sb.

Returns
void
Parameters
sb,thestring buffer where to append the second string buffer
sb2,thestring buffer to append to the fisrt string buffer

Definition at line 271 of file string_buffer.c.

272 {
273  STACK_MAP_X(s, string, string_buffer_append(sb, s), sb2->ins, 0);
274 }

References __string_buffer_head::ins, STACK_MAP_X, and string_buffer_append().

Referenced by freia_spoc_code_buildup(), freia_terapix_call(), and opencl_compile_mergeable_dag().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_buffer_append_xml_text()

void string_buffer_append_xml_text ( string_buffer  sb,
const  string,
bool  also_nl 
)

append a string with XML escapes

Definition at line 342 of file string_buffer.c.

346 {
347  // count needed chars, with a margin
348  int len = 1; // final '\0'
349  char * s = stuff;
350  while (*s) {
351  // only five mandatory ("'&<>), \n added...
352  if (strchr("\"'&<>\n", *s))
353  len += 5;
354  len ++, s ++;
355  }
356 
357  // allocate
358  char * escaped = (char*) malloc(sizeof(char)*len);
359 
360  // copy stuff & insert escapes
361  s = stuff;
362  char * e = escaped;
363  while (*s) {
364  switch (*s) {
365  // mandatory
366  case '"':
367  *e++='&'; *e++='q'; *e++='u'; *e++='o'; *e++='t'; *e++=';'; break;
368  case '\'':
369  *e++='&'; *e++='a'; *e++='p'; *e++='o'; *e++='s'; *e++=';'; break;
370  case '&':
371  *e++='&'; *e++='a'; *e++='m'; *e++='p'; *e++=';'; break;
372  case '<':
373  *e++='&'; *e++='l'; *e++='t'; *e++=';'; break;
374  case '>':
375  *e++='&'; *e++='g'; *e++='t'; *e++=';'; break;
376  // others...
377  case '\n':
378  if (also_nl) {
379  *e++='&'; *e++='#'; *e++='1'; *e++='0'; *e++=';'; break;
380  }
381  // else fall through
382  default:
383  *e++ = *s;
384  }
385  s++;
386  }
387  *e = '\0';
388 
390 }
void * malloc(YYSIZE_T)

References malloc(), and string_buffer_append_internal().

Referenced by append_xml_attribute(), string_buffer_append_symbolic(), string_buffer_append_word(), two_string_buffer_append_symbolic(), xml_Argument(), xml_Array(), xml_AssignArgument(), xml_Call(), xml_Chain_Graph(), xml_Compute_and_Need(), xml_Loop(), xml_ParameterUseToArrayBound(), xml_Pattern_Paving(), xml_Region_Parameter(), xml_Scalar(), xml_TaskParameter(), xml_Transposition(), and xml_Type_Entity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_buffer_cat()

void string_buffer_cat ( string_buffer  sb,
const string  first,
  ... 
)

append a NULL terminated list of string to sb.

Parameters
sbstring buffer to be appended to
first...appended strings

Definition at line 294 of file string_buffer.c.

295 {
296  va_list args;
297  va_start(args, first);
298  string next = first;
299  while (next)
300  {
301  string_buffer_append(sb, next);
302  next = va_arg(args, string);
303  }
304  va_end(args);
305 }

References string_buffer_append().

Referenced by pips_log_xml(), set_to_string_buffer(), and step_directive_to_strings().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_buffer_empty_p()

bool string_buffer_empty_p ( const  string_buffer)

return whether string_buffer sb is empty.

Definition at line 112 of file string_buffer.c.

113 {
114  return string_buffer_size(sb)==0;
115 }
size_t string_buffer_size(const string_buffer sb)
return the size of the string in string_buffer sb

References string_buffer_size().

Referenced by sc_delimiter(), and xml_TaskParameters().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_buffer_free()

void string_buffer_free ( string_buffer psb)

free string buffer structure, also free string contents according to the dup field

  • psb the string_buffer to free

Definition at line 82 of file string_buffer.c.

83 {
84  if ((*psb)->dup)
85  STACK_MAP_X(s, string, free(s), (*psb)->ins, 0);
86  stack_free(&((*psb)->ins));
87  free(*psb);
88  *psb = NULL;
89 }
void free(void *)
void stack_free(stack *)
type, bucket_size, policy
Definition: stack.c:292

References free(), stack_free(), and STACK_MAP_X.

Referenced by dagvtx_dot(), freia_spoc_pipeline(), freia_terapix_call(), freia_trpx_compile_one_dag(), generic_print_xml_application(), get_symbol_table(), gpips_user_error(), gpips_user_warning(), mppa_compile_dag(), mppa_helper_args_params(), open_xml_logfile(), opencl_compile_mergeable_dag(), pips_log_xml(), pips_stop_xml(), safe_get_line_interval(), sc_delimiter(), sc_inst(), set_fprint(), set_to_string(), string_buffer_free_all(), text_to_string_gen(), words_type(), wpips_user_error(), wpips_user_warning(), and xml_Chain_Graph().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_buffer_free_all()

void string_buffer_free_all ( string_buffer psb)

free string buffer structure and force string freeing

  • psb the string_buffer to free

Definition at line 94 of file string_buffer.c.

95 {
96  message_assert("not null pointer", (*psb) != NULL);
97  (*psb)->dup = true;
98  string_buffer_free (psb);
99 }
void string_buffer_free(string_buffer *psb)
free string buffer structure, also free string contents according to the dup field
Definition: string_buffer.c:82

References message_assert, and string_buffer_free().

Referenced by close_extensions(), extensions_to_string(), pragma_to_string(), reductions_get_omp_pragma_str(), and step_directive_to_strings().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_buffer_make()

string_buffer string_buffer_make ( bool  dup)

allocate a new string buffer

Parameters
duptell whether to string duplicate appended strings if so, the strings will be freed later.

Definition at line 58 of file string_buffer.c.

59 {
60  string_buffer n =
61  (string_buffer) malloc(sizeof(struct __string_buffer_head));
62  message_assert("string_buffer is allocated", n!=NULL);
63  n->ins = stack_make(0, 0, 0);
64  n->dup = dup;
65  return n;
66 }
stack stack_make(int, int, int)
allocation
Definition: stack.c:246
struct __string_buffer_head * string_buffer
minimal a la java StringBuffer...
internally defined structure.
Definition: string_buffer.c:47

References __string_buffer_head::dup, __string_buffer_head::ins, malloc(), message_assert, and stack_make().

Referenced by close_extensions(), dagvtx_dot(), extensions_to_string(), freia_spoc_pipeline(), freia_terapix_call(), freia_trpx_compile_one_dag(), generic_print_xml_application(), get_symbol_table(), gpips_user_error(), gpips_user_warning(), mppa_compile_dag(), mppa_helper_args_params(), open_xml_logfile(), opencl_compile_mergeable_dag(), pips_log_xml(), pips_stop_xml(), pragma_to_string(), reductions_get_omp_pragma_str(), safe_get_line_interval(), sc_delimiter(), sc_inst(), set_to_string_buffer(), step_directive_to_strings(), text_to_string_gen(), words_type(), wpips_user_error(), wpips_user_warning(), xml_Boxes(), xml_Chain_Graph(), xml_code(), xml_Compute_and_Need(), xml_Pattern_Paving(), xml_Region_Range(), xml_TaskParameters(), and xml_tiling().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_buffer_printf()

void string_buffer_printf ( string_buffer  sb,
const string  format,
  ... 
)

append a formatted string to sb

Parameters
sbstring buffer to be appended to
formatprintf format string
...values

Definition at line 329 of file string_buffer.c.

333 {
334  va_list args;
335  va_start(args, format);
336  string_buffer_printf_alist(sb, format, &args);
337  va_end(args);
338 }
void string_buffer_printf_alist(string_buffer sb, const string format, va_list *args)
formatted alist version

References string_buffer_printf_alist().

Referenced by append_xml_line_numbers(), gpips_user_error(), gpips_user_warning(), pips_stop_xml(), wpips_user_error(), and wpips_user_warning().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_buffer_printf_alist()

void string_buffer_printf_alist ( string_buffer  sb,
const  string,
va_list *  args 
)

formatted alist version

Definition at line 309 of file string_buffer.c.

313 {
314  va_list acpy;
315  va_copy(acpy, *args);
316  string str;
317  int err = vasprintf(&str, format, acpy);
318  message_assert("vasprintf ok", err >= 0);
319  string_buffer_append(sb, str);
320  if (sb->dup) free(str);
321  va_end(acpy);
322 }
int vasprintf(char **resultp, const char *format, va_list args)
Formatted output to strings.
Definition: vasprintf.c:33

References free(), message_assert, string_buffer_append(), and vasprintf().

Referenced by gpips_user_error(), gpips_user_warning(), string_buffer_printf(), wpips_user_error(), and wpips_user_warning().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_buffer_reset()

void string_buffer_reset ( string_buffer  sb)

remove stack contents

Definition at line 70 of file string_buffer.c.

71 {
72  while (!stack_empty_p(sb->ins)) {
73  string s = (string) stack_pop(sb->ins);
74  if (sb->dup) free(s);
75  }
76 }
bool stack_empty_p(const stack)
void * stack_pop(stack)
POPs one item from stack s.
Definition: stack.c:399
char * string
STRING.
Definition: newgen_types.h:39

References free(), stack_empty_p(), and stack_pop().

Referenced by sc_delimiter(), and sc_inst().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_buffer_size()

size_t string_buffer_size ( const  string_buffer)

return the size of the string in string_buffer sb

Definition at line 103 of file string_buffer.c.

104 {
105  size_t size = 0;
106  STACK_MAP_X(s, string, size+=strlen(s), sb->ins, 0);
107  return size;
108 }

References STACK_MAP_X.

Referenced by freia_terapix_call(), string_buffer_empty_p(), and string_buffer_to_string_internal().

+ Here is the caller graph for this function:

◆ string_buffer_to_file()

void string_buffer_to_file ( const  string_buffer,
FILE *  out 
)

put string buffer into file.

Definition at line 155 of file string_buffer.c.

156 {
157  STACK_MAP_X(s, string, fputs(s, out), sb->ins, 0);
158 }
static FILE * out
Definition: alias_check.c:128

References out, and STACK_MAP_X.

Referenced by dagvtx_dot(), freia_trpx_compile_one_dag(), mppa_compile_dag(), open_xml_logfile(), opencl_compile_mergeable_dag(), pips_log_xml(), pips_stop_xml(), sc_delimiter(), and set_fprint().

+ Here is the caller graph for this function:

◆ string_buffer_to_string()

string string_buffer_to_string ( const  string_buffer)

return malloc'ed string from string buffer sb

Definition at line 141 of file string_buffer.c.

142 {
143  return string_buffer_to_string_internal(sb, false);
144 }
static string string_buffer_to_string_internal(const string_buffer sb, bool rev)
convert to a malloced string, maybe in rev-ersed order of the appends

References string_buffer_to_string_internal().

Referenced by close_extensions(), extensions_to_string(), generic_print_xml_application(), get_symbol_table(), gpips_user_error(), gpips_user_warning(), mppa_helper_args_params(), pragma_to_string(), reductions_get_omp_pragma_str(), safe_get_line_interval(), sc_delimiter(), sc_inst(), set_to_string(), step_directive_to_strings(), text_to_string_gen(), words_type(), wpips_user_error(), wpips_user_warning(), xml_Boxes(), xml_Chain_Graph(), xml_code(), xml_Compute_and_Need(), xml_Pattern_Paving(), xml_Region_Range(), xml_TaskParameters(), and xml_tiling().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ string_buffer_to_string_reverse()

string string_buffer_to_string_reverse ( const  string_buffer)

return malloc'ed string from string buffer sb going from bottom to top

Definition at line 148 of file string_buffer.c.

149 {
150  return string_buffer_to_string_internal(sb, true);
151 }

References string_buffer_to_string_internal().

Referenced by sc_delimiter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: