PIPS
misc.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "linear.h"
#include "genC.h"
#include "text.h"
#include "text-util.h"
#include "ri.h"
#include "ri-util.h"
#include "workspace-util.h"
#include "prettyprint.h"
#include "effects.h"
#include "misc.h"
#include "properties.h"
+ Include dependency graph for misc.c:

Go to the source code of this file.

Data Structures

struct  intrinsic_handler
 precedence needed here According to the Precedence of Operators Arithmetic > Character > Relational > Logical Added by Lei ZHOU Nov. More...
 

Macros

#define MAXIMAL_PRECEDENCE   100
 lint More...
 
#define MINIMAL_ARITHMETIC_PRECEDENCE   19
 
#define PRETTYPRINT_UNSTRUCTURED_BEGIN_MARKER   "\200Unstructured"
 Define the markers used in the raw unstructured output when the PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH property is true: More...
 
#define PRETTYPRINT_UNSTRUCTURED_END_MARKER   "\201Unstructured End"
 
#define PRETTYPRINT_UNSTRUCTURED_ITEM_MARKER   "\202Unstructured Item"
 
#define PRETTYPRINT_UNSTRUCTURED_SUCC_MARKER   "\203Unstructured Successor ->"
 
#define PRETTYPRINT_UNREACHABLE_EXIT_MARKER   "\204Unstructured Unreachable"
 
#define pp_hpf_style_p()   pp_style_p("hpf")
 
#define pp_f90_style_p()   pp_style_p("f90")
 
#define pp_craft_style_p()   pp_style_p("craft")
 
#define pp_cray_style_p()   pp_style_p("cray")
 
#define pp_cmf_style_p()   pp_style_p("cmf")
 
#define pp_doall_style_p()   pp_style_p("doall")
 
#define pp_do_style_p()   pp_style_p("do")
 
#define pp_omp_style_p()   pp_style_p("omp")
 
#define CAST_OPERATOR_PRECEDENCE   (23)
 
#define HPF_SENTINEL   "!HPF$"
 
#define HPF_DIRECTIVE   HPF_SENTINEL " "
 
#define HPF_CONTINUATION   HPF_SENTINEL "x"
 
#define HPF_INDEPENDENT   "INDEPENDENT"
 
#define OMP_SENTINEL   "!$OMP"
 
#define OMP_DIRECTIVE   OMP_SENTINEL " "
 
#define OMP_CONTINUATION   OMP_SENTINEL "x"
 
#define OMP_PARALLELDO   "PARALLEL DO "
 
#define OMP_C_SENTINEL   "#pragma omp"
 
#define OMP_C_DIRECTIVE   OMP_C_SENTINEL " "
 
#define OMP_C_CONTINUATION   OMP_C_SENTINEL "x"
 
#define OMP_C_PARALLELDO   "parallel for "
 

Functions

string get_comment_sentinel ()
 Start a single line comment. More...
 
string get_comment_continuation ()
 Start a single line comment with continuation (blank spaces) More...
 
unsigned int get_prettyprint_indentation ()
 
static list words_cast (cast obj, int precedence, list *ppdl)
 
static list words_sizeofexpression (sizeofexpression obj, bool in_type_declaration, list *ppdl)
 
static list words_subscript (subscript s, list *ppdl)
 
static list words_application (application a, list *ppdl)
 
static text text_forloop (entity module, const char *label, int margin, forloop obj, int n, list *ppdl, bool is_recursive_p)
 
static bool pp_style_p (string s)
 
text empty_text (entity __attribute__((unused)) e, int __attribute__((unused)) m, statement __attribute__((unused)) s)
 
void init_prettyprint (text(*hook)(entity, int, statement))
 checks that the prettyprint hook was actually reset... More...
 
void close_prettyprint ()
 because some prettyprint functions may be used for debug, so the last hook set by somebody may have stayed there although being non sense... More...
 
bool one_liner_p (statement s)
 True is statement "s" can be printed out without enclosing braces when it is the true branch of a test. More...
 
bool gcc_if_block_braces_required_p (test obj)
 
static text insert_locals (text r)
 This function either appends the declaration to the text given as a parameter or return a new text with the declaration. More...
 
static bool mark_block (unformatted *t_beg, unformatted *t_end, int n, int margin)
 This function returns true if BLOCK boundary markers are required. More...
 
static int words_intrinsic_precedence (call)
 
static int intrinsic_precedence (const char *)
 
list words_loop_range (range obj, list *ppdl)
 exported for craft More...
 
list C_loop_range (range obj, entity i, list *ppdl)
 Output a Fortan-like do-loop range as a C-like for-loop index part. More...
 
list words_range (range obj, list *ppdl)
 
list words_subscript_range (range obj, list *ppdl)
 @description FI: array constructor R433, p. More...
 
list words_any_reference (reference obj, list *ppdl, const char *(*enf)(entity))
 exported for expression.c More...
 
list Words_Any_Reference (reference obj, list pdl, const char *(*enf)(entity))
 
list words_reference (reference obj, list *ppdl)
 
list Words_Reference (reference obj)
 
void set_alternate_return_set ()
 
void reset_alternate_return_set ()
 
void add_target_to_alternate_return_set (entity l)
 
text generate_alternate_return_targets ()
 
list words_regular_call (call obj, bool is_a_subroutine, list *ppdl)
 words_regular_call used for user subroutine and user function and intrinsics called like user function such as MOD(). More...
 
list Words_Regular_Call (call obj, bool is_a_subroutine)
 
static list words_genuine_regular_call (call obj, bool is_a_subroutine, list *ppdl)
 To deal with attachment on user module usage. More...
 
list words_call_intrinsic (call obj, int __attribute__((unused)) precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 
static list words_assign_op (call obj, int precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 
static list words_substring_op (call obj, int __attribute__((unused)) precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 
static list words_assign_substring_op (call obj, int __attribute__((unused)) precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 
static const char * renamed_op_handling (const char *name)
 
static list words_omp_red (call obj, int precedence __attribute__((unused)), bool leftmost __attribute__((unused)), list *ppdl)
 
static list words_nullary_op_c (call obj, int precedence __attribute__((unused)), bool leftmost __attribute__((unused)), list *ppdl)
 
static list words_nullary_op_fortran (call obj, int precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 
static list words_nullary_op (call obj, int precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 
static list words_io_control (list *iol, int __attribute__((unused)) precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 
static list words_implied_do (call obj, int __attribute__((unused)) precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 
static list words_unbounded_dimension (call __attribute__((unused)) obj, int __attribute__((unused)) precedence, bool __attribute__((unused)) leftmost, list __attribute__((unused)) *ppdl)
 
static list words_list_directed (call __attribute__((unused)) obj, int __attribute__((unused)) precedence, bool __attribute__((unused)) leftmost, list __attribute__((unused)) *ppdl)
 
static list words_io_inst (call obj, int precedence, bool leftmost, list *ppdl)
 
static list words_stat_io_inst (call obj, int __attribute__((unused)) precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 Implemented for ALLOCATE(), but is applicable for every call to function that take STAT= parameter. More...
 
static list null (call __attribute__((unused)) obj, int __attribute__((unused)) precedence, bool __attribute__((unused)) leftmost, list __attribute__((unused)) *ppdl)
 
static list words_prefix_unary_op (call obj, int precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 
static list words_postfix_unary_op (call obj, int precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 
static list words_unary_minus (call obj, int precedence, bool leftmost, list *ppdl)
 
static list words_inverse_op (call obj, int precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 WARNING : the floating point division is used wether b is an int or not ! (1.0/b) – in fact b should not be an int ! More...
 
list words_goto_label (const char *tlabel)
 This function is useful only for parsed codes since gotos are removed by the controlizer. More...
 
static list eole_fmx_specific_op (call obj, int __attribute__((unused)) precedence, bool __attribute__((unused)) leftmost, bool isadd, list *ppdl)
 
list eole_fma_specific_op (call obj, int precedence, bool leftmost, list *ppdl)
 EOLE : The multiply-add operator is used within the optimize transformation ( JZ - sept 98) - fma(a,b,c) -> ((a*b)+c) More...
 
list eole_fms_specific_op (call obj, int precedence, bool leftmost, list *ppdl)
 MULTIPLY-SUB operator. More...
 
static const char * get_special_prettyprint_for_operator (call obj)
 Check if the given operator is associated with a special prettyprint. More...
 
static list words_brace_op (call obj, int precedence __attribute__((unused)), bool leftmost __attribute__((unused)), list *ppdl)
 
static list words_infix_nary_op (call obj, int precedence, bool leftmost, list *ppdl)
 Extension of "words_infix_binary_op" function for nary operators used in the EOLE project - (since "nary" assumes operators with at least 2 op) - JZ (Oct. More...
 
static list words_infix_binary_op (call obj, int precedence, bool leftmost, list *ppdl)
 
static list words_comma_op (call obj, int precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 Nga Nguyen : this case is added for comma expression in C, but I am not sure about its precedence => to be looked at more carefully. More...
 
static list words_conditional_op (call obj, int precedence, bool __attribute__((unused)) leftmost, list *ppdl)
 
static void init_intrinsic_handlers ()
 
void register_intrinsic_handler (const char *name, intrinsic_desc_t *desc)
 after this call, name and desc are owned by intrinsic_handlers, but will never be deallocated they must point to permanent storage More...
 
static list words_intrinsic_call (call obj, int precedence, bool leftmost, list *ppdl)
 
static list words_va_arg (list obj, list *ppdl)
 
list words_call (call obj, int precedence, bool leftmost, bool is_a_subroutine, list *ppdl)
 exported for cmfortran.c More...
 
list Words_Call (call obj, int precedence, bool leftmost, bool is_a_subroutine)
 
list words_expression (expression obj, list *ppdl)
 This one is exported. More...
 
list Words_Expression (expression obj)
 of string More...
 
list words_syntax (syntax obj, list *ppdl)
 exported for expression.c More...
 
list Words_Syntax (syntax obj)
 
list words_subexpression (expression obj, int precedence, bool leftmost, list *ppdl)
 exported for cmfortran.c More...
 
list Words_Subexpression (expression obj, int precedence, bool leftmost)
 
static sentence sentence_tail (entity e)
 
sentence sentence_goto_label (entity __attribute__((unused)) module, const char *label, int margin, const char *tlabel, int n)
 exported for unstructured.c More...
 
static sentence sentence_goto (entity module, const char *label, int margin, statement obj, int n)
 
static text text_block (entity module, const char *label, int margin, list objs, int n, list *ppdl)
 Build the text of a code block (a list of statements) More...
 
static list loop_private_variables (loop obj, list *ppdl)
 of string More...
 
static string marged (string prefix, int margin)
 returns a formatted text for the HPF independent and new directive well, no continuations and so, but the directives do not fit the unformatted domain, because the directive prolog would not be well managed there. More...
 
static text text_directive (loop obj, int margin, string basic_directive, string basic_continuation, string parallel, list *ppdl)
 
static text text_hpf_directive (loop l, int m)
 
text text_omp_directive (loop l, int m)
 
text text_loop_default (entity module, const char *label, int margin, loop obj, int n, list *ppdl, bool is_recursive_p)
 exported for fortran90.c More...
 
text text_loop (entity module, const char *label, int margin, loop obj, int n, list *ppdl, bool is_recursive_p)
 exported for conversion/look_for_nested_loops.c More...
 
static text text_whileloop (entity module, const char *label, int margin, whileloop obj, int n, list *ppdl, bool is_recursive_p)
 
text init_text_statement (entity module, int margin, statement obj)
 exported for unstructured.c More...
 
static text text_logical_if (entity __attribute__((unused)) module, const char *label, int margin, test obj, int n, list *ppdl, bool is_recursive_p)
 
static bool test_with_no_else_clause_p (test t)
 
static bool test_with_dangling_else_p (test t)
 Some code shared by text_block_if and text_block_ifthen. More...
 
static text text_block_ifthen (entity module, const char *label, int margin, test obj, int n, list *ppdl, bool is_recursive_p)
 Prettyprint if clause of a test. More...
 
static text text_block_else (entity module, const char *label __attribute__((unused)), int margin, statement stmt, int n __attribute__((unused)), list *ppdl)
 
static text text_block_elseif (entity module, const char *label, int margin, test obj, int n, list *ppdl)
 
static text text_block_if (entity module, const char *label, int margin, test obj, int n, list *ppdl, bool is_recursive_p)
 Prettyprint the condition, the true and, possibly, the false branch. More...
 
static text text_io_block_if (entity module, const char *label, int margin, test obj, int n, list *ppdl)
 
static text text_test (entity module, const char *label, int margin, test obj, int n, list *ppdl, bool is_recursive_p)
 
void set_prettyprinter_head_hook (string(*f)(entity))
 
void reset_prettyprinter_head_hook ()
 
static text text_instruction (entity module, const char *label, int margin, instruction obj, int n, list *ppdl, bool is_recursive_p)
 
bool C_comment_p (string c)
 In case the input code is not C code, non-standard comments have to be detected. More...
 
text C_any_comment_to_text (int r_margin, string c)
 In case comments are not formatted according to C rules, e.g. More...
 
text C_standard_comment_to_text (int margin, string comment)
 
text C_comment_to_text (int margin, string comment)
 Special handling for C comments with each line indented according to the context. More...
 
static list cstrsplit (const char *s, char delim)
 Split string into a list of strings according to a separator, delim. More...
 
static string ensure_comment_consistency (const char *i_comments, language l)
 return a formatted comment, that takes care of adding the relevant // or C depending on output language, except for empty lines in C More...
 

Variables

char lib_ri_util_prettyprint_c_rcsid [] = "$Id: misc.c 23181 2016-09-09 12:56:48Z irigoin $"
 misc.c More...
 
static bool precedence_p = true
 This variable is used to disable the precedence system and hence to prettyprint all parentheses, which let the prettyprint reflect the AST. More...
 
static bool prettyprint_all_c_braces_p = false
 This variable is used to print braces around all blocks including blocks with only one statement. More...
 
static bool prettyprint_gcc_c_braces_p = false
 This variable is used to gracefuly print braces around if / else blocks to avoid gcc warnings. More...
 
static text(* text_statement_hook )(entity, int, statement) = empty_text
 
static text local_var
 
static bool local_flg = false
 
static list set_of_labels_required_for_alternate_returns = list_undefined
 Management of alternate returns. More...
 
static struct intrinsic_handler tab_intrinsic_handler []
 
static hash_table intrinsic_handlers = hash_table_undefined
 
static string(* head_hook )(entity) = NULL
 hook for adding something in the head. More...
 

Macro Definition Documentation

◆ CAST_OPERATOR_PRECEDENCE

#define CAST_OPERATOR_PRECEDENCE   (23)

◆ HPF_CONTINUATION

#define HPF_CONTINUATION   HPF_SENTINEL "x"

Definition at line 3063 of file misc.c.

◆ HPF_DIRECTIVE

#define HPF_DIRECTIVE   HPF_SENTINEL " "

Definition at line 3062 of file misc.c.

◆ HPF_INDEPENDENT

#define HPF_INDEPENDENT   "INDEPENDENT"

Definition at line 3064 of file misc.c.

◆ HPF_SENTINEL

#define HPF_SENTINEL   "!HPF$"

Definition at line 3061 of file misc.c.

◆ MAXIMAL_PRECEDENCE

#define MAXIMAL_PRECEDENCE   100

lint

operator precedences are in the [0,100] range

Definition at line 138 of file misc.c.

◆ MINIMAL_ARITHMETIC_PRECEDENCE

#define MINIMAL_ARITHMETIC_PRECEDENCE   19

Definition at line 139 of file misc.c.

◆ OMP_C_CONTINUATION

#define OMP_C_CONTINUATION   OMP_C_SENTINEL "x"

Definition at line 3080 of file misc.c.

◆ OMP_C_DIRECTIVE

#define OMP_C_DIRECTIVE   OMP_C_SENTINEL " "

Definition at line 3079 of file misc.c.

◆ OMP_C_PARALLELDO

#define OMP_C_PARALLELDO   "parallel for "

Definition at line 3081 of file misc.c.

◆ OMP_C_SENTINEL

#define OMP_C_SENTINEL   "#pragma omp"

Definition at line 3078 of file misc.c.

◆ OMP_CONTINUATION

#define OMP_CONTINUATION   OMP_SENTINEL "x"

Definition at line 3076 of file misc.c.

◆ OMP_DIRECTIVE

#define OMP_DIRECTIVE   OMP_SENTINEL " "

Definition at line 3075 of file misc.c.

◆ OMP_PARALLELDO

#define OMP_PARALLELDO   "PARALLEL DO "

Definition at line 3077 of file misc.c.

◆ OMP_SENTINEL

#define OMP_SENTINEL   "!$OMP"

Definition at line 3074 of file misc.c.

◆ pp_cmf_style_p

#define pp_cmf_style_p ( )    pp_style_p("cmf")

Definition at line 212 of file misc.c.

◆ pp_craft_style_p

#define pp_craft_style_p ( )    pp_style_p("craft")

Definition at line 210 of file misc.c.

◆ pp_cray_style_p

#define pp_cray_style_p ( )    pp_style_p("cray")

Definition at line 211 of file misc.c.

◆ pp_do_style_p

#define pp_do_style_p ( )    pp_style_p("do")

Definition at line 214 of file misc.c.

◆ pp_doall_style_p

#define pp_doall_style_p ( )    pp_style_p("doall")

Definition at line 213 of file misc.c.

◆ pp_f90_style_p

#define pp_f90_style_p ( )    pp_style_p("f90")

Definition at line 209 of file misc.c.

◆ pp_hpf_style_p

#define pp_hpf_style_p ( )    pp_style_p("hpf")

Definition at line 208 of file misc.c.

◆ pp_omp_style_p

#define pp_omp_style_p ( )    pp_style_p("omp")

Definition at line 215 of file misc.c.

◆ PRETTYPRINT_UNREACHABLE_EXIT_MARKER

#define PRETTYPRINT_UNREACHABLE_EXIT_MARKER   "\204Unstructured Unreachable"

Definition at line 147 of file misc.c.

◆ PRETTYPRINT_UNSTRUCTURED_BEGIN_MARKER

#define PRETTYPRINT_UNSTRUCTURED_BEGIN_MARKER   "\200Unstructured"

Define the markers used in the raw unstructured output when the PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH property is true:

Definition at line 143 of file misc.c.

◆ PRETTYPRINT_UNSTRUCTURED_END_MARKER

#define PRETTYPRINT_UNSTRUCTURED_END_MARKER   "\201Unstructured End"

Definition at line 144 of file misc.c.

◆ PRETTYPRINT_UNSTRUCTURED_ITEM_MARKER

#define PRETTYPRINT_UNSTRUCTURED_ITEM_MARKER   "\202Unstructured Item"

Definition at line 145 of file misc.c.

◆ PRETTYPRINT_UNSTRUCTURED_SUCC_MARKER

#define PRETTYPRINT_UNSTRUCTURED_SUCC_MARKER   "\203Unstructured Successor ->"

Definition at line 146 of file misc.c.

Function Documentation

◆ add_target_to_alternate_return_set()

void add_target_to_alternate_return_set ( entity  l)

Definition at line 814 of file misc.c.

815 {
816  ifdebug(1) {
817  pips_assert("The target list is initialized",
819  }
822 }
#define list_undefined_p(c)
Return if a list is undefined.
Definition: newgen_list.h:75
list gen_once(const void *vo, list l)
Prepend an item to a list only if it is not already in the list.
Definition: list.c:722
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
static list set_of_labels_required_for_alternate_returns
Management of alternate returns.
Definition: misc.c:793
#define ifdebug(n)
Definition: sg.c:47

References gen_once(), ifdebug, list_undefined_p, pips_assert, and set_of_labels_required_for_alternate_returns.

Referenced by words_regular_call().

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

◆ C_any_comment_to_text()

text C_any_comment_to_text ( int  r_margin,
string  c 
)

In case comments are not formatted according to C rules, e.g.

when prettyprinting Fortran code as C code, add // at beginning of lines

Note: this is supposed to have been dealt with by another function called before, ensure_comment_consistency()

line beginning

line end

current position, pointer in comments

We do not need spaces before a line feed

Parameters
r_margin_margin

Definition at line 4165 of file misc.c.

4166 {
4167  string lb = c; /* line beginning */
4168  string le = c; /* line end */
4169  string cp = c; /* current position, pointer in comments */
4170  text ct = make_text(NIL);
4171  bool is_C_comment = C_comment_p(c);
4172  int e_margin = r_margin;
4173 
4174  /* We do not need spaces before a line feed */
4175  if(strcmp(c, "\n")==0)
4176  e_margin = 0;
4177 
4178  if(strlen(c)>0) {
4179  for(;*cp!='\0';cp++) {
4180  if(*cp=='\n') {
4181  if(cp!=c || true){ // Do not skip \n
4182  string cl = gen_strndup0(lb, le-lb);
4184  if(is_C_comment)
4185  s = MAKE_ONE_WORD_SENTENCE(e_margin, cl);
4186  else if(strlen(cl)>0){
4187  list pc = CHAIN_SWORD(NIL, cl); // cl is uselessly duplicated
4188  pc = CONS(STRING, MAKE_SWORD("//"), pc);
4190  make_unformatted((char *) NULL, 0, e_margin, pc));
4191  }
4192  else {
4193  s = MAKE_ONE_WORD_SENTENCE(0, cl);
4194  }
4195  ADD_SENTENCE_TO_TEXT(ct, s);
4196  free(cl);
4197  }
4198  lb = cp+1;
4199  le = cp+1;
4200  }
4201  else
4202  le++;
4203  }
4204  // Final \n has been removed in the parser presumably by Ronan
4205  // But this is also useful when non-standard comments are added,
4206  // for instance by phase "comment_prepend"
4207  if(lb<cp){
4209  string sl = gen_strndup0(lb,le-lb);
4210  if(is_C_comment) {
4211  s = MAKE_ONE_WORD_SENTENCE(e_margin,sl);
4212  }
4213  else {
4214  list pc = CHAIN_SWORD(NIL, sl); // sl is uselessly duplicated
4215  pc = CONS(STRING, MAKE_SWORD("//"), pc);
4217  make_unformatted((char *) NULL, 0, e_margin, pc));
4218  }
4219  ADD_SENTENCE_TO_TEXT(ct,s);
4220  free(sl);
4221  } else{
4222  //ADD_SENTENCE_TO_TEXT(ct,MAKE_ONE_WORD_SENTENCE(0,""));
4223  ;
4224  }
4225  }
4226  else{// Final \n has been removed by Ronan
4227  //ADD_SENTENCE_TO_TEXT(ct,MAKE_ONE_WORD_SENTENCE(0,""));
4228  ;
4229  }
4230 
4231  return ct;
4232 }
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
text make_text(list a)
Definition: text.c:107
#define STRING(x)
Definition: genC.h:87
void free(void *)
#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
string gen_strndup0(string, size_t)
Like strdup() but copy at most n characters.
Definition: string.c:83
bool C_comment_p(string c)
In case the input code is not C code, non-standard comments have to be detected.
Definition: misc.c:4094
Pvecteur cp
pointeur sur l'egalite ou l'inegalite courante
Definition: sc_read.c:87
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define CHAIN_SWORD(l, s)
#define MAKE_ONE_WORD_SENTENCE(m, s)
#define ADD_SENTENCE_TO_TEXT(t, p)
#define MAKE_SWORD(s)
#define sentence_undefined
Definition: text.h:42
@ is_sentence_unformatted
Definition: text.h:58

References ADD_SENTENCE_TO_TEXT, C_comment_p(), CHAIN_SWORD, CONS, cp, free(), gen_strndup0(), is_sentence_unformatted, MAKE_ONE_WORD_SENTENCE, make_sentence(), MAKE_SWORD, make_text(), make_unformatted(), NIL, sentence_undefined, and STRING.

Referenced by C_comment_to_text().

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

◆ C_comment_p()

bool C_comment_p ( string  c)

In case the input code is not C code, non-standard comments have to be detected.

Definition at line 4094 of file misc.c.

4094  {
4095  bool is_C_comment=true;
4096  char * ccp=c;
4097  char cc=' ';
4098 
4099  init:
4100  cc=*ccp++;
4101  if(cc==' '|| cc=='\t' || cc=='\n')
4102  goto init;
4103  else if( cc=='/')
4104  goto slash;
4105  else if(cc=='\000')
4106  goto end;
4107  else {
4108  is_C_comment=false;
4109  goto end;
4110  }
4111 
4112  slash:
4113  cc=*ccp++;
4114  if(cc=='*')
4115  goto slash_star;
4116  else if(cc=='/')
4117  goto slash_slash;
4118  else{
4119  is_C_comment=false;
4120  goto end;
4121  }
4122 
4123  slash_star:
4124  cc=*ccp++;
4125  if(cc=='*')
4126  goto slash_star_star;
4127  else if(cc=='\0'){
4128  is_C_comment=false;
4129  goto end;
4130  }
4131  else
4132  goto slash_star;
4133 
4134  slash_slash:
4135  cc=*ccp++;
4136  if(cc=='\n')
4137  goto init;
4138  if(cc=='\0') // The comment may not end first with a '\n'
4139  goto end;
4140  else
4141  goto slash_slash;
4142 
4143  slash_star_star:
4144  cc=*ccp++;
4145  if(cc=='/')
4146  goto init;
4147  else if(cc=='*')
4148  goto slash_star_star;
4149  else if(cc=='\0'){
4150  is_C_comment=false;
4151  goto end;
4152  }
4153  else
4154  goto slash_star;
4155 
4156  end : return is_C_comment;
4157 }
char end
Definition: gtk_status.c:82
static int init
Maximal value set for Fortran 77.
Definition: entity.c:320

References end, and init.

Referenced by C_any_comment_to_text(), and C_comment_to_text().

+ Here is the caller graph for this function:

◆ C_comment_to_text()

text C_comment_to_text ( int  margin,
string  comment 
)

Special handling for C comments with each line indented according to the context.

I do not see the interest if the user code is already indented... RK OK, since the blanks outside the comments are removed by the parser.

Parameters
marginargin
commentomment

Definition at line 4270 of file misc.c.

4271 {
4272  text ct = text_undefined;
4273 
4274  if(C_comment_p(comment))
4275  //ct = C_standard_comment_to_text(margin, comment);
4276  ct = C_any_comment_to_text(margin, comment);
4277  else
4278  ct = C_any_comment_to_text(margin, comment);
4279  return ct;
4280 }
static void comment(string_buffer code, spoc_hardware_type hw, dagvtx v, int stage, int side, bool flip)
Definition: freia_spoc.c:52
text C_any_comment_to_text(int r_margin, string c)
In case comments are not formatted according to C rules, e.g.
Definition: misc.c:4165
#define text_undefined
Definition: text.h:91

References C_any_comment_to_text(), C_comment_p(), comment(), and text_undefined.

Referenced by text_trail().

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

◆ C_loop_range()

list C_loop_range ( range  obj,
entity  i,
list ppdl 
)

Output a Fortan-like do-loop range as a C-like for-loop index part.

@description Assume that the increment is an integer so we can generate the good condition. Since the do-loops are recognized in C program part only with this assumptions, it is a good assumption.

call c = syntax_call(expression_syntax(range_increment(obj)));

Complete the initialization assignment

Check the final bound

Increasing or decreasing index?

Assume the increment has an integer value with a known sign If The increment is negative, that means the index is tested against a lower bound Else we assume to test against an upper bound

check if we have something of the form exp -1 as range_upper

Additionally, we want to pretty print a strict comparison if certain conditions are met. This could be the default choice , but the impact on the validation would be huge

Priority for LESS, GREATER, LESS_OR_EQUAL, GREATER_OR_EQUAL: 15

Increment the loop index

Parameters
objbj
ppdlpdl

Definition at line 457 of file misc.c.

458 {
459  list pc;
460  /* call c = syntax_call(expression_syntax(range_increment(obj))); */
461 
462  /* Complete the initialization assignment */
463  pc = words_subexpression(range_lower(obj), 0, true, ppdl);
464  pc = CHAIN_SWORD(pc,"; ");
465 
466  /* Check the final bound */
467  pc = CHAIN_SWORD(pc, entity_user_name(i));
468 
469  /* Increasing or decreasing index? */
470  expression inc = range_increment(obj);
471  /* Assume the increment has an integer value with a known sign
472  If The increment is negative, that means the index is tested against
473  a lower bound
474  Else we assume to test against an upper bound
475  */
476 
477  expression ru = range_upper(obj);
478  /* check if we have something of the form exp -1 as range_upper */
480  copy_expression(ru),
482  );
483 
484  /* Additionally, we want to pretty print a strict comparison if
485  certain conditions are met. This could be the default choice ,
486  but the impact on the validation would be huge */
487  set re = get_referenced_entities(ru);
488  bool references_unsigned_entity_p = false;
489  SET_FOREACH(entity,e,re) {
490  references_unsigned_entity_p |= unsigned_type_p(ultimate_type(entity_type(e)));
491  }
492  set_free(re);
493  if( references_unsigned_entity_p ) {
494  if(positive_expression_p(inc))
495  pc = CHAIN_SWORD(pc, " < ");
496  else if(negative_expression_p(inc))
497  pc = CHAIN_SWORD(pc, " > ");
498  else {
499  //pips_internal_error("loop range cannot be prettyprinted because increment sign"
500  // " is unknown\n");
501  pips_user_warning("loop increment sign is unknown: assumed positive\n");
502  pc = CHAIN_SWORD(pc, " < ");
503  }
504  pc = gen_nconc(pc, words_subexpression(ru_minus_one, 0, true, ppdl));
505  }
506  else {
507  // FI: when inc is not a constant integer,
508  // expression_negative_integer_value_p() always return false
509  if(positive_expression_p(inc))
510  pc = CHAIN_SWORD(pc, " <= ");
511  else if(negative_expression_p(inc))
512  pc = CHAIN_SWORD(pc, " >= ");
513  else {
514  //pips_internal_error("loop range cannot be prettyprinted because increment sign"
515  // " is unknown\n");
516  pips_user_warning("loop increment sign is unknown: assumed positive\n");
517  pc = CHAIN_SWORD(pc, " <= ");
518  }
519  /* Priority for LESS, GREATER, LESS_OR_EQUAL, GREATER_OR_EQUAL: 15 */
520  pc = gen_nconc(pc, words_subexpression(ru, 15, true, ppdl));
521  }
522  free_expression(ru_minus_one);
523  pc = CHAIN_SWORD(pc,"; ");
524 
525  /* Increment the loop index */
526  pc = CHAIN_SWORD(pc, entity_user_name(i));
527  pc = CHAIN_SWORD(pc," += ");
528  pc = gen_nconc(pc, words_expression(inc, ppdl));
529  pc = CHAIN_SWORD(pc,")");
530 
531  return(pc);
532 }
expression copy_expression(expression p)
EXPRESSION.
Definition: ri.c:850
void free_expression(expression p)
Definition: ri.c:853
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define pips_user_warning
Definition: misc-local.h:146
#define SET_FOREACH(type_name, the_item, the_set)
enumerate set elements in their internal order.
Definition: newgen_set.h:78
void set_free(set)
Definition: set.c:332
list words_subexpression(expression obj, int precedence, bool leftmost, list *ppdl)
exported for cmfortran.c
Definition: misc.c:2674
list words_expression(expression obj, list *ppdl)
This one is exported.
Definition: misc.c:2611
#define PLUS_OPERATOR_NAME
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
set get_referenced_entities(void *elem)
retrieves the set of entities used in elem beware that this entities may be formal parameters,...
Definition: entity.c:3063
bool positive_expression_p(expression e)
Use constants and type information to decide if the value of sigma(e) is always positive,...
Definition: eval.c:826
bool negative_expression_p(expression e)
Use constants and type information to decide if the value of sigma(e) is always negative,...
Definition: eval.c:896
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
Definition: expression.c:1188
expression make_op_exp(char *op_name, expression exp1, expression exp2)
================================================================
Definition: expression.c:2012
type ultimate_type(type)
Definition: type.c:3466
bool unsigned_type_p(type)
Predicates on types.
Definition: type.c:2821
#define range_upper(x)
Definition: ri.h:2290
#define range_increment(x)
Definition: ri.h:2292
#define range_lower(x)
Definition: ri.h:2288
#define entity_type(x)
Definition: ri.h:2792
FI: I do not understand why the type is duplicated at the set level.
Definition: set.c:59

References CHAIN_SWORD, copy_expression(), entity_type, entity_user_name(), free_expression(), gen_nconc(), get_referenced_entities(), int_to_expression(), make_op_exp(), negative_expression_p(), pips_user_warning, PLUS_OPERATOR_NAME, positive_expression_p(), range_increment, range_lower, range_upper, SET_FOREACH, set_free(), ultimate_type(), unsigned_type_p(), words_expression(), and words_subexpression().

Referenced by text_loop_default().

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

◆ C_standard_comment_to_text()

text C_standard_comment_to_text ( int  margin,
string  comment 
)

position of a line end

Find the first end of line:

No end-of-line, so use all the rest of the comment:

Skip the '
' at the end since the line concept is the notion of sentence

Analyze the next line:

Do not indent if the line is empty

Parameters
marginargin
commentomment

Definition at line 4237 of file misc.c.

4238 {
4239  string line;
4240  string le = comment; /* position of a line end */
4241  text ct = make_text(NIL);
4242 
4243  do {
4244  /* Find the first end of line: */
4245  le = strchr(comment, '\n');
4246  if (le == NULL)
4247  /* No end-of-line, so use all the rest of the comment: */
4248  line = strdup(comment);
4249  else {
4250  /* Skip the '\n' at the end since the line concept is the notion of
4251  sentence */
4252  line = gen_strndup0(comment, le - comment);
4253  /* Analyze the next line: */
4254  comment = le + 1;
4255  }
4256  /* Do not indent if the line is empty */
4258  MAKE_ONE_WORD_SENTENCE(line[0] == '\0' ? 0 : margin,
4259  line));
4260  } while (le != NULL);
4261  return ct;
4262 }
char * strdup()
static int line
FLEX_SCANNER.
Definition: scanner.c:852

References ADD_SENTENCE_TO_TEXT, comment(), gen_strndup0(), line, MAKE_ONE_WORD_SENTENCE, make_text(), NIL, and strdup().

+ Here is the call graph for this function:

◆ close_prettyprint()

void close_prettyprint ( void  )

because some prettyprint functions may be used for debug, so the last hook set by somebody may have stayed there although being non sense...

Definition at line 242 of file misc.c.

242  {
244 }
text empty_text(entity __attribute__((unused)) e, int __attribute__((unused)) m, statement __attribute__((unused)) s)
Definition: misc.c:219
static text(* text_statement_hook)(entity, int, statement)
Definition: misc.c:225

References empty_text(), and text_statement_hook.

Referenced by generic_print_code_pv(), get_any_comp_regions_text(), get_continuation_condition_text(), get_semantic_text(), print_code_or_source_comp(), print_code_points_to(), print_code_static_control(), print_parallelized_code_common(), print_parallelizedCMF_code(), print_parallelizedCRAFT_code(), store_new_module(), text_code_points_to(), text_code_reductions(), and wp65().

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

◆ cstrsplit()

static list cstrsplit ( const char *  s,
char  delim 
)
static

Split string into a list of strings according to a separator, delim.

Note that the final LF is dropped in C comments

if(delim=='
' && *(e-1)=='
' && *e=='\000')

out=CONS(STRING,strdup(""),out);

Definition at line 4286 of file misc.c.

4286  {
4287  list out = NIL;
4288  const char *b=s,*e=s;
4289  while(*e) {
4290  while(*e && *e!=delim) ++e;
4291  char * word = strndup(b,e-b);
4292  out=CONS(STRING,word,out);
4293  if(*e) {
4294  ++e;
4295  b=e;
4296  }
4297  // This looks necessary for decl64-65.c (1 and 2 empty lines),
4298  // but is impossible for comment14.c (3 empty lines)
4299  /* if(delim=='\n' && *(e-1)=='\n' && *e=='\000') */
4300  /* out=CONS(STRING,strdup(""),out); */
4301  }
4302  return gen_nreverse(out);
4303 }
static FILE * out
Definition: alias_check.c:128
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
char * strndup(char const *s, size_t n)
A replacement function, for systems that lack strndup.
Definition: strndup.c:26

References CONS, gen_nreverse(), NIL, out, STRING, and strndup().

Referenced by ensure_comment_consistency().

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

◆ empty_text()

text empty_text ( entity __attribute__((unused))  e,
int __attribute__((unused))  m,
statement __attribute__((unused))  s 
)

Definition at line 219 of file misc.c.

221  {
222  return make_text(NIL);
223 }

References make_text(), and NIL.

Referenced by close_prettyprint(), init_prettyprint(), init_text_statement(), print_code_or_source(), print_parallelized_code_common(), print_parallelizedCMF_code(), print_parallelizedCRAFT_code(), store_new_module(), and wp65().

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

◆ ensure_comment_consistency()

static string ensure_comment_consistency ( const char *  i_comments,
language  l 
)
static

return a formatted comment, that takes care of adding the relevant // or C depending on output language, except for empty lines in C

Special handling of comments linked to declarations and to the poor job of the lexical analyzer as regards C comments: failure.

lank line

Build the text of a statement recursively

Parameters
modulethe module containing the statement
imargincurrent tabulation
stmtthe statement to print
braces_pthe statement is within a block; this has an impact of the print-out of continue statements in C, ";"
drop_continue_panother condition to control the print-out of ";" or not;
ppdlpointer to the previous declaration list; list of entities that have already been declared and should not be redeclared; this is required for struct and union which may be declared independently or in a nested way. See C_syntax/struct03, 04, 05, etc...
Returns
the text of the statement

Notes:

  • in simple tests, the statement ";" may be mandatory or not.
  • continue may be used to preserve comments and then the ";" may be dropped
  • source fidelity would be easier if a new NOP statement that is never printed out were used.

Handles all statements but tests that are nodes of an unstructured. Those are handled by text_control.

Parameters
modulethe module containing the statement
margincurrent tabulation
stmtthe statement to print
ppdlpointer to the previous declaration list; list of entities that have already been declared and should not be redeclared; this is required for struct and union which may be declared independently or in a nested way. See C_syntax/struct03, 04, 05, etc...
Returns
the text of the statement

return a string from a statement, or NULL if undefined

Keep track of the last statement to decide if a final return can be omitted or not. If no last statement can be found for sure, for instance because it depends on the prettyprinter, last_statement_found is set to statement_undefined which is safe.

FI: for purposes unrelated to prettyprint, see last_statement(). This function is part of the prettyprinter and probably only useful for Fortran code.

Hopefully it is a return statement. Since the semantics of STOP is ignored by the parser, a final STOp should be followed by a RETURN.

loop or test cannot be last statements of a module

recursive call

Too many program transformations and syntheses violate the following assert

No warning needed for C, is it right for C ?

I had a lot of trouble writing the condition for this assert...

let's give up: it's always safe

not a block: any kind of statement...

if a block, then a return

adds a RETURN statement to *ps if necessary

Reuse all declarations of the compilation unit, although some may occur after the module definition.

all types and derived entities used to define the formal parameters must be predefined, or they are local to the formal scope and useless.

Build the text of a module.

The original text of the declarations is used if possible in Fortran. Otherwise, the function text_declaration is called.

< the name of the module

Set the prettyprint language

This guard is correct but could be removed if find_last_statement() were robust and/or if the internal representations were always "correct". See also the guard for reset_last_statement()

Add the original header comments if any:

Add the original header comments if any:

C prettyprinter

Print function header if the current module is not a compilation unit

get the declarations for Fortran codes prettyrinted as C, as the declarations are not located in the module statement. A.Mensi

Declarations linked to formal parameters are performed in a different scope and do not have to be propagated.

No need to print TAIL (}) if the current module is a C compilation unit

The node itentifiers are generated from the ordering, more stable than the control node address:

Display the statements of each node followed by the list of its successors if any:

If we have not displayed the exit node, that mean that it is not connex with the entry node and so the code is unreachable. Anyway, it has to be displayed as for the classical Sequential View:

Note that since the controlizer adds a dummy successor to the exit node, use output_a_graph_view_of_the_unstructured_from_a_control() instead of output_a_graph_view_of_the_unstructured_successors():

Even if the code is unreachable, add the fact that the control above is semantically related to the entry node. Add a dash arrow from the entry node to the exit node in daVinci, for example:

================C prettyprinter functions=================

FI: the test used below is probably too strict I believe, because dimensions are not allowed, but I may be wrong

The type must be fully declared: see struct15.c

Parentheses must be added for array expression like __ctype+1 in (__ctype+1)[*np]

Here we differentiate the indices parenthesis syntax

Print now the indices list

Here we differentiate the indices syntax

Parentheses must be added for function expression

To restitute for(;;)

Definition at line 4308 of file misc.c.

References add_control_node_identifier_to_text(), add_one_unformated_printf_to_text(), ADD_SENTENCE_TO_TEXT, application_arguments, application_function, asprintf, attach_head_to_sentence(), basic_derived, c_module_p(), C_STATEMENT_END_STRING, c_text_entities(), c_words_entity(), c_words_simplified_entity(), CAR, cast_expression, CAST_OPERATOR_PRECEDENCE, cast_type, CHAIN_SWORD, code_declarations, code_decls_text, code_language, compilation_unit_p(), CONS, CONTROL, CONTROL_MAP, control_statement, control_successors, cstrsplit(), debug_off, debug_on, derived_type_p(), empty_comments_p(), ENDP, entity_code(), entity_initial, entity_name, entity_type, entity_undefined, entity_undefined_p, entity_user_name(), exp, EXPRESSION, expression_allocatable_data_access_p(), expression_one_p(), expression_undefined_p, f(), find_last_statement(), FOREACH, forloop_body, forloop_condition, forloop_increment, forloop_initialization, fortran_module_p(), fprintf(), free(), free_text(), gen_copy_seq(), gen_free_list(), gen_in_list_p(), gen_last(), gen_nconc(), gen_once(), generate_alternate_return_targets(), generic_text_statement_enclosed(), get_bool_property(), get_declaration_comments(), get_header_comments(), get_prettyprint_indentation(), get_prettyprint_language_tag(), head_hook, ifdebug, INDENTATION, initialize_previously_declared_entities(), instruction_block, instruction_sequence, insure_return_as_last_statement(), is_language_c, is_language_fortran, is_language_fortran95, is_sentence_formatted, is_sentence_unformatted, label_local_name(), language_c_p, language_fortran95_p, language_fortran_p, language_tag, last_statement_p(), lexp, line, lines, make_block_statement(), MAKE_ONE_WORD_SENTENCE, make_return_statement(), make_sentence(), make_text(), make_unformatted(), MAP, MERGE_TEXTS, module, module_entity_to_compilation_unit_entity(), NIL, num, one_liner_p(), ORDERING_NUMBER, ORDERING_STATEMENT, output_a_graph_view_of_the_unstructured(), output_a_graph_view_of_the_unstructured_from_a_control(), output_a_graph_view_of_the_unstructured_successors(), pips_assert, pips_debug, pips_internal_error, pips_user_warning, POP, precedence_p, prefix, prettyprint_all_c_braces_p, prettyprint_gcc_c_braces_p, prettyprint_language_is_fortran_p(), PRETTYPRINT_UNREACHABLE_EXIT_MARKER, PRETTYPRINT_UNSTRUCTURED_BEGIN_MARKER, PRETTYPRINT_UNSTRUCTURED_END_MARKER, PRETTYPRINT_UNSTRUCTURED_ITEM_MARKER, PRETTYPRINT_UNSTRUCTURED_SUCC_MARKER, print_text(), proper_statement_to_string(), reset_alternate_return_set(), reset_label_counter(), reset_last_statement(), ret, return_statement_p(), sentence_head(), sentence_tail(), sequence_statements, set_alternate_return_set(), set_last_statement(), set_prettyprint_language_from_property(), sizeofexpression_expression, sizeofexpression_type, sizeofexpression_type_p, STATEMENT, statement_block_p, statement_call_p(), statement_comments, statement_declarations, statement_identification(), statement_instruction, statement_label, statement_number, statement_ordering, statement_sequence_p(), statement_undefined, statement_undefined_p, statement_unstructured(), statement_unstructured_p(), strdup(), STRING, subscript_array, subscript_indices, text_declaration(), text_forloop(), text_initializations(), text_module(), text_named_module(), Text_Proper_Statement(), Text_Statement(), text_statement(), Text_Statement_Enclosed(), text_statement_enclosed(), text_to_string_nl(), text_undefined, type_supporting_entities(), type_variable, unstructured_control, unstructured_exit, unstructured_to_trail(), value_code, variable_basic, words_application(), words_cast(), words_expression(), words_sizeofexpression(), words_subexpression(), words_subscript(), and words_type().

◆ eole_fma_specific_op()

list eole_fma_specific_op ( call  obj,
int  precedence,
bool  leftmost,
list ppdl 
)

EOLE : The multiply-add operator is used within the optimize transformation ( JZ - sept 98) - fma(a,b,c) -> ((a*b)+c)

of string

Parameters
objbj
precedencerecedence
leftmosteftmost
ppdlpdl

Definition at line 2049 of file misc.c.

2050 {
2051  return eole_fmx_specific_op(obj, precedence, leftmost, true, ppdl);
2052 }
static list eole_fmx_specific_op(call obj, int __attribute__((unused)) precedence, bool __attribute__((unused)) leftmost, bool isadd, list *ppdl)
Definition: misc.c:1996

References eole_fmx_specific_op().

+ Here is the call graph for this function:

◆ eole_fms_specific_op()

list eole_fms_specific_op ( call  obj,
int  precedence,
bool  leftmost,
list ppdl 
)

MULTIPLY-SUB operator.

of string

Parameters
objbj
precedencerecedence
leftmosteftmost
ppdlpdl

Definition at line 2056 of file misc.c.

2057 {
2058  return eole_fmx_specific_op(obj, precedence, leftmost, false, ppdl);
2059 }

References eole_fmx_specific_op().

+ Here is the call graph for this function:

◆ eole_fmx_specific_op()

static list eole_fmx_specific_op ( call  obj,
int __attribute__((unused))  precedence,
bool __attribute__((unused))  leftmost,
bool  isadd,
list ppdl 
)
static

of strings

of expressions

open parenthese one

open parenthese two

get precedence for mult operator

first argument

mult operator

second argument

close parenthese two

get precedence for add operator

add/sub operator

third argument

close parenthese one

Definition at line 1996 of file misc.c.

2001 {
2002  list /* of strings */ pc = NIL;
2003  list /* of expressions */ args = call_arguments(obj);
2004 
2005  int prec ;
2006 
2007  /* open parenthese one */
2008  pc = CHAIN_SWORD(pc, "(");
2009 
2010  /* open parenthese two */
2011  pc = CHAIN_SWORD(pc, "(");
2012 
2013  /* get precedence for mult operator */
2014  prec = intrinsic_precedence("*");
2015 
2016  /* first argument */
2017  pc = gen_nconc(pc,words_subexpression(EXPRESSION(CAR(args)), prec, true, ppdl));
2018 
2019  /* mult operator */
2020  pc = CHAIN_SWORD(pc,"*");
2021 
2022  /* second argument */
2023  args = CDR(args);
2024  pc = gen_nconc(pc,words_subexpression(EXPRESSION(CAR(args)),prec,true, ppdl));
2025 
2026  /* close parenthese two */
2027  pc = CHAIN_SWORD(pc, ")");
2028 
2029  /* get precedence for add operator */
2030  prec = intrinsic_precedence("+");
2031 
2032  /* add/sub operator */
2033  pc = CHAIN_SWORD(pc, isadd? "+": "-");
2034 
2035  /* third argument */
2036  args = CDR(args);
2037  pc = gen_nconc(pc,words_subexpression(EXPRESSION(CAR(args)),prec,false, ppdl));
2038 
2039  /* close parenthese one */
2040  pc = CHAIN_SWORD(pc,")");
2041 
2042  return pc;
2043 }
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
static int intrinsic_precedence(const char *)
Definition: misc.c:2539
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define call_arguments(x)
Definition: ri.h:711

References call_arguments, CAR, CDR, CHAIN_SWORD, EXPRESSION, gen_nconc(), intrinsic_precedence(), NIL, and words_subexpression().

Referenced by eole_fma_specific_op(), and eole_fms_specific_op().

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

◆ gcc_if_block_braces_required_p()

bool gcc_if_block_braces_required_p ( test  obj)
Parameters
objbj

Definition at line 336 of file misc.c.

337 {
338  statement tb = effective_test_true(obj);
339 
340  if(one_liner_p(tb)) {
341  if (statement_test_p(tb)) {
342  test nested_test = statement_test(tb);
343  statement fb = test_false(nested_test);
344  if (!empty_statement_p(fb)) {
346  }
347  }
348  }
349  return false;
350 }
statement effective_test_true(test)
returns the effective true branch of a test by skipping a possible sequence of one element.
Definition: statement.c:1358
test statement_test(statement)
Get the test of a statement.
Definition: statement.c:1348
bool statement_test_p(statement)
Definition: statement.c:343
bool empty_statement_p(statement)
Test if a statement is empty.
Definition: statement.c:391
bool one_liner_p(statement s)
True is statement "s" can be printed out without enclosing braces when it is the true branch of a tes...
Definition: misc.c:301
static bool prettyprint_gcc_c_braces_p
This variable is used to gracefuly print braces around if / else blocks to avoid gcc warnings.
Definition: misc.c:200
#define test_false(x)
Definition: ri.h:2837

References effective_test_true(), empty_statement_p(), one_liner_p(), prettyprint_gcc_c_braces_p, statement_test(), statement_test_p(), and test_false.

Referenced by text_block_ifthen().

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

◆ generate_alternate_return_targets()

text generate_alternate_return_targets ( void  )

Definition at line 824 of file misc.c.

825 {
826  text ral = text_undefined;
827 
829  list sl = NIL;
832  string str_continue = string_undefined;
833  switch (get_prettyprint_language_tag()) {
835  case is_language_fortran:
836  str_continue = CONTINUE_FUNCTION_NAME;
837  break;
838  case is_language_c:
839  str_continue = C_CONTINUE_FUNCTION_NAME;
840  break;
841  default:
842  pips_internal_error("Language unknown !");
843  break;
844  }
845  unformatted u1 =
848  0,
849  CONS(STRING, strdup(str_continue), NIL));
851  sl = gen_nconc(sl, CONS(SENTENCE, s1, NIL));
852  }
853  ral = make_text(sl);
854  }
855  else {
856  ral = make_text(NIL);
857  }
858  return ral;
859 }
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
enum language_utype get_prettyprint_language_tag()
Definition: language.c:67
#define pips_internal_error
Definition: misc-local.h:149
#define string_undefined
Definition: newgen_types.h:40
#define C_CONTINUE_FUNCTION_NAME
#define STATEMENT_NUMBER_UNDEFINED
default values
#define CONTINUE_FUNCTION_NAME
const char * label_local_name(entity e)
END_EOLE.
Definition: entity.c:604
@ is_language_fortran
Definition: ri.h:1566
@ is_language_fortran95
Definition: ri.h:1568
@ is_language_c
Definition: ri.h:1567
s1
Definition: set.c:247
#define SENTENCE(x)
newgen_unformatted_domain_defined
Definition: text.h:36

References C_CONTINUE_FUNCTION_NAME, CONS, CONTINUE_FUNCTION_NAME, ENDP, FOREACH, gen_nconc(), get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, is_sentence_unformatted, label_local_name(), make_sentence(), make_text(), make_unformatted(), NIL, pips_internal_error, s1, SENTENCE, sentence_undefined, set_of_labels_required_for_alternate_returns, STATEMENT_NUMBER_UNDEFINED, strdup(), STRING, string_undefined, and text_undefined.

Referenced by ensure_comment_consistency().

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

◆ get_comment_continuation()

string get_comment_continuation ( void  )

Start a single line comment with continuation (blank spaces)

Returns
a string containing the begin of a comment line, language dependent

Definition at line 167 of file misc.c.

167  {
168  switch(get_prettyprint_language_tag()) {
169  case is_language_c: return "// ";
170  case is_language_fortran: return "C ";
171  case is_language_fortran95: return "! ";
172  default: pips_internal_error("language unknown not handled"); return NULL ;
173  }
174 }

References get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, and pips_internal_error.

Referenced by text_pointer_value(), text_pointer_values(), text_points_to_relation(), text_points_to_relations(), text_region_no_action(), and text_transformer().

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

◆ get_comment_sentinel()

string get_comment_sentinel ( void  )

Start a single line comment.

Returns
a string containing the begin of a comment line, language dependent

Definition at line 154 of file misc.c.

154  {
155  switch(get_prettyprint_language_tag()) {
156  case is_language_c: return "//";
157  case is_language_fortran: return "C";
158  case is_language_fortran95: return "!";
159  default: pips_internal_error("language unknown not handled"); return NULL ;
160  }
161 }

References get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, and pips_internal_error.

Referenced by init_text_statement(), loop_annotate(), mark_block(), print_any_reductions(), text_complexity(), text_continuation(), text_pointer_value(), text_pointer_values(), text_points_to(), text_points_to_relation(), text_points_to_relations(), text_reductions(), text_region_no_action(), text_transformer(), and text_unstructured().

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

◆ get_prettyprint_indentation()

unsigned int get_prettyprint_indentation ( void  )

Definition at line 177 of file misc.c.

177  {
179  return 0;
180  } else {
181  return INDENTATION;
182  }
183 }
bool prettyprint_language_is_fortran_p()
Definition: language.c:75
#define INDENTATION

References INDENTATION, and prettyprint_language_is_fortran_p().

Referenced by ensure_comment_consistency(), sentence_area(), sentence_basic_declaration(), sentence_data(), sentence_data_statement(), sentence_external(), sentence_symbolic(), and text_entity_declaration().

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

◆ get_special_prettyprint_for_operator()

static const char* get_special_prettyprint_for_operator ( call  obj)
static

Check if the given operator is associated with a special prettyprint.

For instance, n-ary add and multiply operators which are used in the EOLE project use "+" and "*" prettyprints instead of the entity_local_name (JZ - sept 98)

get the entity name

Definition at line 2066 of file misc.c.

2066  {
2067 
2068  static struct special_operator_prettyprint {
2069  const char * name;
2070  const char * op_prettyprint;
2071  } tab_operator_prettyprint[] = {
2072  {EOLE_SUM_OPERATOR_NAME,"+"},
2074  {NULL,NULL}
2075  };
2076  int i = 0;
2077  const char* op_name;
2078 
2079  /* get the entity name */
2080  op_name = entity_local_name(call_function(obj));
2081 
2082  while (tab_operator_prettyprint[i].name) {
2083  if (!strcmp(tab_operator_prettyprint[i].name,op_name))
2084  return tab_operator_prettyprint[i].op_prettyprint;
2085  else i++;
2086  }
2087 
2088  return op_name;
2089 }
#define EOLE_PROD_OPERATOR_NAME
#define EOLE_SUM_OPERATOR_NAME
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453
#define call_function(x)
Definition: ri.h:709

References call_function, entity_local_name(), EOLE_PROD_OPERATOR_NAME, and EOLE_SUM_OPERATOR_NAME.

Referenced by words_infix_nary_op().

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

◆ init_intrinsic_handlers()

static void init_intrinsic_handlers ( )
static

Definition at line 2504 of file misc.c.

2504  {
2507  for(struct intrinsic_handler *p = &tab_intrinsic_handler[0];p->name;p++) {
2508  // no copy because the memory is static
2509  hash_put(intrinsic_handlers,p->name,&p->desc);
2510  }
2511  }
2512 }
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
void hash_put(hash_table htp, const void *key, const void *val)
This functions stores a couple (key,val) in the hash table pointed to by htp.
Definition: hash.c:364
@ hash_string
Definition: newgen_hash.h:32
#define hash_table_undefined_p(h)
Definition: newgen_hash.h:50
static struct intrinsic_handler tab_intrinsic_handler[]
static hash_table intrinsic_handlers
Definition: misc.c:2502
precedence needed here According to the Precedence of Operators Arithmetic > Character > Relational >...
Definition: misc.c:2337
const char * name
Definition: misc.c:2338

References hash_put(), hash_string, hash_table_make(), hash_table_undefined_p, intrinsic_handlers, intrinsic_handler::name, and tab_intrinsic_handler.

Referenced by intrinsic_precedence(), register_intrinsic_handler(), and words_intrinsic_call().

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

◆ init_prettyprint()

void init_prettyprint ( text(*)(entity, int, statement hook)

◆ init_text_statement()

text init_text_statement ( entity  module,
int  margin,
statement  obj 
)

exported for unstructured.c

FI: before calling the hook, statement_ordering(obj) should be checked

Parameters
moduleodule
marginargin
objbj

Definition at line 3462 of file misc.c.

3466 {
3468  text r;
3469 
3470  if (get_bool_property("PRETTYPRINT_ALL_EFFECTS")
3471  || !((instruction_block_p(i) &&
3472  !get_bool_property("PRETTYPRINT_BLOCKS")) ||
3474  !get_bool_property("PRETTYPRINT_UNSTRUCTURED")))) {
3475  /* FI: before calling the hook,
3476  * statement_ordering(obj) should be checked */
3477  r = (*text_statement_hook)( module, margin, obj );
3480  }
3481  else
3482  r = make_text( NIL ) ;
3483 
3484  if (get_bool_property("PRETTYPRINT_ALL_EFFECTS") ||
3485  get_bool_property("PRETTYPRINT_STATEMENT_ORDERING")) {
3486  char *buffer;
3487  int so = statement_ordering(obj) ;
3488 
3490  (! get_bool_property("PRETTYPRINT_BLOCKS")))) {
3491  if (so != STATEMENT_ORDERING_UNDEFINED)
3492  asprintf(&buffer, "%s (%d,%d)\n", get_comment_sentinel(),
3494  else
3495  asprintf(&buffer, "%s (statement ordering unavailable)\n",
3498  buffer));
3499  }
3500  }
3501  return( r ) ;
3502 }
void attach_decoration_to_text(text t)
Attach a decoration:
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define asprintf
Definition: misc-local.h:225
#define STATEMENT_ORDERING_UNDEFINED
mapping.h inclusion
Definition: newgen-local.h:35
static char * module
Definition: pips.c:74
string get_comment_sentinel()
Start a single line comment.
Definition: misc.c:154
#define instruction_block_p(i)
#define ORDERING_NUMBER(o)
#define ORDERING_STATEMENT(o)
#define statement_ordering(x)
Definition: ri.h:2454
#define instruction_unstructured_p(x)
Definition: ri.h:1530
#define statement_instruction(x)
Definition: ri.h:2458
static string buffer
Definition: string.c:113
@ is_sentence_formatted
Definition: text.h:57

References ADD_SENTENCE_TO_TEXT, asprintf, attach_decoration_to_text(), buffer, empty_text(), get_bool_property(), get_comment_sentinel(), instruction_block_p, instruction_unstructured_p, is_sentence_formatted, make_sentence(), make_text(), module, NIL, ORDERING_NUMBER, ORDERING_STATEMENT, statement_instruction, statement_ordering, STATEMENT_ORDERING_UNDEFINED, and text_statement_hook.

Referenced by text_trail().

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

◆ insert_locals()

static text insert_locals ( text  r)
static

This function either appends the declaration to the text given as a parameter or return a new text with the declaration.

Definition at line 363 of file misc.c.

363  {
364  if (local_flg == true) {
365  if ((r != text_undefined) && (r != NULL)){
366  MERGE_TEXTS (r, local_var);
367  }
368  else {
369  r = local_var;
370  }
371  local_flg = false;
372  }
373  return r;
374 }
static text local_var
Definition: misc.c:356
static bool local_flg
Definition: misc.c:357
#define MERGE_TEXTS(r, t)

References local_flg, local_var, MERGE_TEXTS, and text_undefined.

Referenced by text_block(), and text_instruction().

+ Here is the caller graph for this function:

◆ intrinsic_precedence()

static int intrinsic_precedence ( const char *  n)
static

Definition at line 2539 of file misc.c.

2540 {
2543  }
2545  if(d!= HASH_UNDEFINED_VALUE)
2546  return d->prec;
2547  else
2548  return 0;
2549 }
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:449
#define HASH_UNDEFINED_VALUE
value returned by hash_get() when the key is not found; could also be called HASH_KEY_NOT_FOUND,...
Definition: newgen_hash.h:56
static void init_intrinsic_handlers()
Definition: misc.c:2504
for intrinsic registration

References hash_get(), hash_table_undefined_p, HASH_UNDEFINED_VALUE, init_intrinsic_handlers(), intrinsic_handlers, and intrinsic_desc_t::prec.

Referenced by eole_fmx_specific_op(), words_infix_binary_op(), words_infix_nary_op(), and words_intrinsic_precedence().

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

◆ loop_private_variables()

static list loop_private_variables ( loop  obj,
list ppdl 
)
static

of string

Returns
a list of string with the variable that need to be private in the current context. The context takes care of the kind of output. For example in the case of open mp the variables would be encapsulated into the private() clause like this: private (a,b).
Parameters
objthe loop to look at.

stuff around if not empty

This is debugging way to print out code. I do not know which Fortran parser takes this language extension.

In C case, it might be a good idea to re-declare the private variables in the loop body, exceot for outer loop indices, but this is not easy here. PIPS data structures should be updated because loop_private is somehow redundant with statement declarations.

comma-separated list of private variables. built in reverse order to avoid adding at the end...

from now on commas, triggered...

Definition at line 2906 of file misc.c.

2907 {
2908  bool all_private = get_bool_property("PRETTYPRINT_ALL_PRIVATE_VARIABLES"),
2909  hpf_private = pp_hpf_style_p(), omp_private = pp_omp_style_p(),
2910  some_before = false;
2911  list l = NIL;
2912 
2913  // list of local entities
2914  // In case of openmp the variable declared in the loop body should
2915  // not be made private, so ask for removing them from the list of locals.
2916  // If all_private is false -> remove loop indice from the list of locals.
2918  omp_private,
2919  !all_private);
2920 
2921  pips_debug(5, "#printed %zd/%zd\n", gen_length(l),
2922  gen_length(loop_locals(obj)));
2923 
2924  /* stuff around if not empty
2925  */
2926  if (locals) {
2927  string private = string_undefined;
2928  if (hpf_private) {
2929  private = "NEW(";
2930  } else if (omp_private) {
2931  switch (get_prettyprint_language_tag()) {
2932  case is_language_fortran:
2933  private = "PRIVATE(";
2934  break;
2935  case is_language_c:
2936  private = "private(";
2937  break;
2938  case is_language_fortran95:
2939  pips_internal_error("Need to update F95 case");
2940  break;
2941  default:
2942  pips_internal_error("Language unknown !");
2943  break;
2944  }
2946  /* This is debugging way to print out code. I do not know which
2947  Fortran parser takes this language extension. */
2948  private = "PRIVATE ";
2949  }
2950  else {
2951  /* In C case, it might be a good idea to re-declare the private
2952  variables in the loop body, exceot for outer loop indices,
2953  but this is not easy here. PIPS data structures should be
2954  updated because loop_private is somehow redundant with
2955  statement declarations. */
2956  pips_user_warning("Privatized variables are ignored with the "
2957  "current prettyprinter options.\n");
2958  }
2959 
2960  if(!string_undefined_p(private)) {
2961  /* comma-separated list of private variables.
2962  * built in reverse order to avoid adding at the end...
2963  */
2964  FOREACH (ENTITY, p, locals) {
2965  if (some_before)
2966  l = CHAIN_SWORD(l, ",");
2967  else
2968  some_before = true; /* from now on commas, triggered... */
2969  l = gen_nconc(l, words_declaration(p, true, ppdl));
2970  }
2971 
2972  gen_free_list(locals);
2973 
2974  l = CONS(STRING, MAKE_SWORD(private), l);
2975  if (hpf_private || omp_private)
2976  CHAIN_SWORD(l, ")");
2977  }
2978  }
2979 
2980  return l;
2981 }
list loop_private_variables_as_entites(loop obj, bool local, bool index)
Get the variables local or private to a loop.
Definition: loop.c:338
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
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define string_undefined_p(s)
Definition: newgen_types.h:41
list words_declaration(entity e, bool prettyprint_common_variable_dimensions_p, list *ppdl)
some compilers don't like dimensions that are declared twice.
Definition: declarations.c:277
#define pp_hpf_style_p()
Definition: misc.c:208
#define pp_omp_style_p()
Definition: misc.c:215
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define loop_locals(x)
Definition: ri.h:1650

References CHAIN_SWORD, CONS, ENTITY, FOREACH, gen_free_list(), gen_length(), gen_nconc(), get_bool_property(), get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, loop_locals, loop_private_variables_as_entites(), MAKE_SWORD, NIL, pips_debug, pips_internal_error, pips_user_warning, pp_hpf_style_p, pp_omp_style_p, STRING, string_undefined, string_undefined_p, and words_declaration().

Referenced by text_directive(), and text_loop_default().

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

◆ marged()

static string marged ( string  prefix,
int  margin 
)
static

returns a formatted text for the HPF independent and new directive well, no continuations and so, but the directives do not fit the unformatted domain, because the directive prolog would not be well managed there.

Definition at line 2989 of file misc.c.

2992 {
2993  int len = strlen(prefix), i;
2994  string result = (string) malloc(strlen(prefix)+margin+1);
2995  strcpy(result, prefix);
2997  for (i=len; margin-->0;) {
2998  result[i++] = ' '; result[i]='\0';
2999  }
3000  }
3001  return result;
3002 }
void * malloc(YYSIZE_T)
char * string
STRING.
Definition: newgen_types.h:39
static const char * prefix

References malloc(), prefix, and prettyprint_language_is_fortran_p().

Referenced by text_directive().

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

◆ mark_block()

static bool mark_block ( unformatted t_beg,
unformatted t_end,
int  n,
int  margin 
)
static

This function returns true if BLOCK boundary markers are required.

The function also creates the maker when needed.

Definition at line 381 of file misc.c.

384  {
385  bool result = false;
386  if(!get_bool_property("PRETTYPRINT_FOR_FORESYS")
387  && (get_bool_property("PRETTYPRINT_ALL_EFFECTS")
388  || get_bool_property("PRETTYPRINT_BLOCKS")))
389  result = true;
390  if(result == true) {
391  list pbeg = NIL;
392  list pend = NIL;
393  // Here we need to generate block markers for later use:
394  switch(get_prettyprint_language_tag()) {
395  case is_language_fortran:
397  // Fortran case: comments at the begin of the line
398  pbeg = CHAIN_SWORD (NIL, "BEGIN BLOCK");
399  pend = CHAIN_SWORD (NIL, "END BLOCK");
401  n,
402  margin,
403  pbeg);
405  n,
406  margin,
407  pend);
408  break;
409  case is_language_c:
410  // C case: comments alligned with blocks:
413  pbeg = CHAIN_SWORD (pbeg, " BEGIN BLOCK");
414  pend = CHAIN_SWORD (pend, " END BLOCK");
415  *t_beg = make_unformatted(NULL, n, margin, pbeg);
416  *t_end = make_unformatted(NULL, n, margin, pend);
417  break;
418  default:
419  pips_internal_error("Language unknown !");
420  break;
421  }
422  }
423  return result;
424 }

References CHAIN_SWORD, get_bool_property(), get_comment_sentinel(), get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, make_unformatted(), NIL, pips_internal_error, and strdup().

Referenced by text_block().

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

◆ null()

static list null ( call __attribute__((unused))  obj,
int __attribute__((unused))  precedence,
bool __attribute__((unused))  leftmost,
list __attribute__((unused)) *  ppdl 
)
static

Definition at line 1772 of file misc.c.

1776 {
1777  return(NIL);
1778 }

References NIL.

◆ one_liner_p()

bool one_liner_p ( statement  s)

True is statement "s" can be printed out without enclosing braces when it is the true branch of a test.

This is a special case because of dangling else clauses. bool one_liner_true_branch_p(statement s) { bool one_p = false; if(!statement_test_p(s)) one_p = one_liner_p(s); else { test t = instruction_test(statement_instruction(s)); statement f = test_false(t); if(!(empty_statement_p(f) || nop_statement_p(f))) one_p = true; // No need to worry, the else clause exists else { // Make sure there is no internal dangling else... one_p = one_liner_test_p(t); } } return one_p; }

True is test "t" contains a non-empty final "else" clause. bool one_liner_test_p(test t) { bool one_liner_p = false; /* We must make sure that the final else clause is not empty *\/ statement f = test_false(t); if(empty_statement_p(f) || nop_statement_p(f)) one_liner_p = false; else if(statement_test_p(f)) { /* Go down recursively for "else if" constructs. *\/ instruction i = statement_instruction(f); test ft = instruction_test(i); one_liner_p = one_liner_test_p(ft); } else one_liner_p = true; return one_liner_p; }

Can this statement be printed on one line, without enclosing braces, if it is embedded in a loop?

Another test must be used if Statement "s" is embedded in a test a a true branch.

There may be many lines hidden behind another block construct when code is generated in a non canonical way as for {{x=1;y=2;}}

OK, we could check deeper, but this is only useful for redundant internal representations. Let's forget about niceties such as skipping useless braces.

Definition at line 301 of file misc.c.

302 {
306  || return_instruction_p(i));
307 
308  yes = yes && ENDP(statement_declarations(s));
309 
310  if(!yes && instruction_sequence_p(i)) {
312  int sc = gen_length(sl);
313 
314  if(sc==1) {
315  /* There may be many lines hidden behind another block construct
316  when code is generated in a non canonical way as for
317  {{x=1;y=2;}} */
319 
320  if(instruction_sequence_p(ii)) {
321  /* OK, we could check deeper, but this is only useful for
322  redundant internal representations. Let's forget about
323  niceties such as skipping useless braces. */
324  yes = false;
325  }
326  else
327  yes = ENDP(statement_declarations(s));
328  }
329  else
330  yes = (sc < 1) && ENDP(statement_declarations(s));
331  }
332 
333  return yes;
334 }
bool return_instruction_p(instruction i)
Test if an instruction is a C or Fortran "return".
Definition: instruction.c:185
#define instruction_sequence_p(x)
Definition: ri.h:1512
#define instruction_loop_p(x)
Definition: ri.h:1518
#define instruction_forloop_p(x)
Definition: ri.h:1536
#define sequence_statements(x)
Definition: ri.h:2360
#define instruction_sequence(x)
Definition: ri.h:1514
#define instruction_call_p(x)
Definition: ri.h:1527
#define statement_declarations(x)
Definition: ri.h:2460
#define instruction_whileloop_p(x)
Definition: ri.h:1521
#define instruction_test_p(x)
Definition: ri.h:1515
#define instruction_goto_p(x)
Definition: ri.h:1524
#define instruction_expression_p(x)
Definition: ri.h:1539
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413

References CAR, ENDP, gen_length(), instruction_call_p, instruction_expression_p, instruction_forloop_p, instruction_goto_p, instruction_loop_p, instruction_sequence, instruction_sequence_p, instruction_test_p, instruction_whileloop_p, return_instruction_p(), sequence_statements, STATEMENT, statement_declarations, and statement_instruction.

Referenced by ensure_comment_consistency(), gcc_if_block_braces_required_p(), text_block_else(), text_block_elseif(), text_block_ifthen(), text_loop_default(), text_trail(), and text_whileloop().

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

◆ pp_style_p()

static bool pp_style_p ( string  s)
static

Definition at line 204 of file misc.c.

204  {
206 }
char * get_string_property(const char *)
#define same_string_p(s1, s2)
#define PRETTYPRINT_PARALLEL

References get_string_property(), PRETTYPRINT_PARALLEL, and same_string_p.

+ Here is the call graph for this function:

◆ register_intrinsic_handler()

void register_intrinsic_handler ( const char *  name,
intrinsic_desc_t desc 
)

after this call, name and desc are owned by intrinsic_handlers, but will never be deallocated they must point to permanent storage

Parameters
nameame
descesc

Definition at line 2517 of file misc.c.

2517  {
2520  }
2521  hash_put(intrinsic_handlers,name,desc);
2522 }

References hash_put(), hash_table_undefined_p, init_intrinsic_handlers(), and intrinsic_handlers.

Referenced by step_analyse_init().

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

◆ renamed_op_handling()

static const char* renamed_op_handling ( const char *  name)
static
Returns
the external string representation of the operator
Parameters
name,thepips internal representation of the operator

Definition at line 1252 of file misc.c.

1252  {
1253  const char* result = name;
1254 
1255  if ( strcmp(result,PLUS_C_OPERATOR_NAME) == 0 )
1256  result = "+";
1257  else if ( strcmp(result, MINUS_C_OPERATOR_NAME) == 0 )
1258  result = "-";
1259  else if ( strcmp(result,BITWISE_AND_OPERATOR_NAME) == 0 )
1260  result = "&";
1261  else if ( strcmp(result,BITWISE_XOR_OPERATOR_NAME) == 0 )
1262  result = "^";
1263  else if ( strcmp(result,C_AND_OPERATOR_NAME) == 0 )
1264  result = "&&";
1265  else if ( strcmp(result,C_NON_EQUAL_OPERATOR_NAME) == 0 )
1266  result = "!=";
1267  else if ( strcmp(result,C_MODULO_OPERATOR_NAME) == 0 )
1268  result = "%";
1269  else if (prettyprint_language_is_c_p()) {
1270  if(strcasecmp(result, GREATER_THAN_OPERATOR_NAME)==0)
1272  else if(strcasecmp(result, LESS_THAN_OPERATOR_NAME)==0)
1274  else if(strcasecmp(result,GREATER_OR_EQUAL_OPERATOR_NAME)==0)
1276  else if(strcasecmp(result,LESS_OR_EQUAL_OPERATOR_NAME)==0)
1278  else if(strcasecmp(result, EQUAL_OPERATOR_NAME) ==0)
1279  result=C_EQUAL_OPERATOR_NAME;
1280  else if(strcasecmp(result,NON_EQUAL_OPERATOR_NAME)==0)
1281  result= "!=";
1282  else if(strcasecmp(result,AND_OPERATOR_NAME)==0)
1283  result="&&";
1284  else if(strcasecmp(result, OR_OPERATOR_NAME)==0)
1285  result=C_OR_OPERATOR_NAME;
1286  }
1287  return result;
1288 }
bool prettyprint_language_is_c_p()
Definition: language.c:91
#define BITWISE_XOR_OPERATOR_NAME
#define C_LESS_OR_EQUAL_OPERATOR_NAME
#define C_AND_OPERATOR_NAME
#define GREATER_THAN_OPERATOR_NAME
#define C_GREATER_OR_EQUAL_OPERATOR_NAME
#define C_GREATER_THAN_OPERATOR_NAME
#define C_MODULO_OPERATOR_NAME
#define LESS_THAN_OPERATOR_NAME
#define EQUAL_OPERATOR_NAME
#define C_NON_EQUAL_OPERATOR_NAME
#define AND_OPERATOR_NAME
FI: intrinsics are defined at a third place after bootstrap and effects! I guess the name should be d...
#define C_LESS_THAN_OPERATOR_NAME
#define GREATER_OR_EQUAL_OPERATOR_NAME
#define MINUS_C_OPERATOR_NAME
#define LESS_OR_EQUAL_OPERATOR_NAME
#define C_OR_OPERATOR_NAME
#define BITWISE_AND_OPERATOR_NAME
#define OR_OPERATOR_NAME
#define NON_EQUAL_OPERATOR_NAME
#define C_EQUAL_OPERATOR_NAME
#define PLUS_C_OPERATOR_NAME

References AND_OPERATOR_NAME, BITWISE_AND_OPERATOR_NAME, BITWISE_XOR_OPERATOR_NAME, C_AND_OPERATOR_NAME, C_EQUAL_OPERATOR_NAME, C_GREATER_OR_EQUAL_OPERATOR_NAME, C_GREATER_THAN_OPERATOR_NAME, C_LESS_OR_EQUAL_OPERATOR_NAME, C_LESS_THAN_OPERATOR_NAME, C_MODULO_OPERATOR_NAME, C_NON_EQUAL_OPERATOR_NAME, C_OR_OPERATOR_NAME, EQUAL_OPERATOR_NAME, GREATER_OR_EQUAL_OPERATOR_NAME, GREATER_THAN_OPERATOR_NAME, LESS_OR_EQUAL_OPERATOR_NAME, LESS_THAN_OPERATOR_NAME, MINUS_C_OPERATOR_NAME, NON_EQUAL_OPERATOR_NAME, OR_OPERATOR_NAME, PLUS_C_OPERATOR_NAME, and prettyprint_language_is_c_p().

Referenced by words_infix_binary_op(), and words_omp_red().

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

◆ reset_alternate_return_set()

void reset_alternate_return_set ( void  )

Definition at line 804 of file misc.c.

805 {
806  ifdebug(1) {
807  pips_assert("The target list is initialized",
809  }
812 }
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69

References gen_free_list(), ifdebug, list_undefined, list_undefined_p, pips_assert, and set_of_labels_required_for_alternate_returns.

Referenced by ensure_comment_consistency(), fprint_statement(), and statement_to_text().

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

◆ reset_prettyprinter_head_hook()

void reset_prettyprinter_head_hook ( void  )

Definition at line 3964 of file misc.c.

3964 { head_hook=NULL;}
static string(* head_hook)(entity)
hook for adding something in the head.
Definition: misc.c:3962

References head_hook.

Referenced by compile_mpi(), and hpfc_print_code().

+ Here is the caller graph for this function:

◆ sentence_goto()

static sentence sentence_goto ( entity  module,
const char *  label,
int  margin,
statement  obj,
int  n 
)
static

Definition at line 2797 of file misc.c.

2801  {
2802  const char* tlabel = entity_local_name(statement_label(obj)) +
2803  sizeof(LABEL_PREFIX) -1;
2804  pips_assert("Legal label required", strlen(tlabel)!=0);
2805  return sentence_goto_label(module, label, margin, tlabel, n);
2806 }
#define LABEL_PREFIX
Definition: naming-local.h:31
sentence sentence_goto_label(entity __attribute__((unused)) module, const char *label, int margin, const char *tlabel, int n)
exported for unstructured.c
Definition: misc.c:2784
#define statement_label(x)
Definition: ri.h:2450

References entity_local_name(), LABEL_PREFIX, module, pips_assert, sentence_goto_label(), and statement_label.

Referenced by text_instruction().

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

◆ sentence_goto_label()

sentence sentence_goto_label ( entity __attribute__((unused))  module,
const char *  label,
int  margin,
const char *  tlabel,
int  n 
)

exported for unstructured.c

Definition at line 2784 of file misc.c.

2790 {
2791  list pc = words_goto_label(tlabel);
2792 
2794  make_unformatted(label?strdup(label):NULL, n, margin, pc)));
2795 }
list words_goto_label(const char *tlabel)
This function is useful only for parsed codes since gotos are removed by the controlizer.
Definition: misc.c:1917

References is_sentence_unformatted, make_sentence(), make_unformatted(), strdup(), and words_goto_label().

Referenced by sentence_goto(), text_io_block_if(), and text_trail().

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

◆ sentence_tail()

static sentence sentence_tail ( entity  e)
static

In fortran 95, we want the end to be followed by the type of construct and its name.

Definition at line 2710 of file misc.c.

2711 {
2712  sentence result = sentence_undefined;
2713  switch(get_prettyprint_language_tag()) {
2714  case is_language_fortran:
2715  result = MAKE_ONE_WORD_SENTENCE(0, "END");
2716  break;
2717  case is_language_c:
2718  result = MAKE_ONE_WORD_SENTENCE(0, "}");
2719  break;
2720  case is_language_fortran95: {
2721  /* In fortran 95, we want the end to be followed by the type of construct
2722  * and its name.
2723  */
2724  list pc = NIL;
2725  type te = entity_type(e);
2726  functional fe;
2727  type tr;
2728 
2729  pc = CHAIN_SWORD(pc,"END ");
2730 
2731  pips_assert("is functionnal", type_functional_p(te));
2732 
2733  if (static_module_p(e))
2734  pc = CHAIN_SWORD(pc,"static ");
2735 
2736  fe = type_functional(te);
2737  tr = functional_result(fe);
2738 
2739  switch(type_tag(tr)) {
2740  case is_type_void:
2741  if (entity_main_module_p(e))
2742  pc = CHAIN_SWORD(pc,"PROGRAM ");
2743  else {
2744  if (entity_blockdata_p(e))
2745  pc = CHAIN_SWORD(pc, "BLOCKDATA ");
2746  else if (entity_f95module_p(e))
2747  pc = CHAIN_SWORD(pc, "MODULE ");
2748  else
2749  pc = CHAIN_SWORD(pc,"SUBROUTINE ");
2750  }
2751  break;
2752  case is_type_variable: {
2753  pc = CHAIN_SWORD(pc,"FUNCTION ");
2754  break;
2755  }
2756  case is_type_unknown:
2757  /*
2758  * For C functions with no return type.
2759  * It can be treated as of type int, but we keep it unknown
2760  * for the moment, to make the differences and to regenerate initial code
2761  */
2762  break;
2763  default:
2764  pips_internal_error("unexpected type for result");
2765  }
2766 
2767  pc = CHAIN_SWORD(pc, entity_user_name(e));
2769  0,
2770  0,
2771  pc));
2772  break;
2773  }
2774  default:
2775  pips_internal_error("Language unknown !");
2776  break;
2777  }
2778 
2779  return result;
2780 }
bool entity_main_module_p(entity e)
Definition: entity.c:700
bool entity_blockdata_p(entity e)
Definition: entity.c:712
bool entity_f95module_p(entity e)
Definition: entity.c:707
bool static_module_p(entity e)
Check if the given module entity is a static module.
Definition: module.c:80
#define type_functional_p(x)
Definition: ri.h:2950
#define functional_result(x)
Definition: ri.h:1444
#define type_tag(x)
Definition: ri.h:2940
#define type_functional(x)
Definition: ri.h:2952
@ is_type_void
Definition: ri.h:2904
@ is_type_variable
Definition: ri.h:2900
@ is_type_unknown
Definition: ri.h:2903

References CHAIN_SWORD, entity_blockdata_p(), entity_f95module_p(), entity_main_module_p(), entity_type, entity_user_name(), functional_result, get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, is_sentence_unformatted, is_type_unknown, is_type_variable, is_type_void, MAKE_ONE_WORD_SENTENCE, make_sentence(), make_unformatted(), NIL, pips_assert, pips_internal_error, sentence_undefined, static_module_p(), type_functional, type_functional_p, and type_tag.

Referenced by ensure_comment_consistency().

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

◆ set_alternate_return_set()

void set_alternate_return_set ( void  )

Definition at line 795 of file misc.c.

796 {
797  ifdebug(1) {
798  pips_assert("The target list is undefined",
800  }
802 }

References ifdebug, list_undefined_p, NIL, pips_assert, and set_of_labels_required_for_alternate_returns.

Referenced by ensure_comment_consistency(), fprint_statement(), and statement_to_text().

+ Here is the caller graph for this function:

◆ set_prettyprinter_head_hook()

void set_prettyprinter_head_hook ( string(*)(entity f)

Definition at line 3963 of file misc.c.

3963 { head_hook=f;}
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15

References f(), and head_hook.

Referenced by compile_mpi(), and hpfc_print_code().

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

◆ test_with_dangling_else_p()

static bool test_with_dangling_else_p ( test  t)
static

Some code shared by text_block_if and text_block_ifthen.

Do we have a test as a true branch, a test with no else clause?

Definition at line 3588 of file misc.c.

3589 {
3590  statement fb = test_false(t);
3591  bool outer_else_p = !nop_statement_p(fb); // obj contains a non-empty else clause
3592  /* Do we have a test as a true branch, a test with no else clause? */
3594  bool inner_test_p = statement_test_p(ts);
3595  bool inner_else_p = inner_test_p?
3597  bool dangling_else_p = inner_test_p && outer_else_p && !inner_else_p;
3598 
3599  return dangling_else_p;
3600 }
bool nop_statement_p(statement)
Definition: statement.c:407
#define false
Definition: newgen_types.h:80
static bool test_with_no_else_clause_p(test t)
Definition: misc.c:3572

References effective_test_true(), nop_statement_p(), statement_test(), statement_test_p(), test_false, and test_with_no_else_clause_p().

Referenced by text_block_ifthen().

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

◆ test_with_no_else_clause_p()

static bool test_with_no_else_clause_p ( test  t)
static

Definition at line 3572 of file misc.c.

3573 {
3574  bool no_else_p = true;
3576  no_else_p = false;
3577  else {
3578  statement fs = test_false(t);
3579  if(statement_test_p(fs)) // Go down recursively
3580  no_else_p = test_with_no_else_clause_p(statement_test(fs));
3581  else
3582  no_else_p = true;
3583  }
3584  return no_else_p;
3585 }

References empty_statement_p(), statement_test(), statement_test_p(), and test_false.

Referenced by test_with_dangling_else_p().

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

◆ text_block()

static text text_block ( entity  module,
const char *  label,
int  margin,
list  objs,
int  n,
list ppdl 
)
static

Build the text of a code block (a list of statements)

@module is the module entity the code to display belong to

@label is the label associated to the block

Parameters
marginis the indentation level
objsis the list of statements in the sequence to display
nis the statement number of the sequence

@pdl is the parser declaration list to track type declaration display in C

Returns
the text of the block

"Unformatted" to be added at the beginning and at the end of a block:

Since we generate new { }, we increment the margin for the nested statements:

Now begin block markers and declarations have been printed, so print the block instructions:

Get back to previous indentation:

Definition at line 2826 of file misc.c.

2832 {
2833  text r = make_text(NIL);
2834 
2835  if (ENDP(objs)
2836  && ! (get_bool_property("PRETTYPRINT_EMPTY_BLOCKS")
2837  || get_bool_property("PRETTYPRINT_ALL_C_BLOCKS")))
2838  return(r);
2839 
2840  if(!empty_string_p(label)) {
2841  pips_user_warning("Illegal label \"%s\". "
2842  "Blocks cannot carry a label\n",
2843  label);
2844  }
2845 
2846  /* "Unformatted" to be added at the beginning and at the end of a block: */
2847  unformatted bm_beg = NULL;
2848  unformatted bm_end = NULL;
2849  // Test if block markers are required and set them:
2850  bool flg_marker = mark_block(&bm_beg, &bm_end, n, margin);
2851 
2852  // Print the begin block marker(s) if needed:
2853  if (flg_marker == true)
2855  else if ((get_bool_property("PRETTYPRINT_ALL_EFFECTS")
2856  || get_bool_property("PRETTYPRINT_BLOCKS"))
2857  && get_bool_property("PRETTYPRINT_FOR_FORESYS"))
2859  strdup("C$BB\n")));
2860 
2861  if (get_bool_property("PRETTYPRINT_ALL_C_BLOCKS")) {
2862  /* Since we generate new { }, we increment the margin for the nested
2863  statements: */
2864  margin -= INDENTATION;
2865  if (margin < 0)
2866  margin = 0;
2867  ADD_SENTENCE_TO_TEXT(r, MAKE_ONE_WORD_SENTENCE(margin, "{{"));
2868  margin += INDENTATION;
2869  }
2870 
2871  // Append local variables if any:
2872  r = insert_locals (r);
2873 
2874  /* Now begin block markers and declarations have been printed, so print
2875  the block instructions: */
2876  for (; objs != NIL; objs = CDR(objs)) {
2877  statement s = STATEMENT(CAR(objs));
2878 
2879  text t = text_statement_enclosed(module, margin, s, false, true, ppdl);
2881  text_sentences(t) = NIL;
2882  free_text(t);
2883  }
2884 
2885  if (get_bool_property("PRETTYPRINT_ALL_C_BLOCKS")) {
2886  /* Get back to previous indentation: */
2887  margin -= INDENTATION;
2888  ADD_SENTENCE_TO_TEXT(r, MAKE_ONE_WORD_SENTENCE(margin, "}}"));
2889  margin += INDENTATION;
2890  }
2891 
2892  // Print the end block marker(s) if needed:
2893  if (flg_marker == true)
2895 
2896  return r;
2897 }
void free_text(text p)
Definition: text.c:74
bool empty_string_p(const char *s)
Definition: entity_names.c:239
static text insert_locals(text r)
This function either appends the declaration to the text given as a parameter or return a new text wi...
Definition: misc.c:363
static bool mark_block(unformatted *t_beg, unformatted *t_end, int n, int margin)
This function returns true if BLOCK boundary markers are required.
Definition: misc.c:381
text text_statement_enclosed(entity, int, statement, bool, bool, list *)
#define text_sentences(x)
Definition: text.h:113

References ADD_SENTENCE_TO_TEXT, CAR, CDR, empty_string_p(), ENDP, free_text(), gen_nconc(), get_bool_property(), INDENTATION, insert_locals(), is_sentence_formatted, is_sentence_unformatted, MAKE_ONE_WORD_SENTENCE, make_sentence(), make_text(), mark_block(), module, NIL, pips_user_warning, STATEMENT, strdup(), text_sentences, and text_statement_enclosed().

Referenced by text_instruction().

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

◆ text_block_else()

static text text_block_else ( entity  module,
const char *label   __attribute__(unused),
int  margin,
statement  stmt,
int n   __attribute__(unused),
list ppdl 
)
static

Definition at line 3664 of file misc.c.

3670 {
3671  text r = make_text(NIL);
3672 
3675  (empty_statement_p(stmt) && ( get_bool_property("PRETTYPRINT_EMPTY_BLOCKS") )) ||
3676  (continue_statement_p(stmt) && ( get_bool_property("PRETTYPRINT_ALL_LABELS") ))
3677  )
3678  {
3679  switch (get_prettyprint_language_tag()) {
3680  case is_language_fortran:
3681  case is_language_fortran95:
3682  ADD_SENTENCE_TO_TEXT(r, MAKE_ONE_WORD_SENTENCE(margin, "ELSE"));
3683  MERGE_TEXTS(r, text_statement(module, margin+INDENTATION, stmt, ppdl));
3684  break;
3685  case is_language_c:
3687  ADD_SENTENCE_TO_TEXT(r, MAKE_ONE_WORD_SENTENCE(margin,"else"));
3689  margin+INDENTATION,
3690  stmt,
3691  false,
3692  false,
3693  ppdl));
3694  } else {
3695  ADD_SENTENCE_TO_TEXT(r, MAKE_ONE_WORD_SENTENCE(margin, "else {"));
3696  MERGE_TEXTS(r, text_statement(module, margin+INDENTATION, stmt, ppdl));
3698  }
3699  break;
3700  default:
3701  pips_internal_error("Language unknown !");
3702  break;
3703  }
3704  }
3705 
3706  ifdebug(8) {
3707  fprintf(stderr, "else=================================\n");
3708  print_text(stderr, r);
3709  fprintf(stderr, "==============================\n");
3710  }
3711  return r;
3712 }
bool continue_statement_p(statement)
Test if a statement is a CONTINUE, that is the FORTRAN nop, the ";" in C or the "pass" in Python....
Definition: statement.c:203
bool statement_with_empty_comment_p(statement)
Return true if the statement has an empty statement:
Definition: statement.c:126
static bool prettyprint_all_c_braces_p
This variable is used to print braces around all blocks including blocks with only one statement.
Definition: misc.c:197
text text_statement(entity, int, statement, list *)
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
Definition: statement.c:54
void print_text(FILE *fd, text t)
Definition: print.c:195

References ADD_SENTENCE_TO_TEXT, continue_statement_p(), empty_statement_p(), fprintf(), get_bool_property(), get_prettyprint_language_tag(), ifdebug, INDENTATION, is_language_c, is_language_fortran, is_language_fortran95, MAKE_ONE_WORD_SENTENCE, make_text(), MERGE_TEXTS, module, NIL, one_liner_p(), pips_internal_error, prettyprint_all_c_braces_p, print_text(), statement_with_empty_comment_p(), text_statement(), and text_statement_enclosed().

Referenced by text_block_elseif(), and text_block_if().

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

◆ text_block_elseif()

static text text_block_elseif ( entity  module,
const char *  label,
int  margin,
test  obj,
int  n,
list ppdl 
)
static

Definition at line 3715 of file misc.c.

3720  {
3721  text r = make_text(NIL);
3722  list pc = NIL;
3723  statement tb = test_true(obj);
3724  statement fb = test_false(obj);
3725  bool braces_p = !one_liner_p(tb) || prettyprint_all_c_braces_p;
3726 
3727  switch (get_prettyprint_language_tag()) {
3728  case is_language_fortran:
3729  case is_language_fortran95:
3730  pc = CHAIN_SWORD(pc, strdup("ELSEIF ("));
3731  pc = gen_nconc(pc, words_expression(test_condition(obj), ppdl));
3732  pc = CHAIN_SWORD(pc, strdup(") THEN"));
3733  break;
3734  case is_language_c:
3735  pc = CHAIN_SWORD(pc, strdup("else if ("));
3736  pc = gen_nconc(pc, words_expression(test_condition(obj), ppdl));
3737  pc = CHAIN_SWORD(pc, (!braces_p?")":") {"));
3738  break;
3739  default:
3740  pips_internal_error("Language unknown !");
3741  break;
3742  }
3743 
3746  make_unformatted(strdup(label), n,
3747  margin, pc)));
3748 
3750  margin+INDENTATION,
3751  tb,
3752  braces_p,
3753  braces_p,
3754  ppdl));
3755 
3757  && braces_p) {
3759  }
3760 
3765  margin,
3766  statement_test(fb), n, ppdl));
3767 
3768  } else {
3769  MERGE_TEXTS(r, text_block_else(module, label, margin, fb, n, ppdl));
3770  }
3771 
3772  ifdebug(8) {
3773  fprintf(stderr, "elseif=================================\n");
3774  print_text(stderr, r);
3775  fprintf(stderr, "==============================\n");
3776  }
3777  return (r);
3778 }
bool empty_comments_p(const char *)
Definition: statement.c:107
static text text_block_elseif(entity module, const char *label, int margin, test obj, int n, list *ppdl)
Definition: misc.c:3715
static text text_block_else(entity module, const char *label __attribute__((unused)), int margin, statement stmt, int n __attribute__((unused)), list *ppdl)
Definition: misc.c:3664
bool entity_empty_label_p(entity e)
Definition: entity.c:666
#define test_true(x)
Definition: ri.h:2835
#define test_condition(x)
Definition: ri.h:2833
#define statement_comments(x)
Definition: ri.h:2456

References ADD_SENTENCE_TO_TEXT, CHAIN_SWORD, empty_comments_p(), entity_empty_label_p(), fprintf(), gen_nconc(), get_prettyprint_language_tag(), ifdebug, INDENTATION, is_language_c, is_language_fortran, is_language_fortran95, is_sentence_unformatted, label_local_name(), MAKE_ONE_WORD_SENTENCE, make_sentence(), make_text(), make_unformatted(), MERGE_TEXTS, module, NIL, one_liner_p(), pips_internal_error, prettyprint_all_c_braces_p, prettyprint_language_is_c_p(), print_text(), statement_comments, statement_label, statement_test(), statement_test_p(), strdup(), test_condition, test_false, test_true, text_block_else(), text_statement_enclosed(), and words_expression().

Referenced by text_block_if().

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

◆ text_block_if()

static text text_block_if ( entity  module,
const char *  label,
int  margin,
test  obj,
int  n,
list ppdl,
bool  is_recursive_p 
)
static

Prettyprint the condition, the true and, possibly, the false branch.

Manage redundant braces in C according to either the standard, or gcc guidelines or a request to print them all.

Brace management is a bit complex because the clausing brace of the true block may be printed with the else branch or as a final brace when the else branch is empty.

Braces are now managed by text_block_ifthen, text_block_elseif or text_block_else to factorize the work and facilitate the engineering. A difference on the output code can be to not put "}" and else in the same line?

Prettyprint the true branch

Prettyprint the false branch if it is useful

one test in the false branch => "ELSEIF" Fortran block or "else if" C construct

Prettyprint the closing of the test

management of braces are take into account inside text_block_ifthen text_block_elseif text_block_else

Definition at line 3795 of file misc.c.

3802 {
3803  text r = make_text(NIL);
3804 
3805  /* Prettyprint the true branch */
3806  r = text_block_ifthen(module, label, margin, obj, n, ppdl, is_recursive_p);
3807 
3808  if(is_recursive_p) {
3809  /* Prettyprint the false branch if it is useful */
3810  statement test_false_obj = test_false(obj);
3811  if(statement_undefined_p(test_false_obj)) {
3812  pips_internal_error("undefined statement");
3813  }
3814  /* one test in the false branch => "ELSEIF" Fortran block
3815  * or "else if" C construct */
3816  else if (statement_test_p(test_false_obj)
3817  && empty_comments_p(statement_comments(test_false_obj))
3818  && entity_empty_label_p(statement_label(test_false_obj))
3819  && !get_bool_property("PRETTYPRINT_BLOCK_IF_ONLY")) {
3820  MERGE_TEXTS(r,
3822  label_local_name(statement_label(test_false_obj)),
3823  margin, statement_test(test_false_obj), n, ppdl));
3824  }
3825  else {
3826  MERGE_TEXTS(r,
3827  text_block_else(module, label, margin, test_false_obj, n, ppdl));
3828  }
3829 
3830  /* Prettyprint the closing of the test */
3831  switch (get_prettyprint_language_tag()) {
3832  case is_language_fortran:
3833  case is_language_fortran95:
3834  ADD_SENTENCE_TO_TEXT(r, MAKE_ONE_WORD_SENTENCE(margin,strdup("ENDIF")));
3835  break;
3836  case is_language_c:
3837  //nothing to do in C
3838  /* management of braces are take into account inside
3839  * text_block_ifthen
3840  * text_block_elseif
3841  * text_block_else
3842  */
3843  break;
3844  default:
3845  pips_internal_error("Language unknown !");
3846  break;
3847  }
3848  }
3849 
3850  ifdebug(8) {
3851  fprintf(stderr, "text_block_if=================================\n");
3852  print_text(stderr, r);
3853  fprintf(stderr, "==============================\n");
3854  }
3855  return (r);
3856 }
static text text_block_ifthen(entity module, const char *label, int margin, test obj, int n, list *ppdl, bool is_recursive_p)
Prettyprint if clause of a test.
Definition: misc.c:3603
#define statement_undefined_p(x)
Definition: ri.h:2420

References ADD_SENTENCE_TO_TEXT, empty_comments_p(), entity_empty_label_p(), fprintf(), get_bool_property(), get_prettyprint_language_tag(), ifdebug, is_language_c, is_language_fortran, is_language_fortran95, label_local_name(), MAKE_ONE_WORD_SENTENCE, make_text(), MERGE_TEXTS, module, NIL, pips_internal_error, print_text(), statement_comments, statement_label, statement_test(), statement_test_p(), statement_undefined_p, strdup(), test_false, text_block_else(), text_block_elseif(), and text_block_ifthen().

Referenced by text_test().

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

◆ text_block_ifthen()

static text text_block_ifthen ( entity  module,
const char *  label,
int  margin,
test  obj,
int  n,
list ppdl,
bool  is_recursive_p 
)
static

Prettyprint if clause of a test.

Definition at line 3603 of file misc.c.

3609  {
3610  text r = make_text(NIL);
3611  list pc = NIL;
3612  statement tb = test_true(obj);
3613  bool one_liner_true_statement_p = one_liner_p(tb);
3614  bool dangling_else_p = test_with_dangling_else_p(obj);
3615  bool gcc_braces_p = gcc_if_block_braces_required_p(obj);
3616  bool braces_p =
3617  !one_liner_true_statement_p // several statement in the true branch
3618  || prettyprint_all_c_braces_p // use request for braces
3619  || dangling_else_p // else clause would be associated to the wrong if
3620  || gcc_braces_p; // gcc warning [-Wparentheses]
3621 
3622  switch (get_prettyprint_language_tag()) {
3623  case is_language_fortran:
3624  case is_language_fortran95:
3625  pc = CHAIN_SWORD(pc, "IF (");
3626  pc = gen_nconc(pc, words_expression(test_condition(obj), ppdl));
3627  pc = CHAIN_SWORD(pc, ") THEN");
3628  break;
3629  case is_language_c:
3630  pc = CHAIN_SWORD(pc, "if (");
3631  pc = gen_nconc(pc, words_expression(test_condition(obj), ppdl));
3632  pc = CHAIN_SWORD(pc, (!braces_p?")":") {"));
3633  break;
3634  default:
3635  pips_internal_error("Language unknown !");
3636  break;
3637  }
3638 
3641  make_unformatted(strdup(label), n,
3642  margin, pc)));
3643  if(is_recursive_p) {
3645  margin+INDENTATION,
3646  tb,
3647  braces_p,
3648  braces_p,
3649  ppdl));
3651  && braces_p)
3653  }
3654 
3655  ifdebug(8) {
3656  fprintf(stderr, "if=================================\n");
3657  print_text(stderr, r);
3658  fprintf(stderr, "==============================\n");
3659  }
3660  return (r);
3661 }
bool gcc_if_block_braces_required_p(test obj)
Definition: misc.c:336
static bool test_with_dangling_else_p(test t)
Some code shared by text_block_if and text_block_ifthen.
Definition: misc.c:3588

References ADD_SENTENCE_TO_TEXT, CHAIN_SWORD, fprintf(), gcc_if_block_braces_required_p(), gen_nconc(), get_prettyprint_language_tag(), ifdebug, INDENTATION, is_language_c, is_language_fortran, is_language_fortran95, is_sentence_unformatted, MAKE_ONE_WORD_SENTENCE, make_sentence(), make_text(), make_unformatted(), MERGE_TEXTS, module, NIL, one_liner_p(), pips_internal_error, prettyprint_all_c_braces_p, prettyprint_language_is_c_p(), print_text(), strdup(), test_condition, test_true, test_with_dangling_else_p(), text_statement_enclosed(), and words_expression().

Referenced by text_block_if().

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

◆ text_directive()

static text text_directive ( loop  obj,
int  margin,
string  basic_directive,
string  basic_continuation,
string  parallel,
list ppdl 
)
static

???

of string

start buffer

what about reductions? should be associated to the ri somewhere.

Parameters
marginthe loop we're interested in

Definition at line 3005 of file misc.c.

3010  {
3011  string dir = marged(basic_directive, margin), cont =
3012  marged(basic_continuation, margin);
3013  text t = make_text(NIL);
3014  char buffer[100]; /* ??? */
3015  list /* of string */l = NIL;
3016  bool is_hpf = pp_hpf_style_p(), is_omp = pp_omp_style_p();
3017  bool space_p = get_bool_property("PRETTYPRINT_LISTS_WITH_SPACES");
3018 
3019  /* start buffer */
3020  buffer[0] = '\0';
3021 
3023  add_to_current_line(buffer, dir, cont, t);
3024  add_to_current_line(buffer, parallel, cont, t);
3025  l = loop_private_variables(obj, ppdl);
3026  if (l && is_hpf)
3027  add_to_current_line(buffer, space_p ? ", " : ",", cont, t);
3028  } else if (get_bool_property("PRETTYPRINT_ALL_PRIVATE_VARIABLES")) {
3029  l = loop_private_variables(obj, ppdl);
3030  if (l) {
3031  add_to_current_line(buffer, dir, cont, t);
3032  if (is_omp) {
3033  switch (get_prettyprint_language_tag()) {
3034  case is_language_fortran:
3035  case is_language_fortran95:
3036  add_to_current_line(buffer, "DO ", cont, t);
3037  break;
3038  case is_language_c:
3039  add_to_current_line(buffer, "for ", cont, t);
3040  break;
3041  default:
3042  pips_internal_error("Language unknown !");
3043  break;
3044  }
3045  }
3046  }
3047  }
3048 
3049  if (strlen(buffer) > 0)
3050  MAP(STRING, s, add_to_current_line(buffer, s, cont, t), l);
3051 
3052  /* what about reductions? should be associated to the ri somewhere.
3053  */
3054 
3055  close_current_line(buffer, t, cont);
3056  free(dir);
3057  free(cont);
3058  return t;
3059 }
#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
static string marged(string prefix, int margin)
returns a formatted text for the HPF independent and new directive well, no continuations and so,...
Definition: misc.c:2989
static list loop_private_variables(loop obj, list *ppdl)
of string
Definition: misc.c:2906
#define loop_execution(x)
Definition: ri.h:1648
#define execution_parallel_p(x)
Definition: ri.h:1211
void close_current_line(string, text, string)
Definition: util.c:235
void add_to_current_line(string, const char *, string, text)
Definition: util.c:140

References add_to_current_line(), buffer, close_current_line(), execution_parallel_p, free(), get_bool_property(), get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, loop_execution, loop_private_variables(), make_text(), MAP, marged(), NIL, pips_internal_error, pp_hpf_style_p, pp_omp_style_p, and STRING.

Referenced by text_hpf_directive(), and text_omp_directive().

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

◆ text_forloop()

static text text_forloop ( entity  module,
const char *  label,
int  margin,
forloop  obj,
int  n,
list ppdl,
bool  is_recursive_p 
)
static

Referenced by ensure_comment_consistency(), and text_instruction().

+ Here is the caller graph for this function:

◆ text_hpf_directive()

static text text_hpf_directive ( loop  l,
int  m 
)
static

Definition at line 3066 of file misc.c.

3067 {
3068  list pdl = NIL; // pdl is useless in Fortran
3070  HPF_INDEPENDENT, &pdl);
3071  return t;
3072 }
static text text_directive(loop obj, int margin, string basic_directive, string basic_continuation, string parallel, list *ppdl)
Definition: misc.c:3005
#define HPF_INDEPENDENT
Definition: misc.c:3064
#define HPF_CONTINUATION
Definition: misc.c:3063
#define HPF_DIRECTIVE
Definition: misc.c:3062

References HPF_CONTINUATION, HPF_DIRECTIVE, HPF_INDEPENDENT, NIL, and text_directive().

Referenced by text_loop_default().

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

◆ text_instruction()

static text text_instruction ( entity  module,
const char *  label,
int  margin,
instruction  obj,
int  n,
list ppdl,
bool  is_recursive_p 
)
static

FI: in C at least, this has already been decided by the caller, text_statement_enclosed(); but apparently not in Fortran. Also, the source code may be in Fortran, but the user wants it prettyprinted as C.

Definition at line 3966 of file misc.c.

3972  {
3973  text r = text_undefined;
3974 
3975  switch(instruction_tag(obj)) {
3976  case is_instruction_block: {
3977  r = text_block(module, label, margin, instruction_block(obj), n, ppdl);
3978  break;
3979  }
3980  case is_instruction_test: {
3981  r = text_test(module, label, margin, instruction_test(obj), n, ppdl, is_recursive_p);
3982  break;
3983  }
3984  case is_instruction_loop: {
3985  r = text_loop(module, label, margin, instruction_loop(obj), n, ppdl, is_recursive_p);
3986  break;
3987  }
3988  case is_instruction_whileloop: {
3989  r = text_whileloop(module,
3990  label,
3991  margin,
3992  instruction_whileloop(obj),
3993  n,
3994  ppdl,
3995  is_recursive_p);
3996  break;
3997  }
3998  case is_instruction_goto: {
3999  r = make_text(CONS(SENTENCE,
4000  sentence_goto(module, label, margin,
4001  instruction_goto(obj), n), NIL));
4002  break;
4003  }
4004  case is_instruction_call: {
4005  unformatted u;
4006  sentence s;
4007  /* FI: in C at least, this has already been decided by the
4008  caller, text_statement_enclosed(); but apparently not in
4009  Fortran. Also, the source code may be in Fortran, but the
4010  user wants it prettyprinted as C. */
4012  && instruction_continue_p(obj) && empty_string_p(label)
4013  && !get_bool_property("PRETTYPRINT_ALL_LABELS")) {
4014  pips_debug(5, "useless Fortran CONTINUE not printed\n");
4015  r = make_text(NIL);
4016  } else {
4017  switch (get_prettyprint_language_tag()) {
4018  case is_language_fortran:
4019  case is_language_fortran95:
4020  u = make_unformatted(strdup(label),
4021  n,
4022  margin,
4024  0,
4025  true,
4026  true,
4027  ppdl));
4028  break;
4029  case is_language_c:
4030  u = make_unformatted(strdup(label),
4031  n,
4032  margin,
4034  0, true, true, ppdl),
4036  break;
4037  default:
4038  pips_internal_error("Language unknown !");
4040  break;
4041  }
4043  r = make_text(CONS(SENTENCE, s, NIL));
4044  }
4045  break;
4046  }
4048  // append local variables if there is some.
4049  // local variable need to be inserted before diging the
4050  // unstructured graph.
4051  r = insert_locals(r);
4052 
4053  text tmp = text_undefined;
4054  tmp = text_unstructured(module,
4055  label,
4056  margin,
4058  n,
4059  ppdl);
4060 
4061  // append the unstructured to the current text if it exists
4062  if ((r != text_undefined) && (r != NULL)) {
4063  MERGE_TEXTS (r, tmp);
4064  } else {
4065  r = tmp;
4066  }
4067 
4068  break;
4069  }
4070  case is_instruction_forloop: {
4071  r = text_forloop(module, label, margin, instruction_forloop(obj), n, ppdl, is_recursive_p);
4072  break;
4073  }
4075  list pc = words_expression(instruction_expression(obj), ppdl);
4076  unformatted u;
4078  u = make_unformatted(strdup(label), n, margin, pc);
4079  r = make_text(CONS(SENTENCE,
4081  NIL));
4082  break;
4083  }
4084  default: {
4085  pips_internal_error("unexpected tag");
4086  }
4087  }
4088  return (r);
4089 }
bool instruction_continue_p(instruction i)
Test if an instruction is a CONTINUE, that is the FORTRAN nop, the ";" in C or the "pass" in Python....
Definition: instruction.c:173
static text text_block(entity module, const char *label, int margin, list objs, int n, list *ppdl)
Build the text of a code block (a list of statements)
Definition: misc.c:2826
text text_loop(entity module, const char *label, int margin, loop obj, int n, list *ppdl, bool is_recursive_p)
exported for conversion/look_for_nested_loops.c
Definition: misc.c:3264
static sentence sentence_goto(entity module, const char *label, int margin, statement obj, int n)
Definition: misc.c:2797
static text text_test(entity module, const char *label, int margin, test obj, int n, list *ppdl, bool is_recursive_p)
Definition: misc.c:3913
list words_call(call obj, int precedence, bool leftmost, bool is_a_subroutine, list *ppdl)
exported for cmfortran.c
Definition: misc.c:2575
static text text_whileloop(entity module, const char *label, int margin, whileloop obj, int n, list *ppdl, bool is_recursive_p)
Definition: misc.c:3341
static text text_forloop(entity module, const char *label, int margin, forloop obj, int n, list *ppdl, bool is_recursive_p)
text text_unstructured(entity, const char *, int, unstructured, int, list *)
unstructured.c
Definition: unstructured.c:55
#define C_STATEMENT_END_STRING
#define is_instruction_block
soft block->sequence transition
#define instruction_block(i)
#define instruction_loop(x)
Definition: ri.h:1520
#define instruction_goto(x)
Definition: ri.h:1526
@ is_instruction_goto
Definition: ri.h:1473
@ is_instruction_unstructured
Definition: ri.h:1475
@ is_instruction_whileloop
Definition: ri.h:1472
@ is_instruction_expression
Definition: ri.h:1478
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_forloop
Definition: ri.h:1477
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511
#define instruction_forloop(x)
Definition: ri.h:1538
#define instruction_expression(x)
Definition: ri.h:1541
#define instruction_whileloop(x)
Definition: ri.h:1523
#define instruction_call(x)
Definition: ri.h:1529
#define instruction_test(x)
Definition: ri.h:1517
#define instruction_unstructured(x)
Definition: ri.h:1532
#define unformatted_undefined
Definition: text.h:123

References C_CONTINUE_FUNCTION_NAME, C_STATEMENT_END_STRING, CHAIN_SWORD, CONS, empty_string_p(), get_bool_property(), get_prettyprint_language_tag(), insert_locals(), instruction_block, instruction_call, instruction_continue_p(), instruction_expression, instruction_forloop, instruction_goto, instruction_loop, instruction_tag, instruction_test, instruction_unstructured, instruction_whileloop, is_instruction_block, is_instruction_call, is_instruction_expression, is_instruction_forloop, is_instruction_goto, is_instruction_loop, is_instruction_test, is_instruction_unstructured, is_instruction_whileloop, is_language_c, is_language_fortran, is_language_fortran95, is_sentence_unformatted, make_sentence(), make_text(), make_unformatted(), MERGE_TEXTS, module, NIL, pips_debug, pips_internal_error, prettyprint_language_is_fortran_p(), SENTENCE, sentence_goto(), strdup(), text_block(), text_forloop(), text_loop(), text_test(), text_undefined, text_unstructured(), text_whileloop(), unformatted_undefined, words_call(), and words_expression().

+ Here is the call graph for this function:

◆ text_io_block_if()

static text text_io_block_if ( entity  module,
const char *  label,
int  margin,
test  obj,
int  n,
list ppdl 
)
static

Definition at line 3859 of file misc.c.

3864  {
3865  text r = make_text(NIL);
3866  list pc = NIL;
3867 
3868  if (!empty_statement_p(test_true(obj))) {
3870  char* strglab= label_local_name + 1;
3871 
3872  r = make_text(CONS(SENTENCE,
3873  sentence_goto_label(module, label, margin,
3874  strglab, n),
3875  NIL));
3876 
3879  make_unformatted(strdup(label), n,
3880  margin, pc)));
3881  MERGE_TEXTS(r, text_statement(module, margin,
3882  test_true(obj), ppdl));
3883  string str = string_undefined;
3884  switch (get_prettyprint_language_tag()) {
3885  case is_language_fortran:
3887  break;
3888  case is_language_c:
3890  break;
3891  case is_language_fortran95:
3892  pips_internal_error("Need to update F95 case");
3893  break;
3894  default:
3895  pips_internal_error("Language unknown !");
3896  break;
3897  }
3898 
3900  make_unformatted(strdup(strglab), n, margin,
3901  CONS(STRING, str, NIL))));
3903  }
3904 
3905  if (!empty_statement_p(test_false(obj)))
3906  MERGE_TEXTS(r, text_statement(module, margin,
3907  test_false(obj), ppdl));
3908 
3909  return (r);
3910 }
char * new_label_local_name(entity module)
Definition: entity.c:326

References ADD_SENTENCE_TO_TEXT, C_CONTINUE_FUNCTION_NAME, CONS, CONTINUE_FUNCTION_NAME, empty_statement_p(), free(), get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, is_sentence_unformatted, label_local_name(), make_sentence(), make_text(), make_unformatted(), MERGE_TEXTS, module, new_label_local_name(), NIL, pips_internal_error, SENTENCE, sentence_goto_label(), strdup(), STRING, string_undefined, test_false, test_true, and text_statement().

Referenced by text_test().

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

◆ text_logical_if()

static text text_logical_if ( entity __attribute__((unused))  module,
const char *  label,
int  margin,
test  obj,
int  n,
list ppdl,
bool  is_recursive_p 
)
static

Definition at line 3504 of file misc.c.

3510  {
3511  text r = make_text(NIL);
3512  list pc = NIL;
3513  statement tb = test_true(obj);
3514 
3515  switch(get_prettyprint_language_tag()) {
3516  case is_language_fortran:
3517  case is_language_fortran95:
3518  pc = CHAIN_SWORD(pc, strdup("IF ("));
3519  break;
3520  case is_language_c:
3521  pc = CHAIN_SWORD(pc, strdup("if ("));
3522  break;
3523  default:
3524  pips_internal_error("Language unknown !");
3525  break;
3526  }
3527 
3528  pc = gen_nconc(pc, words_expression(test_condition(obj), ppdl));
3530  call c = call_undefined;
3531  text t = text_undefined;
3532  switch (get_prettyprint_language_tag()) {
3533  case is_language_fortran:
3534  case is_language_fortran95:
3535  pc = CHAIN_SWORD(pc, ") ");
3536  if(is_recursive_p) {
3537  ti = statement_instruction(tb);
3538  c = instruction_call(ti);
3539  pc = gen_nconc(pc, words_call(c, 0, true, true, ppdl));
3540  }
3543  make_unformatted(strdup(label), n,
3544  margin, pc)));
3545  break;
3546  case is_language_c:
3547  pc = CHAIN_SWORD(pc, ")"); // Do not add a useless SPACE
3550  make_unformatted(strdup(label), n,
3551  margin, pc)));
3552  if(is_recursive_p) {
3553  t = text_statement(module, margin + INDENTATION, tb, ppdl);
3555  text_sentences(t) = NIL;
3556  free_text(t);
3557  }
3558  break;
3559  default:
3560  pips_internal_error("Language unknown !");
3561  break;
3562  }
3563 
3564  ifdebug(8) {
3565  fprintf(stderr, "logical_if=================================\n");
3566  print_text(stderr, r);
3567  fprintf(stderr, "==============================\n");
3568  }
3569  return (r);
3570 }
#define instruction_undefined
Definition: ri.h:1454
#define call_undefined
Definition: ri.h:685

References ADD_SENTENCE_TO_TEXT, call_undefined, CHAIN_SWORD, fprintf(), free_text(), gen_nconc(), get_prettyprint_language_tag(), ifdebug, INDENTATION, instruction_call, instruction_undefined, is_language_c, is_language_fortran, is_language_fortran95, is_sentence_unformatted, make_sentence(), make_text(), make_unformatted(), module, NIL, pips_internal_error, print_text(), statement_instruction, strdup(), test_condition, test_true, text_sentences, text_statement(), text_undefined, words_call(), and words_expression().

Referenced by text_test().

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

◆ text_loop()

text text_loop ( entity  module,
const char *  label,
int  margin,
loop  obj,
int  n,
list ppdl,
bool  is_recursive_p 
)

exported for conversion/look_for_nested_loops.c

small hack to show the initial label of the loop to name it...

quite ugly management of other prettyprints...

Parameters
moduleodule
labelabel
marginargin
objbj
ppdlpdl
is_recursive_ps_recursive_p

Definition at line 3264 of file misc.c.

3272 {
3273  text r = make_text(NIL);
3274  statement body = loop_body( obj ) ;
3275  entity the_label = loop_label(obj);
3276  const char* do_label = entity_local_name(the_label)+sizeof(LABEL_PREFIX) -1;
3277  bool structured_do = entity_empty_label_p(the_label);
3278  bool do_enddo_p = get_bool_property("PRETTYPRINT_DO_LABEL_AS_COMMENT");
3279 
3280  /* small hack to show the initial label of the loop to name it...
3281  */
3282  if(!structured_do && do_enddo_p)
3283  {
3285  strdup(concatenate("! INITIALLY: DO ", do_label, "\n", NULL))));
3286  }
3287 
3288  /* quite ugly management of other prettyprints...
3289  */
3290  switch(execution_tag(loop_execution(obj)) ) {
3292  MERGE_TEXTS(r, text_loop_default(module, label, margin, obj, n, ppdl, is_recursive_p));
3293  break ;
3294  case is_execution_parallel:
3295  if (pp_cmf_style_p()) {
3296  text aux_r;
3297  if((aux_r = text_loop_cmf(module, label, margin, obj, n, NIL, NIL))
3298  != text_undefined) {
3299  MERGE_TEXTS(r, aux_r);
3300  }
3301  }
3302  else if (pp_craft_style_p()) {
3303  text aux_r;
3304  if((aux_r = text_loop_craft(module, label, margin, obj, n, NIL, NIL))
3305  != text_undefined) {
3306  MERGE_TEXTS(r, aux_r);
3307  }
3308  }
3309  else if (pp_f90_style_p()) {
3310  instruction bi = statement_instruction(body); // body instruction
3311  bool success_p = false;
3312  if(instruction_assign_p(bi) ) {
3313  MERGE_TEXTS(r, text_loop_90(module, label, margin, obj, n));
3314  success_p = true;
3315  }
3316  else if(instruction_sequence_p(bi)) {
3318  if(gen_length(sl)==1) {
3319  statement ibs = STATEMENT(CAR(sl));
3321  if(instruction_assign_p(ibi) ) {
3322  MERGE_TEXTS(r, text_loop_90(module, label, margin, obj, n));
3323  success_p = true;
3324  }
3325  }
3326  }
3327  if(!success_p) {
3328  MERGE_TEXTS(r, text_loop_default(module, label, margin, obj, n, ppdl, is_recursive_p));
3329  }
3330  }
3331  else {
3332  MERGE_TEXTS(r, text_loop_default(module, label, margin, obj, n, ppdl, is_recursive_p));
3333  }
3334  break ;
3335  default:
3336  pips_internal_error("Unknown \"execution\" tag") ;
3337  }
3338  return r;
3339 }
text text_loop_cmf(entity module, const char *label, int margin, loop obj, int n, list lr, list lidx)
=====================================================================
Definition: cmfortran.c:66
text text_loop_craft(entity module, const char *label, int margin, loop obj, int n, list lr, list lidx)
=====================================================================
Definition: craft.c:92
bool instruction_assign_p(instruction i)
Test if an instruction is an assignment.
Definition: instruction.c:164
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
text text_loop_90(entity module, const char *label, int margin, loop obj, int n)
Generate range subscript for simple loop with only one assignment.
Definition: fortran90.c:77
#define pp_cmf_style_p()
Definition: misc.c:212
#define pp_craft_style_p()
Definition: misc.c:210
#define pp_f90_style_p()
Definition: misc.c:209
text text_loop_default(entity module, const char *label, int margin, loop obj, int n, list *ppdl, bool is_recursive_p)
exported for fortran90.c
Definition: misc.c:3118
#define execution_tag(x)
Definition: ri.h:1207
#define loop_body(x)
Definition: ri.h:1644
#define loop_label(x)
Definition: ri.h:1646
@ is_execution_parallel
Definition: ri.h:1190
@ is_execution_sequential
Definition: ri.h:1189

References ADD_SENTENCE_TO_TEXT, CAR, concatenate(), entity_empty_label_p(), entity_local_name(), execution_tag, gen_length(), get_bool_property(), instruction_assign_p(), instruction_sequence, instruction_sequence_p, is_execution_parallel, is_execution_sequential, is_sentence_formatted, LABEL_PREFIX, loop_body, loop_execution, loop_label, make_sentence(), make_text(), MERGE_TEXTS, module, NIL, pips_internal_error, pp_cmf_style_p, pp_craft_style_p, pp_f90_style_p, sequence_statements, STATEMENT, statement_instruction, strdup(), text_loop_90(), text_loop_cmf(), text_loop_craft(), text_loop_default(), and text_undefined.

Referenced by print_loops_list(), and text_instruction().

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

◆ text_loop_default()

text text_loop_default ( entity  module,
const char *  label,
int  margin,
loop  obj,
int  n,
list ppdl,
bool  is_recursive_p 
)

exported for fortran90.c

HPF directives before the loop if required (INDEPENDENT and NEW)

idem if Open MP directives are required

LOOP prologue.

builds the PRIVATE scalar declaration if required

of string

local_var is a global variable which is exploited later...

FI: I do not understand why the local declarations were not added right away. I hope my change (simplification) does not break something else that is not tested by our non-regression suite.

loop BODY

LOOP postlogue

Parameters
moduleodule
labelabel
marginargin
objbj
ppdlpdl
is_recursive_ps_recursive_p

Definition at line 3118 of file misc.c.

3124  {
3125  list pc = NIL;
3126  sentence first_sentence = sentence_undefined;
3127  unformatted u;
3128  text r = make_text(NIL);
3129  statement body = loop_body( obj );
3130  entity the_label = loop_label(obj);
3131  const char* do_label = entity_local_name(the_label) + sizeof(LABEL_PREFIX) -1;
3132  bool structured_do = entity_empty_label_p(the_label);
3133  bool doall_loop_p = false;
3134  bool hpf_prettyprint = pp_hpf_style_p();
3135  bool do_enddo_p = get_bool_property("PRETTYPRINT_DO_LABEL_AS_COMMENT");
3136  bool all_private = get_bool_property("PRETTYPRINT_ALL_PRIVATE_VARIABLES");
3137  bool braces_p = !one_liner_p(body) || prettyprint_all_c_braces_p;
3138 
3140  doall_loop_p = false;
3141  } else {
3142  doall_loop_p = pp_doall_style_p();
3143  }
3144 
3145  /* HPF directives before the loop if required (INDEPENDENT and NEW) */
3146  if (hpf_prettyprint)
3147  MERGE_TEXTS(r, text_hpf_directive(obj, margin));
3148  /* idem if Open MP directives are required */
3149  if (pp_omp_style_p())
3150  MERGE_TEXTS(r, text_omp_directive(obj, margin));
3151 
3152  /* LOOP prologue.
3153  */
3154  switch (get_prettyprint_language_tag()) {
3155  case is_language_fortran:
3156  case is_language_fortran95:
3157  pc = CHAIN_SWORD(NIL, (doall_loop_p) ? "DOALL " : "DO " );
3158  if (!structured_do && !doall_loop_p && !do_enddo_p) {
3159  pc = CHAIN_SWORD(pc, concatenate(do_label, " ", NULL));
3160  }
3161  break;
3162  case is_language_c:
3163  pc = CHAIN_SWORD(NIL, (doall_loop_p) ? "forall(" : "for(" );
3164  break;
3165  default:
3166  pips_internal_error("Language unknown !");
3167  break;
3168  }
3169 
3170  //pc = CHAIN_SWORD(pc, entity_local_name(loop_index(obj)));
3171  pc = CHAIN_SWORD(pc, entity_user_name(loop_index(obj)));
3172  pc = CHAIN_SWORD(pc, " = ");
3173 
3174  switch (get_prettyprint_language_tag()) {
3175  case is_language_fortran:
3176  case is_language_fortran95:
3177  pc = gen_nconc(pc, words_loop_range(loop_range(obj), ppdl));
3178  u = make_unformatted(strdup(label), n, margin, pc);
3179  ADD_SENTENCE_TO_TEXT(r, first_sentence =
3181  break;
3182  case is_language_c:
3183  pc = gen_nconc(pc, C_loop_range(loop_range(obj), loop_index(obj), ppdl));
3184  if (braces_p)
3185  pc = CHAIN_SWORD(pc," {");
3186  if ((label != NULL) && (label[0] != '\0')) {
3187  pips_debug(9, "the label %s need to be print for a for C loop", label);
3188  u = make_unformatted(strdup(label), 0, 0, NULL);
3189  ADD_SENTENCE_TO_TEXT(r, first_sentence =
3191  }
3192  u = make_unformatted(NULL, n, margin, pc);
3194  break;
3195  default:
3196  pips_internal_error("Language tag unknown!");
3197  break;
3198  }
3199 
3200  if(is_recursive_p) {
3201  /* builds the PRIVATE scalar declaration if required
3202  */
3203  if (!ENDP(loop_locals(obj)) && (doall_loop_p || all_private)
3204  && !hpf_prettyprint) {
3205  list /* of string */lp = loop_private_variables(obj, ppdl);
3206 
3207  // initialize the local variable text if needed
3208  if ((local_flg == false) && (lp)) {
3209  local_flg = true;
3210  local_var = make_text(NIL);
3211  }
3212 
3213  if (lp)
3214  /* local_var is a global variable which is exploited
3215  later... */
3216  /* FI: I do not understand why the local declarations were
3217  not added right away. I hope my change (simplification)
3218  does not break something else that is not tested by our
3219  non-regression suite. */
3220  if (!pp_omp_style_p()) {
3222  // ( local_var,
3223  ( r,
3225  make_unformatted(NULL, 0, margin+INDENTATION, lp)));
3226  }
3227  }
3228 
3229  /* loop BODY
3230  */
3232  margin+INDENTATION,
3233  body,
3234  !one_liner_p(body),
3235  !one_liner_p(body),
3236  ppdl));
3237 
3238  /* LOOP postlogue
3239  */
3240  switch (get_prettyprint_language_tag()) {
3241  case is_language_fortran:
3242  case is_language_fortran95:
3243  if (structured_do || doall_loop_p || do_enddo_p || pp_cray_style_p()
3244  || pp_craft_style_p() || pp_cmf_style_p()) {
3245  ADD_SENTENCE_TO_TEXT(r, MAKE_ONE_WORD_SENTENCE(margin,"ENDDO"));
3246  }
3247  break;
3248  case is_language_c:
3249  if (braces_p)
3251  break;
3252  default:
3253  pips_internal_error("Language unknown !");
3254  break;
3255  }
3256 
3257  attach_loop_to_sentence_up_to_end_of_text(first_sentence, r, obj);
3258  }
3259 
3260  return r;
3261 }
void attach_loop_to_sentence_up_to_end_of_text(sentence s, text t, loop l)
The user interface:
list C_loop_range(range obj, entity i, list *ppdl)
Output a Fortan-like do-loop range as a C-like for-loop index part.
Definition: misc.c:457
static text text_hpf_directive(loop l, int m)
Definition: misc.c:3066
#define pp_cray_style_p()
Definition: misc.c:211
#define pp_doall_style_p()
Definition: misc.c:213
text text_omp_directive(loop l, int m)
Definition: misc.c:3084
list words_loop_range(range obj, list *ppdl)
exported for craft
Definition: misc.c:434
#define execution_sequential_p(x)
Definition: ri.h:1208
#define loop_range(x)
Definition: ri.h:1642
#define loop_index(x)
Definition: ri.h:1640

References ADD_SENTENCE_TO_TEXT, attach_loop_to_sentence_up_to_end_of_text(), C_loop_range(), CHAIN_SWORD, concatenate(), ENDP, entity_empty_label_p(), entity_local_name(), entity_user_name(), execution_sequential_p, gen_nconc(), get_bool_property(), get_prettyprint_language_tag(), INDENTATION, is_language_c, is_language_fortran, is_language_fortran95, is_sentence_unformatted, LABEL_PREFIX, local_flg, local_var, loop_body, loop_execution, loop_index, loop_label, loop_locals, loop_private_variables(), loop_range, MAKE_ONE_WORD_SENTENCE, make_sentence(), make_text(), make_unformatted(), MERGE_TEXTS, module, NIL, one_liner_p(), pips_debug, pips_internal_error, pp_cmf_style_p, pp_craft_style_p, pp_cray_style_p, pp_doall_style_p, pp_hpf_style_p, pp_omp_style_p, prettyprint_all_c_braces_p, sentence_undefined, strdup(), text_hpf_directive(), text_omp_directive(), text_statement_enclosed(), and words_loop_range().

Referenced by text_loop(), and text_loop_90().

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

◆ text_omp_directive()

text text_omp_directive ( loop  l,
int  m 
)

Definition at line 3084 of file misc.c.

3085 {
3086  list pdl = NIL; // pdl is useless in Fortran
3087  text t = text_undefined;
3088 
3089  switch(get_prettyprint_language_tag()) {
3090  case is_language_fortran:
3091  case is_language_fortran95:
3092  t = text_directive(l,
3093  m,
3094  "\n" OMP_DIRECTIVE,
3097  &pdl);
3098  break;
3099  case is_language_c:
3100  // text_directive function takes care of private variables
3101  // More should be done to take care of shared variables, reductions
3102  // and other specific omp clause like lastprivate, copyin ...
3103  t = text_directive(l,
3104  m,
3108  &pdl);
3109  break;
3110  default:
3111  pips_internal_error("Language unknown !");
3112  break;
3113  }
3114  return t;
3115 }
#define OMP_CONTINUATION
Definition: misc.c:3076
#define OMP_C_CONTINUATION
Definition: misc.c:3080
#define OMP_C_DIRECTIVE
Definition: misc.c:3079
#define OMP_PARALLELDO
Definition: misc.c:3077
#define OMP_C_PARALLELDO
Definition: misc.c:3081
#define OMP_DIRECTIVE
Definition: misc.c:3075

References get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, NIL, OMP_C_CONTINUATION, OMP_C_DIRECTIVE, OMP_C_PARALLELDO, OMP_CONTINUATION, OMP_DIRECTIVE, OMP_PARALLELDO, pips_internal_error, text_directive(), and text_undefined.

Referenced by text_loop_default().

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

◆ text_test()

static text text_test ( entity  module,
const char *  label,
int  margin,
test  obj,
int  n,
list ppdl,
bool  is_recursive_p 
)
static

1st case: one statement in the true branch => Fortran logical IF or no braces in C

Definition at line 3913 of file misc.c.

3919  {
3920  text r = text_undefined;
3921  statement tb = test_true(obj);
3922  statement fb = test_false(obj);
3923 
3924  /* 1st case: one statement in the true branch => Fortran logical IF
3925  or no braces in C */
3926  if (nop_statement_p(fb)
3927  && statement_call_p(tb)
3930  && !continue_statement_p(tb)
3931  && !get_bool_property("PRETTYPRINT_BLOCK_IF_ONLY")
3933  && get_bool_property("PRETTYPRINT_REGENERATE_ALTERNATE_RETURNS") )
3935  {
3936  r = text_logical_if(module, label, margin, obj, n, ppdl, is_recursive_p);
3937  }
3938  else {
3940 
3941  if (syntax_reference_p(c)
3943  && !get_bool_property("PRETTYPRINT_CHECK_IO_STATEMENTS"))
3944  r = text_io_block_if(module, label, margin, obj, n, ppdl);
3945  else
3946  r = text_block_if(module, label, margin, obj, n, ppdl, is_recursive_p);
3947  }
3948 
3949  ifdebug(8) {
3950  fprintf(stderr, "text_test=================================\n");
3951  print_text(stderr, r);
3952  fprintf(stderr, "==============================\n");
3953  }
3954  return r;
3955 }
call statement_call(statement)
Get the call of a statement.
Definition: statement.c:1406
bool statement_call_p(statement)
Definition: statement.c:364
static text text_io_block_if(entity module, const char *label, int margin, test obj, int n, list *ppdl)
Definition: misc.c:3859
static text text_logical_if(entity __attribute__((unused)) module, const char *label, int margin, test obj, int n, list *ppdl, bool is_recursive_p)
Definition: misc.c:3504
static text text_block_if(entity module, const char *label, int margin, test obj, int n, list *ppdl, bool is_recursive_p)
Prettyprint the condition, the true and, possibly, the false branch.
Definition: misc.c:3795
bool io_entity_p(entity e)
Several implicit entities are declared to define the implicit effects of IO statements.
Definition: entity.c:1139
bool call_contains_alternate_returns_p(call)
Definition: variable.c:1835
#define syntax_reference_p(x)
Definition: ri.h:2728
#define syntax_reference(x)
Definition: ri.h:2730
#define reference_variable(x)
Definition: ri.h:2326
#define expression_syntax(x)
Definition: ri.h:1247

References call_contains_alternate_returns_p(), continue_statement_p(), empty_comments_p(), entity_empty_label_p(), expression_syntax, fprintf(), get_bool_property(), get_prettyprint_language_tag(), ifdebug, io_entity_p(), is_language_c, module, nop_statement_p(), prettyprint_all_c_braces_p, print_text(), reference_variable, statement_call(), statement_call_p(), statement_comments, statement_label, syntax_reference, syntax_reference_p, test_condition, test_false, test_true, text_block_if(), text_io_block_if(), text_logical_if(), and text_undefined.

Referenced by text_instruction().

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

◆ text_whileloop()

static text text_whileloop ( entity  module,
const char *  label,
int  margin,
whileloop  obj,
int  n,
list ppdl,
bool  is_recursive_p 
)
static

Show the initial label of the loop to name it... FI: I believe this is useless for while loops since they cannot be parallelized.

LOOP prologue.

loop BODY

LOOP postlogue

C do { s; } while (cond); loop

attach_loop_to_sentence_up_to_end_of_text(first_sentence, r, obj);

Definition at line 3341 of file misc.c.

3347  {
3348  list pc = NIL;
3349  sentence first_sentence;
3350  unformatted u;
3351  text r = make_text(NIL);
3352  statement body = whileloop_body( obj );
3353  entity the_label = whileloop_label(obj);
3354  const char* do_label = entity_local_name(the_label) + sizeof(LABEL_PREFIX) -1;
3355  bool structured_do = entity_empty_label_p(the_label);
3356  bool do_enddo_p = get_bool_property("PRETTYPRINT_DO_LABEL_AS_COMMENT");
3357 
3359 
3360  /* Show the initial label of the loop to name it...
3361  * FI: I believe this is useless for while loops since they cannot
3362  * be parallelized.
3363  */
3364  if(!structured_do && do_enddo_p) {
3366  strdup(concatenate("! INITIALLY: DO ", do_label, "\n", NULL))));
3367  }
3368 
3369  if(evaluation_before_p(eval)) {
3370  switch(get_prettyprint_language_tag()) {
3371  case is_language_fortran:
3372  case is_language_fortran95:
3373  /* LOOP prologue.
3374  */
3375  pc = CHAIN_SWORD(NIL, "DO " );
3376 
3377  if(!structured_do && !do_enddo_p) {
3378  pc = CHAIN_SWORD(pc, concatenate(do_label, " ", NULL));
3379  }
3380  pc = CHAIN_SWORD(pc, "WHILE (");
3381  pc = gen_nconc(pc, words_expression(whileloop_condition(obj), ppdl));
3382  pc = CHAIN_SWORD(pc, ")");
3383  u = make_unformatted(strdup(label), n, margin, pc);
3384  ADD_SENTENCE_TO_TEXT(r, first_sentence =
3386 
3387  if(is_recursive_p) {
3388  /* loop BODY
3389  */
3390  MERGE_TEXTS(r, text_statement(module, margin+INDENTATION, body, ppdl));
3391 
3392  /* LOOP postlogue
3393  */
3394  if(structured_do) {
3395  ADD_SENTENCE_TO_TEXT(r, MAKE_ONE_WORD_SENTENCE(margin,"ENDDO"));
3396  }
3397  }
3398  break;
3399  case is_language_c:
3400  {
3401  bool braces_p = !one_liner_p(body) || prettyprint_all_c_braces_p;
3402  if(!braces_p) {
3403  pc = CHAIN_SWORD(NIL,"while (");
3404  pc = gen_nconc(pc, words_expression(whileloop_condition(obj), ppdl));
3405  pc = CHAIN_SWORD(pc,")");
3406  u = make_unformatted(strdup(label), n, margin, pc);
3408  if(is_recursive_p) {
3410  margin+INDENTATION,
3411  body,
3412  !one_liner_p(body),
3413  !one_liner_p(body),
3414  ppdl));
3415 
3416  //if (structured_do)
3417  //ADD_SENTENCE_TO_TEXT(r, MAKE_ONE_WORD_SENTENCE(margin,"}"));
3418  }
3419  } else {
3420  pc = CHAIN_SWORD(NIL,"while (");
3421  pc = gen_nconc(pc, words_expression(whileloop_condition(obj), ppdl));
3422  pc = CHAIN_SWORD(pc,") {");
3423  u = make_unformatted(strdup(label), n, margin, pc);
3425  if(is_recursive_p) {
3426  MERGE_TEXTS(r, text_statement(module, margin+INDENTATION, body, ppdl));
3427  if(structured_do)
3429  }
3430  }
3431  }
3432  break;
3433  default:
3434  pips_internal_error("Language unknown !");
3435  break;
3436  }
3437  } else {
3438  pips_assert ("Only C language is managed here",
3440  /* C do { s; } while (cond); loop*/
3441  if(is_recursive_p) {
3442  pc = CHAIN_SWORD(NIL,"do {");
3443  u = make_unformatted(strdup(label), n, margin, pc);
3445  MERGE_TEXTS(r, text_statement(module, margin+INDENTATION, body, ppdl));
3447  }
3448  pc = CHAIN_SWORD(NIL,"while (");
3449  pc = gen_nconc(pc, words_expression(whileloop_condition(obj), ppdl));
3450  pc = CHAIN_SWORD(pc, ");");
3451  u = make_unformatted(NULL, n, margin, pc);
3453  }
3454 
3455  /* attach_loop_to_sentence_up_to_end_of_text(first_sentence, r, obj); */
3456  return r;
3457 }
static Value eval(Pvecteur pv, Value val, Variable var)
#define whileloop_evaluation(x)
Definition: ri.h:3166
#define whileloop_label(x)
Definition: ri.h:3164
#define whileloop_body(x)
Definition: ri.h:3162
#define whileloop_condition(x)
Definition: ri.h:3160
#define evaluation_before_p(x)
Definition: ri.h:1159

References ADD_SENTENCE_TO_TEXT, CHAIN_SWORD, concatenate(), entity_empty_label_p(), entity_local_name(), eval(), evaluation_before_p, gen_nconc(), get_bool_property(), get_prettyprint_language_tag(), INDENTATION, is_language_c, is_language_fortran, is_language_fortran95, is_sentence_formatted, is_sentence_unformatted, LABEL_PREFIX, MAKE_ONE_WORD_SENTENCE, make_sentence(), make_text(), make_unformatted(), MERGE_TEXTS, module, NIL, one_liner_p(), pips_assert, pips_internal_error, prettyprint_all_c_braces_p, prettyprint_language_is_c_p(), strdup(), text_statement(), text_statement_enclosed(), whileloop_body, whileloop_condition, whileloop_evaluation, whileloop_label, and words_expression().

Referenced by text_instruction().

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

◆ words_any_reference()

list words_any_reference ( reference  obj,
list ppdl,
const char *(*)(entity enf 
)

exported for expression.c

Should only be used to prettyprint proper C references.

We don't want to print these special entity, they are there for internal purpose only

Print the entity first

Let's print the indices now

Definition at line 704 of file misc.c.

705 {
706  list pc = NIL;
707  string begin_attachment;
708  entity e = reference_variable(obj);
709 
710 
712  /* We don't want to print these special entity, they are there for
713  * internal purpose only
714  */
715 
716  /* Print the entity first */
717  pc = CHAIN_SWORD(pc, (*enf)(e));
718 
719  begin_attachment = STRING(CAR(pc));
720 
721  /* Let's print the indices now */
722  if(reference_indices(obj) != NIL) {
723  switch(get_prettyprint_language_tag()) {
725  case is_language_fortran: {
726  int count = 0;
727  pc = CHAIN_SWORD(pc,"(");
729  syntax ssubscript = expression_syntax(subscript);
730  if(count > 0)
731  pc = CHAIN_SWORD(pc,",");
732  else
733  count++;
734  if(syntax_range_p(ssubscript)) {
735  pc = gen_nconc(pc,
737  ppdl));
738  } else {
739  pc = gen_nconc(pc, words_subexpression(subscript, 0, true, ppdl));
740  }
741  }
742  pc = CHAIN_SWORD(pc,")");
743  break;
744  }
745  case is_language_c: {
747  syntax ssubscript = expression_syntax(subscript);
748  pc = CHAIN_SWORD(pc, "[");
749  if(syntax_range_p(ssubscript)) {
750  pc = gen_nconc(pc,
752  ppdl));
753  } else {
754  pc = gen_nconc(pc, words_subexpression(subscript, 0, true, ppdl));
755  }
756  pc = CHAIN_SWORD(pc, "]");
757  }
758  break;
759  }
760  default:
761  pips_internal_error("Language unknown !");
762  }
763  }
764  attach_reference_to_word_list(begin_attachment,
765  STRING(CAR(gen_last(pc))),
766  obj);
767  }
768 
769 
770  return(pc);
771 }
static int count
Definition: SDG.c:519
void attach_reference_to_word_list(string begin_word, string end_word, reference r)
Attach a module usage (CALL or function call):
list gen_last(list l)
Return the last element of a list.
Definition: list.c:578
list words_subscript_range(range obj, list *ppdl)
@description FI: array constructor R433, p.
Definition: misc.c:629
#define ENTITY_ALLOCATABLE_BOUND_P(e)
#define syntax_range(x)
Definition: ri.h:2733
#define reference_indices(x)
Definition: ri.h:2328
#define syntax_range_p(x)
Definition: ri.h:2731

References attach_reference_to_word_list(), CAR, CHAIN_SWORD, count, ENTITY_ALLOCATABLE_BOUND_P, EXPRESSION, expression_syntax, FOREACH, gen_last(), gen_nconc(), get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, NIL, pips_internal_error, reference_indices, reference_variable, STRING, syntax_range, syntax_range_p, words_subexpression(), and words_subscript_range().

Referenced by Words_Any_Reference(), and words_reference().

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

◆ Words_Any_Reference()

list Words_Any_Reference ( reference  obj,
list  pdl,
const char *(*)(entity enf 
)

Definition at line 773 of file misc.c.

774 {
775  list npdl = pdl;
776  list pc = words_any_reference(obj, &npdl, enf);
777  gen_free_list(npdl);
778  return pc;
779 }
list words_any_reference(reference obj, list *ppdl, const char *(*enf)(entity))
exported for expression.c
Definition: misc.c:704

References gen_free_list(), and words_any_reference().

Referenced by points_to_words_reference(), and Words_Reference().

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

◆ words_application()

static list words_application ( application  a,
list ppdl 
)
static

Referenced by ensure_comment_consistency(), and words_syntax().

+ Here is the caller graph for this function:

◆ words_assign_op()

static list words_assign_op ( call  obj,
int  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)
static

FI: space_p could be used here to control spacing around assignment

= is not a Fortran operator. No need for parentheses ever, even with the parenthesis option

Brace expressions are not allowed in standard assignments

Be careful with expression lists, they may require surrounding parentheses.

Definition at line 1118 of file misc.c.

1122 {
1123  list pc = NIL, args = call_arguments(obj);
1124  int prec = words_intrinsic_precedence(obj);
1125  const char* fun = entity_local_name(call_function(obj));
1126 
1127  pc = gen_nconc(pc, words_subexpression(EXPRESSION(CAR(args)), prec, true, ppdl));
1128 
1129  if (strcmp(fun, MODULO_UPDATE_OPERATOR_NAME) == 0)
1130  fun = "%=";
1131  else if (strcmp(fun, BITWISE_AND_UPDATE_OPERATOR_NAME) == 0)
1132  fun = "&=";
1133  else if (strcmp(fun, BITWISE_XOR_UPDATE_OPERATOR_NAME) == 0)
1134  fun = "^=";
1135 
1136  /* FI: space_p could be used here to control spacing around assignment */
1137  pc = CHAIN_SWORD(pc," ");
1138  pc = CHAIN_SWORD(pc, fun);
1139  pc = CHAIN_SWORD(pc," ");
1141  switch (get_prettyprint_language_tag()) {
1142  case is_language_fortran:
1143  case is_language_fortran95:
1144  exp = EXPRESSION(CAR(CDR(args)));
1145  if (expression_call_p(exp)) {
1146  /* = is not a Fortran operator. No need for parentheses ever,
1147  even with the parenthesis option */
1148  /*
1149  call c = syntax_call(expression_syntax(e));
1150  pc = gen_nconc(pc, words_call(c, 0, true, true, ppdl));
1151  */
1152  pc = gen_nconc(pc, words_syntax(expression_syntax(exp), ppdl));
1153  } else
1154  pc = gen_nconc(pc, words_subexpression(EXPRESSION(CAR(CDR(args))),
1155  prec,
1156  true,
1157  ppdl));
1158  break;
1159  case is_language_c:
1160  /* Brace expressions are not allowed in standard assignments */
1161  exp = EXPRESSION(CAR(CDR(args)));
1162  if (ENTITY_ASSIGN_P(call_function(obj))) {
1163  if (brace_expression_p(exp)) {
1164  // use GCC constructor extension */
1165  pips_internal_error("this should not happen: a constructor is represnetd as a cas on brace expression\n");
1166  }
1167  else {
1168  /* Be careful with expression lists, they may require
1169  surrounding parentheses. */
1170  pc = gen_nconc(pc, words_subexpression(exp, prec, true, ppdl));
1171  }
1172  } else {
1173  pc = gen_nconc(pc, words_subexpression(exp, prec, true, ppdl));
1174  }
1175  break;
1176  default:
1177  pips_internal_error("Language unknown !");
1178  break;
1179  }
1180  if (prec < precedence || (!precedence_p && precedence > 0)) {
1181  pc = CONS(STRING, MAKE_SWORD("("), pc);
1182  pc = CHAIN_SWORD(pc, ")");
1183  }
1184  return (pc);
1185 }
static bool precedence_p
This variable is used to disable the precedence system and hence to prettyprint all parentheses,...
Definition: misc.c:194
list words_syntax(syntax obj, list *ppdl)
exported for expression.c
Definition: misc.c:2623
static int words_intrinsic_precedence(call)
Definition: misc.c:2552
#define ENTITY_ASSIGN_P(e)
#define MODULO_UPDATE_OPERATOR_NAME
#define BITWISE_XOR_UPDATE_OPERATOR_NAME
#define BITWISE_AND_UPDATE_OPERATOR_NAME
bool expression_call_p(expression e)
Definition: expression.c:415
bool brace_expression_p(expression e)
Return bool indicating if expression e is a brace expression.
Definition: expression.c:3384
#define expression_undefined
Definition: ri.h:1223
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207

References BITWISE_AND_UPDATE_OPERATOR_NAME, BITWISE_XOR_UPDATE_OPERATOR_NAME, brace_expression_p(), call_arguments, call_function, CAR, CDR, CHAIN_SWORD, CONS, ENTITY_ASSIGN_P, entity_local_name(), exp, EXPRESSION, expression_call_p(), expression_syntax, expression_undefined, gen_nconc(), get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, MAKE_SWORD, MODULO_UPDATE_OPERATOR_NAME, NIL, pips_internal_error, precedence_p, STRING, words_intrinsic_precedence(), words_subexpression(), and words_syntax().

+ Here is the call graph for this function:

◆ words_assign_substring_op()

static list words_assign_substring_op ( call  obj,
int __attribute__((unused))  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)
static

The assign substring function call is reduced to a syntactic construct

Definition at line 1227 of file misc.c.

1231 {
1232  /* The assign substring function call is reduced to a syntactic construct */
1233  list pc = NIL;
1235  int prec = words_intrinsic_precedence(obj);
1236 
1237  pips_assert("words_substring_op", gen_length(call_arguments(obj)) == 4);
1238 
1239  e = EXPRESSION(CAR(CDR(CDR(CDR(call_arguments(obj))))));
1240 
1241  pc = gen_nconc(pc, words_substring_op(obj, prec, true, ppdl));
1242  pc = CHAIN_SWORD(pc, " = ");
1243  pc = gen_nconc(pc, words_subexpression(e, prec, true, ppdl));
1244 
1245  return(pc);
1246 }
static list words_substring_op(call obj, int __attribute__((unused)) precedence, bool __attribute__((unused)) leftmost, list *ppdl)
Definition: misc.c:1187

References call_arguments, CAR, CDR, CHAIN_SWORD, EXPRESSION, expression_undefined, gen_length(), gen_nconc(), NIL, pips_assert, words_intrinsic_precedence(), words_subexpression(), and words_substring_op().

+ Here is the call graph for this function:

◆ words_brace_op()

static list words_brace_op ( call  obj,
int precedence   __attribute__(unused),
bool leftmost   __attribute__(unused),
list ppdl 
)
static

Definition at line 2091 of file misc.c.

2095 {
2097  list l = words_brace_expression(fake, ppdl);
2098  free_expression(fake);
2099  return l;
2100 }
call copy_call(call p)
CALL.
Definition: ri.c:233
list words_brace_expression(expression exp, list *ppdl)
Definition: declarations.c:910
expression call_to_expression(call c)
Build an expression that call a function or procedure.
Definition: expression.c:309

References call_to_expression(), copy_call(), free_expression(), and words_brace_expression().

+ Here is the call graph for this function:

◆ Words_Call()

list Words_Call ( call  obj,
int  precedence,
bool  leftmost,
bool  is_a_subroutine 
)
Parameters
objbj
precedencerecedence
leftmosteftmost
is_a_subroutines_a_subroutine

Definition at line 2597 of file misc.c.

2602 {
2603  list npdl = NIL;
2604  list pc = words_call(obj, precedence, leftmost, is_a_subroutine, &npdl);
2605  gen_free_list(npdl);
2606  return pc;
2607 }

References gen_free_list(), NIL, and words_call().

Referenced by defs_elim_of_assign_call(), do_simdizer_init(), io_filter(), and text_loop_cmf().

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

◆ words_call()

list words_call ( call  obj,
int  precedence,
bool  leftmost,
bool  is_a_subroutine,
list ppdl 
)

exported for cmfortran.c

Parameters
objbj
precedencerecedence
leftmosteftmost
is_a_subroutines_a_subroutine
ppdlpdl

Definition at line 2575 of file misc.c.

2581 {
2582  list pc;
2583  entity f = call_function(obj);
2584  value i = entity_initial(f);
2585 
2586  if(value_intrinsic_p(i)) {
2587  int effective_precedence = (precedence_p||precedence<=1)?
2588  precedence : MAXIMAL_PRECEDENCE;
2589 
2590  pc = words_intrinsic_call(obj, effective_precedence, leftmost, ppdl);
2591  }
2592  else
2593  pc = words_genuine_regular_call(obj, is_a_subroutine, ppdl);
2594  return pc;
2595 }
static list words_intrinsic_call(call obj, int precedence, bool leftmost, list *ppdl)
Definition: misc.c:2525
#define MAXIMAL_PRECEDENCE
lint
Definition: misc.c:138
static list words_genuine_regular_call(call obj, bool is_a_subroutine, list *ppdl)
To deal with attachment on user module usage.
Definition: misc.c:1090
#define value_intrinsic_p(x)
Definition: ri.h:3074
#define entity_initial(x)
Definition: ri.h:2796

References call_function, entity_initial, f(), MAXIMAL_PRECEDENCE, precedence_p, value_intrinsic_p, words_genuine_regular_call(), and words_intrinsic_call().

Referenced by text_instruction(), text_logical_if(), Words_Call(), words_subexpression(), and words_syntax().

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

◆ words_call_intrinsic()

list words_call_intrinsic ( call  obj,
int __attribute__((unused))  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)

Definition at line 1109 of file misc.c.

1113 {
1114  return words_regular_call(obj, true, ppdl);
1115 }
list words_regular_call(call obj, bool is_a_subroutine, list *ppdl)
words_regular_call used for user subroutine and user function and intrinsics called like user functio...
Definition: misc.c:868

References words_regular_call().

+ Here is the call graph for this function:

◆ words_cast()

static list words_cast ( cast  obj,
int  precedence,
list ppdl 
)
static

Referenced by ensure_comment_consistency(), words_subexpression(), and words_syntax().

+ Here is the caller graph for this function:

◆ words_comma_op()

static list words_comma_op ( call  obj,
int  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)
static

Nga Nguyen : this case is added for comma expression in C, but I am not sure about its precedence => to be looked at more carefully.

Definition at line 2285 of file misc.c.

2289 {
2290  list pc = NIL, args = call_arguments(obj);
2291  int prec = words_intrinsic_precedence(obj);
2292  bool space_p = get_bool_property("PRETTYPRINT_LISTS_WITH_SPACES");
2293 
2294  if(prec < precedence || !precedence_p)
2295  pc = CHAIN_SWORD(pc,"(");
2296  pc = gen_nconc(pc, words_subexpression(EXPRESSION(CAR(args)), prec, true, ppdl));
2297  while (!ENDP(CDR(args)))
2298  {
2299  pc = CHAIN_SWORD(pc,space_p?", " : ",");
2300  pc = gen_nconc(pc, words_subexpression(EXPRESSION(CAR(CDR(args))), prec, true, ppdl));
2301  args = CDR(args);
2302  }
2303  if(prec < precedence || !precedence_p)
2304  pc = CHAIN_SWORD(pc,")");
2305  return(pc);
2306 }

References call_arguments, CAR, CDR, CHAIN_SWORD, ENDP, EXPRESSION, gen_nconc(), get_bool_property(), NIL, precedence_p, words_intrinsic_precedence(), and words_subexpression().

+ Here is the call graph for this function:

◆ words_conditional_op()

static list words_conditional_op ( call  obj,
int  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)
static

Definition at line 2308 of file misc.c.

2312 {
2313  list pc = NIL, args = call_arguments(obj);
2314  int prec = words_intrinsic_precedence(obj);
2315 
2316  if(prec < precedence || !precedence_p)
2317  pc = CHAIN_SWORD(pc,"(");
2318  pc = gen_nconc(pc, words_subexpression(EXPRESSION(CAR(args)), prec, true, ppdl));
2319  pc = CHAIN_SWORD(pc,"?");
2320  pc = gen_nconc(pc, words_subexpression(EXPRESSION(CAR(CDR(args))), prec, true, ppdl));
2321  pc = CHAIN_SWORD(pc,":");
2322  pc = gen_nconc(pc, words_subexpression(EXPRESSION(CAR(CDR(CDR(args)))), prec, true, ppdl));
2323  if(prec < precedence || !precedence_p)
2324  pc = CHAIN_SWORD(pc,")");
2325  return(pc);
2326 }

References call_arguments, CAR, CDR, CHAIN_SWORD, EXPRESSION, gen_nconc(), NIL, precedence_p, words_intrinsic_precedence(), and words_subexpression().

+ Here is the call graph for this function:

◆ Words_Expression()

list Words_Expression ( expression  obj)

of string

Parameters
objbj

Definition at line 2616 of file misc.c.

2617 {
2618  return Words_Syntax(expression_syntax(obj));
2619 }
list Words_Syntax(syntax obj)
Definition: misc.c:2664

References expression_syntax, and Words_Syntax().

Referenced by can_terapixify_expression_p(), effect_words_reference(), eval_var(), reference_conversion_expression(), words_cmf_loop_range(), words_loop_list(), words_numerical_dimension(), and words_test_list().

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

◆ words_expression()

◆ words_genuine_regular_call()

static list words_genuine_regular_call ( call  obj,
bool  is_a_subroutine,
list ppdl 
)
static

To deal with attachment on user module usage.

The call is not used to code a constant:

The module name is the first one except if it is a procedure CALL.

Definition at line 1090 of file misc.c.

1091 {
1092  list pc = words_regular_call(obj, is_a_subroutine, ppdl);
1093 
1094  if (call_arguments(obj) != NIL) {
1095  /* The call is not used to code a constant: */
1096  //entity f = call_function(obj);
1097  //type t = entity_type(f);
1098  /* The module name is the first one except if it is a procedure CALL. */
1101  else
1103  }
1104 
1105  return pc;
1106 }
void attach_regular_call_to_word(string word, call c)
Attach a reference:
type call_compatible_type(type)
returns the type necessary to generate or check a call to an object of type t.
Definition: type.c:3791
#define type_void_p(x)
Definition: ri.h:2959

References attach_regular_call_to_word(), call_arguments, call_compatible_type(), call_function, CAR, CDR, entity_type, functional_result, NIL, STRING, type_functional, type_void_p, and words_regular_call().

Referenced by words_call().

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

◆ words_goto_label()

list words_goto_label ( const char *  tlabel)

This function is useful only for parsed codes since gotos are removed by the controlizer.

of string

<<<<<< .working switch (get_prettyprint_language_tag()) { case is_language_fortran: case is_language_fortran95: pc = CHAIN_SWORD(pc, RETURN_FUNCTION_NAME); break; case is_language_c: pc = CHAIN_SWORD(pc, C_RETURN_FUNCTION_NAME); pc = CHAIN_SWORD(pc, ";"); break; default: pips_internal_error("Language unknown !"); break;

}

In C, a label cannot begin with a number so "l" is added for this case

In C, a label cannot begin with a number so "l" is added for this case

Parameters
tlabellabel

Definition at line 1917 of file misc.c.

1918 {
1919  list pc = NIL;
1920  if (strcmp(tlabel, RETURN_LABEL_NAME) == 0) {
1921  /*<<<<<<< .working
1922  switch (get_prettyprint_language_tag()) {
1923  case is_language_fortran:
1924  case is_language_fortran95:
1925  pc = CHAIN_SWORD(pc, RETURN_FUNCTION_NAME);
1926  break;
1927  case is_language_c:
1928  pc = CHAIN_SWORD(pc, C_RETURN_FUNCTION_NAME);
1929  pc = CHAIN_SWORD(pc, ";");
1930  break;
1931  default:
1932  pips_internal_error("Language unknown !");
1933  break;
1934  }
1935  =======*/
1936  switch (get_prettyprint_language_tag()) {
1937  case is_language_fortran:
1938  case is_language_fortran95:
1940  break;
1941  case is_language_c: {
1943 
1944  if(void_function_p(f)) {
1945  // FI: this hides the parsed code structure and is wrong
1946  // in C because a value may have to be returned;
1948  pc = CHAIN_SWORD(pc, ";");
1949  }
1950  else {
1952  pc = CHAIN_SWORD(pc, C_RETURN_FUNCTION_NAME" ");
1953  pc = CHAIN_SWORD(pc, entity_user_name(rv));
1954  pc = CHAIN_SWORD(pc, ";");
1955  }
1956  if(false) {
1957  // the gotos are maintained, but the final return must be printed out
1958  // FI: this would only work if the final return were printed
1959  // out for sure and with its label
1960  /* In C, a label cannot begin with a number so "l" is added
1961  for this case*/
1962  pc = CHAIN_SWORD(pc, strdup((isdigit(tlabel[0])?"goto l":"goto ")));
1963  pc = CHAIN_SWORD(pc, tlabel);
1965  }
1966  break;
1967  }
1968  default:
1969  pips_internal_error("Language unknown !");
1970  break;
1971  }
1972  //>>>>>>> .merge-right.r18859
1973  } else {
1974  switch (get_prettyprint_language_tag()) {
1975  case is_language_fortran:
1976  case is_language_fortran95:
1977  pc = CHAIN_SWORD(pc, strdup("GOTO "));
1978  pc = CHAIN_SWORD(pc, tlabel);
1979  break;
1980  case is_language_c:
1981  /* In C, a label cannot begin with a number so "l" is added
1982  for this case*/
1983  pc = CHAIN_SWORD(pc, strdup((isdigit(tlabel[0])?"goto l":"goto ")));
1984  pc = CHAIN_SWORD(pc, tlabel);
1986  break;
1987  default:
1988  pips_internal_error("Language unknown !");
1989  break;
1990  }
1991  }
1992  return pc;
1993 }
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
#define RETURN_LABEL_NAME
Definition: naming-local.h:106
#define RETURN_FUNCTION_NAME
#define C_RETURN_FUNCTION_NAME
bool void_function_p(entity m)
Check if m is a C void function or a Fortran subroutine.
Definition: module.c:538
entity function_to_return_value(entity m)
Returns the entity rv that carries the value returned by module m, when m is not a C void function or...
Definition: module.c:509

References C_CONTINUE_FUNCTION_NAME, C_RETURN_FUNCTION_NAME, CHAIN_SWORD, entity_user_name(), f(), function_to_return_value(), get_current_module_entity(), get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, NIL, pips_internal_error, RETURN_FUNCTION_NAME, RETURN_LABEL_NAME, strdup(), and void_function_p().

Referenced by sentence_goto_label(), and text_trail().

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

◆ words_implied_do()

static list words_implied_do ( call  obj,
int __attribute__((unused))  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)
static

Definition at line 1508 of file misc.c.

1512 {
1513  list pc = NIL;
1514  list pcc;
1515  expression index;
1516  syntax s;
1517  range r;
1518  bool space_p = get_bool_property("PRETTYPRINT_LISTS_WITH_SPACES");
1519 
1520  pcc = call_arguments(obj);
1521  index = EXPRESSION(CAR(pcc));
1522 
1523  pcc = CDR(pcc);
1524  s = expression_syntax(EXPRESSION(CAR(pcc)));
1525  if (! syntax_range_p(s)) {
1526  pips_internal_error("range expected");
1527  }
1528  r = syntax_range(s);
1529 
1530  pc = CHAIN_SWORD(pc, "(");
1531  MAPL(pcp, {
1532  pc = gen_nconc(pc, words_expression(EXPRESSION(CAR(pcp)), ppdl));
1533  if (CDR(pcp) != NIL)
1534  pc = CHAIN_SWORD(pc, space_p? ", " : ",");
1535  }, CDR(pcc));
1536  pc = CHAIN_SWORD(pc, space_p? ", " : ",");
1537 
1538  pc = gen_nconc(pc, words_expression(index, ppdl));
1539  pc = CHAIN_SWORD(pc, " = ");
1540  pc = gen_nconc(pc, words_loop_range(r, ppdl));
1541  pc = CHAIN_SWORD(pc, ")");
1542 
1543  return(pc);
1544 }
#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

References call_arguments, CAR, CDR, CHAIN_SWORD, EXPRESSION, expression_syntax, gen_nconc(), get_bool_property(), MAPL, NIL, pips_internal_error, syntax_range, syntax_range_p, words_expression(), and words_loop_range().

+ Here is the call graph for this function:

◆ words_infix_binary_op()

static list words_infix_binary_op ( call  obj,
int  precedence,
bool  leftmost,
list ppdl 
)
static

handling of internally renamed operators

Do we want to add a space in case we2 starts with a dereferencing operator "*"? Nga suggests to look at the quake benchmark of SPEC2000.

precedence is greater than * or /

If the operator in the second subexpression has the same priority as the current operator, it has to be parenthesized to respect the structure imposed by the programmer. For instance, a+(b+c) does require parentheses whereas (a+b)+c is the same as a+b+c. So we1 and we2 cannot be processed exactly in the same way.

Use precedence to generate or not parentheses, unless parentheses are always required

Check that C ambiguities such as "a+++b" for "a++ + b" or "a + ++b" are not generated

Definition at line 2176 of file misc.c.

2177 {
2178  list pc = NIL;
2179  list args = call_arguments(obj);
2180  int prec = words_intrinsic_precedence(obj);
2181  list we1 = words_subexpression(EXPRESSION(CAR(args)), prec,
2182  prec>=MINIMAL_ARITHMETIC_PRECEDENCE? leftmost: true, ppdl);
2183  list we2;
2184  const char* fun = entity_local_name(call_function(obj));
2185 
2186  /* handling of internally renamed operators */
2187  fun = renamed_op_handling (fun);
2188 
2189  if(strcmp(fun, DIVIDE_OPERATOR_NAME) == 0) {
2190  /* Do we want to add a space in case we2 starts with a dereferencing operator "*"?
2191  Nga suggests to look at the quake benchmark of SPEC2000. */
2192  we2 = words_subexpression(EXPRESSION(CAR(CDR(args))), MAXIMAL_PRECEDENCE, false, ppdl);
2193  }
2194  else if (strcmp(fun, MINUS_OPERATOR_NAME) == 0 ) {
2195  expression exp = EXPRESSION(CAR(CDR(args)));
2196  if(expression_call_p(exp) &&
2199  /* precedence is greater than * or / */
2200  we2 = words_subexpression(exp, prec, false, ppdl);
2201  else
2202  we2 = words_subexpression(exp, MAXIMAL_PRECEDENCE, false, ppdl);
2203  }
2204  else if(strcmp(fun, MULTIPLY_OPERATOR_NAME) == 0) {
2205  expression exp = EXPRESSION(CAR(CDR(args)));
2206  if(expression_call_p(exp) &&
2208  basic bexp = basic_of_expression(exp);
2209 
2210  if(basic_int_p(bexp)) {
2211  we2 = words_subexpression(exp, MAXIMAL_PRECEDENCE, false, ppdl);
2212  }
2213  else
2214  we2 = words_subexpression(exp, prec, false, ppdl);
2215  free_basic(bexp);
2216  }
2217  else
2218  we2 = words_subexpression(exp, prec, false, ppdl);
2219  }
2220  else {
2221  /* If the operator in the second subexpression has the same
2222  priority as the current operator, it has to be parenthesized
2223  to respect the structure imposed by the programmer. For
2224  instance, a+(b+c) does require parentheses whereas (a+b)+c is
2225  the same as a+b+c. So we1 and we2 cannot be processed exactly
2226  in the same way. */
2227  we2 = words_subexpression(EXPRESSION(CAR(CDR(args))), prec+1,
2228  prec<MINIMAL_ARITHMETIC_PRECEDENCE, ppdl);
2229  }
2230 
2231  /* Use precedence to generate or not parentheses,
2232  * unless parentheses are always required */
2233  if(prec < precedence || (!precedence_p && precedence>0)) {
2234  pc = CHAIN_SWORD(pc, "(");
2235  }
2236 
2238  && strcmp(fun, FIELD_OPERATOR_NAME) == 0) {
2239  pc = gen_nconc(pc, we1);
2240  }
2241  else if(prettyprint_language_is_c_p()) {
2242  /* Check that C ambiguities such as "a+++b" for "a++ + b" or "a +
2243  ++b" are not generated */
2244  if(strcmp(fun,"+")==0 || strcmp(fun, "-")==0) {
2245  pips_assert("left and right subexpressions are defined",
2246  !ENDP(we1) && !ENDP(we2));
2247  string l = STRING(CAR(gen_last(we1)));
2248  string f = STRING(CAR(we2));
2249  char lc = *(l+strlen(l)-1);
2250  char fc = *f;
2251  string pre = "";
2252  string post = "";
2253  if(*fun==lc)
2254  pre = " ";
2255  if(*fun==fc)
2256  post = " ";
2257  pc = gen_nconc(pc, we1);
2258  pc = CHAIN_SWORD(pc, pre);
2259  pc = CHAIN_SWORD(pc, fun);
2260  pc = CHAIN_SWORD(pc, post);
2261  pc = gen_nconc(pc, we2);
2262  }
2263  else {
2264  pc = gen_nconc(pc, we1);
2265  pc = CHAIN_SWORD(pc, fun);
2266  pc = gen_nconc(pc, we2);
2267  }
2268  }
2269  else {
2270  pc = gen_nconc(pc, we1);
2271  pc = CHAIN_SWORD(pc, fun);
2272  pc = gen_nconc(pc, we2);
2273  }
2274 
2275  if(prec < precedence || (!precedence_p && precedence>0)) {
2276  pc = CHAIN_SWORD(pc, ")");
2277  }
2278 
2279  return(pc);
2280 }
void free_basic(basic p)
Definition: ri.c:107
bool prettyprint_language_is_fortran95_p()
Definition: language.c:83
#define MINIMAL_ARITHMETIC_PRECEDENCE
Definition: misc.c:139
static const char * renamed_op_handling(const char *name)
Definition: misc.c:1252
#define ENTITY_DIVIDE_P(e)
#define MINUS_OPERATOR_NAME
#define FIELD_OPERATOR_NAME
Definition: ri-util-local.h:91
#define DIVIDE_OPERATOR_NAME
#define MULTIPLY_OPERATOR_NAME
basic basic_of_expression(expression)
basic basic_of_expression(expression exp): Makes a basic of the same basic as the expression "exp".
Definition: type.c:1383
#define basic_int_p(x)
Definition: ri.h:614
#define syntax_call(x)
Definition: ri.h:2736

References basic_int_p, basic_of_expression(), call_arguments, call_function, CAR, CDR, CHAIN_SWORD, DIVIDE_OPERATOR_NAME, ENDP, ENTITY_DIVIDE_P, entity_local_name(), exp, EXPRESSION, expression_call_p(), expression_syntax, f(), FIELD_OPERATOR_NAME, free_basic(), gen_last(), gen_nconc(), intrinsic_precedence(), MAXIMAL_PRECEDENCE, MINIMAL_ARITHMETIC_PRECEDENCE, MINUS_OPERATOR_NAME, MULTIPLY_OPERATOR_NAME, NIL, pips_assert, precedence_p, prettyprint_language_is_c_p(), prettyprint_language_is_fortran95_p(), renamed_op_handling(), STRING, syntax_call, words_intrinsic_precedence(), and words_subexpression().

+ Here is the call graph for this function:

◆ words_infix_nary_op()

static list words_infix_nary_op ( call  obj,
int  precedence,
bool  leftmost,
list ppdl 
)
static

Extension of "words_infix_binary_op" function for nary operators used in the EOLE project - (since "nary" assumes operators with at least 2 op) - JZ (Oct.

98) of string

f string

of expressions

get current operator precedence

open parenthese if necessary

reach the second arg

for all args

divide operator

minus operator

precedence is greater than * or /

operator prettyprint

close parenthese if necessary

Definition at line 2107 of file misc.c.

2108 {
2109  list /*of string*/ pc = NIL;
2110  list /* of expressions */ args = call_arguments(obj);
2111 
2112  /* get current operator precedence */
2113  int prec = words_intrinsic_precedence(obj);
2114 
2115  expression exp1 = EXPRESSION(CAR(args));
2116  expression exp2;
2117 
2118  list we1 = words_subexpression(exp1, prec,
2119  prec>=MINIMAL_ARITHMETIC_PRECEDENCE? leftmost: true, ppdl);
2120  list we2;
2121 
2122  /* open parenthese if necessary */
2123  if ( prec < precedence )
2124  pc = CHAIN_SWORD(pc, "(");
2125  pc = gen_nconc(pc, we1);
2126 
2127  /* reach the second arg */
2128  args = CDR(args);
2129 
2130  for(; args; args=CDR(args)) { /* for all args */
2131  exp2 = EXPRESSION(CAR(args));
2132 
2133  /*
2134  * If the infix operator is either "-" or "/", I prefer not to delete
2135  * the parentheses of the second expression.
2136  * Ex: T = X - ( Y - Z ) and T = X / (Y*Z)
2137  *
2138  * Lei ZHOU Nov. 4 , 1991
2139  */
2140  if ( strcmp(entity_local_name(call_function(obj)), "/") == 0 ) /* divide operator */
2141  we2 = words_subexpression(exp2, MAXIMAL_PRECEDENCE, false, ppdl);
2142  else if ( strcmp(entity_local_name(call_function(obj)), "-") == 0 ) { /* minus operator */
2143  if ( expression_call_p(exp2) &&
2145  intrinsic_precedence("*") )
2146  /* precedence is greater than * or / */
2147  we2 = words_subexpression(exp2, prec, false, ppdl);
2148  else
2149  we2 = words_subexpression(exp2, MAXIMAL_PRECEDENCE, false, ppdl);
2150  }
2151  else {
2152  we2 = words_subexpression(exp2, prec,
2153  prec<MINIMAL_ARITHMETIC_PRECEDENCE, ppdl);
2154  }
2155 
2156  /* operator prettyprint */
2158 
2159  pc = gen_nconc(pc, we2);
2160  }
2161  /* close parenthese if necessary */
2162  if ( prec < precedence )
2163  pc = CHAIN_SWORD(pc, ")");
2164 
2165  return(pc);
2166 }
static const char * get_special_prettyprint_for_operator(call obj)
Check if the given operator is associated with a special prettyprint.
Definition: misc.c:2066

References call_arguments, call_function, CAR, CDR, CHAIN_SWORD, entity_local_name(), EXPRESSION, expression_call_p(), expression_syntax, gen_nconc(), get_special_prettyprint_for_operator(), intrinsic_precedence(), MAXIMAL_PRECEDENCE, MINIMAL_ARITHMETIC_PRECEDENCE, NIL, syntax_call, words_intrinsic_precedence(), and words_subexpression().

+ Here is the call graph for this function:

◆ words_intrinsic_call()

static list words_intrinsic_call ( call  obj,
int  precedence,
bool  leftmost,
list ppdl 
)
static

Definition at line 2525 of file misc.c.

2526 {
2529  }
2530  const char *n = entity_local_name(call_function(obj));
2532  if(d!= HASH_UNDEFINED_VALUE)
2533  return d->f(obj, precedence, leftmost, ppdl);
2534  else
2535  return words_regular_call(obj, false, ppdl);
2536 }
list(* f)(call, int, bool, list *)

References call_function, entity_local_name(), intrinsic_desc_t::f, hash_get(), hash_table_undefined_p, HASH_UNDEFINED_VALUE, init_intrinsic_handlers(), intrinsic_handlers, and words_regular_call().

Referenced by words_call().

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

◆ words_intrinsic_precedence()

static int words_intrinsic_precedence ( call  obj)
static

Definition at line 2552 of file misc.c.

2553 {
2554  const char *n = entity_local_name(call_function(obj));
2555  return intrinsic_precedence(n);
2556 }

References call_function, entity_local_name(), and intrinsic_precedence().

Referenced by words_assign_op(), words_assign_substring_op(), words_comma_op(), words_conditional_op(), words_infix_binary_op(), words_infix_nary_op(), words_inverse_op(), words_postfix_unary_op(), words_prefix_unary_op(), words_substring_op(), and words_unary_minus().

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

◆ words_inverse_op()

static list words_inverse_op ( call  obj,
int  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)
static

WARNING : the floating point division is used wether b is an int or not ! (1.0/b) – in fact b should not be an int !

of string

of string

Definition at line 1892 of file misc.c.

1896 {
1897  list /* of string */ pc = NIL;
1898 
1900  int prec = words_intrinsic_precedence(obj);
1901 
1902  if ( prec < precedence)
1903  pc = CHAIN_SWORD(pc, "(");
1904  pc = CHAIN_SWORD(pc, "1./");
1906  false, ppdl));
1907 
1908  if ( prec < precedence)
1909  pc = CHAIN_SWORD(pc, ")");
1910 
1911  return(pc);
1912 }

References call_arguments, CAR, CHAIN_SWORD, EXPRESSION, gen_nconc(), MAXIMAL_PRECEDENCE, NIL, words_intrinsic_precedence(), and words_subexpression().

+ Here is the call graph for this function:

◆ words_io_control()

static list words_io_control ( list iol,
int __attribute__((unused))  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)
static

Definition at line 1467 of file misc.c.

1471 {
1472  list pc = NIL;
1473  list pio = *iol;
1474 
1475  while (pio != NIL) {
1477  call c;
1478 
1479  if (! syntax_call_p(s)) {
1480  pips_internal_error("call expected");
1481  }
1482 
1483  c = syntax_call(s);
1484 
1485  if (strcmp(entity_local_name(call_function(c)), IO_LIST_STRING_NAME) == 0) {
1486  *iol = CDR(pio);
1487  return(pc);
1488  }
1489 
1490  if (pc != NIL)
1491  pc = CHAIN_SWORD(pc, ",");
1492 
1494  pc = gen_nconc(pc, words_expression(EXPRESSION(CAR(CDR(pio))), ppdl));
1495 
1496  pio = CDR(CDR(pio));
1497  }
1498 
1499  if (pio != NIL)
1500  pips_internal_error("bad format");
1501 
1502  *iol = NIL;
1503 
1504  return(pc);
1505 }
#define IO_LIST_STRING_NAME
Definition: ri-util-local.h:82
#define syntax_call_p(x)
Definition: ri.h:2734

References call_function, CAR, CDR, CHAIN_SWORD, entity_local_name(), EXPRESSION, expression_syntax, gen_nconc(), IO_LIST_STRING_NAME, NIL, pips_internal_error, syntax_call, syntax_call_p, and words_expression().

Referenced by words_io_inst().

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

◆ words_io_inst()

static list words_io_inst ( call  obj,
int  precedence,
bool  leftmost,
list ppdl 
)
static

AP: I try to convert WRITE to PRINT. Three conditions must be fullfilled. The first, and obvious, one, is that the function has to be WRITE. Secondly, "FMT" has to be equal to "*". Finally, "UNIT" has to be equal either to "*" or "6". In such case, "WRITE(*,*)" is replaced by "PRINT *,".

GO: Not anymore for UNIT=6 leave it ...

Avoid to use words_expression(arg) because it set some attachments and unit_words may not be used later... RK.

The * format is coded as a call to "LIST_DIRECTED_FORMAT_NAME" function:

To display the format later:

Avoid to use words_expression(arg) because it set some attachments and unit_words may not be used later... RK.

The * format is coded as a call to "LIST_DIRECTED_FORMAT_NAME" function:

To display the unit later:

WRITE (*,*) -> PRINT *

WRITE (*,*) pio -> PRINT *, pio

WRITE (*,*) -> PRINT *

READ (*,*) -> READ *

READ (*,*) pio -> READ *, pio

READ (*,*) -> READ *

There is a FORMAT:

FI: missing argument; I use "precedence" because I've no clue; see LZ

because the "IOLIST=" keyword is embedded in the list and because the first IOLIST= has already been skipped, only odd elements are printed

Definition at line 1573 of file misc.c.

1575 {
1576  list pc = NIL;
1577  list pcio = call_arguments(obj);
1578  list pio_write = pcio;
1579  bool good_fmt = false;
1580  bool good_unit = false;
1581  bool iolist_reached = false;
1582  bool complex_io_control_list = false;
1583  expression fmt_arg = expression_undefined;
1584  expression unit_arg = expression_undefined;
1585  const char* called = entity_local_name(call_function(obj));
1586  bool space_p = get_bool_property("PRETTYPRINT_LISTS_WITH_SPACES");
1587 
1588  /* AP: I try to convert WRITE to PRINT. Three conditions must be
1589  fullfilled. The first, and obvious, one, is that the function has
1590  to be WRITE. Secondly, "FMT" has to be equal to "*". Finally,
1591  "UNIT" has to be equal either to "*" or "6". In such case,
1592  "WRITE(*,*)" is replaced by "PRINT *,". */
1593  /* GO: Not anymore for UNIT=6 leave it ... */
1594  while((pio_write != NIL) && (!iolist_reached)) {
1595  syntax s = expression_syntax(EXPRESSION(CAR(pio_write)));
1596  call c;
1597  expression arg = EXPRESSION(CAR(CDR(pio_write)));
1598 
1599  if(!syntax_call_p(s)) {
1600  pips_internal_error("call expected");
1601  }
1602 
1603  c = syntax_call(s);
1604  if(strcmp(entity_local_name(call_function(c)), "FMT=") == 0) {
1605  /* Avoid to use words_expression(arg) because it set some
1606  attachments and unit_words may not be used
1607  later... RK. */
1608  entity f;
1609  /* The * format is coded as a call to
1610  "LIST_DIRECTED_FORMAT_NAME" function: */
1611  good_fmt = syntax_call_p(expression_syntax(arg))
1614  && (strcmp(entity_local_name(f), LIST_DIRECTED_FORMAT_NAME) == 0);
1615  pio_write = CDR(CDR(pio_write));
1616  /* To display the format later: */
1617  fmt_arg = arg;
1618  } else if(strcmp(entity_local_name(call_function(c)), "UNIT=") == 0) {
1619  /* Avoid to use words_expression(arg) because it set some
1620  attachments and unit_words may not be used
1621  later... RK. */
1622  entity f;
1623  /* The * format is coded as a call to
1624  "LIST_DIRECTED_FORMAT_NAME" function: */
1625  good_unit = syntax_call_p(expression_syntax(arg))
1628  && (strcmp(entity_local_name(f), LIST_DIRECTED_FORMAT_NAME) == 0);
1629  /* To display the unit later: */
1630  unit_arg = arg;
1631  pio_write = CDR(CDR(pio_write));
1632  } else if(strcmp(entity_local_name(call_function(c)), IO_LIST_STRING_NAME)
1633  == 0) {
1634  iolist_reached = true;
1635  pio_write = CDR(pio_write);
1636  } else {
1637  complex_io_control_list = true;
1638  pio_write = CDR(CDR(pio_write));
1639  }
1640  }
1641 
1642  if(good_fmt && good_unit && same_string_p(called, "WRITE")) {
1643  /* WRITE (*,*) -> PRINT * */
1644 
1645  if(pio_write != NIL) /* WRITE (*,*) pio -> PRINT *, pio */
1646  {
1647  pc = CHAIN_SWORD(pc, "PRINT *, ");
1648  } else /* WRITE (*,*) -> PRINT * */
1649  {
1650  pc = CHAIN_SWORD(pc, "PRINT * ");
1651  }
1652 
1653  pcio = pio_write;
1654  } else if(good_fmt && good_unit && same_string_p(called, "READ")) {
1655  /* READ (*,*) -> READ * */
1656 
1657  if(pio_write != NIL) /* READ (*,*) pio -> READ *, pio */
1658  {
1659  switch(get_prettyprint_language_tag()) {
1660  case is_language_fortran:
1661  case is_language_fortran95:
1662  pc = CHAIN_SWORD(pc, "READ *, ");
1663  break;
1664  case is_language_c:
1665  pc = CHAIN_SWORD(pc, "_f77_intrinsics_read_(");
1666  break;
1667  default:
1668  pips_internal_error("Language unknown !");
1669  break;
1670  }
1671  } else /* READ (*,*) -> READ * */
1672  {
1673  pc = CHAIN_SWORD(pc, "READ * ");
1674  }
1675  pcio = pio_write;
1676  } else if(!complex_io_control_list) {
1677  list unit_words = words_expression(unit_arg, ppdl);
1678  pips_assert("A unit must be defined", !ENDP(unit_words));
1680  pc = CHAIN_SWORD(pc, " (");
1681  pc = gen_nconc(pc, unit_words);
1682 
1683  if(!expression_undefined_p(fmt_arg)) {
1684  /* There is a FORMAT: */
1685  pc = CHAIN_SWORD(pc, space_p? ", " : ",");
1686  pc = gen_nconc(pc, words_expression(fmt_arg, ppdl));
1687  }
1688 
1689  pc = CHAIN_SWORD(pc, ") ");
1690  pcio = pio_write;
1691  } else {
1693  pc = CHAIN_SWORD(pc, " (");
1694  /* FI: missing argument; I use "precedence" because I've no clue;
1695  see LZ */
1696  pc = gen_nconc(pc, words_io_control(&pcio, precedence, leftmost, ppdl));
1697  pc = CHAIN_SWORD(pc, ") ");
1698  /*
1699  free_words(fmt_words);
1700  */
1701  }
1702 
1703  /* because the "IOLIST=" keyword is embedded in the list
1704  and because the first IOLIST= has already been skipped,
1705  only odd elements are printed */
1706  MAPL(pp, {
1707  pc = gen_nconc(pc, words_expression(EXPRESSION(CAR(pp)), ppdl));
1708  if (CDR(pp) != NIL) {
1709  POP(pp);
1710  if(pp==NIL)
1711  pips_internal_error("missing element in IO list");
1712  pc = CHAIN_SWORD(pc, space_p? ", " : ",");
1713  }
1714  }, pcio);
1715 
1717  pc = CHAIN_SWORD(pc, ") ");
1718 
1719  return (pc);
1720 }
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define LIST_DIRECTED_FORMAT_NAME
Definition: naming-local.h:97
static list words_io_control(list *iol, int __attribute__((unused)) precedence, bool __attribute__((unused)) leftmost, list *ppdl)
Definition: misc.c:1467
#define expression_undefined_p(x)
Definition: ri.h:1224

References call_arguments, call_function, CAR, CDR, CHAIN_SWORD, ENDP, entity_initial, entity_local_name(), EXPRESSION, expression_syntax, expression_undefined, expression_undefined_p, f(), gen_nconc(), get_bool_property(), get_prettyprint_language_tag(), IO_LIST_STRING_NAME, is_language_c, is_language_fortran, is_language_fortran95, LIST_DIRECTED_FORMAT_NAME, MAPL, NIL, pips_assert, pips_internal_error, POP, prettyprint_language_is_c_p(), same_string_p, syntax_call, syntax_call_p, value_intrinsic_p, words_expression(), and words_io_control().

+ Here is the call graph for this function:

◆ words_list_directed()

static list words_list_directed ( call __attribute__((unused))  obj,
int __attribute__((unused))  precedence,
bool __attribute__((unused))  leftmost,
list __attribute__((unused)) *  ppdl 
)
static

Definition at line 1560 of file misc.c.

1564 {
1565  list pc = NIL;
1566 
1567  pc = CHAIN_SWORD(pc, "*");
1568 
1569  return(pc);
1570 }

References CHAIN_SWORD, and NIL.

◆ words_loop_range()

list words_loop_range ( range  obj,
list ppdl 
)

exported for craft

expression_constant_p(range_increment(obj)) &&

Parameters
objbj
ppdlpdl

Definition at line 434 of file misc.c.

434  {
435  list pc;
437 
438  pc = words_subexpression(range_lower(obj), 0, true, ppdl);
439  pc = CHAIN_SWORD(pc,", ");
440  pc = gen_nconc(pc, words_subexpression(range_upper(obj), 0, true, ppdl));
441  if (/* expression_constant_p(range_increment(obj)) && */
442  strcmp( entity_local_name(call_function(c)), "1") == 0 )
443  return(pc);
444  pc = CHAIN_SWORD(pc,", ");
445  pc = gen_nconc(pc, words_expression(range_increment(obj), ppdl));
446 
447  return(pc);
448 }

References call_function, CHAIN_SWORD, entity_local_name(), expression_syntax, gen_nconc(), range_increment, range_lower, range_upper, syntax_call, words_expression(), and words_subexpression().

Referenced by text_loop_craft(), text_loop_default(), and words_implied_do().

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

◆ words_nullary_op()

static list words_nullary_op ( call  obj,
int  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)
static

Definition at line 1445 of file misc.c.

1448  {
1449  list result = NIL;
1450  switch (get_prettyprint_language_tag()) {
1451  case is_language_fortran:
1452  case is_language_fortran95:
1453  result = words_nullary_op_fortran(obj, precedence, leftmost, ppdl);
1454  break;
1455  case is_language_c:
1456  result = words_nullary_op_c(obj, precedence, leftmost, ppdl);
1457  break;
1458  default:
1459  pips_internal_error("Language unknown !");
1460  break;
1461  }
1462  return result;
1463 }
static list words_nullary_op_c(call obj, int precedence __attribute__((unused)), bool leftmost __attribute__((unused)), list *ppdl)
Definition: misc.c:1330
static list words_nullary_op_fortran(call obj, int precedence, bool __attribute__((unused)) leftmost, list *ppdl)
Definition: misc.c:1405

References get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, NIL, pips_internal_error, words_nullary_op_c(), and words_nullary_op_fortran().

+ Here is the call graph for this function:

◆ words_nullary_op_c()

static list words_nullary_op_c ( call  obj,
int precedence   __attribute__(unused),
bool leftmost   __attribute__(unused),
list ppdl 
)
static

STOP and PAUSE and RETURN in Fortran may have 0 or 1 argument. STOP and PAUSE are prettyprinted in C using PIPS specific C functions.

Definition at line 1330 of file misc.c.

1335 {
1336  list pc = NIL;
1337  list args = call_arguments(obj);
1338  entity func = call_function(obj);
1339  const char* fname = entity_local_name(func);
1340  int nargs = gen_length(args);
1341  bool parentheses_p=true;
1342 
1343  /* STOP and PAUSE and RETURN in Fortran may have 0 or 1 argument.
1344  STOP and PAUSE are prettyprinted in C using PIPS specific C functions. */
1345 
1346  if (nargs==0)
1347  {
1349  pc = CHAIN_SWORD(pc, "exit(0)");
1350  else if(same_string_p(fname,RETURN_FUNCTION_NAME)
1352  pc = CHAIN_SWORD(pc, "return");
1353  else if(same_string_p(fname,PAUSE_FUNCTION_NAME))
1354  pc = CHAIN_SWORD(pc, "_f77_intrinsics_pause_(0)");
1355  else if(same_string_p(fname,CONTINUE_FUNCTION_NAME))
1356  pc = CHAIN_SWORD(pc, "");
1357  else if ((same_string_p(fname,OMP_OMP_FUNCTION_NAME)) ||
1360  pc = CHAIN_SWORD(pc, fname);
1361  else
1362  pips_internal_error("Unknown nullary operator");
1363  }
1364  else if (nargs==1){
1365  expression e = EXPRESSION(CAR(args));
1366 
1367  if(same_string_p(fname,STOP_FUNCTION_NAME)){
1368  basic b=expression_basic(e);
1369  if(basic_int_p(b)){
1370  // Missing: declaration of exit() if Fortran code handled
1371  pc = CHAIN_SWORD(pc, "exit");
1372  }
1373  else if(basic_string_p(b)){
1374  pc = CHAIN_SWORD(pc, "_f77_intrinsics_stop_");
1375  }
1376  }
1377  else if(same_string_p(fname,RETURN_FUNCTION_NAME)
1379  pc = CHAIN_SWORD(pc, "return");
1380  parentheses_p = false;
1381  //pips_user_error("alternate returns are not supported in C\n");
1382  }
1383  else if(same_string_p(fname, PAUSE_FUNCTION_NAME)){
1384  pc = CHAIN_SWORD(pc, "_f77_intrinsics_pause_");
1385  }
1386  else {
1387  pips_internal_error("unexpected one argument");
1388  }
1389  pc = CHAIN_SWORD(pc, parentheses_p?"(":" ");
1390  pc = gen_nconc(pc, words_subexpression(e, precedence, true, ppdl));
1391  pc = CHAIN_SWORD(pc, parentheses_p?")":"");
1392  }
1393  else {
1394  // should always be an error? workaround for p4a test, FC 2015-11-27
1395  pips_user_warning("function %s: %d arguments instead of 0 or 1.",
1396  fname, nargs);
1398  pips_internal_error("unexpected %s call with %d arguments", fname, nargs);
1399  }
1400 
1401  return pc;
1402 }
#define OMP_FOR_FUNCTION_NAME
#define OMP_OMP_FUNCTION_NAME
#define OMP_PARALLEL_FUNCTION_NAME
#define STOP_FUNCTION_NAME
#define PAUSE_FUNCTION_NAME
basic expression_basic(expression)
Definition: type.c:1115
#define basic_string_p(x)
Definition: ri.h:629

References basic_int_p, basic_string_p, C_RETURN_FUNCTION_NAME, call_arguments, call_function, CAR, CHAIN_SWORD, CONTINUE_FUNCTION_NAME, entity_local_name(), EXPRESSION, expression_basic(), gen_length(), gen_nconc(), NIL, OMP_FOR_FUNCTION_NAME, OMP_OMP_FUNCTION_NAME, OMP_PARALLEL_FUNCTION_NAME, PAUSE_FUNCTION_NAME, pips_internal_error, pips_user_warning, RETURN_FUNCTION_NAME, same_string_p, STOP_FUNCTION_NAME, and words_subexpression().

Referenced by words_nullary_op().

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

◆ words_nullary_op_fortran()

static list words_nullary_op_fortran ( call  obj,
int  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)
static

Definition at line 1405 of file misc.c.

1409 {
1410  list pc = NIL;
1411  list args = call_arguments(obj);
1412  entity func = call_function(obj);
1413  const char* fname = entity_local_name(func);
1414 
1418  else if (same_string_p(fname,OMP_FOR_FUNCTION_NAME))
1419  pc = CHAIN_SWORD(pc, "do");
1420  else
1421  pc = CHAIN_SWORD(pc, fname);
1422 
1423  // STOP and PAUSE and RETURN in fortran may have 0 or 1 argument.A Mensi
1424  if(gen_length(args)==1) {
1429  expression e = EXPRESSION(CAR(args));
1430  pc = CHAIN_SWORD(pc, " ");
1431  pc = gen_nconc(pc, words_subexpression(e, precedence, true, ppdl));
1432  }
1433  else {
1434  pips_internal_error("unexpected arguments");
1435  }
1436  }
1437  else if(gen_length(args)>1) {
1438  pips_internal_error("unexpected arguments");
1439  }
1440 
1441  return(pc);
1442 }

References C_RETURN_FUNCTION_NAME, call_arguments, call_function, CAR, CHAIN_SWORD, entity_local_name(), EXPRESSION, gen_length(), gen_nconc(), NIL, OMP_FOR_FUNCTION_NAME, PAUSE_FUNCTION_NAME, pips_internal_error, RETURN_FUNCTION_NAME, same_string_p, STOP_FUNCTION_NAME, and words_subexpression().

Referenced by words_nullary_op().

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

◆ words_omp_red()

static list words_omp_red ( call  obj,
int precedence   __attribute__(unused),
bool leftmost   __attribute__(unused),
list ppdl 
)
static
Returns
a list of string with the prettyprint of a omp reduction clause

Definition at line 1293 of file misc.c.

1297 {
1298  list result = NIL;
1299  entity fct = call_function(obj);
1300  result = CHAIN_SWORD(result, entity_user_name(fct));
1301  result = CHAIN_SWORD(result, "(");
1302  // the reduction arguments as an expression list
1303  list args = call_arguments (obj);
1304  pips_assert ("no arguments for reduction clause", args != NIL);
1305  int nb_arg = 0;
1306  FOREACH (EXPRESSION, arg, args) {
1307  if (nb_arg == 0) {
1308  // the first argument is an operator and need to be handle separately
1309  // because of the intenal management of operator
1310  const char* op;
1311  syntax syn = expression_syntax (arg);
1312  pips_assert ("should be a reference", syntax_tag (syn) == is_syntax_reference);
1314  op = renamed_op_handling (op);
1315  CHAIN_SWORD(result, op);
1316  }
1317  else { // (nb_arg != 0)
1318  result = (nb_arg == 1)? CHAIN_SWORD(result,":") : CHAIN_SWORD(result,",");
1319  result = gen_nconc (result, words_expression(arg, ppdl));
1320  }
1321  nb_arg++;
1322  }
1323  pips_assert ("reduction clause has at least two arguments", nb_arg > 1);
1324  result = CHAIN_SWORD(result, ")");
1325  return result;
1326 }
#define syntax_tag(x)
Definition: ri.h:2727
@ is_syntax_reference
Definition: ri.h:2691

References call_arguments, call_function, CHAIN_SWORD, entity_local_name(), entity_user_name(), EXPRESSION, expression_syntax, FOREACH, gen_nconc(), is_syntax_reference, NIL, pips_assert, reference_variable, renamed_op_handling(), syntax_reference, syntax_tag, and words_expression().

+ Here is the call graph for this function:

◆ words_postfix_unary_op()

static list words_postfix_unary_op ( call  obj,
int  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)
static

Definition at line 1831 of file misc.c.

1835 {
1836  list pc = NIL;
1838  int prec = words_intrinsic_precedence(obj);
1839  const char* fun = entity_local_name(call_function(obj));
1840 
1841  pc = gen_nconc(pc, words_subexpression(e, prec, false, ppdl));
1842 
1843  if (strcmp(fun,POST_INCREMENT_OPERATOR_NAME) == 0)
1844  fun = "++";
1845  else if (strcmp(fun,POST_DECREMENT_OPERATOR_NAME) == 0)
1846  fun = "--";
1847 
1848  pc = CHAIN_SWORD(pc,fun);
1849 
1850  if(prec < precedence || (!precedence_p && precedence>0)) {
1851  pc = CONS(STRING, MAKE_SWORD("("), pc);
1852  pc = CHAIN_SWORD(pc, ")");
1853  }
1854 
1855  return(pc);
1856 }
#define POST_DECREMENT_OPERATOR_NAME
Definition: ri-util-local.h:98
#define POST_INCREMENT_OPERATOR_NAME
Definition: ri-util-local.h:97

References call_arguments, call_function, CAR, CHAIN_SWORD, CONS, entity_local_name(), EXPRESSION, gen_nconc(), MAKE_SWORD, NIL, POST_DECREMENT_OPERATOR_NAME, POST_INCREMENT_OPERATOR_NAME, precedence_p, STRING, words_intrinsic_precedence(), and words_subexpression().

+ Here is the call graph for this function:

◆ words_prefix_unary_op()

static list words_prefix_unary_op ( call  obj,
int  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)
static

Since we put no spaces around an operator (to not change Fortran), the blank before '*' is used to avoid the confusion in the case of divide operator, i.e d1 = 1.0 / *det in function inv_j, SPEC2000 quake benchmark.

But we do not want this in a lhs and espcially with a double dereferencing.

You do not want to transform +1 + +1 into +1++ 1

Maybe the precedence could be useful to avoid adding a useless SPACE, but unary plus is rare enough to reduce the ROI of such anoptimization to zero.

Definition at line 1781 of file misc.c.

1785 {
1786  list pc = NIL;
1788  int prec = words_intrinsic_precedence(obj);
1789  const char* fun = entity_local_name(call_function(obj));
1790  if (strcmp(fun,PRE_INCREMENT_OPERATOR_NAME) == 0)
1791  fun = "++";
1792  else if (strcmp(fun,PRE_DECREMENT_OPERATOR_NAME) == 0)
1793  fun = "--";
1794  else if (strcmp(fun,ADDRESS_OF_OPERATOR_NAME) == 0)
1795  fun = "&";
1796  else if (strcmp(fun,C_NOT_OPERATOR_NAME) == 0)
1797  fun = "!";
1798  else if (strcmp(fun,BITWISE_NOT_OPERATOR_NAME) == 0)
1799  fun = "~";
1800  else if (strcmp(fun,DEREFERENCING_OPERATOR_NAME) == 0)
1801  /* Since we put no spaces around an operator (to not change Fortran), the blank
1802  before '*' is used to avoid the confusion in the case of divide operator, i.e
1803  d1 = 1.0 / *det in function inv_j, SPEC2000 quake benchmark.
1804 
1805  But we do not want this in a lhs and espcially with a double dereferencing. */
1806  fun = "*";
1807  else if(prettyprint_language_is_c_p()){
1808  if(strcasecmp(fun, NOT_OPERATOR_NAME)==0)
1809  fun="!";
1810  if(strcasecmp(fun, UNARY_PLUS_OPERATOR_NAME)==0) {
1811  /* You do not want to transform +1 + +1 into +1++ 1 */
1812  /* Maybe the precedence could be useful to avoid adding a
1813  useless SPACE, but unary plus is rare enough to reduce
1814  the ROI of such anoptimization to zero. */
1815  fun=" +";
1816  }
1817  }
1818 
1819  pc = CHAIN_SWORD(pc,fun);
1820  pc = gen_nconc(pc, words_subexpression(e, prec, false, ppdl));
1821 
1822  if(prec < precedence || (!precedence_p && precedence>0)) {
1823  pc = CONS(STRING, MAKE_SWORD("("), pc);
1824  pc = CHAIN_SWORD(pc, ")");
1825  }
1826 
1827  return(pc);
1828 }
#define DEREFERENCING_OPERATOR_NAME
Definition: ri-util-local.h:93
#define C_NOT_OPERATOR_NAME
#define ADDRESS_OF_OPERATOR_NAME
#define PRE_DECREMENT_OPERATOR_NAME
#define UNARY_PLUS_OPERATOR_NAME
#define BITWISE_NOT_OPERATOR_NAME
#define PRE_INCREMENT_OPERATOR_NAME
Definition: ri-util-local.h:99
#define NOT_OPERATOR_NAME

References ADDRESS_OF_OPERATOR_NAME, BITWISE_NOT_OPERATOR_NAME, C_NOT_OPERATOR_NAME, call_arguments, call_function, CAR, CHAIN_SWORD, CONS, DEREFERENCING_OPERATOR_NAME, entity_local_name(), EXPRESSION, gen_nconc(), MAKE_SWORD, NIL, NOT_OPERATOR_NAME, PRE_DECREMENT_OPERATOR_NAME, PRE_INCREMENT_OPERATOR_NAME, precedence_p, prettyprint_language_is_c_p(), STRING, UNARY_PLUS_OPERATOR_NAME, words_intrinsic_precedence(), and words_subexpression().

+ Here is the call graph for this function:

◆ words_range()

list words_range ( range  obj,
list ppdl 
)
Returns
a list of string

if undefined I print a star, why not!?

C does not include ranges, but the PIPS internal representation does. For instance, constant ranges can be useful to express effects or regions for intrinsics. To be discussed with Beatrice: e.g. memcpy(), strncp(). Especially when they are called with constant arguments.

Parameters
objbj
ppdlpdl

Definition at line 538 of file misc.c.

538  {
539  list pc = NIL;
540 
541  /* if undefined I print a star, why not!? */
543  pc = CONS(STRING, MAKE_SWORD("*"), NIL);
544  } else {
545  switch(get_prettyprint_language_tag()) {
546  case is_language_fortran: {
548 
549  pc = CHAIN_SWORD(pc,"(/ (I,I=");
550  pc = gen_nconc(pc, words_expression(range_lower(obj), ppdl));
551  pc = CHAIN_SWORD(pc,",");
552  pc = gen_nconc(pc, words_expression(range_upper(obj), ppdl));
553  if(strcmp(entity_local_name(call_function(c)), "1") != 0) {
554  pc = CHAIN_SWORD(pc,",");
555  pc = gen_nconc(pc, words_expression(range_increment(obj), ppdl));
556  }
557  pc = CHAIN_SWORD(pc,") /)") ;
558  break;
559  }
560  case is_language_fortran95: {
561  // Print the lower bound if != *
563  pc = gen_nconc(pc, words_expression(range_lower(obj), ppdl));
564  }
565 
566  // Print the upper bound if != *
567  pc = CHAIN_SWORD(pc,":");
569  pc = gen_nconc(pc, words_expression(range_upper(obj), ppdl));
570  }
571 
572  // Print the increment if != 1
574  if(strcmp(entity_local_name(call_function(c)), "1") != 0) {
575  pc = CHAIN_SWORD(pc,":");
576  pc = gen_nconc(pc, words_expression(range_increment(obj), ppdl));
577  }
578  break;
579  }
580  case is_language_c:
581  /* C does not include ranges, but the PIPS internal
582  representation does. For instance, constant ranges can be
583  useful to express effects or regions for intrinsics. To be
584  discussed with Beatrice: e.g. memcpy(), strncp(). Especially
585  when they are called with constant arguments. */
586 
587  // FI: we might still want a warning, but the compiler will
588  // choke anyway if this is used to prettyprint some C source code
589  // pips_internal_error("I don't know how to print a range in C !");
590 
591  // FI: copied from Fortran 95, but we may prefer to see the stars
592 
593  // Print the lower bound if != *
595  pc = gen_nconc(pc, words_expression(range_lower(obj), ppdl));
596  }
597 
598  // Print the upper bound if != *
599  pc = CHAIN_SWORD(pc,":");
601  pc = gen_nconc(pc, words_expression(range_upper(obj), ppdl));
602  }
603 
604  // Print the increment if != 1
606  if(strcmp(entity_local_name(call_function(c)), "1") != 0) {
607  pc = CHAIN_SWORD(pc,":");
608  pc = gen_nconc(pc, words_expression(range_increment(obj), ppdl));
609  }
610 
611  break;
612  default:
613  pips_internal_error("Language unknown !");
614  break;
615  }
616  }
617  return pc;
618 }
bool unbounded_expression_p(expression e)
Definition: expression.c:4329

References call_function, CHAIN_SWORD, CONS, entity_local_name(), expression_syntax, expression_undefined_p, gen_nconc(), get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, MAKE_SWORD, NIL, pips_internal_error, range_increment, range_lower, range_upper, STRING, syntax_call, unbounded_expression_p(), and words_expression().

Referenced by make_bounds(), and words_syntax().

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

◆ Words_Reference()

list Words_Reference ( reference  obj)
Parameters
objbj

Definition at line 786 of file misc.c.

787 {
789 }
list Words_Any_Reference(reference obj, list pdl, const char *(*enf)(entity))
Definition: misc.c:773

References entity_user_name(), NIL, and Words_Any_Reference().

Referenced by text_region_no_action(), and words_reduction().

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

◆ words_reference()

list words_reference ( reference  obj,
list ppdl 
)
Parameters
objbj
ppdlpdl

Definition at line 781 of file misc.c.

782 {
783  return words_any_reference(obj, ppdl, entity_user_name);
784 }

References entity_user_name(), and words_any_reference().

Referenced by adg_fprint_dataflow(), fprint_reference(), reference_to_string(), and words_syntax().

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

◆ Words_Regular_Call()

list Words_Regular_Call ( call  obj,
bool  is_a_subroutine 
)
Parameters
objbj
is_a_subroutines_a_subroutine

Definition at line 1081 of file misc.c.

1082 {
1083  list pdl = NIL;
1084  list pc = words_regular_call(obj, is_a_subroutine, &pdl);
1085  gen_free_list(pdl);
1086  return pc;
1087 }

References gen_free_list(), NIL, and words_regular_call().

Referenced by get_sp_of_call_p().

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

◆ words_regular_call()

list words_regular_call ( call  obj,
bool  is_a_subroutine,
list ppdl 
)

words_regular_call used for user subroutine and user function and intrinsics called like user function such as MOD().

used also by library static_controlize

special cases for stdarg builtin macros

Special cases for stdio.h

else if (ENTITY__IO_GETC_P(f))

pc = CHAIN_SWORD(pc, "getc");

else if (ENTITY__IO_PUTC_P(f))

pc = CHAIN_SWORD(pc, "putc");

Special cases for Fortran intrinsics not available in C

the implied complex operator is hidden... [D]CMPLX_(x,y) -> (x,y)

The corresponding formal parameter cannot be checked by formal_label_replacement_p() because the called modules may not have been parsed yet.

Alternate return actual argument have been replaced by character strings by the parser.

pips_assert("ls has at least four characters", strlen(ls)>=4);

Get rid of initial and final quotes

free(ls1);

The actual label cannot always be used because it might have been eliminated as part of dead code by PIPS since it is not used with the STOP option.

The assertion may be wrong if this piece of code is used to print intermediate statements

words_expression cannot be called because of the C comma operator which require surrounding parentheses in this context. Be careful with unary minus.

alse

Parameters
objbj
is_a_subroutines_a_subroutine
ppdlpdl

Definition at line 868 of file misc.c.

869 {
870  list pc = NIL;
871 
872  entity f = call_function(obj);
873  value i = entity_initial(f);
874  type t = entity_type(f);
875  bool space_p = get_bool_property("PRETTYPRINT_LISTS_WITH_SPACES");
876 
877  if (call_arguments(obj) == NIL) {
878  if (type_statement_p(t))
879  return (CHAIN_SWORD(pc, entity_local_name(f)+sizeof(LABEL_PREFIX) -1));
880  if (value_constant_p(i) || value_symbolic_p(i)) {
881  switch (get_prettyprint_language_tag()) {
882  case is_language_fortran:
884  return (CHAIN_SWORD(pc, entity_user_name(f)));
885  break;
886  case is_language_c:
887  if (ENTITY_TRUE_P(f))
888  return (CHAIN_SWORD(pc, "true"));
889  if (ENTITY_FALSE_P(f))
890  return (CHAIN_SWORD(pc, "false"));
891  return (CHAIN_SWORD(pc, entity_user_name(f)));
892  break;
893  default:
894  pips_internal_error("Language unknown !");
895  break;
896  }
897  }
898  }
899 
901  bool function_p = type_void_p(functional_result(type_functional(calltype)));
902 
903  if (function_p) {
904  if (is_a_subroutine) {
905  switch (get_prettyprint_language_tag()) {
906  case is_language_fortran:
908  pc = CHAIN_SWORD(pc, "CALL ");
909  break;
910  case is_language_c:
911  pc = CHAIN_SWORD(pc, "");
912  break;
913  default:
914  pips_internal_error("Language unknown !");
915  break;
916  }
917  } else {
918  switch (get_prettyprint_language_tag()) {
919  case is_language_fortran:
920  pips_user_warning("subroutine '%s' used as a function.\n",
921  entity_name(f));
922  break;
923  case is_language_c:
924  // no warning in C
925  break;
927  pips_internal_error("Need to update F95 case");
928  break;
929  default:
930  pips_internal_error("Language unknown !");
931  break;
932  }
933  }
934  } else if (is_a_subroutine) {
935  switch (get_prettyprint_language_tag()) {
936  case is_language_fortran:
938  pips_user_warning("function '%s' used as a subroutine.\n",
939  entity_name(f));
940  pc = CHAIN_SWORD(pc, "CALL ");
941  break;
942  case is_language_c:
943  // no warning in C
944  pc = CHAIN_SWORD(pc, "");
945  break;
946  default:
947  pips_internal_error("Language unknown !");
948  break;
949  }
950  }
951 
952  /* special cases for stdarg builtin macros */
953  bool add_argument_count_p = false;
954  if (ENTITY_VA_END_P(f)) {
955  //pc = CHAIN_SWORD(pc, "va_end");
956  pc = CHAIN_SWORD(pc, "__builtin_va_end");
957  }
958  else if (ENTITY_VA_START_P(f)) {
959  //pc = CHAIN_SWORD(pc, "va_start");
960  pc = CHAIN_SWORD(pc, "__builtin_va_start");
961  }
962  else if (ENTITY_VA_COPY_P(f)) {
963  //pc = CHAIN_SWORD(pc, "va_copy");
964  pc = CHAIN_SWORD(pc, "__builtin_va_copy");
965  }
966 
967  /* Special cases for stdio.h */
968  /* else if (ENTITY__IO_GETC_P(f)) */
969 /* pc = CHAIN_SWORD(pc, "getc"); */
970 /* else if (ENTITY__IO_PUTC_P(f)) */
971 /* pc = CHAIN_SWORD(pc, "putc"); */
972  else if (ENTITY_ISOC99_SCANF_P(f))
974  else if (ENTITY_ISOC99_FSCANF_P(f))
976  else if (ENTITY_ISOC99_SSCANF_P(f))
978  else if (ENTITY_ISOC99_VFSCANF_P(f))
980  else if (ENTITY_ISOC99_VSCANF_P(f))
982  else if (ENTITY_ISOC99_VSSCANF_P(f))
984 
985  /* Special cases for Fortran intrinsics not available in C */
987  && !get_bool_property("PRETTYPRINT_INTERNAL_INTRINSICS")) {
988  add_argument_count_p = true;
990  }
992  && !get_bool_property("PRETTYPRINT_INTERNAL_INTRINSICS")) {
993  add_argument_count_p = true;
995  }
996 
997  /* the implied complex operator is hidden... [D]CMPLX_(x,y) -> (x,y)
998  */
1000  pc = CHAIN_SWORD(pc, entity_user_name(f));
1001 
1002 
1003  /* The corresponding formal parameter cannot be checked by
1004  formal_label_replacement_p() because the called modules may not have
1005  been parsed yet. */
1006 
1007  if(!ENDP(call_arguments(obj))) {
1008  list pa = list_undefined;
1009  pc = CHAIN_SWORD(pc, "(");
1010 
1011  if(add_argument_count_p) {
1012  int n = gen_length(call_arguments(obj));
1013  string narg;
1014  asprintf(&narg,"%d", n);
1015  pc = CHAIN_SWORD(pc, narg);
1016  pc = CHAIN_SWORD(pc, ", ");
1017  }
1018 
1019  for(pa = call_arguments(obj); !ENDP(pa); POP(pa)) {
1020  expression eap = EXPRESSION(CAR(pa));
1021  if(get_bool_property("PRETTYPRINT_REGENERATE_ALTERNATE_RETURNS")
1023  /* Alternate return actual argument have been replaced by
1024  character strings by the parser. */
1026  const char* ls = entity_local_name(cf);
1027  string ls1 = malloc(strlen(ls));
1028  /* pips_assert("ls has at least four characters", strlen(ls)>=4); */
1029 
1030  /* Get rid of initial and final quotes */
1031  ls1 = strncpy(ls1, ls+1, strlen(ls)-2);
1032  *(ls1+strlen(ls)-2) = '\000';
1033  pips_assert("eap must be a call to a constant string", expression_call_p(eap));
1034  if(strcmp(get_string_property("PARSER_SUBSTITUTE_ALTERNATE_RETURNS"), "STOP")!=0) {
1035  pc = CHAIN_SWORD(pc, ls1);
1036  /* free(ls1); */
1037  }
1038  else {
1039  /* The actual label cannot always be used because it might have been
1040  eliminated as part of dead code by PIPS since it is not used
1041  with the STOP option. */
1043  pc = CHAIN_SWORD(pc, ls1);
1044  }
1045  else {
1047 
1048  /* The assertion may be wrong if this piece of code is used to
1049  print intermediate statements */
1050  pips_assert("Label els1 has been defined although it is not used anymore",
1051  !entity_undefined_p(els1));
1052 
1053  pc = CHAIN_SWORD(pc, ls1);
1055  }
1056  }
1057  }
1058  else {
1059  /* words_expression cannot be called because of the C comma
1060  operator which require surrounding parentheses in this
1061  context. Be careful with unary minus. */
1064  true/*false*/,
1065  ppdl));
1066  }
1067  if (CDR(pa) != NIL)
1068  pc = CHAIN_SWORD(pc, space_p? ", ": ",");
1069  }
1070 
1071  pc = CHAIN_SWORD(pc, ")");
1072  }
1074  !is_a_subroutine || prettyprint_language_is_c_p()) {
1075  pc = CHAIN_SWORD(pc, "()");
1076  }
1077 
1078  return pc;
1079 }
const char * get_current_module_name(void)
Get the name of the current module.
Definition: static.c:121
void add_target_to_alternate_return_set(entity l)
Definition: misc.c:814
#define ISOC99_VFSCANF_USER_FUNCTION_NAME
#define ENTITY_ISOC99_VFSCANF_P(e)
#define ENTITY_IMPLIED_DCMPLX_P(e)
#define ISOC99_SSCANF_USER_FUNCTION_NAME
#define ENTITY_TRUE_P(e)
#define ENTITY_ISOC99_SSCANF_P(e)
#define ISOC99_VSCANF_USER_FUNCTION_NAME
#define PIPS_C_MAX_OPERATOR_NAME
#define ISOC99_VSSCANF_USER_FUNCTION_NAME
#define ISOC99_FSCANF_USER_FUNCTION_NAME
#define ENTITY_ISOC99_SCANF_P(e)
#define ENTITY_MAX_P(e)
#define ENTITY_VA_END_P(e)
Defined elsewhere: #define ENTITY_ADDRESS_OF_P(e) entity_an_operator_p(e, ADDRESS_OF)
#define ENTITY_VA_START_P(e)
#define PIPS_C_MIN_OPERATOR_NAME
PIPS run-time support for C code generation.
#define ENTITY_MIN_P(e)
#define ENTITY_ISOC99_FSCANF_P(e)
#define ENTITY_VA_COPY_P(e)
#define ASSIGN_OPERATOR_PRECEDENCE
Definition: ri-util-local.h:96
#define ENTITY_ISOC99_VSSCANF_P(e)
#define ENTITY_IMPLIED_CMPLX_P(e)
#define ENTITY_ISOC99_VSCANF_P(e)
#define ENTITY_FALSE_P(e)
#define ISOC99_SCANF_USER_FUNCTION_NAME
bool label_string_defined_in_current_module_p(string ls)
Definition: entity.c:407
bool actual_label_replacement_p(expression)
Assumes that eap is a call.
Definition: variable.c:1811
entity find_label_entity(const char *, const char *)
util.c
Definition: util.c:43
#define type_statement_p(x)
Definition: ri.h:2941
#define value_constant_p(x)
Definition: ri.h:3071
#define entity_undefined_p(x)
Definition: ri.h:2762
#define value_symbolic_p(x)
Definition: ri.h:3068
#define entity_name(x)
Definition: ri.h:2790

References actual_label_replacement_p(), add_target_to_alternate_return_set(), asprintf, ASSIGN_OPERATOR_PRECEDENCE, call_arguments, call_compatible_type(), call_function, CAR, CDR, CHAIN_SWORD, ENDP, ENTITY_FALSE_P, ENTITY_IMPLIED_CMPLX_P, ENTITY_IMPLIED_DCMPLX_P, entity_initial, ENTITY_ISOC99_FSCANF_P, ENTITY_ISOC99_SCANF_P, ENTITY_ISOC99_SSCANF_P, ENTITY_ISOC99_VFSCANF_P, ENTITY_ISOC99_VSCANF_P, ENTITY_ISOC99_VSSCANF_P, entity_local_name(), ENTITY_MAX_P, ENTITY_MIN_P, entity_name, ENTITY_TRUE_P, entity_type, entity_undefined_p, entity_user_name(), ENTITY_VA_COPY_P, ENTITY_VA_END_P, ENTITY_VA_START_P, EXPRESSION, expression_call_p(), expression_syntax, f(), find_label_entity(), functional_result, gen_length(), gen_nconc(), get_bool_property(), get_current_module_name(), get_prettyprint_language_tag(), get_string_property(), is_language_c, is_language_fortran, is_language_fortran95, ISOC99_FSCANF_USER_FUNCTION_NAME, ISOC99_SCANF_USER_FUNCTION_NAME, ISOC99_SSCANF_USER_FUNCTION_NAME, ISOC99_VFSCANF_USER_FUNCTION_NAME, ISOC99_VSCANF_USER_FUNCTION_NAME, ISOC99_VSSCANF_USER_FUNCTION_NAME, LABEL_PREFIX, label_string_defined_in_current_module_p(), list_undefined, malloc(), NIL, pips_assert, PIPS_C_MAX_OPERATOR_NAME, PIPS_C_MIN_OPERATOR_NAME, pips_internal_error, pips_user_warning, POP, prettyprint_language_is_c_p(), syntax_call, type_functional, type_statement_p, type_void_p, value_constant_p, value_symbolic_p, and words_subexpression().

Referenced by words_call_intrinsic(), words_genuine_regular_call(), words_intrinsic_call(), and Words_Regular_Call().

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

◆ words_sizeofexpression()

static list words_sizeofexpression ( sizeofexpression  obj,
bool  in_type_declaration,
list ppdl 
)
static

Referenced by ensure_comment_consistency(), and words_syntax().

+ Here is the caller graph for this function:

◆ words_stat_io_inst()

static list words_stat_io_inst ( call  obj,
int __attribute__((unused))  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)
static

Implemented for ALLOCATE(), but is applicable for every call to function that take STAT= parameter.

Write call function

STAT= is a call

We got it !

FIXME : strdup ?

get argument

It's not a call

Definition at line 1727 of file misc.c.

1730  {
1731  list pc = NIL;
1732  list pcio = call_arguments(obj);
1733  list pio_write = pcio;
1734  const char* called = entity_local_name(call_function(obj));
1735  bool space_p = get_bool_property("PRETTYPRINT_LISTS_WITH_SPACES");
1736 
1737  /* Write call function */
1738  pc = CHAIN_SWORD(pc, called);
1739  pc = CHAIN_SWORD(pc, " (");
1740 
1741  while ( ( pio_write != NIL ) ) {
1742  expression expr = EXPRESSION(CAR(pio_write));
1743  syntax s = expression_syntax(expr);
1744  call c;
1745 
1746  if ( syntax_call_p(s) ) { /* STAT= is a call */
1747  c = syntax_call(s);
1748  if ( strcmp( entity_local_name( call_function(c) ), "STAT=" ) == 0 ) {
1749  /* We got it ! */
1750  pc = CHAIN_SWORD(pc, strdup("STAT=")); /* FIXME : strdup ? */
1751  /* get argument */
1752  pio_write = CDR(pio_write);
1753  expression arg = EXPRESSION(CAR(pio_write));
1754  pc = gen_nconc( pc, words_expression( arg, ppdl ) );
1755  }
1756  } else { /* It's not a call */
1757  pc = gen_nconc( pc, words_expression( expr, ppdl ) );
1758  }
1759  pio_write = CDR(pio_write);
1760  if(pio_write) {
1761  pc = CHAIN_SWORD(pc, space_p? ", " : ",");
1762  }
1763  }
1764 
1765  pc = CHAIN_SWORD(pc, ") ");
1766 
1767  return ( pc );
1768 }

References call_arguments, call_function, CAR, CDR, CHAIN_SWORD, entity_local_name(), EXPRESSION, expression_syntax, gen_nconc(), get_bool_property(), NIL, strdup(), syntax_call, syntax_call_p, and words_expression().

+ Here is the call graph for this function:

◆ Words_Subexpression()

list Words_Subexpression ( expression  obj,
int  precedence,
bool  leftmost 
)
Parameters
objbj
precedencerecedence
leftmosteftmost

Definition at line 2695 of file misc.c.

2699 {
2700  list pdl = NIL;
2701  list pc = words_subexpression(obj, precedence, leftmost, &pdl);
2702  gen_free_list(pdl);
2703  return pc;
2704 }

References gen_free_list(), NIL, and words_subexpression().

Referenced by words_cmf_loop_range().

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

◆ words_subexpression()

list words_subexpression ( expression  obj,
int  precedence,
bool  leftmost,
list ppdl 
)

exported for cmfortran.c

Parameters
objbj
precedencerecedence
leftmosteftmost
ppdlpdl

Definition at line 2674 of file misc.c.

2679 {
2680  list pc;
2681 
2682  if ( expression_call_p(obj) )
2684  precedence, leftmost, false, ppdl);
2685  else if(expression_cast_p(obj)) {
2686  cast c = expression_cast(obj);
2687  pc = words_cast(c, precedence, ppdl);
2688  }
2689  else
2690  pc = words_syntax(expression_syntax(obj), ppdl);
2691 
2692  return pc;
2693 }
static list words_cast(cast obj, int precedence, list *ppdl)
bool expression_cast_p(expression e)
Definition: expression.c:450
cast expression_cast(expression e)
Definition: expression.c:455

References expression_call_p(), expression_cast(), expression_cast_p(), expression_syntax, syntax_call, words_call(), words_cast(), and words_syntax().

Referenced by C_loop_range(), ensure_comment_consistency(), eole_fmx_specific_op(), words_any_reference(), words_assign_op(), words_assign_substring_op(), words_comma_op(), words_conditional_op(), words_infix_binary_op(), words_infix_nary_op(), words_inverse_op(), words_loop_range(), words_nullary_op_c(), words_nullary_op_fortran(), words_postfix_unary_op(), words_prefix_unary_op(), words_regular_call(), Words_Subexpression(), words_substring_op(), words_unary_minus(), and words_variable_or_function().

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

◆ words_subscript()

static list words_subscript ( subscript  s,
list ppdl 
)
static

Referenced by ensure_comment_consistency(), and words_syntax().

+ Here is the caller graph for this function:

◆ words_subscript_range()

list words_subscript_range ( range  obj,
list ppdl 
)

@description FI: array constructor R433, p.

37 in Fortran 90 standard, can be used anywhere in arithmetic expressions whereas the triplet notation is restricted to subscript expressions. The triplet notation is used to define array sections (see R619, p. 64).

Returns
a list of string corresponding to the range

if undefined I print a star, why not!?

Parameters
objbj
ppdlpdl

Definition at line 629 of file misc.c.

629  {
630  list pc = NIL;
631 
632  /* if undefined I print a star, why not!? */
634  pc = CONS(STRING, MAKE_SWORD("*"), NIL);
635  } else {
636  switch(get_prettyprint_language_tag()) {
637  case is_language_fortran: {
639 
640  pc = gen_nconc(pc, words_expression(range_lower(obj), ppdl));
641  pc = CHAIN_SWORD(pc,":");
642  pc = gen_nconc(pc, words_expression(range_upper(obj), ppdl));
643  if(strcmp(entity_local_name(call_function(c)), "1") != 0) {
644  pc = CHAIN_SWORD(pc,":");
645  pc = gen_nconc(pc, words_expression(range_increment(obj), ppdl));
646  }
647  break;
648  }
649  case is_language_fortran95: {
650  // Print the lower bound if != *
652  pc = gen_nconc(pc, words_expression(range_lower(obj), ppdl));
653  }
654 
655  // Print the upper bound if != *
656  pc = CHAIN_SWORD(pc,":");
658  pc = gen_nconc(pc, words_expression(range_upper(obj), ppdl));
659  }
660 
661  // Print the increment if != 1
663  if(strcmp(entity_local_name(call_function(c)), "1") != 0) {
664  pc = CHAIN_SWORD(pc,":");
665  pc = gen_nconc(pc, words_expression(range_increment(obj), ppdl));
666  }
667  break;
668  }
669  case is_language_c:
670  // T is no way to print range in C
671  // The notation with ":" has been chosen to simplify prettyprint
672  {
673  // Print the lower bound if != *
675  pc = gen_nconc(pc, words_expression(range_lower(obj), ppdl));
676  }
677 
678  // Print the upper bound if != *
679  pc = CHAIN_SWORD(pc,":");
681  pc = gen_nconc(pc, words_expression(range_upper(obj), ppdl));
682  }
683 
684  // Print the increment if != 1
686  if(strcmp(entity_local_name(call_function(c)), "1") != 0) {
687  pc = CHAIN_SWORD(pc,":");
688  pc = gen_nconc(pc, words_expression(range_increment(obj), ppdl));
689  }
690  break;
691  }
692  default:
693  pips_internal_error("Language unknown !");
694  break;
695  }
696  }
697  return pc;
698 }

References call_function, CHAIN_SWORD, CONS, entity_local_name(), expression_syntax, expression_undefined_p, gen_nconc(), get_prettyprint_language_tag(), is_language_c, is_language_fortran, is_language_fortran95, MAKE_SWORD, NIL, pips_internal_error, range_increment, range_lower, range_upper, STRING, syntax_call, unbounded_expression_p(), and words_expression().

Referenced by words_any_reference().

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

◆ words_substring_op()

static list words_substring_op ( call  obj,
int __attribute__((unused))  precedence,
bool __attribute__((unused))  leftmost,
list ppdl 
)
static

The substring function call is reduced to a syntactic construct

expression e = EXPRESSION(CAR(CDR(CDR(CDR(call_arguments(obj))))));

An unknown upper bound is encoded as a call to UNBOUNDED_DIMENSION_NAME and nothing must be printed

Definition at line 1187 of file misc.c.

1190  {
1191  /* The substring function call is reduced to a syntactic construct */
1192  list pc = NIL;
1196  /* expression e = EXPRESSION(CAR(CDR(CDR(CDR(call_arguments(obj)))))); */
1197  int prec = words_intrinsic_precedence(obj);
1198 
1199  pips_assert("words_substring_op", gen_length(call_arguments(obj)) == 3 ||
1200  gen_length(call_arguments(obj)) == 4);
1201 
1202  r = EXPRESSION(CAR(call_arguments(obj)));
1203  l = EXPRESSION(CAR(CDR(call_arguments(obj))));
1204  u = EXPRESSION(CAR(CDR(CDR(call_arguments(obj)))));
1205 
1206  pc = gen_nconc(pc, words_subexpression(r, prec, true, ppdl));
1207  pc = CHAIN_SWORD(pc, "(");
1208  pc = gen_nconc(pc, words_subexpression(l, prec, true, ppdl));
1209  pc = CHAIN_SWORD(pc, ":");
1210 
1211  /* An unknown upper bound is encoded as a call to
1212  UNBOUNDED_DIMENSION_NAME and nothing must be printed */
1216  pc = gen_nconc(pc, words_subexpression(u, prec, true, ppdl));
1217  }
1218  else {
1219  pc = gen_nconc(pc, words_subexpression(u, prec, true, ppdl));
1220  }
1221  pc = CHAIN_SWORD(pc, ")");
1222 
1223  return(pc);
1224 }
#define UNBOUNDED_DIMENSION_NAME
Definition: ri-util-local.h:74
entity CreateIntrinsic(string name)
this function does not create an intrinsic function because they must all be created beforehand by th...
Definition: entity.c:1311

References call_arguments, call_function, CAR, CDR, CHAIN_SWORD, CreateIntrinsic(), EXPRESSION, expression_syntax, expression_undefined, gen_length(), gen_nconc(), NIL, pips_assert, syntax_call, syntax_call_p, UNBOUNDED_DIMENSION_NAME, words_intrinsic_precedence(), and words_subexpression().

Referenced by words_assign_substring_op().

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

◆ Words_Syntax()

list Words_Syntax ( syntax  obj)
Parameters
objbj

Definition at line 2664 of file misc.c.

2665 {
2666  list npdl = NIL;
2667  list pc = words_syntax(obj, &npdl);
2668  gen_free_list(npdl);
2669  return pc;
2670 }

References gen_free_list(), NIL, and words_syntax().

Referenced by comp_regions_of_syntax(), Words_Expression(), and xml_Argument().

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

◆ words_syntax()

list words_syntax ( syntax  obj,
list ppdl 
)

exported for expression.c

FI->SG: I do not know if in_type_declaration is true, false or a formal parameter

Parameters
objbj
ppdlpdl

Definition at line 2623 of file misc.c.

2624 {
2625  list pc = NIL;
2626 
2627  switch (syntax_tag(obj)) {
2628  case is_syntax_reference :
2629  pc = words_reference(syntax_reference(obj), ppdl);
2630  break;
2631  case is_syntax_range:
2632  pc = words_range(syntax_range(obj), ppdl);
2633  break;
2634  case is_syntax_call:
2635  pc = words_call(syntax_call(obj), 0, true, false, ppdl);
2636  break;
2637  case is_syntax_cast:
2638  pc = words_cast(syntax_cast(obj), 0, ppdl);
2639  break;
2641  /* FI->SG: I do not know if in_type_declaration is true, false
2642  or a formal parameter */
2643  bool in_type_declaration = true;
2645  in_type_declaration, ppdl);
2646  break;
2647  }
2648  case is_syntax_subscript:
2649  pc = words_subscript(syntax_subscript(obj), ppdl);
2650  break;
2651  case is_syntax_application:
2652  pc = words_application(syntax_application(obj), ppdl);
2653  break;
2654  case is_syntax_va_arg:
2655  pc = words_va_arg(syntax_va_arg(obj), ppdl);
2656  break;
2657  default:
2658  pips_internal_error("unexpected tag");
2659  }
2660 
2661  return(pc);
2662 }
static list words_sizeofexpression(sizeofexpression obj, bool in_type_declaration, list *ppdl)
list words_range(range obj, list *ppdl)
Definition: misc.c:538
static list words_application(application a, list *ppdl)
static list words_subscript(subscript s, list *ppdl)
static list words_va_arg(list obj, list *ppdl)
Definition: misc.c:2558
list words_reference(reference obj, list *ppdl)
Definition: misc.c:781
#define syntax_cast(x)
Definition: ri.h:2739
#define syntax_application(x)
Definition: ri.h:2748
#define syntax_va_arg(x)
Definition: ri.h:2751
@ is_syntax_range
Definition: ri.h:2692
@ is_syntax_application
Definition: ri.h:2697
@ is_syntax_cast
Definition: ri.h:2694
@ is_syntax_call
Definition: ri.h:2693
@ is_syntax_va_arg
Definition: ri.h:2698
@ is_syntax_sizeofexpression
Definition: ri.h:2695
@ is_syntax_subscript
Definition: ri.h:2696
#define syntax_sizeofexpression(x)
Definition: ri.h:2742
#define syntax_subscript(x)
Definition: ri.h:2745

References is_syntax_application, is_syntax_call, is_syntax_cast, is_syntax_range, is_syntax_reference, is_syntax_sizeofexpression, is_syntax_subscript, is_syntax_va_arg, NIL, pips_internal_error, syntax_application, syntax_call, syntax_cast, syntax_range, syntax_reference, syntax_sizeofexpression, syntax_subscript, syntax_tag, syntax_va_arg, words_application(), words_call(), words_cast(), words_range(), words_reference(), words_sizeofexpression(), words_subscript(), and words_va_arg().

Referenced by fprint_expression(), print_syntax(), words_assign_op(), words_expression(), words_subexpression(), and Words_Syntax().

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

◆ words_unary_minus()

static list words_unary_minus ( call  obj,
int  precedence,
bool  leftmost,
list ppdl 
)
static

make sure the minus can not be split apart from its argument

Definition at line 1860 of file misc.c.

1861 {
1862  list pc = NIL;
1864  int prec = words_intrinsic_precedence(obj);
1865 
1866  if ( prec < precedence || !leftmost || (!precedence_p && precedence>0))
1867  pc = CHAIN_SWORD(pc, "(");
1868  /* make sure the minus can not be split apart from its argument */
1869  list sub = words_subexpression(e, prec, false, ppdl);
1870  string fst = STRING(CAR(sub));
1871  POP(sub);
1872  string nfst ;
1873  asprintf(&nfst,"-%s",fst);
1874  free(fst);
1875  sub=CONS(STRING,nfst,sub);
1876  pc = gen_nconc(pc, sub);
1877 
1878  if ( prec < precedence || !leftmost || (!precedence_p && precedence>0))
1879  pc = CHAIN_SWORD(pc, ")");
1880 
1881  return(pc);
1882 }

References asprintf, call_arguments, CAR, CHAIN_SWORD, CONS, EXPRESSION, free(), gen_nconc(), NIL, POP, precedence_p, STRING, words_intrinsic_precedence(), and words_subexpression().

+ Here is the call graph for this function:

◆ words_unbounded_dimension()

static list words_unbounded_dimension ( call __attribute__((unused))  obj,
int __attribute__((unused))  precedence,
bool __attribute__((unused))  leftmost,
list __attribute__((unused)) *  ppdl 
)
static

Definition at line 1547 of file misc.c.

1551 {
1552  list pc = NIL;
1553 
1554  pc = CHAIN_SWORD(pc, "*");
1555 
1556  return(pc);
1557 }

References CHAIN_SWORD, and NIL.

◆ words_va_arg()

static list words_va_arg ( list  obj,
list ppdl 
)
static

Definition at line 2558 of file misc.c.

2559 {
2560  list pc = NIL;
2563  bool space_p = get_bool_property("PRETTYPRINT_LISTS_WITH_SPACES");
2564 
2565  pc = CHAIN_SWORD(pc,"va_arg(");
2566  pc = gen_nconc(pc, words_expression(e1, ppdl));
2567  pc = CHAIN_SWORD(pc, space_p? ", " : ",");
2568  pc = gen_nconc(pc, words_type(t2, ppdl, false));
2569  pc = CHAIN_SWORD(pc,")");
2570  return pc;
2571 }
list words_type(type obj, list *ppdl, bool argument_p)
obj is the type to describe
Definition: declarations.c:821
#define SIZEOFEXPRESSION(x)
SIZEOFEXPRESSION.
Definition: ri.h:2364
#define sizeofexpression_type(x)
Definition: ri.h:2406
#define sizeofexpression_expression(x)
Definition: ri.h:2409

References CAR, CDR, CHAIN_SWORD, gen_nconc(), get_bool_property(), NIL, SIZEOFEXPRESSION, sizeofexpression_expression, sizeofexpression_type, words_expression(), and words_type().

Referenced by words_syntax().

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

Variable Documentation

◆ head_hook

string(* head_hook) (entity) ( entity  ) = NULL
static

hook for adding something in the head.

used by hpfc. done so to avoid hpfc->prettyprint dependence in the libs. FC. 29/12/95.

Definition at line 3962 of file misc.c.

Referenced by ensure_comment_consistency(), reset_prettyprinter_head_hook(), and set_prettyprinter_head_hook().

◆ intrinsic_handlers

◆ lib_ri_util_prettyprint_c_rcsid

char lib_ri_util_prettyprint_c_rcsid[] = "$Id: misc.c 23181 2016-09-09 12:56:48Z irigoin $"

misc.c

Definition at line 29 of file misc.c.

◆ local_flg

bool local_flg = false
static

Definition at line 357 of file misc.c.

Referenced by insert_locals(), and text_loop_default().

◆ local_var

text local_var
static

Definition at line 356 of file misc.c.

Referenced by insert_locals(), and text_loop_default().

◆ precedence_p

bool precedence_p = true
static

This variable is used to disable the precedence system and hence to prettyprint all parentheses, which let the prettyprint reflect the AST.

Definition at line 194 of file misc.c.

Referenced by ensure_comment_consistency(), words_assign_op(), words_call(), words_comma_op(), words_conditional_op(), words_infix_binary_op(), words_postfix_unary_op(), words_prefix_unary_op(), and words_unary_minus().

◆ prettyprint_all_c_braces_p

bool prettyprint_all_c_braces_p = false
static

This variable is used to print braces around all blocks including blocks with only one statement.

Definition at line 197 of file misc.c.

Referenced by ensure_comment_consistency(), text_block_else(), text_block_elseif(), text_block_ifthen(), text_loop_default(), text_test(), and text_whileloop().

◆ prettyprint_gcc_c_braces_p

bool prettyprint_gcc_c_braces_p = false
static

This variable is used to gracefuly print braces around if / else blocks to avoid gcc warnings.

Definition at line 200 of file misc.c.

Referenced by ensure_comment_consistency(), and gcc_if_block_braces_required_p().

◆ set_of_labels_required_for_alternate_returns

list set_of_labels_required_for_alternate_returns = list_undefined
static

Management of alternate returns.

Definition at line 793 of file misc.c.

Referenced by add_target_to_alternate_return_set(), generate_alternate_return_targets(), reset_alternate_return_set(), and set_alternate_return_set().

◆ tab_intrinsic_handler

struct intrinsic_handler tab_intrinsic_handler[]
static

Referenced by init_intrinsic_handlers().

◆ text_statement_hook

text(* text_statement_hook) (entity, int, statement) ( entity  ,
int  ,
statement   
) = empty_text
static

Definition at line 225 of file misc.c.

Referenced by close_prettyprint(), init_prettyprint(), and init_text_statement().