PIPS
text-util.h File Reference
#include "text.h"
#include "linear.h"
#include "ri.h"
+ Include dependency graph for text-util.h:

Go to the source code of this file.

Macros

#define FORESYS_CONTINUATION_PREFIX   "C$&" " "
 Warning! Do not modify this file that is automatically generated! More...
 
#define MAKE_SWORD(s)   strdup(s)
 
#define MAKE_IWORD(i)   int2a(i)
 
#define MAKE_FWORD(f)   f2a(f)
 
#define CHAIN_SWORD(l, s)   gen_nconc(l, CONS(STRING, MAKE_SWORD(s), NIL))
 
#define CHAIN_IWORD(l, i)   gen_nconc(l, CONS(STRING, MAKE_IWORD(i), NIL))
 
#define CHAIN_FWORD(l, f)   gen_nconc(l, CONS(STRING, MAKE_FWORD(f), NIL))
 
#define MAKE_ONE_WORD_SENTENCE(m, s)
 
#define ADD_SENTENCE_TO_TEXT(t, p)
 
#define MERGE_TEXTS(r, t)
 
#define MAX_LINE_LENGTH   72
 maximum length of a line when prettyprinting... More...
 

Functions

void print_sentence (FILE *, sentence)
 cproto-generated files More...
 
void print_text (FILE *, text)
 
void dump_sentence (sentence)
 
void dump_text (text)
 FI: print_text() should be fprint_text() and dump_text(), print_text() More...
 
string words_join (list, const char *)
 
string words_to_string (list)
 Convert a word list into a string and translate the position of eventual attachment accordingly: More...
 
string sentence_to_string (sentence)
 SG: moved here from icfdg. More...
 
string text_to_string_gen (text, bool)
 
string text_to_string (text)
 SG: moved here from ricedg. More...
 
string text_to_string_nl (text)
 
void print_words (FILE *, list)
 
void dump_words (list)
 
void debug_words (list)
 
void debug_sentence (sentence)
 
void debug_text (text)
 
char * int2a (int)
 util.c More...
 
char * f2a (float)
 
void add_one_unformated_printf_to_text (text, string,...)
 
string first_word_of_sentence (sentence)
 Return the first word of a sentence: More...
 
string last_word_of_sentence (sentence)
 Return the last word of a sentence: More...
 
void add_to_current_line (string, const char *, string, text)
 
void close_current_line (string, text, string)
 
void add_words_to_text (text, list)
 Add the word list wl to the end of the last sentence of text t. More...
 
language get_prettyprint_language (void)
 language.c More...
 
enum language_utype get_prettyprint_language_tag (void)
 
bool prettyprint_language_is_fortran_p (void)
 
bool prettyprint_language_is_fortran95_p (void)
 
bool prettyprint_language_is_c_p (void)
 
void set_prettyprint_language_from_property (enum language_utype)
 set the prettyprint language according to the property PRETTYPRINT_LANGUAGE @description If the property PRETTYPRINT_LANGUAGE is set to the special value "native" then the language passed in arg is used, usually it's the module native language. More...
 
void set_prettyprint_language (language)
 set the prettyprint language from a newgen language object More...
 
void set_prettyprint_language_tag (enum language_utype)
 set the prettyprint language from a language_utype argument More...
 
string get_C_label_printf_format (const char *)
 Get the prettyprint format of a C label. More...
 
void begin_attachment_prettyprint (void)
 The translation functions between unique names and objects: More...
 
void end_attachment_prettyprint (void)
 Clean the things related with the attachment of properties: More...
 
void attach_loop_to_sentence_up_to_end_of_text (sentence, text, loop)
 The user interface: More...
 
sentence attach_head_to_sentence (sentence, entity)
 Attach the PROGRAM/FUNCTION head: More...
 
void attach_reference_to_word_list (string, string, reference)
 Attach a module usage (CALL or function call): More...
 
void attach_regular_call_to_word (string, call)
 Attach a reference: More...
 
void attach_declaration_to_words (list, entity)
 Attach a declaration to all the words of the given list: More...
 
void attach_declaration_type_to_words (list, string)
 Attach a declaration type to all the words of the given list. More...
 
void attach_declaration_size_type_to_words (list, string, int)
 Attach a declaration type with its size to all the words of the given list. More...
 
void attach_statement_information_to_text (text, statement)
 Attach some statement information to text: More...
 
void attach_decoration_to_text (text)
 Attach a decoration: More...
 
void attach_cumulated_effects_decoration_to_text (text)
 Attach a cumulated effects decoration: More...
 
void attach_proper_effects_decoration_to_text (text)
 Attach a proper effects decoration: More...
 
void attach_preconditions_decoration_to_text (text)
 Attach a preconditions decoration: More...
 
void attach_total_preconditions_decoration_to_text (text)
 
void attach_transformers_decoration_to_text (text)
 Attach a transformers decoration: More...
 
void deal_with_attachments_at_this_character (char *, int)
 Try to find some attachments in the given character that are printed out. More...
 
void deal_with_attachments_in_this_string (string, int)
 Try to find some attachments in the given string. More...
 
void deal_with_attachments_in_this_string_length (string, int, int)
 Try to find some attachments in the a_length first characters of the given string. More...
 
void relocate_attachments (char *, char *)
 Many pretty-printers format their own pseudo-comment by their own and move in memory words that have attachments on them. More...
 
char * strcat_word_and_migrate_attachments (char *, const char *)
 Concatenate source to target and update the source attachments to point to the new location: More...
 
char * strdup_and_migrate_attachments (char *)
 Duplicate a string and update the attachments to point to the new returned string: More...
 
void write_an_attachment_file (string)
 Add the attachment in Emacs mode by creating a twin file that is decorated with Emacs properties: More...
 

Variables

list attachments_before_sorting
 attachment_pretty_print.c More...
 

Macro Definition Documentation

◆ ADD_SENTENCE_TO_TEXT

#define ADD_SENTENCE_TO_TEXT (   t,
 
)
Value:
do { \
text _t_ = (t); \
text_sentences(_t_) = \
gen_nconc(text_sentences(_t_), CONS(SENTENCE, (p), NIL)); \
} while(0)
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#define SENTENCE(x)
newgen_unformatted_domain_defined
Definition: text.h:36
#define text_sentences(x)
Definition: text.h:113

Definition at line 51 of file text-util.h.

◆ CHAIN_FWORD

#define CHAIN_FWORD (   l,
  f 
)    gen_nconc(l, CONS(STRING, MAKE_FWORD(f), NIL))

Definition at line 45 of file text-util.h.

◆ CHAIN_IWORD

#define CHAIN_IWORD (   l,
 
)    gen_nconc(l, CONS(STRING, MAKE_IWORD(i), NIL))

Definition at line 44 of file text-util.h.

◆ CHAIN_SWORD

#define CHAIN_SWORD (   l,
 
)    gen_nconc(l, CONS(STRING, MAKE_SWORD(s), NIL))

Definition at line 43 of file text-util.h.

◆ FORESYS_CONTINUATION_PREFIX

#define FORESYS_CONTINUATION_PREFIX   "C$&" " "

Warning! Do not modify this file that is automatically generated!

Modify src/Libs/text-util/text-util-local.h instead, to add your own modifications. header file built by cproto text_util-local.h

Definition at line 37 of file text-util.h.

◆ MAKE_FWORD

#define MAKE_FWORD (   f)    f2a(f)

Definition at line 41 of file text-util.h.

◆ MAKE_IWORD

#define MAKE_IWORD (   i)    int2a(i)

Definition at line 40 of file text-util.h.

◆ MAKE_ONE_WORD_SENTENCE

#define MAKE_ONE_WORD_SENTENCE (   m,
 
)
Value:
make_unformatted((char *) NULL, 0, m, CHAIN_SWORD(NIL, s)))
unformatted make_unformatted(string a1, intptr_t a2, intptr_t a3, list a4)
Definition: text.c:149
sentence make_sentence(enum sentence_utype tag, void *val)
Definition: text.c:59
#define CHAIN_SWORD(l, s)
Definition: text-util.h:43
@ is_sentence_unformatted
Definition: text.h:58

Definition at line 47 of file text-util.h.

◆ MAKE_SWORD

#define MAKE_SWORD (   s)    strdup(s)

Definition at line 39 of file text-util.h.

◆ MAX_LINE_LENGTH

#define MAX_LINE_LENGTH   72

maximum length of a line when prettyprinting...

from 0 to 69, i.e. 70 chars, plus "\n\0"

Definition at line 70 of file text-util.h.

◆ MERGE_TEXTS

#define MERGE_TEXTS (   r,
 
)
Value:
do { \
text _r_ = (r); text _t_ = (t); \
text_sentences(_r_) = \
gen_nconc(text_sentences(_r_), text_sentences(_t_)); \
text_sentences(_t_) = NIL; \
free_text(_t_); \
} while(0)

Definition at line 58 of file text-util.h.

Function Documentation

◆ add_one_unformated_printf_to_text()

void add_one_unformated_printf_to_text ( text  r,
string  a_format,
  ... 
)

beurk

Parameters
a_format_format

Definition at line 59 of file util.c.

61 {
62  /* beurk */
63  char *buffer;
64  va_list some_arguments;
65  va_start(some_arguments, a_format);
66  int ret = vasprintf(&buffer, a_format, some_arguments);
67  pips_assert("vasprintf is ok", ret >= 0);
69  buffer));
70  va_end(some_arguments);
71 }
#define ret(why, what)
true if not a remapping for old.
Definition: dynamic.c:986
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
static string buffer
Definition: string.c:113
#define ADD_SENTENCE_TO_TEXT(t, p)
@ is_sentence_formatted
Definition: text.h:57
int vasprintf(char **resultp, const char *format, va_list args)
Formatted output to strings.
Definition: vasprintf.c:33

References ADD_SENTENCE_TO_TEXT, buffer, is_sentence_formatted, make_sentence(), pips_assert, ret, and vasprintf().

Referenced by ensure_comment_consistency().

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

◆ add_to_current_line()

void add_to_current_line ( string  buffer,
const char *  append,
string  continuation,
text  txt 
)

special case: appends a sole "," on end of line...

2 = strlen("\n\0")

cannot append the string. must go next line.

save the end of the line

trunc!

happend new line.

now regenerate the beginning of the line

get back saved part

current line + new line are too large. Try to append the buffer alone, before trying to add the new line alone

Append the new line

this shouldn't happen. it can occur if lappend+lcontinuation is too large.

Cut the comment

G: warning: I removed the const modifier here

Parameters
bufferuffer
appendppend
continuationontinuation
txtxt

Definition at line 140 of file util.c.

145 {
146  bool divide;
147  char tmp[MAX_LINE_LENGTH];
148  int last_cut;
149  int lappend;
150  int lbuffer = strlen(buffer);
151  bool comment = false;
152  char stmp;
153  /* special case: appends a sole "," on end of line... */
154  if (same_string_p(append, ", ") && lbuffer+3==MAX_LINE_LENGTH)
155  append = ",";
156 
157  lappend = strlen(append);
158 
159 
160  if (lbuffer + lappend + 2 > MAX_LINE_LENGTH) /* 2 = strlen("\n\0") */
161  {
162  /* cannot append the string. must go next line.
163  */
164  last_cut = last_comma_or_clopar(buffer);
165 
166  divide = (last_cut > 0)
167  && (last_cut != lbuffer-1)
168  && (lbuffer - last_cut + lappend +strlen(continuation)
169  < MAX_LINE_LENGTH - 2);
170 
171  if (divide)
172  {
173  int nl_cut = last_cut;
174  while (buffer[nl_cut+1]==' ') nl_cut++;
175  strcpy(tmp, buffer+nl_cut+1); /* save the end of the line */
176  buffer[last_cut+1] = '\0'; /* trunc! */
177  }
178 
179  /* happend new line. */
180  strcat(buffer, LINE_SUFFIX);
183 
184  /* now regenerate the beginning of the line */
185  strcpy(buffer, continuation);
186 
187  if (divide) {
188  strcat(buffer, tmp); /* get back saved part */
189 
190  if (strlen(buffer) + lappend + 2 > MAX_LINE_LENGTH
192  /* current line + new line are too large. Try to append the
193  buffer alone, before trying to add the new line alone */
194  strcat(buffer, LINE_SUFFIX);
197  strcpy(buffer, continuation);
198  }
199  }
200 
201  }
202 
203  /* Append the new line */
204  lbuffer = strlen(buffer);
205  stmp = continuation[0];
206  comment = (stmp == 'c'|| stmp == 'C' || stmp == '!'|| stmp == '*'
207  || (continuation[0] == '/' && continuation[1] == '/')
208  || (continuation[0] == '/' && continuation[1] == '*'));
209 
210  if (strlen(buffer) + lappend + 2 > MAX_LINE_LENGTH) {
211  /* this shouldn't happen.
212  * it can occur if lappend+lcontinuation is too large.
213  */
214  if (comment) {
215  /* Cut the comment */
216  int coupure = MAX_LINE_LENGTH-2 -lbuffer;
217  char tmp2[2*MAX_LINE_LENGTH];
218  strcpy(tmp2,append+coupure);
219  /*SG: warning: I removed the const modifier here */
220  ((char*)append)[coupure]='\0';
221 
224 
225  }
226  else
227  pips_internal_error("line code too large...");
228  }
229  else if (! same_string_p(append, " ")
231  strcat(buffer, append);
232 }
#define append(s)
text text_region_no_action(effect reg) input : a region output : a text consisting of several lines o...
Definition: prettyprint.c:77
#define divide(a, b)
#define continuation
Definition: prettyprint.c:102
static void comment(string_buffer code, spoc_hardware_type hw, dagvtx v, int stage, int side, bool flip)
Definition: freia_spoc.c:52
#define pips_internal_error
Definition: misc-local.h:149
#define same_string_p(s1, s2)
char * strdup()
#define MAX_LINE_LENGTH
maximum length of a line when prettyprinting...
void add_to_current_line(string buffer, const char *append, string continuation, text txt)
Definition: util.c:140
static int last_comma_or_clopar(string s)
returns a possible index where to cut the string.
Definition: util.c:130
#define LINE_SUFFIX
Definition: util.c:125

References ADD_SENTENCE_TO_TEXT, add_to_current_line(), append, buffer, comment(), continuation, divide, is_sentence_formatted, last_comma_or_clopar(), LINE_SUFFIX, make_sentence(), MAX_LINE_LENGTH, pips_internal_error, same_string_p, and strdup().

Referenced by add_separation(), add_to_current_line(), add_Value_to_current_line(), close_current_line(), constante_to_textline(), contrainte_to_text_2(), contraintes_text_format(), entity_list_text_format(), signed_operation_to_textline(), system_sorted_text_format(), text_directive(), and unsigned_operation_to_textline().

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

◆ add_words_to_text()

void add_words_to_text ( text  t,
list  wl 
)

Add the word list wl to the end of the last sentence of text t.

Parameters
wll

Definition at line 273 of file util.c.

274 {
275  list sl = text_sentences(t);
276 
277  if(ENDP(sl)) {
278  pips_internal_error("what kind of sentence to make?");
279  }
280  else {
281  sentence s = SENTENCE(CAR(gen_last(sl)));
282  if(sentence_formatted_p(s)) {
283  pips_internal_error("Not implemented");
284  }
285  else {
288  }
289  }
290  pips_assert("t is consistent", text_consistent_p(t));
291 }
bool text_consistent_p(text p)
Definition: text.c:80
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
list gen_last(list l)
Return the last element of a list.
Definition: list.c:578
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define sentence_unformatted(x)
Definition: text.h:81
#define unformatted_words(x)
Definition: text.h:155
#define sentence_formatted_p(x)
Definition: text.h:76

References CAR, ENDP, gen_last(), gen_nconc(), pips_assert, pips_internal_error, SENTENCE, sentence_formatted_p, sentence_unformatted, text_consistent_p(), text_sentences, and unformatted_words.

Referenced by c_text_related_entities().

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

◆ attach_cumulated_effects_decoration_to_text()

void attach_cumulated_effects_decoration_to_text ( text  t)

Attach a cumulated effects decoration:

Definition at line 416 of file attachment_pretty_print.c.

417 {
420 }
attachee make_attachee(enum attachee_utype tag, void *val)
static bool is_emacs_pretty_print_asked
To store the fact a prettyprinter ask for Emacs attachments:
static void attach_to_text(text t, attachee a)
Attach something to all a text:
#define UU
Definition: newgen_types.h:98
@ is_attachee_cumulated_effects

References attach_to_text(), is_attachee_cumulated_effects, is_emacs_pretty_print_asked, make_attachee(), and UU.

+ Here is the call graph for this function:

◆ attach_declaration_size_type_to_words()

void attach_declaration_size_type_to_words ( list  l,
string  declaration_type,
int  size 
)

Attach a declaration type with its size to all the words of the given list.

No need to use strdup():

Parameters
declaration_typeeclaration_type
sizeize

Definition at line 374 of file attachment_pretty_print.c.

377 {
379  char * size_char = int2a(size);
381  concatenate(declaration_type,
382  "*",
383  size_char,
384  NIL));
385  free(size_char);
386  }
387 }
void attach_declaration_type_to_words(list l, string declaration_type)
Attach a declaration type to all the words of the given list.
void free(void *)
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
char * int2a(int)
util.c
Definition: util.c:42

References attach_declaration_type_to_words(), concatenate(), free(), int2a(), is_emacs_pretty_print_asked, and NIL.

Referenced by text_entity_declaration().

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

◆ attach_declaration_to_words()

void attach_declaration_to_words ( list  l,
entity  e 
)

Attach a declaration to all the words of the given list:

Definition at line 348 of file attachment_pretty_print.c.

350 {
352  attach_to_words(l,
354 }
static void attach_to_words(list l, attachee a)
Attach something to all the words of the list given in argument:
@ is_attachee_declaration

References attach_to_words(), is_attachee_declaration, is_emacs_pretty_print_asked, and make_attachee().

Referenced by words_declaration().

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

◆ attach_declaration_type_to_words()

void attach_declaration_type_to_words ( list  l,
string  declaration_type 
)

Attach a declaration type to all the words of the given list.

No need to use strdup(). May accept an empty list:

Parameters
declaration_typeeclaration_type

Definition at line 360 of file attachment_pretty_print.c.

362 {
364  if (l != NIL)
365  attach_to_words(l,
367  strdup(declaration_type)));
368 }
@ is_attachee_type

References attach_to_words(), is_attachee_type, is_emacs_pretty_print_asked, make_attachee(), NIL, and strdup().

Referenced by attach_declaration_size_type_to_words(), and text_entity_declaration().

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

◆ attach_decoration_to_text()

void attach_decoration_to_text ( text  t)

Attach a decoration:

Some prettyprinters such as effects generate NULL text... Just ignore.

Definition at line 405 of file attachment_pretty_print.c.

406 {
408  /* Some prettyprinters such as effects generate NULL
409  text... Just ignore. */
411 }
@ is_attachee_decoration

References attach_to_text(), is_attachee_decoration, is_emacs_pretty_print_asked, make_attachee(), NIL, text_sentences, and UU.

Referenced by get_semantic_text(), and init_text_statement().

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

◆ attach_head_to_sentence()

sentence attach_head_to_sentence ( sentence  s,
entity  module 
)

Attach the PROGRAM/FUNCTION head:

Parameters
moduleodule

Definition at line 313 of file attachment_pretty_print.c.

314 {
317 
318  return s;
319 }
static void attach_to_sentence(sentence s, attachee a)
Attach something to a sentence:
static char * module
Definition: pips.c:74
@ is_attachee_module_head

References attach_to_sentence(), is_attachee_module_head, is_emacs_pretty_print_asked, make_attachee(), and module.

Referenced by ensure_comment_consistency().

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

◆ attach_loop_to_sentence_up_to_end_of_text()

void attach_loop_to_sentence_up_to_end_of_text ( sentence  s,
text  t,
loop  l 
)

The user interface:

Attach a loop:

Definition at line 302 of file attachment_pretty_print.c.

303 {
307  l));
308 }
static void attach_to_sentence_up_to_end_of_text(sentence s, text t, attachee a)
Attach something to a sentence up to the end of the given text:
@ is_attachee_loop

References attach_to_sentence_up_to_end_of_text(), is_attachee_loop, is_emacs_pretty_print_asked, and make_attachee().

Referenced by text_loop_default().

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

◆ attach_preconditions_decoration_to_text()

void attach_preconditions_decoration_to_text ( text  t)

Attach a preconditions decoration:

Definition at line 434 of file attachment_pretty_print.c.

References attach_to_text(), is_attachee_preconditions, is_emacs_pretty_print_asked, make_attachee(), and UU.

Referenced by get_semantic_text(), and semantic_to_text().

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

◆ attach_proper_effects_decoration_to_text()

void attach_proper_effects_decoration_to_text ( text  t)

Attach a proper effects decoration:

Definition at line 425 of file attachment_pretty_print.c.

References attach_to_text(), is_attachee_proper_effects, is_emacs_pretty_print_asked, make_attachee(), and UU.

+ Here is the call graph for this function:

◆ attach_reference_to_word_list()

void attach_reference_to_word_list ( string  begin_word,
string  end_word,
reference  r 
)

Attach a module usage (CALL or function call):

Parameters
begin_wordegin_word
end_wordnd_word

Definition at line 324 of file attachment_pretty_print.c.

327 {
329  attach_to_word_list(begin_word,
330  end_word,
332 }
static void attach_to_word_list(string begin_word, string end_word, attachee at)
Attach something to a word list, from begin_word to end_word:
@ is_attachee_reference

References attach_to_word_list(), is_attachee_reference, is_emacs_pretty_print_asked, and make_attachee().

Referenced by effect_words_reference(), and words_any_reference().

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

◆ attach_regular_call_to_word()

void attach_regular_call_to_word ( string  word,
call  c 
)

Attach a reference:

Parameters
wordord

Definition at line 337 of file attachment_pretty_print.c.

338 {
340  attach_to_word_list(word,
341  word,
343 }
@ is_attachee_call

References attach_to_word_list(), is_attachee_call, is_emacs_pretty_print_asked, and make_attachee().

Referenced by words_genuine_regular_call().

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

◆ attach_statement_information_to_text()

void attach_statement_information_to_text ( text  t,
statement  s 
)

Attach some statement information to text:

Some prettyprinters such as effects generate NULL text... Just ignore.

Definition at line 392 of file attachment_pretty_print.c.

394 {
396  /* Some prettyprinters such as effects generate NULL
397  text... Just ignore. */
399  (void*) statement_number(s)));
400 }
#define statement_number(x)
Definition: ri.h:2452
@ is_attachee_statement_line_number

References attach_to_text(), is_attachee_statement_line_number, is_emacs_pretty_print_asked, make_attachee(), NIL, statement_number, and text_sentences.

+ Here is the call graph for this function:

◆ attach_total_preconditions_decoration_to_text()

void attach_total_preconditions_decoration_to_text ( text  )

◆ attach_transformers_decoration_to_text()

void attach_transformers_decoration_to_text ( text  t)

Attach a transformers decoration:

Definition at line 451 of file attachment_pretty_print.c.

References attach_to_text(), is_attachee_transformers, is_emacs_pretty_print_asked, make_attachee(), and UU.

Referenced by get_semantic_text(), and semantic_to_text().

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

◆ begin_attachment_prettyprint()

void begin_attachment_prettyprint ( void  )

The translation functions between unique names and objects:

Initialize some things related with the attachment of propertie. To be conservative, if a prettyprinter does not call begin_attachment_prettyprint(), all the attachment stuff is disable. Thus, old prettyprinter can go on without Emacs mode:

Definition at line 145 of file attachment_pretty_print.c.

146 {
147  if (get_bool_property("PRETTYPRINT_ADD_EMACS_PROPERTIES")) {
149  // word_text_attachment_mapping = hash_table_make(hash_pointer, 0);
150  // Initialize the local mapings:
151  init_word_to_attachments_begin();
152  init_word_to_attachments_end();
153  }
154 }
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....

References get_bool_property(), and is_emacs_pretty_print_asked.

Referenced by print_code_or_source(), print_code_semantics(), and print_parallelized_code_common().

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

◆ close_current_line()

void close_current_line ( string  buffer,
text  txt,
string  continuation 
)

do not append an empty line to text

Parameters
bufferuffer
txtxt
continuationontinuation

Definition at line 235 of file util.c.

239 {
240  if (strlen(buffer)!=0) /* do not append an empty line to text */ {
241  int lbuffer=0;
242  char stmp = continuation[0];
243  char stmp1 = continuation[1];
244  bool comment = stmp == 'c'|| stmp == 'C'
245  || stmp == '!'|| stmp == '*'
246  || (stmp == '/' && stmp1 == '*') || (stmp == '/' && stmp1 == '/');
247 
248  if ((lbuffer=strlen(buffer))+2>MAX_LINE_LENGTH) {
249  if (comment) {
250  int coupure = MAX_LINE_LENGTH-2;
251  char tmp2[2*MAX_LINE_LENGTH];
252  strcpy(tmp2,buffer+coupure);
253  buffer[coupure]='\0';
254 
258  }
259  else
260  pips_assert("buffer is too large",
261  strlen(buffer)+1<MAX_LINE_LENGTH);
262  }
263  else {
264  strcat(buffer, LINE_SUFFIX);
267  buffer[0] = '\0';
268  }
269  }
270 }
void close_current_line(string buffer, text txt, string continuation)
Definition: util.c:235

References ADD_SENTENCE_TO_TEXT, add_to_current_line(), buffer, close_current_line(), comment(), continuation, is_sentence_formatted, LINE_SUFFIX, make_sentence(), MAX_LINE_LENGTH, pips_assert, and strdup().

Referenced by close_current_line(), text_continuation(), text_directive(), text_pointer_value(), text_points_to_relation(), text_region_no_action(), and text_transformer().

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

◆ deal_with_attachments_at_this_character()

void deal_with_attachments_at_this_character ( char *  a_character,
int  position_in_the_output 
)

Try to find some attachments in the given character that are printed out.

If any, note the boundary position.

Look for attachment starts:

Look for attachment ends:

Parameters
a_character_character
position_in_the_outputosition_in_the_output

Definition at line 498 of file attachment_pretty_print.c.

500 {
502  debug_on("ATTACHMENT_DEBUG_LEVEL");
503 
504  /* Look for attachment starts: */
505  debug(8, "deal_with_attachment_boundaries",
506  "Looking for attachment starts\n");
507  deal_with_attachment_boundary(a_character,
509  load_word_to_attachments_begin,
510  bound_word_to_attachments_begin_p);
511  /* Look for attachment ends: */
512  debug(8, "deal_with_attachment_boundaries",
513  "Looking for attachment ends\n");
514  deal_with_attachment_boundary(a_character,
516  load_word_to_attachments_end,
517  bound_word_to_attachments_end_p);
518  debug_off();
519  }
520 }
static void deal_with_attachment_boundary(char *a_character, int position_in_the_output, attachments(*load_word_to_attachments_boundary)(void_star), bool(*bound_word_to_attachments_boundary_p)(void_star))
Try to find some attachments in the given character.
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
static int position_in_the_output
FI: just to make sure that text.h is built; pips-makemake -l does not take into account a library who...
Definition: text_print.c:45

References deal_with_attachment_boundary(), debug(), debug_off, debug_on, is_emacs_pretty_print_asked, and position_in_the_output.

Referenced by deal_with_attachments_in_this_string(), deal_with_attachments_in_this_string_length(), and print_sentence().

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

◆ deal_with_attachments_in_this_string()

void deal_with_attachments_in_this_string ( string  a_string,
int  position_in_the_output 
)

Try to find some attachments in the given string.

If any, note the boundary position.

Parameters
a_string_string
position_in_the_outputosition_in_the_output

Definition at line 526 of file attachment_pretty_print.c.

528 {
529  int i;
530 
531  for(i = 0; a_string[i] != '\0'; i++)
534 }
void deal_with_attachments_at_this_character(char *a_character, int position_in_the_output)
Try to find some attachments in the given character that are printed out.
#define a_string
Definition: genread_lex.c:843

References a_string, deal_with_attachments_at_this_character(), and position_in_the_output.

Referenced by print_sentence().

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

◆ deal_with_attachments_in_this_string_length()

void deal_with_attachments_in_this_string_length ( string  a_string,
int  position_in_the_output,
int  a_length 
)

Try to find some attachments in the a_length first characters of the given string.

If any, note the boundary position.

Parameters
a_string_string
position_in_the_outputosition_in_the_output
a_length_length

Definition at line 540 of file attachment_pretty_print.c.

543 {
544  int i;
545 
546  for(i = 0; i < a_length; i++) {
547  pips_assert("Length is too big since end of string encountered",
548  a_string[i] != '\0');
551  }
552 }

References a_string, deal_with_attachments_at_this_character(), pips_assert, and position_in_the_output.

Referenced by print_sentence().

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

◆ debug_sentence()

void debug_sentence ( sentence  s)

Definition at line 501 of file text_print.c.

502 {
503  fprintf(stderr, "# sentence\n");
504  switch (sentence_tag(s))
505  {
508  break;
511  break;
512  default:
513  pips_internal_error("unexpected sentence tag %d", sentence_tag(s));
514  }
515 
516  fprintf(stderr,"# end sentence\n");
517 }
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
#define sentence_formatted(x)
Definition: text.h:78
#define sentence_tag(x)
Definition: text.h:75
static void debug_unformatted(unformatted u)
Definition: text_print.c:492
static void debug_formatted(string s)
Definition: text_print.c:487

References debug_formatted(), debug_unformatted(), fprintf(), is_sentence_formatted, is_sentence_unformatted, pips_internal_error, sentence_formatted, sentence_tag, and sentence_unformatted.

Referenced by debug_text().

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

◆ debug_text()

void debug_text ( text  t)

Definition at line 519 of file text_print.c.

520 {
521  fprintf(stderr, "# text\n");
523  fprintf(stderr,"# end text\n");
524 }
void gen_map(gen_iter_func_t fp, const list l)
Definition: list.c:172
void(* gen_iter_func_t)(void *)
Definition: newgen_types.h:116
void debug_sentence(sentence s)
Definition: text_print.c:501

References debug_sentence(), fprintf(), gen_map(), and text_sentences.

+ Here is the call graph for this function:

◆ debug_words()

void debug_words ( list  l)
Parameters
lof string

Definition at line 481 of file text_print.c.

482 {
484 }
static void debug_word(string w)
Definition: text_print.c:475

References debug_word(), and gen_map().

Referenced by debug_unformatted().

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

◆ dump_sentence()

void dump_sentence ( sentence  s)

Definition at line 190 of file print.c.

191 {
192  print_sentence(stderr, s);
193 }
void print_sentence(FILE *fd, sentence s)
FI: just to make sure that text.h is built; pips-makemake -l does not tale into account a library who...
Definition: print.c:53

References print_sentence().

+ Here is the call graph for this function:

◆ dump_text()

void dump_text ( text  t)

FI: print_text() should be fprint_text() and dump_text(), print_text()

Definition at line 205 of file print.c.

207 {
208  print_text(stderr, t);
209 }
void print_text(FILE *fd, text t)
Definition: print.c:195

References print_text().

Referenced by get_semantic_text(), and text_transformer().

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

◆ dump_words()

void dump_words ( list  lw)
Parameters
lww

Definition at line 251 of file print.c.

252 {
253  print_words(stderr, lw);
254 }
void print_words(FILE *fd, cons *lw)
Definition: print.c:263

References print_words().

Referenced by dump_strings(), print_qualifiers(), and print_type().

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

◆ end_attachment_prettyprint()

void end_attachment_prettyprint ( void  )

Clean the things related with the attachment of properties:

Strings in attachments should already have been freed by print_sentence and attachement it-self (witout "s") by output_an_attachment():

Should be OK since output_the_attachments_for_emacs() has already unlinked the attachment from ord_to_attachments_begin:

ree_names_of_almost_everything_in_a_module();

Definition at line 159 of file attachment_pretty_print.c.

160 {
163 
164  /* Strings in attachments should already have been freed by
165  print_sentence and attachement it-self (witout "s") by
166  output_an_attachment(): */
167  close_word_to_attachments_begin();
168  /* Should be OK since output_the_attachments_for_emacs() has
169  already unlinked the attachment from
170  ord_to_attachments_begin: */
171  close_word_to_attachments_end();
172 
173  /*free_names_of_almost_everything_in_a_module();*/
174  }
175 }

References is_emacs_pretty_print_asked.

Referenced by print_code_or_source(), print_code_semantics(), and print_parallelized_code_common().

+ Here is the caller graph for this function:

◆ f2a()

char* f2a ( float  f)

Definition at line 51 of file util.c.

52 {
53  char *buffer;
54  asprintf(&buffer, "%f", f);
55  return buffer;
56 }
#define asprintf
Definition: misc-local.h:225
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15

References asprintf, buffer, and f().

+ Here is the call graph for this function:

◆ first_word_of_sentence()

string first_word_of_sentence ( sentence  s)

Return the first word of a sentence:

The sentence is seen as a big word:

From the first word to the last one. Label should is skipped:

Definition at line 76 of file util.c.

77 {
78  string begin = string_undefined;
79 
80  if (sentence_formatted_p(s))
81  /* The sentence is seen as a big word: */
82  begin = sentence_formatted(s);
83  else if (sentence_unformatted_p(s)) {
85  /* From the first word to the last one. Label should is
86  skipped: */
87  begin = STRING(CAR(l));
88  }
89  else {
90  pips_assert("s should be formatted or unformatted...", 0);
91  // redundant... to avoid a warning
92  abort();
93  }
94 
95  return begin;
96 }
#define STRING(x)
Definition: genC.h:87
#define abort()
Definition: misc-local.h:53
#define string_undefined
Definition: newgen_types.h:40
#define sentence_unformatted_p(x)
Definition: text.h:79

References abort, CAR, pips_assert, sentence_formatted, sentence_formatted_p, sentence_unformatted, sentence_unformatted_p, STRING, string_undefined, and unformatted_words.

Referenced by attach_to_sentence_list(), get_vertex_by_string(), print_graph_of_text_to_daVinci(), and safe_make_successor().

+ Here is the caller graph for this function:

◆ get_C_label_printf_format()

string get_C_label_printf_format ( const char *  label)

Get the prettyprint format of a C label.

Parameters
labela string to render
Returns
the printf-format string

If the label begin with a digit, prefix it with a 'l' to be C compatible.

Hmmm, this does not verify that there is no such label in the program already... :-( Should be solved quite earlier anyway...

Parameters
labelabel

Definition at line 155 of file language.c.

155  {
156  /* If the label begin with a digit, prefix it with a 'l' to be C
157  compatible.
158 
159  Hmmm, this does not verify that there is no such label in the program
160  already... :-( Should be solved quite earlier anyway...
161  */
162  return isdigit(label[0]) ? "l%s:" : "%s:";
163 }

Referenced by print_sentence().

+ Here is the caller graph for this function:

◆ get_prettyprint_language()

language get_prettyprint_language ( void  )

language.c

language.c

Returns
the prettyprint language as a newgen language object

Definition at line 57 of file language.c.

57  {
60  return prettyprint_language;
61 }
language make_language_fortran(void)
Definition: ri.c:1250
static language prettyprint_language
==================== Language management ===========
Definition: language.c:51
#define language_undefined
Definition: ri.h:1551

References language_undefined, make_language_fortran(), and prettyprint_language.

Referenced by add_loop_parallel_threshold(), and merge_on_outer().

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

◆ get_prettyprint_language_tag()

enum language_utype get_prettyprint_language_tag ( void  )
Returns
the prettyprint language as a language_utype

Definition at line 57 of file language.c.

67  {
69 }
language get_prettyprint_language()
please avoid using this function directly, use predicate instead (see below)
Definition: language.c:57
#define language_tag(x)
Definition: ri.h:1590

Referenced by effect_words_reference(), ensure_comment_consistency(), generate_alternate_return_targets(), get_comment_continuation(), get_comment_sentinel(), loop_annotate(), loop_private_variables(), loop_test(), mark_block(), pragma_to_string(), prettyprint_language_is_c_p(), prettyprint_language_is_fortran95_p(), prettyprint_language_is_fortran_p(), print_code_or_source(), print_parallelized_code_common(), print_sentence(), sentence_head(), sentence_tail(), store_sc_text_line(), text_block_else(), text_block_elseif(), text_block_if(), text_block_ifthen(), text_directive(), text_instruction(), text_io_block_if(), text_logical_if(), text_loop_default(), text_omp_directive(), text_test(), text_trail(), text_whileloop(), this_entity_cdeclaration(), whileloop_test(), words_any_reference(), words_assign_op(), words_basic(), words_declaration(), words_dimension(), words_dimensions(), words_goto_label(), words_io_inst(), words_loop_list(), words_nullary_op(), words_parameters(), words_range(), words_regular_call(), words_subscript_range(), and words_test_list().

+ Here is the caller graph for this function:

◆ int2a()

◆ last_word_of_sentence()

string last_word_of_sentence ( sentence  s)

Return the last word of a sentence:

The sentence is seen as a big word:

From the first word to the last one. Label should is skipped:

Definition at line 101 of file util.c.

102 {
103  string end = string_undefined;
104 
105  if (sentence_formatted_p(s))
106  /* The sentence is seen as a big word: */
107  end = sentence_formatted(s);
108  else if (sentence_unformatted_p(s)) {
110  /* From the first word to the last one. Label should is
111  skipped: */
112  end = STRING(CAR(gen_last(l)));
113  }
114  else {
115  pips_assert("s should be formatted or unformatted...", 0);
116  // redundant... to avoid a warning
117  abort();
118  }
119 
120  return end;
121 }
char end
Definition: gtk_status.c:82

References abort, CAR, end, gen_last(), pips_assert, sentence_formatted, sentence_formatted_p, sentence_unformatted, sentence_unformatted_p, STRING, string_undefined, and unformatted_words.

Referenced by attach_to_sentence_list().

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

◆ prettyprint_language_is_c_p()

bool prettyprint_language_is_c_p ( void  )
Returns
true if the language is C

Definition at line 91 of file language.c.

91  {
93 }
enum language_utype get_prettyprint_language_tag()
Definition: language.c:67
@ is_language_c
Definition: ri.h:1567

References get_prettyprint_language_tag(), and is_language_c.

Referenced by compilation_unit_text(), renamed_op_handling(), sentence_head(), text_block_elseif(), text_block_ifthen(), text_whileloop(), words_infix_binary_op(), words_io_inst(), words_prefix_unary_op(), and words_regular_call().

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

◆ prettyprint_language_is_fortran95_p()

bool prettyprint_language_is_fortran95_p ( void  )
Returns
true if the language is f95

Definition at line 83 of file language.c.

83  {
85 }
@ is_language_fortran95
Definition: ri.h:1568

References get_prettyprint_language_tag(), and is_language_fortran95.

Referenced by f77_f95_style_management(), text_entity_declaration(), and words_infix_binary_op().

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

◆ prettyprint_language_is_fortran_p()

bool prettyprint_language_is_fortran_p ( void  )
Returns
true if the language is f77

Definition at line 75 of file language.c.

75  {
77 }
@ is_language_fortran
Definition: ri.h:1566

References get_prettyprint_language_tag(), and is_language_fortran.

Referenced by close_pragma(), create_module_with_statement(), ensure_comment_consistency(), get_prettyprint_indentation(), marged(), omp_operator_entity(), omp_operator_str(), pragma_to_string(), print_sentence(), reductions_get_omp_pragma_str(), and text_instruction().

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

◆ print_sentence()

void print_sentence ( FILE *  fd,
sentence  s 
)

cproto-generated files

text_print.c

cproto-generated files

print_sentence:

FI: I had to change this module to handle string longer than the space available on one line; I tried to preserve as much as I could of the previous behavior to avoid pseudo-hyphenation at the wrong place and to avoid extensicve problems with validate; the resulting code is lousy, of course; FI, 15 March 1993

RK: the print_sentence could print lower case letter according to a property... 17/12/1993.

FI/FC: Why on earth?!? (void) putc((islower((int) c) ? (char) toupper((int) c) : c), fd);

if the string fits on the current line: no problem

if the string fits on one line: use the 88 algorithm to break as few syntactic constructs as possible

complete current line

start a new line with its prefix

Special label for Cray directives

if the string has to be broken in at least two lines: new algorithmic part to avoid line overflow (FI, March 1993)

complete the current line

start a new line with its prefix but no indentation since string constants may be broken onto two lines

Special label for Cray directives

col: the next column number, starting from 1. it means tha columns 1 to col-1 have been output. I guess. FC.

first 6 columns (0-5)

05/08/2003 - Nga Nguyen - Add code for C prettyprinter

Keep track of the attachment against the padding:

C prettyprinter: a label cannot begin with a number so "l" is added for this case

FI: do not indent too much (9 June 1995)

Initial tabulation, if needed: do not put useless SPACEs in output file. Well, it's difficult to know if it is useful or not. The test below leads to misplaced opening braces.

& gen_length(lw)>1 && !same_string_p(STRING(CAR(lw)), "\n")

Fortran77 start on 7th column

if the string fits on the current line: no problem

if the string fits on one line: use the 88 algorithm to break as few syntactic constructs as possible

Complete current line with the statement line number, if it is significative:

prepare to cut the line

start a new line with its prefix

Special label for Cray directives

if the string has to be broken in at least two lines: new algorithmic part to avoid line overflow (FI, March 1993)

Complete the current line, but not after :-)

start a new line with its prefix but no indentation since string constants may be broken onto two lines

prepare to cut the line

Special label for Cray directives

statement line number starts at different column depending on the used language : C or fortran

fortran case right the line number on the right where characters are ignored by a f77 parser

C and F95 case, try to align the line number on the right using commentaries. The alignment is done modulo C_STATEMENT_LINE_STEP

Output the statement line number on the right end of the line:

Parameters
fdd

Definition at line 53 of file print.c.

54 {
55  if (sentence_formatted_p(s)) {
56  string ps = sentence_formatted(s);
57  while (*ps) {
58  char c = *ps++;
59  /* FI/FC: Why on earth?!?
60  (void) putc((islower((int) c) ? (char) toupper((int) c) : c), fd);
61  */
62  (void) putc( c, fd);
63  }
64  }
65  else {
67  int col;
68  int i;
69  int line_num = 1;
70  string label = unformatted_label(u);
71  int em = unformatted_extra_margin(u);
72  int n = unformatted_number(u);
73  cons *lw = unformatted_words(u);
74 
75  if (label != (char *) NULL) {
76  fprintf(fd, "%-5s ", label);
77  }
79  fputs(" ", fd);
80  }
81 
82 
83  for (i = 0; i < em; i++)
84  putc(' ', fd);
85  col = 7+em;
86 
87  pips_assert("print_sentence", col <= MAX_LINE_LENGTH);
88 
89  while (lw) {
90  string w = STRING(CAR(lw));
91 
92  STRING(CAR(lw)) = NULL;
93  lw = CDR(lw);
94 
95  /* if the string fits on the current line: no problem */
96  if (col + strlen(w) <= 70) {
97  (void) fprintf(fd, "%s", w);
98  col += strlen(w);
99  }
100  /* if the string fits on one line:
101  * use the 88 algorithm to break as few
102  * syntactic constructs as possible */
103  else if(strlen(w) < 70-7-em) {
104  if (col + strlen(w) > 70) {
105  /* complete current line */
106  if (n > 0) {
107  for (i = col; i <= MAX_LINE_LENGTH; i++) putc(' ', fd);
108  fprintf(fd, "%04d", n);
109  }
110 
111  /* start a new line with its prefix */
112  putc('\n', fd);
113 
114  if(label != (char *) NULL
115  && (strcmp(label,"CDIR$")==0
116  || strcmp(label,"CDIR@")==0
117  || strcmp(label,"CMIC$")==0)) {
118  /* Special label for Cray directives */
119  fputs(label, fd);
120  fprintf(fd, "%d", (++line_num)%10);
121  }
122  else
123  fputs(" &", fd);
124 
125  for (i = 0; i < em; i++)
126  putc(' ', fd);
127 
128  col = 7+em;
129  }
130  (void) fprintf(fd, "%s", w);
131  col += strlen(w);
132  }
133  /* if the string has to be broken in at least two lines:
134  * new algorithmic part
135  * to avoid line overflow (FI, March 1993) */
136  else {
137  char * line = w;
138  int ncar;
139 
140  /* complete the current line */
141  ncar = MAX_LINE_LENGTH - col + 1;
142  fprintf(fd,"%.*s", ncar, line);
143  line += ncar;
144  col = 73;
145 
146  /*
147  if (n > 0) {
148  for (i = col; i <= 72; i++) putc(' ', fd);
149  fprintf(fd, "%04d", n);
150  }
151  */
152 
153  while(strlen(line)!=0) {
154  ncar = MIN(MAX_LINE_LENGTH - 7 +1, strlen(line));
155 
156  /* start a new line with its prefix but no indentation
157  * since string constants may be broken onto two lines */
158  putc('\n', fd);
159 
160  if(label != (char *) NULL
161  && (strcmp(label,"CDIR$")==0
162  || strcmp(label,"CDIR@")==0
163  || strcmp(label,"CMIC$")==0)) {
164  /* Special label for Cray directives */
165  fputs(label, fd);
166  (void) fprintf(fd, "%d", (++line_num)%10);
167  }
168  else
169  fputs(" &", fd);
170 
171  col = 7 ;
172  (void) fprintf(fd,"%.*s", ncar, line);
173  line += ncar;
174  col += ncar;
175  }
176  }
177  free(w);
178  }
179 
180  pips_assert("print_sentence", col <= MAX_LINE_LENGTH);
181 
182  if (n > 0) {
183  for (i = col; i <= MAX_LINE_LENGTH; i++) putc(' ', fd);
184  fprintf(fd, "%04d", n);
185  }
186  putc('\n', fd);
187  }
#define MIN(x, y)
minimum and maximum if they are defined somewhere else, they are very likely to be defined the same w...
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
bool prettyprint_language_is_fortran_p()
Definition: language.c:75
static int line
FLEX_SCANNER.
Definition: scanner.c:852
#define unformatted_number(x)
Definition: text.h:151
#define unformatted_extra_margin(x)
Definition: text.h:153
#define unformatted_label(x)
Definition: text.h:149

References C_STATEMENT_LINE_COLUMN, C_STATEMENT_LINE_STEP, CAR, CDR, deal_with_attachments_at_this_character(), deal_with_attachments_in_this_string(), deal_with_attachments_in_this_string_length(), ENDP, FOREACH, fprintf(), fprintf_sentence(), free(), get_bool_property(), get_C_label_printf_format(), get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, line, MAX_END_COLUMN_DEFAULT, MAX_END_COLUMN_F77, MAX_END_COLUMN_F95, MAX_LINE_LENGTH, MAX_START_COLUMN, MIN, pips_assert, pips_debug, pips_internal_error, position_in_the_output, prettyprint_language_is_fortran_p(), putc_sentence(), sentence_formatted, sentence_formatted_p, sentence_unformatted, STRING, string_undefined_p, unformatted_extra_margin, unformatted_label, unformatted_number, and unformatted_words.

Referenced by dump_sentence(), make_emulated_shared_variable(), print_text(), and set_dimensions_of_local_variable_family().

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

◆ print_text()

◆ print_words()

void print_words ( FILE *  fd,
list  lw 
)
Parameters
fdd
lww

Definition at line 460 of file text_print.c.

461 {
462  string s = words_to_string(lw);
463  fputs(s, fd);
464  free(s);
465 }
string words_to_string(list ls)
Convert a word list into a string and translate the position of eventual attachment accordingly:
Definition: text_print.c:412

References free(), and words_to_string().

Referenced by dump_words().

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

◆ relocate_attachments()

void relocate_attachments ( char *  source,
char *  new_position 
)

Many pretty-printers format their own pseudo-comment by their own and move in memory words that have attachments on them.

To be able to track them up to the output, we need to overload the movement function to keep track of these.

Parameters
sourceource
new_positionew_position

Definition at line 560 of file attachment_pretty_print.c.

562 {
563  int i;
564  int source_length = strlen(source);
565 
566  debug_on("ATTACHMENT_DEBUG_LEVEL");
567 
568  pips_debug(5, "source = \"%s\" (%p), new_position = \"%s\" (%p)\n",
569  source, source,
570  new_position, new_position);
571 
572  for(i = 0; i < source_length; i++) {
573  if (bound_word_to_attachments_begin_p(source + i)) {
574  pips_debug(4, "Relocating begin of attachment from %p to %p\n",
575  source + i,
576  new_position + i);
577  pips_assert("There is already an attachment on the target",
578  !bound_word_to_attachments_begin_p(new_position + i));
579  store_word_to_attachments_begin(new_position + i,
580  load_word_to_attachments_begin(source + i));
581  delete_word_to_attachments_begin(source + i);
582  }
583  if (bound_word_to_attachments_end_p(source + i)) {
584  pips_debug(4, "Relocating end of attachment from %p to %p\n",
585  source + i,
586  new_position + i);
587  pips_assert("There is already an attachment on the target",
588  !bound_word_to_attachments_end_p(new_position + i));
589  store_word_to_attachments_end(new_position + i,
590  load_word_to_attachments_end(source + i));
591  delete_word_to_attachments_end(source + i);
592  }
593  }
594  debug_off();
595 }
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145

References debug_off, debug_on, pips_assert, and pips_debug.

Referenced by strcat_word_and_migrate_attachments(), and strdup_and_migrate_attachments().

+ Here is the caller graph for this function:

◆ sentence_to_string()

string sentence_to_string ( sentence  sen)

SG: moved here from icfdg.

SG: moved here from icfdg.

Parameters
senen

Definition at line 230 of file print.c.

231 {
232  if (!sentence_formatted_p(sen))
234  else
235  return sentence_formatted(sen);
236 }
string words_to_string(cons *lw)
Definition: print.c:211

References sentence_formatted, sentence_formatted_p, sentence_unformatted, unformatted_words, and words_to_string().

Referenced by print_graph_of_text_to_daVinci(), print_marged_text_from_starting_node(), print_module_icfg(), text_to_string(), and text_to_string_gen().

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

◆ set_prettyprint_language()

void set_prettyprint_language ( language  lang)

set the prettyprint language from a newgen language object

Parameters
lang,thelanguage to be used to set the prettyprint_language variable, content is copied so caller may free if it was malloced
Parameters
langang

Definition at line 130 of file language.c.

References language_undefined, make_language_fortran(), and prettyprint_language.

+ Here is the call graph for this function:

◆ set_prettyprint_language_from_property()

void set_prettyprint_language_from_property ( enum language_utype  native)

set the prettyprint language according to the property PRETTYPRINT_LANGUAGE @description If the property PRETTYPRINT_LANGUAGE is set to the special value "native" then the language passed in arg is used, usually it's the module native language.

The user can set "F77", "F95", or "C" to force the prettyprint of a language.

Parameters
nativeative

Definition at line 103 of file language.c.

103  {
106  }
107  const char* lang = get_string_property ("PRETTYPRINT_LANGUAGE");
108  if (strcmp (lang, "F77") == 0) {
110  }
111  else if (strcmp (lang, "C") == 0) {
113  }
114  else if (strcmp (lang, "F95") == 0) {
116  }
117  else if (strcmp (lang, "native") == 0) {
119  } else {
120  pips_internal_error("bad property value for language");
121  }
122 }
char * get_string_property(const char *)

References get_string_property(), is_language_c, is_language_fortran, is_language_fortran95, language_tag, language_undefined, make_language_fortran(), pips_internal_error, and prettyprint_language.

Referenced by controlizer(), ensure_comment_consistency(), new_controlizer(), omp_loop_parallel_threshold_set(), omp_merge_pragma(), print_code_or_source(), and static_controlize().

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

◆ set_prettyprint_language_tag()

void set_prettyprint_language_tag ( enum language_utype  lang)

set the prettyprint language from a language_utype argument

Parameters
lang,thelanguage to be used to set the prettyprint_language variable
Parameters
langang

Definition at line 143 of file language.c.

References language_tag, language_undefined, make_language_fortran(), and prettyprint_language.

Referenced by actual_c_parser(), actual_symbol_table_dump(), add_new_module_from_text(), MakeCaseStatement(), missing_file_initializer(), and this_entity_cdeclaration().

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

◆ strcat_word_and_migrate_attachments()

char* strcat_word_and_migrate_attachments ( char *  target,
const char *  source 
)

Concatenate source to target and update the source attachments to point to the new location:

The actual copy:

The actual copy:

Parameters
targetarget
sourceource

Definition at line 601 of file attachment_pretty_print.c.

603 {
604  char * new_string;
605 
607  int target_length = strlen(target);
608 
609  /* The actual copy: */
610  new_string = strcat(target, source);
611  relocate_attachments((char*)source, target + target_length);
612  }
613  else
614  /* The actual copy: */
615  new_string = strcat(target, source);
616 
617  return new_string;
618 }
void relocate_attachments(char *source, char *new_position)
Many pretty-printers format their own pseudo-comment by their own and move in memory words that have ...

References is_emacs_pretty_print_asked, and relocate_attachments().

Referenced by words_join().

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

◆ strdup_and_migrate_attachments()

char* strdup_and_migrate_attachments ( char *  a_string)

Duplicate a string and update the attachments to point to the new returned string:

Parameters
a_string_string

Definition at line 624 of file attachment_pretty_print.c.

625 {
626  char * new_string = strdup(a_string);
627 
628  if (new_string != NULL && is_emacs_pretty_print_asked)
629  relocate_attachments(a_string, new_string);
630  return new_string;
631 }

References a_string, is_emacs_pretty_print_asked, relocate_attachments(), and strdup().

+ Here is the call graph for this function:

◆ text_to_string()

string text_to_string ( text  t)

SG: moved here from ricedg.

Definition at line 239 of file print.c.

240 {
241  string str = strdup("");
242  string str_new;
243  MAP(SENTENCE, sen, {
244  str_new = strdup(concatenate(str, sentence_to_string(sen), NULL));
245  free(str);
246  str = str_new;
247  }, text_sentences(t));
248  return(str);
249 }
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226
string sentence_to_string(sentence sen)
SG: moved here from icfdg.
Definition: print.c:230

References concatenate(), free(), MAP, SENTENCE, sentence_to_string(), strdup(), text_sentences, and text_to_string_gen().

Referenced by concerned_entity_p(), control_graph(), debug_print_effects_list(), insert_impact_description_as_comment(), prettyprint_dot_label(), region_to_statement(), step_compute_CHAINS_DG_remove_summary_regions(), step_print_directives_regions(), step_translate_and_map(), and subtsitute_variable_in_reference().

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

◆ text_to_string_gen()

string text_to_string_gen ( text  t,
bool  with_newline 
)
Parameters
with_newlineith_newline

Definition at line 428 of file text_print.c.

429 {
431 
433  {
434  string ss = sentence_to_string(sen);
436  // try to avoid a memory leak... see comments above
437  if (sentence_unformatted_p(sen))
438  free(ss);
439  if (with_newline)
440  string_buffer_append(sb, "\n");
441  }
442 
443  string s = string_buffer_to_string(sb);
445 
446  return s;
447 }
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 th...
string string_buffer_to_string(const string_buffer)
return malloc'ed string from string buffer sb
void string_buffer_free(string_buffer *)
free string buffer structure, also free string contents according to the dup field
Definition: string_buffer.c:82
string_buffer string_buffer_make(bool dup)
allocate a new string buffer
Definition: string_buffer.c:58
internally defined structure.
Definition: string_buffer.c:47
Definition: statement.c:4047
string sentence_to_string(sentence sen)
SG: moved here from icfdg BUG (FC): words_to_string is malloced, but sentence_formatted is not:-(.
Definition: text_print.c:420

References FOREACH, free(), sentence_to_string(), sentence_unformatted_p, string_buffer_append(), string_buffer_free(), string_buffer_make(), string_buffer_to_string(), and text_sentences.

Referenced by text_to_string(), and text_to_string_nl().

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

◆ text_to_string_nl()

string text_to_string_nl ( text  t)

Definition at line 455 of file text_print.c.

456 {
457  return text_to_string_gen(t, true);
458 }
string text_to_string_gen(text t, bool with_newline)
Definition: text_print.c:428

References text_to_string_gen().

Referenced by ensure_comment_consistency().

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

◆ words_join()

string words_join ( list  ls,
const char *  sep 
)

1 for null termination.

computes the buffer length.

appends to the buffer...

Parameters
lss
sepep

Definition at line 385 of file text_print.c.

386 {
387  int size = 1; /* 1 for null termination. */
388  size_t sep_sz = strlen(sep);
389  string buffer, p;
390 
391  /* computes the buffer length.
392  */
393  MAP(STRING, s, size+=strlen(s)+sep_sz, ls);
394  buffer = (char*) malloc(sizeof(char)*size);
395  pips_assert("malloc ok", buffer);
396 
397  /* appends to the buffer...
398  */
399  buffer[0] = '\0';
400  p=buffer;
401  FOREACH(STRING, s,ls) {
404  p+=strlen(s);
405  p+=sep_sz;
406  }
407  return buffer;
408 }
char * strcat_word_and_migrate_attachments(char *target, const char *source)
Concatenate source to target and update the source attachments to point to the new location:
void * malloc(YYSIZE_T)

References buffer, FOREACH, malloc(), MAP, pips_assert, strcat_word_and_migrate_attachments(), and STRING.

Referenced by words_to_string().

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

◆ words_to_string()

string words_to_string ( list  ls)

Convert a word list into a string and translate the position of eventual attachment accordingly:

Parameters
lss

Definition at line 412 of file text_print.c.

413 {
414  return words_join(ls,"");
415 }
string words_join(list ls, const char *sep)
Definition: text_print.c:385

References words_join().

Referenced by print_words(), and sentence_to_string().

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

◆ write_an_attachment_file()

void write_an_attachment_file ( string  file_name)

Add the attachment in Emacs mode by creating a twin file that is decorated with Emacs properties:

Now include the original plain file:

Strange semantics: must have read the character first:

Just backslashify the '"' and '\':

Actually add the interesting stuff:

Parameters
file_nameile_name

Definition at line 912 of file attachment_pretty_print.c.

913 {
915  FILE * file_stream;
916  char * emacs_file_name = strdup(concatenate(file_name, EMACS_FILE_EXT, NULL));
917  FILE * emacs_file_stream = safe_fopen(emacs_file_name, "w");
918  init_output_the_attachments_for_emacs(emacs_file_stream);
919  /* Now include the original plain file: */
920  file_stream = safe_fopen(file_name, "r");
921  for(;;) {
922  char c = getc(file_stream);
923  /* Strange semantics: must have read the character first: */
924  if (feof(file_stream))
925  break;
926 
927  /* Just backslashify the '"' and '\': */
928  if (c == '"' || c == '\\')
929  (void) putc('\\', emacs_file_stream);
930 
931  (void) putc(c, emacs_file_stream);
932  }
933  safe_fclose(file_stream, file_name);
934  /* Actually add the interesting stuff: */
935  output_the_attachments_for_emacs(emacs_file_stream);
936  safe_fclose(emacs_file_stream, emacs_file_name);
937  free(emacs_file_name);
938  }
939 }
static void output_the_attachments_for_emacs(FILE *output_file)
Output the list of all the attachments found in the text file with Emacs Lisp syntax:
static void init_output_the_attachments_for_emacs(FILE *output_file)
Begin the Emacs Lisp file:
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
static string file_name

References concatenate(), file_name, free(), init_output_the_attachments_for_emacs(), is_emacs_pretty_print_asked, output_the_attachments_for_emacs(), safe_fclose(), safe_fopen(), and strdup().

Referenced by make_resource_from_starting_node(), and make_text_resource().

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

Variable Documentation

◆ attachments_before_sorting