PIPS
attachment_pretty_print.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "linear.h"
#include "genC.h"
#include "misc.h"
#include "properties.h"
#include "naming.h"
#include "text-util.h"
#include "word_attachment.h"
#include "constants.h"
+ Include dependency graph for attachment_pretty_print.c:

Go to the source code of this file.

Macros

#define ADD_AN_ATTACHMENT_TO_A_MAPPING(a, a_char, a_mapping)
 Use to create or extend the attachment list of a character: More...
 

Typedefs

typedef char * void_star
 Used in word_to_attachments: More...
 

Enumerations

enum  { POSITION_UNDEFINED = -1 }
 

Functions

static const char * module_local_name (entity e)
 Declare the various mapping between the words and attachments: 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...
 
static void attach_to_character_region (char *begin_char, char *end_char, attachee at)
 Attach something from begin_char up to end_char: More...
 
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: More...
 
static void attach_to_words (list l, attachee a)
 Attach something to all the words of the list given in argument: More...
 
static void attach_to_sentence_list (sentence begin, sentence end, attachee a)
 Attach something to a sentence list: More...
 
static void attach_to_sentence (sentence s, attachee a)
 Attach something to a sentence: More...
 
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: More...
 
static void attach_to_text (text t, attachee a)
 Attach something to all a text: More...
 
void attach_loop_to_sentence_up_to_end_of_text (sentence s, text t, loop l)
 The user interface: More...
 
sentence attach_head_to_sentence (sentence s, entity module)
 Attach the PROGRAM/FUNCTION head: More...
 
void attach_reference_to_word_list (string begin_word, string end_word, reference r)
 Attach a module usage (CALL or function call): More...
 
void attach_regular_call_to_word (string word, call c)
 Attach a reference: More...
 
void attach_declaration_to_words (list l, entity e)
 Attach a declaration to all the words of the given list: More...
 
void attach_declaration_type_to_words (list l, string declaration_type)
 Attach a declaration type to all the words of the given list. More...
 
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. More...
 
void attach_statement_information_to_text (text t, statement s)
 Attach some statement information to text: More...
 
void attach_decoration_to_text (text t)
 Attach a decoration: More...
 
void attach_cumulated_effects_decoration_to_text (text t)
 Attach a cumulated effects decoration: More...
 
void attach_proper_effects_decoration_to_text (text t)
 Attach a proper effects decoration: More...
 
void attach_preconditions_decoration_to_text (text t)
 Attach a preconditions decoration: More...
 
void attach_total_preconditions_decoration_to_text (text __attribute__((unused)) t)
 Attach a total preconditions decoration: More...
 
void attach_transformers_decoration_to_text (text t)
 Attach a transformers decoration: More...
 
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. More...
 
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. More...
 
void deal_with_attachments_in_this_string (string a_string, int position_in_the_output)
 Try to find some attachments in the given string. More...
 
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. More...
 
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. More...
 
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: More...
 
char * strdup_and_migrate_attachments (char *a_string)
 Duplicate a string and update the attachments to point to the new returned string: More...
 
static void output_an_attachment (FILE *output_file, attachment a)
 Output an attachment to the output file: More...
 
static int compare_attachment_for_qsort (const void *xp, const void *yp)
 The function used by qsort to compare 2 attachment structures: More...
 
static void output_the_attachments_in_a_sorted_order (FILE *output_file)
 Output the attachment in a sorted order with less precise property first: More...
 
static bool put_an_attachment_in_the_list (attachment a)
 Add the attachment to the intermediate list: More...
 
static void rewrite_an_attachment (attachment __attribute__((unused)) a)
 Nothing to do... More...
 
static void init_output_the_attachments_for_emacs (FILE *output_file)
 Begin the Emacs Lisp file: More...
 
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: More...
 
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: More...
 

Variables

static bool is_emacs_pretty_print_asked
 To store the fact a prettyprinter ask for Emacs attachments: More...
 
list attachments_before_sorting = NIL
 To store the attachment before sorting: More...
 

Macro Definition Documentation

◆ ADD_AN_ATTACHMENT_TO_A_MAPPING

#define ADD_AN_ATTACHMENT_TO_A_MAPPING (   a,
  a_char,
  a_mapping 
)
Value:
if (bound_##a_mapping##_p(a_char)) { \
attachments ats = load_##a_mapping(a_char); \
list l = attachments_attachment(ats); \
l = CONS(ATTACHMENT, a, l); \
attachments_attachment(ats) = l; \
} \
else { \
store_##a_mapping(a_char, \
a, \
NIL))); \
}
attachments make_attachments(list a)
#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 ATTACHMENT(x)
ATTACHMENT.
#define attachments_attachment(x)

Use to create or extend the attachment list of a character:

Definition at line 179 of file attachment_pretty_print.c.

Typedef Documentation

◆ void_star

typedef char* void_star

Used in word_to_attachments:

Definition at line 42 of file attachment_pretty_print.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
POSITION_UNDEFINED 

Definition at line 50 of file attachment_pretty_print.c.

50 {POSITION_UNDEFINED = -1};
@ POSITION_UNDEFINED

Function Documentation

◆ 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 }
char * strdup()
@ 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 }
#define text_sentences(x)
Definition: text.h:113
@ 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_to_character_region()

static void attach_to_character_region ( char *  begin_char,
char *  end_char,
attachee  at 
)
static

Attach something from begin_char up to end_char:

Attach the begin to the first character:

Attach the end to the last character:

Definition at line 197 of file attachment_pretty_print.c.

201 {
202  // We do not know the position of the attachement in the output file yet:
204 
205  debug_on("ATTACHMENT_DEBUG_LEVEL");
206  debug(6, "attach_to_character_region",
207  "Attach attachment %p (attachee %p, tag %d) from \"%c\" (%p) to \"%c\" (%p)\n",
208  a, at, attachee_tag(at),
209  *begin_char, begin_char,
210  *end_char, end_char);
211 
212  /* Attach the begin to the first character: */
214  begin_char,
215  word_to_attachments_begin);
216 
217  /* Attach the end to the last character: */
219  end_char,
220  word_to_attachments_end);
221  debug_off();
222 }
attachment make_attachment(attachee a1, intptr_t a2, intptr_t a3)
#define ADD_AN_ATTACHMENT_TO_A_MAPPING(a, a_char, a_mapping)
Use to create or extend the attachment list of a 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
#define attachee_tag(x)

References ADD_AN_ATTACHMENT_TO_A_MAPPING, attachee_tag, debug(), debug_off, debug_on, make_attachment(), and POSITION_UNDEFINED.

Referenced by attach_to_word_list().

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

◆ attach_to_sentence()

static void attach_to_sentence ( sentence  s,
attachee  a 
)
static

Attach something to a sentence:

Definition at line 271 of file attachment_pretty_print.c.

273 {
274  attach_to_sentence_list(s, s, a);
275 }
static void attach_to_sentence_list(sentence begin, sentence end, attachee a)
Attach something to a sentence list:

References attach_to_sentence_list().

Referenced by attach_head_to_sentence().

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

◆ attach_to_sentence_list()

static void attach_to_sentence_list ( sentence  begin,
sentence  end,
attachee  a 
)
static

Attach something to a sentence list:

Definition at line 259 of file attachment_pretty_print.c.

262 {
265  a);
266 }
char end
Definition: gtk_status.c:82
string first_word_of_sentence(sentence)
Return the first word of a sentence:
Definition: util.c:76
string last_word_of_sentence(sentence)
Return the last word of a sentence:
Definition: util.c:101

References attach_to_word_list(), end, first_word_of_sentence(), and last_word_of_sentence().

Referenced by attach_to_sentence(), attach_to_sentence_up_to_end_of_text(), and attach_to_text().

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

◆ attach_to_sentence_up_to_end_of_text()

static void attach_to_sentence_up_to_end_of_text ( sentence  s,
text  t,
attachee  a 
)
static

Attach something to a sentence up to the end of the given text:

Definition at line 280 of file attachment_pretty_print.c.

283 {
285 }
#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
#define SENTENCE(x)
newgen_unformatted_domain_defined
Definition: text.h:36

References attach_to_sentence_list(), CAR, gen_last(), SENTENCE, and text_sentences.

Referenced by attach_loop_to_sentence_up_to_end_of_text().

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

◆ attach_to_text()

static void attach_to_text ( text  t,
attachee  a 
)
static

◆ attach_to_word_list()

static void attach_to_word_list ( string  begin_word,
string  end_word,
attachee  at 
)
static

Attach something to a word list, from begin_word to end_word:

Attach from the first character of the first word up to the last character of the last word:

Definition at line 227 of file attachment_pretty_print.c.

230 {
231  debug_on("ATTACHMENT_DEBUG_LEVEL");
232  debug(6, "attach_to_word_list",
233  "Attach attachee %p from \"%s\" (%p) to \"%s\" (%p)\n",
234  at,
235  begin_word, begin_word,
236  end_word, end_word);
237 
238  /* Attach from the first character of the first word up to the
239  last character of the last word: */
240  attach_to_character_region(begin_word,
241  end_word + strlen(end_word) - 1,
242  at);
243  debug_off();
244 }
static void attach_to_character_region(char *begin_char, char *end_char, attachee at)
Attach something from begin_char up to end_char:

References attach_to_character_region(), debug(), debug_off, and debug_on.

Referenced by attach_reference_to_word_list(), attach_regular_call_to_word(), attach_to_sentence_list(), and attach_to_words().

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

◆ attach_to_words()

static void attach_to_words ( list  l,
attachee  a 
)
static

Attach something to all the words of the list given in argument:

Definition at line 248 of file attachment_pretty_print.c.

250 {
252  STRING(CAR(gen_last(l))),
253  a);
254 }
#define STRING(x)
Definition: genC.h:87

References attach_to_word_list(), CAR, gen_last(), and STRING.

Referenced by attach_declaration_to_words(), and attach_declaration_type_to_words().

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

◆ attach_total_preconditions_decoration_to_text()

void attach_total_preconditions_decoration_to_text ( text __attribute__((unused))  t)

Attach a total preconditions decoration:

Definition at line 442 of file attachment_pretty_print.c.

443 {
445  pips_internal_error("not implemented yet");
446 }
#define pips_internal_error
Definition: misc-local.h:149

References is_emacs_pretty_print_asked, and pips_internal_error.

Referenced by get_semantic_text(), and semantic_to_text().

+ Here is the caller graph for this function:

◆ 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:

◆ compare_attachment_for_qsort()

static int compare_attachment_for_qsort ( const void *  xp,
const void *  yp 
)
static

The function used by qsort to compare 2 attachment structures:

Sort according attachment x begins before y:

Sort according attachment x ends after y:

If they have the same range, sort according to the type:

Definition at line 779 of file attachment_pretty_print.c.

781 {
782  attachment x = *(attachment *) xp;
783  attachment y = *(attachment *) yp;
784 
786  /* Sort according attachment x begins before y: */
787  return attachment_begin(x) - attachment_begin(y);
788 
789  if (attachment_end(x) != attachment_end(y))
790  /* Sort according attachment x ends after y: */
791  return attachment_end(y) - attachment_begin(x);
792 
793  /* If they have the same range, sort according to the type: */
796 }
static char * x
Definition: split_file.c:159
#define attachment_begin(x)
#define attachment_attachee(x)
#define attachment_end(x)

References attachee_tag, attachment_attachee, attachment_begin, attachment_end, and x.

Referenced by output_the_attachments_in_a_sorted_order().

+ Here is the caller graph for this function:

◆ deal_with_attachment_boundary()

static void deal_with_attachment_boundary ( char *  a_character,
int  position_in_the_output,
attachments(*)(void_star load_word_to_attachments_boundary,
bool(*)(void_star bound_word_to_attachments_boundary_p 
)
static

Try to find some attachments in the given character.

If any, note the boundary position, that is a start or an end according to the functions given in parameters:

Well, this word is an attachment boundary:

Remind the position of the boundary of the attachment:

Definition at line 462 of file attachment_pretty_print.c.

466 {
467  debug(8, "deal_with_attachment_boundary",
468  "Looking for \"%c\" (%p) at %d\n",
469  *a_character,a_character, position_in_the_output);
470 
471  if (bound_word_to_attachments_boundary_p(a_character)) {
472  /* Well, this word is an attachment boundary: */
473  list some_attachments =
474  attachments_attachment(load_word_to_attachments_boundary(a_character));
475  MAP(ATTACHMENT, an_attachment,
476  {
477  debug(4, "deal_with_attachment_boundary",
478  "*** Found attachment = %p for \"%c\" (%p) at %d\n",
479  an_attachment, *a_character,
480  a_character, position_in_the_output);
481 
482  /* Remind the position of the boundary of the
483  attachment: */
484  if (load_word_to_attachments_boundary
485  == load_word_to_attachments_begin)
486  attachment_begin(an_attachment) = position_in_the_output;
487  else
488  attachment_end(an_attachment) = position_in_the_output;
489  },
490  some_attachments);
491  };
492 }
#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
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
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 ATTACHMENT, attachment_begin, attachment_end, attachments_attachment, debug(), MAP, and position_in_the_output.

Referenced by deal_with_attachments_at_this_character().

+ 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.

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 }
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172

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:

◆ 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:

◆ init_output_the_attachments_for_emacs()

static void init_output_the_attachments_for_emacs ( FILE *  output_file)
static

Begin the Emacs Lisp file:

Begin a string with Emacs Lisp properties:

Definition at line 853 of file attachment_pretty_print.c.

854 {
855  /* Begin a string with Emacs Lisp properties: */
856  fprintf(output_file, "(insert \"");
857 }
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References fprintf().

Referenced by write_an_attachment_file().

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

◆ module_local_name()

static const char* module_local_name ( entity  e)
static

Declare the various mapping between the words and attachments:

Returns the module local user name FC: DUPLICATED FROM ri-util TO AVOID A DEPENDENCY

No difference between modules and other entities, except for prefixes

Definition at line 74 of file attachment_pretty_print.c.

75 {
76  /* No difference between modules and other entities, except for prefixes */
77  const char* name = local_name(entity_name(e));
78 
79  return (name
81 }
const char * local_name(const char *s)
Does not take care of block scopes and returns a pointer.
Definition: entity_names.c:221
#define COMMON_PREFIX
Definition: naming-local.h:34
#define F95MODULE_PREFIX
Definition: naming-local.h:36
#define MAIN_PREFIX
Definition: naming-local.h:32
#define BLOCKDATA_PREFIX
Definition: naming-local.h:35
#define entity_name(x)
Definition: ri.h:2790

References BLOCKDATA_PREFIX, COMMON_PREFIX, entity_name, F95MODULE_PREFIX, local_name(), and MAIN_PREFIX.

Referenced by output_an_attachment().

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

◆ output_an_attachment()

static void output_an_attachment ( FILE *  output_file,
attachment  a 
)
static

Output an attachment to the output file:

Begin an Emacs Lisp properties. + 1 since in a buffer (and not a string). (end + 1) + 1 since the property is set between start and end in Emacs.Use backquoting to evaluate keymaps later:

Evaluate the keymap:

Evaluate the keymap:

Output the address as a string because Emacs cannot store 32-bit numbers:

End an Emacs Lisp properties:

Definition at line 636 of file attachment_pretty_print.c.

638 {
640  int begin = attachment_begin(a);
641  int end = attachment_end(a);
642 
643  pips_debug(5, "begin: %d, end: %d, attachment %p (attachee %p)\n",
644  begin, end, a, at);
645 
646  if (begin == POSITION_UNDEFINED || end == POSITION_UNDEFINED)
647  {
648  pips_user_warning("begin and end should be initialized.\n");
649  return;
650  }
651 
652  /* Begin an Emacs Lisp properties. + 1 since in a buffer (and not
653  a string). (end + 1) + 1 since the property is set between
654  start and end in Emacs.Use backquoting to evaluate keymaps
655  later: */
656  fprintf(output_file, "(add-text-properties %d %d `(", begin + 1, end + 2);
657 
658  switch(attachee_tag(at))
659  {
661  {
663  pips_debug(5, "\treference %p\n", r);
664  /* Evaluate the keymap: */
665  fprintf(output_file, "face epips-face-reference mouse-face epips-mouse-face-reference local-map ,epips-reference-keymap epips-property-reference \"%p\" epips-property-reference-variable \"%p\"",
666  r, reference_variable(r));
667  break;
668  }
669 
670  case is_attachee_call:
671  {
672  call c = attachee_call(at);
673  pips_debug(5, "\treference %p\n", c);
674  /* Evaluate the keymap: */
675  fprintf(output_file, "face epips-face-call mouse-face epips-mouse-face-call local-map ,epips-call-keymap epips-property-call \"%p\"",
676  c);
677  break;
678  }
679 
681  {
683  pips_debug(5, "\tdeclaration %p\n", e);
684  /* Output the address as a string because Emacs cannot
685  store 32-bit numbers: */
686  fprintf(output_file, "face epips-face-declaration epips-property-declaration \"%p\"",
687  e);
688  break;
689  }
690 
691  case is_attachee_type:
692  {
693  string s = attachee_type(at);
694  pips_debug(5, "\ttype \"%s\"\n", s);
695  fprintf(output_file, "epips-property-type \"%s\"", s);
696  break;
697  }
698 
699  case is_attachee_loop:
700  {
701  loop l = attachee_loop(at);
702  pips_debug(5, "\tloop %p\n", l);
704  fprintf(output_file, "face epips-face-parallel-loop ");
705  fprintf(output_file, "epips-property-loop \"%p\"", l);
706  break;
707  }
708 
710  {
711  entity head = attachee_module_head(at);
712  pips_debug(5, "\tmodule_head %p\n", head);
713  fprintf(output_file,
714  "face epips-face-module-head epips-module-head-name \"%s\"",
715  module_local_name(head));
716  break;
717  }
718 
720  {
721  pips_debug(5, "\tdecoration\n");
722  fprintf(output_file,
723  "invisible epips-invisible-decoration");
724  break;
725  }
726 
728  {
729  pips_debug(5, "\tpreconditions\n");
730  fprintf(output_file,
731  "face epips-face-preconditions invisible epips-invisible-preconditions");
732  break;
733  }
734 
736  {
737  pips_debug(5, "\ttransformers\n");
738  fprintf(output_file,
739  "face epips-face-transformers invisible epips-invisible-transformers");
740  break;
741  }
742 
744  {
745  pips_debug(5, "\tcumulated-effect\n");
746  fprintf(output_file,
747  "face epips-face-cumulated-effect invisible epips-invisible-cumulated-effect");
748  break;
749  }
750 
752  {
753  pips_debug(5, "\tproper-effect\n");
754  fprintf(output_file,
755  "face epips-face-proper-effect invisible epips-invisible-proper-effect");
756  break;
757  }
758 
760  {
761  int line_number = attachee_statement_line_number(at);
762 
763  pips_debug(5, "\tstatement_line_number %d\n", line_number);
764  fprintf(output_file, "epips-line-number %d", line_number);
765  break;
766  }
767 
768  default:
769  pips_internal_error("attachee_tag inconsistent");
770  }
771 
772  /* End an Emacs Lisp properties: */
773  fprintf(output_file, "))\n");
774 }
static const char * module_local_name(entity e)
Declare the various mapping between the words and attachments:
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_user_warning
Definition: misc-local.h:146
#define loop_execution(x)
Definition: ri.h:1648
#define reference_variable(x)
Definition: ri.h:2326
#define execution_parallel_p(x)
Definition: ri.h:1211
#define attachee_type(x)
#define attachee_call(x)
#define attachee_module_head(x)
#define attachee_declaration(x)
#define attachee_loop(x)
#define attachee_reference(x)
#define attachee_statement_line_number(x)

References attachee_call, attachee_declaration, attachee_loop, attachee_module_head, attachee_reference, attachee_statement_line_number, attachee_tag, attachee_type, attachment_attachee, attachment_begin, attachment_end, end, execution_parallel_p, fprintf(), is_attachee_call, is_attachee_cumulated_effects, is_attachee_declaration, is_attachee_decoration, is_attachee_loop, is_attachee_module_head, is_attachee_preconditions, is_attachee_proper_effects, is_attachee_reference, is_attachee_statement_line_number, is_attachee_transformers, is_attachee_type, loop_execution, module_local_name(), pips_debug, pips_internal_error, pips_user_warning, POSITION_UNDEFINED, and reference_variable.

Referenced by output_the_attachments_in_a_sorted_order().

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

◆ output_the_attachments_for_emacs()

static void output_the_attachments_for_emacs ( FILE *  output_file)
static

Output the list of all the attachments found in the text file with Emacs Lisp syntax:

End the string part:

Enumerate all the attachments:

Now we try to output the stuff in a decent order:

Just for fun, the previous gen_recurse will also recurse through the words of the mapping but it is not deep and thus it does not worth using a gen_multi_recurse with a string_domain and a filter returning always stop to avoid this unnecessary recursion.

Unlink the attachment from attachments to avoid double free later since referenced both by word_to_attachments_begin and word_to_attachments_end:

End the property part:

fprintf(output_file, "\n\t)\n)\n");

Definition at line 863 of file attachment_pretty_print.c.

864 {
865  debug_on("ATTACHMENT_DEBUG_LEVEL");
866 
867  /* End the string part: */
868  fprintf(output_file, "\")\n");
869 
870  /* Enumerate all the attachments: */
871  gen_multi_recurse(get_word_to_attachments_begin(),
875  NULL);
876 
877  /* Now we try to output the stuff in a decent order: */
879 
880  /* Just for fun, the previous gen_recurse will also recurse
881  through the words of the mapping but it is not deep and thus it
882  does not worth using a gen_multi_recurse with a string_domain
883  and a filter returning always stop to avoid this unnecessary
884  recursion. */
885 
886  WORD_TO_ATTACHMENTS_MAP(word_pointer, attachment_list,
887  {
888  pips_debug(6, "Key %p, value %p\n", word_pointer, attachment_list);
889  /* Unlink the attachment from
890  attachments to avoid double free
891  later since referenced both by
892  word_to_attachments_begin and
893  word_to_attachments_end: */
894  MAPL(ats,
895  {
897  },
898  attachments_attachment(attachment_list));
899  },
900  get_word_to_attachments_begin());
901 
902  /* End the property part: */
903  /* fprintf(output_file, "\n\t)\n)\n"); */
904 
905  debug_off();
906 }
static void rewrite_an_attachment(attachment __attribute__((unused)) a)
Nothing to do...
static bool put_an_attachment_in_the_list(attachment a)
Add the attachment to the intermediate list:
static void output_the_attachments_in_a_sorted_order(FILE *output_file)
Output the attachment in a sorted order with less precise property first:
void gen_multi_recurse(void *o,...)
Multi recursion visitor function.
Definition: genClib.c:3428
#define MAPL(_map_list_cp, _code, _l)
Apply some code on the addresses of all the elements of a list.
Definition: newgen_list.h:203
#define attachment_domain
newgen_attachee_domain_defined
#define attachment_undefined
#define ATTACHMENT_(x)
#define WORD_TO_ATTACHMENTS_MAP(k, v, c, f)

References ATTACHMENT_, attachment_domain, attachment_undefined, attachments_attachment, CAR, debug_off, debug_on, fprintf(), gen_multi_recurse(), MAPL, output_the_attachments_in_a_sorted_order(), pips_debug, put_an_attachment_in_the_list(), rewrite_an_attachment(), and WORD_TO_ATTACHMENTS_MAP.

Referenced by write_an_attachment_file().

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

◆ output_the_attachments_in_a_sorted_order()

static void output_the_attachments_in_a_sorted_order ( FILE *  output_file)
static

Output the attachment in a sorted order with less precise property first:

The attachments them self will be removed later:

Definition at line 802 of file attachment_pretty_print.c.

803 {
804  attachment * as;
805  int i;
806 
807  int number_of_attachments = gen_length(attachments_before_sorting);
808 
809  as = (attachment *) malloc(number_of_attachments*sizeof(attachment));
810  i = 0;
811  MAP(ATTACHMENT, a, {
812  as[i++] = a;
814 
815  qsort((char *)as,
816  number_of_attachments,
817  sizeof(attachment),
819 
820  for(i = 0; i < number_of_attachments; i++) {
821  output_an_attachment(output_file, as[i]);
822  }
823 
824  /* The attachments them self will be removed later: */
827 }
list attachments_before_sorting
To store the attachment before sorting:
static int compare_attachment_for_qsort(const void *xp, const void *yp)
The function used by qsort to compare 2 attachment structures:
static void output_an_attachment(FILE *output_file, attachment a)
Output an attachment to the output file:
void * malloc(YYSIZE_T)
size_t gen_length(const list l)
Definition: list.c:150
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327

References ATTACHMENT, attachments_before_sorting, compare_attachment_for_qsort(), gen_free_list(), gen_length(), malloc(), MAP, NIL, and output_an_attachment().

Referenced by output_the_attachments_for_emacs().

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

◆ put_an_attachment_in_the_list()

static bool put_an_attachment_in_the_list ( attachment  a)
static

Add the attachment to the intermediate list:

We do not want to go on the recursion:

Definition at line 832 of file attachment_pretty_print.c.

833 {
835  a,
837 
838  /* We do not want to go on the recursion: */
839  return false;
840 }

References ATTACHMENT, attachments_before_sorting, and CONS.

Referenced by output_the_attachments_for_emacs().

+ 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 }

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:

◆ rewrite_an_attachment()

static void rewrite_an_attachment ( attachment __attribute__((unused))  a)
static

Nothing to do...

Definition at line 845 of file attachment_pretty_print.c.

846 {
847  return;
848 }

Referenced by output_the_attachments_for_emacs().

+ 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:

◆ 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

list attachments_before_sorting = NIL

To store the attachment before sorting:

attachment_pretty_print.c

Definition at line 65 of file attachment_pretty_print.c.

Referenced by output_the_attachments_in_a_sorted_order(), and put_an_attachment_in_the_list().

◆ is_emacs_pretty_print_asked