PIPS
|
#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"
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... | |
#define ADD_AN_ATTACHMENT_TO_A_MAPPING | ( | a, | |
a_char, | |||
a_mapping | |||
) |
Use to create or extend the attachment list of a character:
Definition at line 179 of file attachment_pretty_print.c.
typedef char* void_star |
Used in word_to_attachments:
Definition at line 42 of file attachment_pretty_print.c.
anonymous enum |
void attach_cumulated_effects_decoration_to_text | ( | text | t | ) |
Attach a cumulated effects decoration:
Definition at line 416 of file attachment_pretty_print.c.
References attach_to_text(), is_attachee_cumulated_effects, is_emacs_pretty_print_asked, make_attachee(), and UU.
Attach a declaration type with its size to all the words of the given list.
No need to use strdup():
declaration_type | eclaration_type |
size | ize |
Definition at line 374 of file attachment_pretty_print.c.
References attach_declaration_type_to_words(), concatenate(), free(), int2a(), is_emacs_pretty_print_asked, and NIL.
Referenced by text_entity_declaration().
Attach a declaration to all the words of the given list:
Definition at line 348 of file attachment_pretty_print.c.
References attach_to_words(), is_attachee_declaration, is_emacs_pretty_print_asked, and make_attachee().
Referenced by words_declaration().
Attach a declaration type to all the words of the given list.
No need to use strdup(). May accept an empty list:
declaration_type | eclaration_type |
Definition at line 360 of file attachment_pretty_print.c.
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().
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.
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().
Attach the PROGRAM/FUNCTION head:
module | odule |
Definition at line 313 of file attachment_pretty_print.c.
References attach_to_sentence(), is_attachee_module_head, is_emacs_pretty_print_asked, make_attachee(), and module.
Referenced by ensure_comment_consistency().
The user interface:
Attach a loop:
Definition at line 302 of file attachment_pretty_print.c.
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().
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().
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.
Attach a module usage (CALL or function call):
begin_word | egin_word |
end_word | nd_word |
Definition at line 324 of file attachment_pretty_print.c.
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().
Attach a reference:
word | ord |
Definition at line 337 of file attachment_pretty_print.c.
References attach_to_word_list(), is_attachee_call, is_emacs_pretty_print_asked, and make_attachee().
Referenced by words_genuine_regular_call().
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.
References attach_to_text(), is_attachee_statement_line_number, is_emacs_pretty_print_asked, make_attachee(), NIL, statement_number, and text_sentences.
|
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.
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().
Attach something to a sentence:
Definition at line 271 of file attachment_pretty_print.c.
References attach_to_sentence_list().
Referenced by attach_head_to_sentence().
Attach something to a sentence list:
Definition at line 259 of file attachment_pretty_print.c.
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().
Attach something to a sentence up to the end of the given text:
Definition at line 280 of file attachment_pretty_print.c.
References attach_to_sentence_list(), CAR, gen_last(), SENTENCE, and text_sentences.
Referenced by attach_loop_to_sentence_up_to_end_of_text().
Attach something to all a text:
Definition at line 290 of file attachment_pretty_print.c.
References attach_to_sentence_list(), CAR, gen_last(), SENTENCE, and text_sentences.
Referenced by attach_cumulated_effects_decoration_to_text(), attach_decoration_to_text(), attach_preconditions_decoration_to_text(), attach_proper_effects_decoration_to_text(), attach_statement_information_to_text(), and attach_transformers_decoration_to_text().
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.
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().
Attach something to all the words of the list given in argument:
Definition at line 248 of file attachment_pretty_print.c.
References attach_to_word_list(), CAR, gen_last(), and STRING.
Referenced by attach_declaration_to_words(), and attach_declaration_type_to_words().
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.
References is_emacs_pretty_print_asked, and pips_internal_error.
Referenced by get_semantic_text(), and semantic_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().
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.
References get_bool_property(), and is_emacs_pretty_print_asked.
Referenced by print_code_or_source(), print_code_semantics(), and print_parallelized_code_common().
|
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.
References attachee_tag, attachment_attachee, attachment_begin, attachment_end, and x.
Referenced by output_the_attachments_in_a_sorted_order().
|
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.
References ATTACHMENT, attachment_begin, attachment_end, attachments_attachment, debug(), MAP, and position_in_the_output.
Referenced by 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:
a_character | _character |
position_in_the_output | osition_in_the_output |
Definition at line 498 of file attachment_pretty_print.c.
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().
Try to find some attachments in the given string.
If any, note the boundary position.
a_string | _string |
position_in_the_output | osition_in_the_output |
Definition at line 526 of file attachment_pretty_print.c.
References a_string, deal_with_attachments_at_this_character(), and position_in_the_output.
Referenced by print_sentence().
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.
a_string | _string |
position_in_the_output | osition_in_the_output |
a_length | _length |
Definition at line 540 of file attachment_pretty_print.c.
References a_string, deal_with_attachments_at_this_character(), pips_assert, and position_in_the_output.
Referenced by print_sentence().
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.
References is_emacs_pretty_print_asked.
Referenced by print_code_or_source(), print_code_semantics(), and print_parallelized_code_common().
|
static |
Begin the Emacs Lisp file:
Begin a string with Emacs Lisp properties:
Definition at line 853 of file attachment_pretty_print.c.
References fprintf().
Referenced by write_an_attachment_file().
|
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.
References BLOCKDATA_PREFIX, COMMON_PREFIX, entity_name, F95MODULE_PREFIX, local_name(), and MAIN_PREFIX.
Referenced by output_an_attachment().
|
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.
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().
|
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.
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().
|
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.
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().
|
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.
References ATTACHMENT, attachments_before_sorting, and CONS.
Referenced by output_the_attachments_for_emacs().
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.
source | ource |
new_position | ew_position |
Definition at line 560 of file attachment_pretty_print.c.
References debug_off, debug_on, pips_assert, and pips_debug.
Referenced by strcat_word_and_migrate_attachments(), and strdup_and_migrate_attachments().
|
static |
Nothing to do...
Definition at line 845 of file attachment_pretty_print.c.
Referenced by output_the_attachments_for_emacs().
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:
target | arget |
source | ource |
Definition at line 601 of file attachment_pretty_print.c.
References is_emacs_pretty_print_asked, and relocate_attachments().
Referenced by words_join().
char* strdup_and_migrate_attachments | ( | char * | a_string | ) |
Duplicate a string and update the attachments to point to the new returned string:
a_string | _string |
Definition at line 624 of file attachment_pretty_print.c.
References a_string, is_emacs_pretty_print_asked, relocate_attachments(), and strdup().
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:
file_name | ile_name |
Definition at line 912 of file attachment_pretty_print.c.
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().
To store the attachment before sorting:
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().
|
static |
To store the fact a prettyprinter ask for Emacs attachments:
Definition at line 48 of file attachment_pretty_print.c.
Referenced by attach_cumulated_effects_decoration_to_text(), attach_declaration_size_type_to_words(), attach_declaration_to_words(), attach_declaration_type_to_words(), attach_decoration_to_text(), attach_head_to_sentence(), attach_loop_to_sentence_up_to_end_of_text(), attach_preconditions_decoration_to_text(), attach_proper_effects_decoration_to_text(), attach_reference_to_word_list(), attach_regular_call_to_word(), attach_statement_information_to_text(), attach_total_preconditions_decoration_to_text(), attach_transformers_decoration_to_text(), begin_attachment_prettyprint(), deal_with_attachments_at_this_character(), end_attachment_prettyprint(), strcat_word_and_migrate_attachments(), strdup_and_migrate_attachments(), and write_an_attachment_file().