PIPS
print_code_smalltalk.c File Reference
#include <stdio.h>
#include <ctype.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "resources.h"
#include "misc.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "effects-util.h"
#include "pipsdbm.h"
#include "text-util.h"
#include "smalltalk-defs.h"
+ Include dependency graph for print_code_smalltalk.c:

Go to the source code of this file.

Data Structures

struct  s_ppt
 

Macros

#define STPRETTY   ".st"
 This phase is used for PHRASE project. More...
 
#define RESULT_NAME   "result"
 
#define current_module_is_a_function()    (entity_function_p(get_current_module_entity()))
 

Typedefs

typedef string(* prettyprinter) (string, list)
 

Functions

static string st_statement (statement s)
 This method returns Smalltalk-like string representation (pretty-print) for a statement s. More...
 
static string st_sequence (sequence seq)
 This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Sequence Statement (an ordered set of sequential statements) More...
 
static string st_call (call c)
 This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Call Statement (a code line) More...
 
static string st_expression (expression)
 
static string st_reference (reference r)
 This function return a string representation of a reference r. More...
 
static string st_test (test t)
 This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Test Statement (IF/THEN/ELSE) More...
 
static string st_loop (loop l)
 This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Loop Statement (DO...ENDDO) More...
 
static string st_whileloop (whileloop w)
 This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a While-Loop Statement (DO WHILE...ENDDO) More...
 
static string st_forloop (forloop f)
 This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a For-Loop Statement (I don't know how to specify in fortran !!!) More...
 
static string st_entity_local_name (entity var)
 Return beautified string representing name for entity var. More...
 
static string st_brace_expression_as_string (expression exp)
 Return string representing expression enclosed by parenthesis. More...
 
static string st_dimension_reference_as_string (dimension dim, expression old_expression)
 Return a string representing dimension reference for a dimension dim and an expression e This function automatically convert bounds in fortran to bounds starting from 0 by doing new_reference = old_reference - lower This function is valid even in case of non-directly-cumputable expressions. More...
 
static string st_dimension_bound_as_string (dimension dim)
 Return a string representing dimension bounds of a dimension dim This function automatically convert bounds in fortran to bounds starting from 0 by doing upbound = (upper - lower + 1) This function is valid even in case of non-directly-cumputable expressions. More...
 
static string st_dim_string (string svar, list ldim)
 Return string representing array initialization for variable svar in SMALLTALK. More...
 
static string c_basic_string (basic b)
 Return a string C-like representation of basic b. More...
 
static string st_declaration (entity var)
 Return a string representing Smalltalk declaration for entity (constant or variable) var NB: old function this_entity_cdeclaration(entity var) More...
 
static string st_declaration_init (entity var)
 Return a string representing Smalltalk declaration initialisation for entity (constant or variable) var. More...
 
static string st_declaration_comment (entity var)
 Return a string representing Smalltalk declaration initialisation for entity (constant or variable) var. More...
 
static bool constant_p (entity e)
 This function return a bool indicating if related entity e represents a constant. More...
 
static bool variable_p (entity e)
 This function return a bool indicating if related entity e represents a variable. More...
 
static bool argument_p (entity e)
 This function return a bool indicating if related entity e represents an argument. More...
 
static string st_arguments (entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep)
 Return string representing arguments declaration written in SmallTalk style. More...
 
static string st_declarations (entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep)
 Return string representing variables or constants declaration written in SmallTalk style. More...
 
static string st_declarations_init (entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep)
 Return string representing variables or constants declaration initialisation written in SmallTalk style. More...
 
static string st_declarations_comment (entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep)
 Return string representing variables or constants declaration initialisation written in SmallTalk style. More...
 
static string st_header (entity module)
 Generate header for SMALLTALK module. More...
 
static string smalltalk_code_string (entity module, statement stat)
 
static bool expression_needs_parenthesis_p (expression e)
 Return bool indicating if expression e must be enclosed in parenthesis. More...
 
static string ppt_assignement (string in_smalltalk, list le)
 Return string representation for a list of expression le representing an assignement, asserting that le is a list of expressions containing exactly TWO expressions. More...
 
static string ppt_binary (string in_smalltalk, list le)
 Return string representation for a list of expression le representing a BINARY relation, asserting that le is a list of expressions containing exactly TWO expressions. More...
 
static string ppt_unary (string in_smalltalk, list le)
 Return string representation for a list of expression le representing a UNARY relation, asserting that le is a list of expressions containing exactly ONE expression. More...
 
static string ppt_unary_post (string in_smalltalk, list le)
 Return string representation for a list of expression le representing a UNARY POST relation, asserting that le is a list of expressions containing exactly ONE expression. More...
 
static string ppt_call (string in_smalltalk, list le)
 
static struct s_pptget_ppt (entity f)
 Return the prettyprinter structure for SmallTalk. More...
 
bool print_code_smalltalk (const char *module_name)
 print_code_smalltalk.c More...
 

Variables

static struct s_ppt intrinsic_to_smalltalk []
 This data structure encodes the differents intrinsic allowing to convert fortran code to smalltalk code. More...
 

Macro Definition Documentation

◆ current_module_is_a_function

#define current_module_is_a_function ( )     (entity_function_p(get_current_module_entity()))

Definition at line 76 of file print_code_smalltalk.c.

◆ RESULT_NAME

#define RESULT_NAME   "result"

Definition at line 74 of file print_code_smalltalk.c.

◆ STPRETTY

#define STPRETTY   ".st"

This phase is used for PHRASE project.

NB: The PHRASE project is an attempt to automatically (or semi-automatically) transform high-level language for partial evaluation in reconfigurable logic (such as FPGAs or DataPaths).

This pass is used in context of PHRASE project for synthetisation of reconfigurable logic for a portion of initial code. This function can be viewed as a Smalltalk pretty-printer of a subset of Fortran.

alias print_code_smalltalk 'Smalltalk Pretty-Printer'

print_code_smalltalk > MODULE.smalltalk_code < PROGRAM.entities < MODULE.code

The Smalltalk code will be available in SMALLTALK_CODE_FILE

NB: This code is highly inspired from PRINT_C_CODE phase written by nguyen

Definition at line 70 of file print_code_smalltalk.c.

Typedef Documentation

◆ prettyprinter

typedef string(* prettyprinter) (string, list)

Definition at line 958 of file print_code_smalltalk.c.

Function Documentation

◆ argument_p()

static bool argument_p ( entity  e)
static

This function return a bool indicating if related entity e represents an argument.

Formal variables

Definition at line 679 of file print_code_smalltalk.c.

680 {
681  /* Formal variables */
682  return type_variable_p(entity_type(e)) &&
684 }
#define storage_formal_p(x)
Definition: ri.h:2522
#define entity_storage(x)
Definition: ri.h:2794
#define entity_type(x)
Definition: ri.h:2792
#define type_variable_p(x)
Definition: ri.h:2947

References entity_storage, entity_type, storage_formal_p, and type_variable_p.

Referenced by generic_c_words_simplified_entity(), st_header(), and words_type().

+ Here is the caller graph for this function:

◆ c_basic_string()

static string c_basic_string ( basic  b)
static

Return a string C-like representation of basic b.

Definition at line 332 of file print_code_smalltalk.c.

333 {
334  string result = "UNKNOWN_BASIC" SPACE;
335  switch (basic_tag(b))
336  {
337  case is_basic_int:
338  {
339  pips_debug(2,"Basic int\n");
340  switch (basic_int(b))
341  {
342  case 1: result = "char" SPACE;
343  break;
344  case 2: result = "short" SPACE;
345  break;
346  case 4: result = "int" SPACE;
347  break;
348  case 6: result = "long" SPACE;
349  break;
350  case 8: result = "long long" SPACE;
351  break;
352  case 11: result = "unsigned char" SPACE;
353  break;
354  case 12: result = "unsigned short" SPACE;
355  break;
356  case 14: result = "unsigned int" SPACE;
357  break;
358  case 16: result = "unsigned long" SPACE;
359  break;
360  case 18: result = "unsigned long long" SPACE;
361  break;
362  case 21: result = "signed char" SPACE;
363  break;
364  case 22: result = "signed short" SPACE;
365  break;
366  case 24: result = "signed int" SPACE;
367  break;
368  case 26: result = "signed long" SPACE;
369  break;
370  case 28: result = "signed long long" SPACE;
371  break;
372  }
373  break;
374  }
375  case is_basic_float:
376  switch (basic_float(b))
377  {
378  case 4: result = "float" SPACE;
379  break;
380  case 8: result = "double" SPACE;
381  break;
382  }
383  break;
384  case is_basic_logical:
385  result = "int" SPACE;
386  break;
387  case is_basic_string:
388  result = "char" SPACE;
389  break;
390  case is_basic_bit:
391  {
392  result = "Basic bit not handled";
393  break;
394  }
395  case is_basic_pointer:
396  {
397  result = "Basic pointer not handled";
398  break;
399  }
400  case is_basic_derived:
401  {
402  result = "Basic derived not handled";
403  break;
404  }
405  case is_basic_typedef:
406  {
407  result = "Basic typedef not handled";
408  break;
409  }
410  default:
411  pips_internal_error("case not handled");
412  }
413  return strdup(result);
414 }
#define SPACE
Definition: codegen.c:216
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_internal_error
Definition: misc-local.h:149
@ is_basic_derived
Definition: ri.h:579
@ is_basic_string
Definition: ri.h:576
@ is_basic_float
Definition: ri.h:572
@ is_basic_bit
Definition: ri.h:577
@ is_basic_pointer
Definition: ri.h:578
@ is_basic_int
Definition: ri.h:571
@ is_basic_logical
Definition: ri.h:573
@ is_basic_typedef
Definition: ri.h:580
#define basic_int(x)
Definition: ri.h:616
#define basic_tag(x)
Definition: ri.h:613
#define basic_float(x)
Definition: ri.h:619
char * strdup()

References basic_float, basic_int, basic_tag, is_basic_bit, is_basic_derived, is_basic_float, is_basic_int, is_basic_logical, is_basic_pointer, is_basic_string, is_basic_typedef, pips_debug, pips_internal_error, SPACE, and strdup().

Referenced by st_declaration_comment().

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

◆ constant_p()

static bool constant_p ( entity  e)
static

◆ expression_needs_parenthesis_p()

static bool expression_needs_parenthesis_p ( expression  e)
static

Return bool indicating if expression e must be enclosed in parenthesis.

Definition at line 1243 of file print_code_smalltalk.c.

1244 {
1245  syntax s = expression_syntax(e);
1246  switch (syntax_tag(s))
1247  {
1248  case is_syntax_call:
1249  {
1250  struct s_ppt * p = get_ppt(call_function(syntax_call(s)));
1251  return p->ppt==ppt_binary;
1252  }
1253  case is_syntax_reference:
1254  case is_syntax_range:
1255  default:
1256  return false;
1257  }
1258 }
static struct s_ppt * get_ppt(entity f)
Return the prettyprinter structure for SmallTalk.
static string ppt_binary(string in_smalltalk, list le)
Return string representation for a list of expression le representing a BINARY relation,...
#define syntax_tag(x)
Definition: ri.h:2727
#define call_function(x)
Definition: ri.h:709
@ is_syntax_range
Definition: ri.h:2692
@ is_syntax_call
Definition: ri.h:2693
@ is_syntax_reference
Definition: ri.h:2691
#define syntax_call(x)
Definition: ri.h:2736
#define expression_syntax(x)
Definition: ri.h:1247
prettyprinter ppt

References call_function, expression_syntax, get_ppt(), is_syntax_call, is_syntax_range, is_syntax_reference, s_ppt::ppt, ppt_binary(), syntax_call, and syntax_tag.

Referenced by ppt_assignement(), ppt_binary(), and st_reference().

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

◆ get_ppt()

static struct s_ppt* get_ppt ( entity  f)
static

Return the prettyprinter structure for SmallTalk.

Definition at line 1230 of file print_code_smalltalk.c.

1231 {
1232  const char* called = entity_local_name(f);
1233  struct s_ppt * table = intrinsic_to_smalltalk;
1234  while (table->intrinsic && !same_string_p(called, table->intrinsic))
1235  table++;
1236  return table;
1237 }
#define same_string_p(s1, s2)
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
static struct s_ppt intrinsic_to_smalltalk[]
This data structure encodes the differents intrinsic allowing to convert fortran code to smalltalk co...
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
char * intrinsic

References entity_local_name(), f(), s_ppt::intrinsic, intrinsic_to_smalltalk, and same_string_p.

Referenced by expression_needs_parenthesis_p(), and st_call().

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

◆ ppt_assignement()

static string ppt_assignement ( string  in_smalltalk,
list  le 
)
static

Return string representation for a list of expression le representing an assignement, asserting that le is a list of expressions containing exactly TWO expressions.

This is a scalar variable

Definition at line 974 of file print_code_smalltalk.c.

975 {
976  string result, svar;
977  expression e1, e2;
978  string s1, s2;
979  bool p1, p2, pr1, pr2;
980  syntax s;
981  reference r;
982  entity var;
983  type t;
984  variable v;
985  list ldim;
986 
987  pips_assert("2 arguments to assignment call", gen_length(le)==2);
988 
989  e1 = EXPRESSION(CAR(le));
990  s = expression_syntax(e1);
991  pips_assert("assignment call: first expression is reference",
993 
994 
995  r = syntax_reference(s);
996  var = reference_variable(r);
997  t = entity_type(var);
998  v = type_variable(t);
999  ldim = variable_dimensions(v);
1000 
1001  svar = st_entity_local_name(var);
1002 
1003  e2 = EXPRESSION(CAR(CDR(le)));
1005  s2 = st_expression(e2);
1006 
1007 
1008  if (gen_length(ldim) == 0) {
1009  /* This is a scalar variable */
1010 
1012  s1 = st_reference(r);
1013  result = strdup(concatenate(p1? OPENPAREN: EMPTY, s1, p1? CLOSEPAREN: EMPTY,
1014  SPACE, in_smalltalk, SPACE,
1015  p2? OPENPAREN: EMPTY, s2, p2? CLOSEPAREN: EMPTY,
1016  NULL));
1017  free(s1);
1018  }
1019 
1020  else if (gen_length(ldim) == 1) {
1021 
1022  dimension dim = DIMENSION(gen_nth(0,ldim));
1025 
1026  dim = DIMENSION(gen_nth(0,ldim));
1027 
1028  result = strdup(concatenate(svar, SPACE, ARRAY_AT_PUT_1, SPACE,
1029  pr1? OPENPAREN: EMPTY,
1031  pr1? CLOSEPAREN: EMPTY, SPACE,
1033  p2? OPENPAREN: EMPTY, s2, p2? CLOSEPAREN: EMPTY,
1034  NULL));
1035  }
1036 
1037  else if (gen_length(ldim) == 2) {
1038 
1039  dimension dim1 = DIMENSION(gen_nth(0,ldim));
1041  dimension dim2 = DIMENSION(gen_nth(1,ldim));
1045 
1047  pr1? OPENPAREN: EMPTY,
1049  pr1? CLOSEPAREN: EMPTY, SPACE,
1051  pr2? OPENPAREN: EMPTY,
1053  pr2? CLOSEPAREN: EMPTY, SPACE,
1055  p2? OPENPAREN: EMPTY, s2, p2? CLOSEPAREN: EMPTY,
1056  NULL));
1057  }
1058 
1059  else {
1060  result = strdup("Arrays more than 2D are not handled !");
1061  }
1062 
1063  free(s2);
1064 
1065  return result;
1066 }
void free(void *)
size_t gen_length(const list l)
Definition: list.c:150
#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
gen_chunk gen_nth(int n, const list l)
to be used as ENTITY(gen_nth(3, l))...
Definition: list.c:710
#define CLOSEPAREN
#define OPENPAREN
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
static string st_entity_local_name(entity var)
Return beautified string representing name for entity var.
static string st_reference(reference r)
This function return a string representation of a reference r.
static string st_dimension_reference_as_string(dimension dim, expression old_expression)
Return a string representing dimension reference for a dimension dim and an expression e This functio...
static string st_expression(expression)
static bool expression_needs_parenthesis_p(expression)
Return bool indicating if expression e must be enclosed in parenthesis.
#define syntax_reference(x)
Definition: ri.h:2730
#define reference_variable(x)
Definition: ri.h:2326
#define type_variable(x)
Definition: ri.h:2949
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define reference_indices(x)
Definition: ri.h:2328
#define variable_dimensions(x)
Definition: ri.h:3122
s1
Definition: set.c:247
#define ARRAY_AT_PUT_1
#define ARRAY2D_AT_AT_PUT_2
#define ARRAY2D_AT_AT_PUT_3
#define ARRAY2D_AT_AT_PUT_1
#define ARRAY_AT_PUT_2
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define EMPTY

References ARRAY2D_AT_AT_PUT_1, ARRAY2D_AT_AT_PUT_2, ARRAY2D_AT_AT_PUT_3, ARRAY_AT_PUT_1, ARRAY_AT_PUT_2, CAR, CDR, CLOSEPAREN, concatenate(), DIMENSION, EMPTY, entity_type, EXPRESSION, expression_needs_parenthesis_p(), expression_syntax, free(), gen_length(), gen_nth(), is_syntax_reference, OPENPAREN, pips_assert, reference_indices, reference_variable, s1, SPACE, st_dimension_reference_as_string(), st_entity_local_name(), st_expression(), st_reference(), strdup(), syntax_reference, syntax_tag, type_variable, and variable_dimensions.

+ Here is the call graph for this function:

◆ ppt_binary()

static string ppt_binary ( string  in_smalltalk,
list  le 
)
static

Return string representation for a list of expression le representing a BINARY relation, asserting that le is a list of expressions containing exactly TWO expressions.

Definition at line 1073 of file print_code_smalltalk.c.

1074 {
1075  string result;
1076  expression e1, e2;
1077  string s1, s2;
1078  bool p1, p2;
1079 
1080  pips_assert("2 arguments to binary call", gen_length(le)==2);
1081 
1082  e1 = EXPRESSION(CAR(le));
1084  s1 = st_expression(e1);
1085 
1086  e2 = EXPRESSION(CAR(CDR(le)));
1088  s2 = st_expression(e2);
1089 
1090  result = strdup(concatenate(p1? OPENPAREN: EMPTY, s1, p1? CLOSEPAREN: EMPTY,
1091  SPACE, in_smalltalk, SPACE,
1092  p2? OPENPAREN: EMPTY, s2, p2? CLOSEPAREN: EMPTY,
1093  NULL));
1094 
1095  free(s1);
1096  free(s2);
1097 
1098  return result;
1099 }

References CAR, CDR, CLOSEPAREN, concatenate(), EMPTY, EXPRESSION, expression_needs_parenthesis_p(), free(), gen_length(), OPENPAREN, pips_assert, s1, SPACE, st_expression(), and strdup().

Referenced by expression_needs_parenthesis_p().

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

◆ ppt_call()

static string ppt_call ( string  in_smalltalk,
list  le 
)
static

Attention: not like this for io statements

Definition at line 1131 of file print_code_smalltalk.c.

1132 {
1133  string scall, old;
1134  if (le == NIL)
1135  {
1136  scall = strdup(concatenate(in_smalltalk, NULL));
1137  }
1138  else
1139  {
1140  bool first = true;
1141  scall = strdup(concatenate(in_smalltalk, OPENPAREN, NULL));
1142 
1143  /* Attention: not like this for io statements*/
1144  MAP(EXPRESSION, e,
1145  {
1146  string arg = st_expression(e);
1147  old = scall;
1148  scall = strdup(concatenate(old, first? "": ", ", arg, NULL));
1149  free(arg);
1150  free(old);
1151  first = false;
1152  },le);
1153 
1154  old = scall;
1155  scall = strdup(concatenate(old, CLOSEPAREN, NULL));
1156  free(old);
1157  }
1158  return scall;
1159 }
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#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

◆ ppt_unary()

static string ppt_unary ( string  in_smalltalk,
list  le 
)
static

Return string representation for a list of expression le representing a UNARY relation, asserting that le is a list of expressions containing exactly ONE expression.

Definition at line 1106 of file print_code_smalltalk.c.

1107 {
1108  string e, result;
1109  pips_assert("one arg to unary call", gen_length(le)==1);
1110  e = st_expression(EXPRESSION(CAR(le)));
1111  result = strdup(concatenate(in_smalltalk, SPACE, e, NULL));
1112  free(e);
1113  return result;
1114 }

References CAR, concatenate(), EXPRESSION, free(), gen_length(), pips_assert, SPACE, st_expression(), and strdup().

+ Here is the call graph for this function:

◆ ppt_unary_post()

static string ppt_unary_post ( string  in_smalltalk,
list  le 
)
static

Return string representation for a list of expression le representing a UNARY POST relation, asserting that le is a list of expressions containing exactly ONE expression.

Definition at line 1121 of file print_code_smalltalk.c.

1122 {
1123  string e, result;
1124  pips_assert("one arg to unary post call", gen_length(le)==1);
1125  e = st_expression(EXPRESSION(CAR(le)));
1126  result = strdup(concatenate(e, SPACE, in_smalltalk, NULL));
1127  free(e);
1128  return result;
1129 }

References CAR, concatenate(), EXPRESSION, free(), gen_length(), pips_assert, SPACE, st_expression(), and strdup().

+ Here is the call graph for this function:

◆ print_code_smalltalk()

bool print_code_smalltalk ( const char *  module_name)

print_code_smalltalk.c

We first build the future resource file, with a .st

save to file

Parameters
module_nameodule_name

Definition at line 1670 of file print_code_smalltalk.c.

1671 {
1672  FILE * out;
1673  string ppt, smalltalkcode, dir, filename;
1674  entity module;
1675  statement stat;
1676 
1677  /* We first build the future resource file, with a .st */
1678  smalltalkcode = db_build_file_resource_name(DBR_SMALLTALK_CODE_FILE, module_name, STPRETTY);
1681  filename = strdup(concatenate(dir, "/", smalltalkcode, NULL));
1682  stat = (statement) db_get_memory_resource(DBR_CODE, module_name, true);
1683 
1686 
1687  debug_on("SMALLTALK_PRETTYPRINTER_DEBUG_LEVEL");
1688  pips_debug(1, "Begin SMALLTALK prettyprinter for %s\n", entity_name(module));
1689  ppt = smalltalk_code_string(module, stat);
1690  pips_debug(1, "End SMALLTALK prettyprinter for %s\n", entity_name(module));
1691 
1692  pips_debug(3, "What i got is \n%s\n", ppt);
1693 
1694  /* save to file */
1695  out = safe_fopen(filename, "w");
1696  fprintf(out, "/* SMALLTALK pretty print for module %s. */\n%s", module_name, ppt);
1697  safe_fclose(out, filename);
1698 
1699  free(ppt);
1700  free(dir);
1701  free(filename);
1702 
1703  DB_PUT_FILE_RESOURCE(DBR_SMALLTALK_CODE_FILE, module_name, smalltalkcode);
1704 
1707 
1708  return true;
1709 }
static FILE * out
Definition: alias_check.c:128
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement(void)
Reset the current module statement.
Definition: static.c:221
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755
#define DB_PUT_FILE_RESOURCE
Put a file resource into the current workspace database.
Definition: pipsdbm-local.h:85
string db_build_file_resource_name(const char *rname, const char *oname, const char *suffix)
returns an allocated file name for a file resource.
Definition: lowlevel.c:169
#define debug_on(env)
Definition: misc-local.h:157
static char * module
Definition: pips.c:74
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
static string smalltalk_code_string(entity module, statement stat)
#define STPRETTY
This phase is used for PHRASE project.
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
#define entity_name(x)
Definition: ri.h:2790
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References concatenate(), db_build_file_resource_name(), db_get_current_workspace_directory(), db_get_memory_resource(), DB_PUT_FILE_RESOURCE, debug_on, entity_name, fprintf(), free(), module, module_name(), module_name_to_entity(), out, pips_debug, s_ppt::ppt, reset_current_module_entity(), reset_current_module_statement(), safe_fclose(), safe_fopen(), set_current_module_entity(), set_current_module_statement(), smalltalk_code_string(), STPRETTY, and strdup().

+ Here is the call graph for this function:

◆ smalltalk_code_string()

static string smalltalk_code_string ( entity  module,
statement  stat 
)
static

HEAD generates the header

Generates the variables declarations

What about declarations associated to statements ???

Generates the constant declarations

Generates the variables declarations initialisation

Generates the variables declarations comments

Generates the constant declarations initialisation

Generates the body

Definition at line 860 of file print_code_smalltalk.c.

861 {
862  string st_head, st_variables, st_constants;
863  string st_variables_init, st_constants_init;
864  string st_variables_comment;
865  string st_body, result;
866 
867  ifdebug(2) {
868  printf("Module statement: \n");
869  print_statement(stat);
870  printf("and declarations: \n");
872  }
873 
874  /* HEAD generates the header */
875  st_head = st_header(module);
876  ifdebug(3) {
877  printf("HEAD: \n");
878  printf("%s \n", st_head);
879  }
880 
881  /* Generates the variables declarations */
882  /* What about declarations associated to statements ??? */
883  st_variables = st_declarations(module,
884  variable_p,
885  SPACE,
886  true);
887  ifdebug(3) {
888  printf("VARIABLES: \n");
889  printf("%s \n", st_variables);
890  }
891 
892  /* Generates the constant declarations */
893  st_constants = st_declarations (module,
894  constant_p,
895  SPACE,
896  true);
897  ifdebug(3) {
898  printf("CONSTANTS: \n");
899  printf("%s \n", st_constants);
900  }
901 
902  /* Generates the variables declarations initialisation */
903  st_variables_init = st_declarations_init (module,
904  variable_p,
905  STSEMICOLON,
906  true);
907  ifdebug(3) {
908  printf("VARIABLES INIT: \n");
909  printf("%s \n", st_variables_init);
910  }
911 
912  /* Generates the variables declarations comments */
913  st_variables_comment = st_declarations_comment (module,
914  variable_p,
915  NL,
916  true);
917  ifdebug(3) {
918  printf("VARIABLES COMMENT: \n");
919  printf("%s \n", st_variables_comment);
920  }
921 
922  /* Generates the constant declarations initialisation */
923  st_constants_init = st_declarations_init (module,
924  constant_p,
925  STSEMICOLON,
926  true);
927  ifdebug(3) {
928  printf("CONSTANTS INIT: \n");
929  printf("%s \n", st_constants_init);
930  }
931 
932  /* Generates the body */
933  st_body = st_statement(stat);
934  ifdebug(3) {
935  printf("BODY: \n");
936  printf("%s \n", st_body);
937  }
938 
939  result = strdup(concatenate(st_head, NL,
940  st_variables_comment, NL
941  BEGINTEMPVAR, st_constants,
942  st_variables, ENDTEMPVAR, NL, NL,
943  st_constants_init, NL,
944  st_variables_init, NL,
945  st_body, NL,
946  NULL));
947 
948  free(st_head);
949  free(st_variables);
950  free(st_constants);
951  free(st_body);
952 
953  return result;
954 }
void print_statement(statement)
Print a statement on stderr.
Definition: statement.c:98
static bool variable_p(entity e)
This function return a bool indicating if related entity e represents a variable.
static string st_header(entity module)
Generate header for SMALLTALK module.
static string st_declarations(entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep)
Return string representing variables or constants declaration written in SmallTalk style.
static string st_statement(statement s)
This method returns Smalltalk-like string representation (pretty-print) for a statement s.
static string st_declarations_comment(entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep)
Return string representing variables or constants declaration initialisation written in SmallTalk sty...
static bool constant_p(entity e)
This function return a bool indicating if related entity e represents a constant.
static string st_declarations_init(entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep)
Return string representing variables or constants declaration initialisation written in SmallTalk sty...
void print_entities(list l)
Definition: entity.c:167
#define statement_declarations(x)
Definition: ri.h:2460
int printf()
#define ifdebug(n)
Definition: sg.c:47
#define BEGINTEMPVAR
#define ENDTEMPVAR
#define STSEMICOLON
#define NL
Definition: xml_output.c:48

References BEGINTEMPVAR, concatenate(), constant_p(), ENDTEMPVAR, free(), ifdebug, module, NL, print_entities(), print_statement(), printf(), SPACE, st_declarations(), st_declarations_comment(), st_declarations_init(), st_header(), st_statement(), statement_declarations, strdup(), STSEMICOLON, and variable_p().

Referenced by print_code_smalltalk().

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

◆ st_arguments()

static string st_arguments ( entity  module,
bool(*)(entity consider_this_entity,
string  separator,
bool  lastsep 
)
static

Return string representing arguments declaration written in SmallTalk style.

Assert that entity represent a value code

Definition at line 691 of file print_code_smalltalk.c.

695 {
696  string result = strdup("");
697  code c;
698  bool first = true;
699 
700  /* Assert that entity represent a value code */
701  pips_assert("it is a code", value_code_p(entity_initial(module)));
702 
704  MAP(ENTITY, var,
705  {
706  debug(2, "\n Prettyprinter declaration for argument :",st_entity_local_name(var));
707  if (consider_this_entity(var))
708  {
709  string old = result;
710  string svar = strdup(concatenate("with:",st_entity_local_name(var), NULL));
711  result = strdup(concatenate(old, !first && !lastsep? separator: "",
712  svar, lastsep? separator: "", NULL));
713  free(old);
714  free(svar);
715  first = false;
716  }
717  },code_declarations(c));
718  return result;
719 }
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
#define value_code_p(x)
Definition: ri.h:3065
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define code_declarations(x)
Definition: ri.h:784
#define value_code(x)
Definition: ri.h:3067

References code_declarations, concatenate(), debug(), ENTITY, entity_initial, free(), MAP, module, pips_assert, st_entity_local_name(), strdup(), value_code, and value_code_p.

Referenced by st_header().

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

◆ st_brace_expression_as_string()

static string st_brace_expression_as_string ( expression  exp)
static

Return string representing expression enclosed by parenthesis.

Definition at line 132 of file print_code_smalltalk.c.

133 {
134  string result = OPENBRACKET;
136 
137  bool first = true;
138  MAP(EXPRESSION,e,
139  {
140  if (brace_expression_p(e))
141  result = strdup(concatenate(result,first?"":",",st_brace_expression_as_string(e),NULL));
142  else
143  result = strdup(concatenate(result,first?"":",",
144  expression_to_string(e),NULL));
145  first = false;
146  },args);
147  result = strdup(concatenate(result,CLOSEBRACKET,NULL));
148  return result;
149 }
string expression_to_string(expression e)
Definition: expression.c:77
static string st_brace_expression_as_string(expression exp)
Return string representing expression enclosed by parenthesis.
bool brace_expression_p(expression e)
Return bool indicating if expression e is a brace expression.
Definition: expression.c:3384
#define call_arguments(x)
Definition: ri.h:711
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207
#define CLOSEBRACKET
#define OPENBRACKET

References brace_expression_p(), call_arguments, CLOSEBRACKET, concatenate(), exp, EXPRESSION, expression_syntax, expression_to_string(), MAP, OPENBRACKET, strdup(), and syntax_call.

Referenced by st_declaration_init().

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

◆ st_call()

static string st_call ( call  c)
static

This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Call Statement (a code line)

special case...

Definition at line 1532 of file print_code_smalltalk.c.

1533 {
1534  entity called = call_function(c);
1535  struct s_ppt * ppt = get_ppt(called);
1536  string result;
1537 
1538  /* special case... */
1539  if (same_string_p(entity_local_name(called), "STOP")) {
1540  result = NULL;
1541  }
1542  else if (same_string_p(entity_local_name(called), "CONTINUE")) {
1543  result = NULL;
1544  }
1545  else if (same_string_p(entity_local_name(called), "RETURN"))
1546  {
1548  result = strdup(RETURNVALUE " 0");
1549  else if (current_module_is_a_function())
1550  result = strdup(RETURNVALUE SPACE RESULT_NAME);
1551  else
1552  result = strdup(RETURNVALUE);
1553  }
1554  else if (call_constant_p(c))
1555  {
1556  result = st_entity_local_name(called);
1557  }
1558  else
1559  {
1560  string s = st_entity_local_name(called);
1561  result = ppt->ppt(ppt->c? ppt->c: s, call_arguments(c));
1562  free(s);
1563  }
1564 
1565  return result;
1566 }
#define call_constant_p(C)
Definition: flint_check.c:51
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
#define current_module_is_a_function()
#define RESULT_NAME
bool entity_main_module_p(entity e)
Definition: entity.c:700
#define RETURNVALUE

References s_ppt::c, call_arguments, call_constant_p, call_function, current_module_is_a_function, entity_local_name(), entity_main_module_p(), free(), get_current_module_entity(), get_ppt(), s_ppt::ppt, RESULT_NAME, RETURNVALUE, same_string_p, SPACE, st_entity_local_name(), and strdup().

Referenced by st_expression(), and st_statement().

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

◆ st_declaration()

static string st_declaration ( entity  var)
static

Return a string representing Smalltalk declaration for entity (constant or variable) var NB: old function this_entity_cdeclaration(entity var)

Definition at line 421 of file print_code_smalltalk.c.

422 {
423  string result = "Undefined entity";
424  const char* name = entity_local_name(var);
425  type t = entity_type(var);
426  storage s = entity_storage(var);
427 
428  switch (storage_tag(s)) {
429  case is_storage_rom:
430  {
431  string svar = st_entity_local_name(var);
432  result = strdup(svar);
433  free(svar);
434  }
435  default:
436  break;
437  }
438  switch (type_tag(t)) {
439  case is_type_variable:
440  {
441  string svar;
442  svar = st_entity_local_name(var);
443  result = strdup(svar);
444  free(svar);
445  break;
446  }
447  case is_type_struct:
448  {
449  result = strdup(concatenate(name, ": undefined STRUCT in SMALLTALK", NULL));
450  break;
451  }
452  case is_type_union:
453  {
454  result = strdup(concatenate(name, ": undefined UNION in SMALLTALK", NULL));
455  break;
456  }
457  case is_type_enum:
458  {
459  result = strdup(concatenate(name, ": undefined ENUM in SMALLTALK", NULL));
460  break;
461  }
462  default:
463  break;
464  }
465 
466  return result? result: strdup("");
467 }
#define storage_tag(x)
Definition: ri.h:2515
#define type_tag(x)
Definition: ri.h:2940
@ is_storage_rom
Definition: ri.h:2494
@ is_type_enum
Definition: ri.h:2907
@ is_type_variable
Definition: ri.h:2900
@ is_type_union
Definition: ri.h:2906
@ is_type_struct
Definition: ri.h:2905

References concatenate(), entity_local_name(), entity_storage, entity_type, free(), is_storage_rom, is_type_enum, is_type_struct, is_type_union, is_type_variable, st_entity_local_name(), storage_tag, strdup(), and type_tag.

Referenced by st_declarations(), and st_statement().

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

◆ st_declaration_comment()

static string st_declaration_comment ( entity  var)
static

Return a string representing Smalltalk declaration initialisation for entity (constant or variable) var.

Definition at line 591 of file print_code_smalltalk.c.

592 {
593  string comment = "Undefined entity";
594  string svar = st_entity_local_name(var);
595  type t = entity_type(var);
596 
597  pips_debug(2,"st_declaration_comment for entity : %s\n",entity_name(var));
598 
599  switch (type_tag(t)) {
600  case is_type_variable:
601  {
602  int dimensions;
603  variable v = type_variable(t);
604  string st = c_basic_string(variable_basic(v));
605 
606  dimensions = gen_length(variable_dimensions(v));
607  pips_debug(4,"Dimensions: %zd\n", gen_length(variable_dimensions(v)));
608 
609  if (dimensions == 0) {
610  comment = strdup(concatenate(COMMENT, svar, ",", st, COMMENT, NULL));
611  }
612 
613  else if (dimensions < 3) {
614 
615  if (dimensions == 1) {
616  comment = strdup(concatenate(COMMENT, svar, ",", st, ", 1 dimension", COMMENT, NULL));
617  }
618  else if (dimensions == 2) {
619  comment = strdup(concatenate(COMMENT, svar, ",", st, ", 2 dimensions", COMMENT, NULL));
620  }
621  }
622 
623  else {
624  comment = strdup(concatenate(COMMENT, svar, ",", st, ", Arrays dimension > 2 not handled", COMMENT, NULL));
625  }
626 
627  break;
628  }
629  case is_type_struct:
630  {
631  comment = strdup(concatenate(COMMENT, svar, " : undefined STRUCT in SMALLTALK", COMMENT, NULL));
632  break;
633  }
634  case is_type_union:
635  {
636  comment = strdup(concatenate(COMMENT, svar, " : undefined UNION in SMALLTALK", COMMENT, NULL));
637  break;
638  }
639  case is_type_enum:
640  {
641  comment = strdup(concatenate(COMMENT, svar, " : undefined ENUM in SMALLTALK", COMMENT, NULL));
642  break;
643  }
644  default:
645  comment = strdup(concatenate(COMMENT, svar, " : undefined declaration in SMALLTALK", COMMENT, NULL));
646  }
647 
648  free(svar);
649  return comment;
650 }
static void comment(string_buffer code, spoc_hardware_type hw, dagvtx v, int stage, int side, bool flip)
Definition: freia_spoc.c:52
static string c_basic_string(basic b)
Return a string C-like representation of basic b.
#define variable_basic(x)
Definition: ri.h:3120
#define COMMENT
Definition: sc_lex.c:786

References c_basic_string(), COMMENT, comment(), concatenate(), entity_name, entity_type, free(), gen_length(), is_type_enum, is_type_struct, is_type_union, is_type_variable, pips_debug, st_entity_local_name(), strdup(), type_tag, type_variable, variable_basic, and variable_dimensions.

Referenced by st_declarations_comment().

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

◆ st_declaration_init()

static string st_declaration_init ( entity  var)
static

Return a string representing Smalltalk declaration initialisation for entity (constant or variable) var.

This is a constant, we must initialize it

This variable must be initialized Anyway, i don't know how to initialize a variable at declaration in Fortran !!!

Definition at line 473 of file print_code_smalltalk.c.

474 {
475  string result = NULL;
476  type t = entity_type(var);
477  storage s = entity_storage(var);
478 
479  pips_debug(2,"st_declaration_init for entity : %s\n",entity_name(var));
480 
481  switch (storage_tag(s)) {
482  case is_storage_rom:
483  {
484  /* This is a constant, we must initialize it */
485 
486  value va = entity_initial(var);
487 
488  if (!value_undefined_p(va))
489  {
490  constant c = NULL;
491  pips_debug(4,"Constant with defined value\n");
492  if (value_constant_p(va))
493  c = value_constant(va);
494  else if (value_symbolic_p(va))
496  if (c)
497  {
498  if (constant_int_p(c))
499  {
500  string sval = int2a(constant_int(c));
501  string svar = st_entity_local_name(var);
502  pips_debug(4,"Constant is an integer\n");
503  result = strdup(concatenate(svar, SPACE, SETVALUE
504  SPACE, sval, NULL));
505 
506  free(svar);
507  free(sval);
508  return result;
509  }
510  else
511  {
512  string svar = st_entity_local_name(var);
513  pips_debug(4,"Type of constant not handled\n");
514  result = strdup(concatenate(svar, SPACE, SETVALUE
515  SPACE, "undefined", NULL));
516  }
517  }
518  }
519  break;
520  }
521  default:
522  break;
523  }
524  switch (type_tag(t)) {
525  case is_type_variable:
526  {
527  int dimensions;
528  variable v = type_variable(t);
529  string svar;
530  value val = entity_initial(var);
531 
532  svar = st_entity_local_name(var);
533 
534  dimensions = gen_length(variable_dimensions(v));
535  pips_debug(4,"Dimensions: %zd\n", gen_length(variable_dimensions(v)));
536 
537  if (dimensions == 0) {
538 
539  if (!value_undefined_p(val)) {
540  if (value_expression_p(val)) {
541  /* This variable must be initialized
542  * Anyway, i don't know how to initialize a variable
543  * at declaration in Fortran !!! */
545  if (brace_expression_p(exp))
547  else
548  result = strdup(concatenate(result,SETVALUE,expression_to_string(exp),NULL));
549  }
550  }
551  }
552 
553  else if (dimensions < 3) {
554  pips_debug(2,"Init for arrays \n");
555  result = strdup(st_dim_string (svar, variable_dimensions(v)));
556  }
557 
558  else {
559  pips_debug(2,"Arrays dimension > 2 not handled\n");
560  }
561 
562  free(svar);
563  break;
564  }
565  case is_type_struct:
566  {
567  result = "undefined STRUCT in SMALLTALK";
568  break;
569  }
570  case is_type_union:
571  {
572  result = "undefined UNION in SMALLTALK";
573  break;
574  }
575  case is_type_enum:
576  {
577  result = "undefined ENUM in SMALLTALK";
578  break;
579  }
580  default:
581  break;
582  }
583 
584  return result;
585 }
static string st_dim_string(string svar, list ldim)
Return string representing array initialization for variable svar in SMALLTALK.
#define value_undefined_p(x)
Definition: ri.h:3017
#define value_constant(x)
Definition: ri.h:3073
#define symbolic_constant(x)
Definition: ri.h:2599
#define constant_int(x)
Definition: ri.h:850
#define value_constant_p(x)
Definition: ri.h:3071
#define value_symbolic(x)
Definition: ri.h:3070
#define constant_int_p(x)
Definition: ri.h:848
#define value_expression_p(x)
Definition: ri.h:3080
#define value_expression(x)
Definition: ri.h:3082
#define SETVALUE
char * int2a(int)
util.c
Definition: util.c:42

References brace_expression_p(), concatenate(), constant_int, constant_int_p, entity_initial, entity_name, entity_storage, entity_type, exp, expression_to_string(), free(), gen_length(), int2a(), is_storage_rom, is_type_enum, is_type_struct, is_type_union, is_type_variable, pips_debug, SETVALUE, SPACE, st_brace_expression_as_string(), st_dim_string(), st_entity_local_name(), storage_tag, strdup(), symbolic_constant, type_tag, type_variable, value_constant, value_constant_p, value_expression, value_expression_p, value_symbolic, value_symbolic_p, value_undefined_p, and variable_dimensions.

Referenced by st_declarations_init().

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

◆ st_declarations()

static string st_declarations ( entity  module,
bool(*)(entity consider_this_entity,
string  separator,
bool  lastsep 
)
static

Return string representing variables or constants declaration written in SmallTalk style.

Assert that entity represent a value code

Definition at line 726 of file print_code_smalltalk.c.

730 {
731  string result = strdup("");
732  code c;
733  bool first = true;
734 
735  /* Assert that entity represent a value code */
736  pips_assert("it is a code", value_code_p(entity_initial(module)));
737 
739  MAP(ENTITY, var,
740  {
741  debug(2, "\n Prettyprinter declaration for variable :",st_entity_local_name(var));
742  if (consider_this_entity(var))
743  {
744  string old = result;
745  string svar = st_declaration(var);
746  result = strdup(concatenate(old, !first && !lastsep? separator: "",
747  svar, lastsep? separator: "", NULL));
748  free(old);
749  free(svar);
750  first = false;
751  }
752  },code_declarations(c));
753  return result;
754 }
static string st_declaration(entity var)
Return a string representing Smalltalk declaration for entity (constant or variable) var NB: old func...

References code_declarations, concatenate(), debug(), ENTITY, entity_initial, free(), MAP, module, pips_assert, st_declaration(), st_entity_local_name(), strdup(), value_code, and value_code_p.

Referenced by smalltalk_code_string().

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

◆ st_declarations_comment()

static string st_declarations_comment ( entity  module,
bool(*)(entity consider_this_entity,
string  separator,
bool  lastsep 
)
static

Return string representing variables or constants declaration initialisation written in SmallTalk style.

Assert that entity represent a value code

Definition at line 801 of file print_code_smalltalk.c.

805 {
806  string result = strdup("");
807  code c;
808  bool first = true;
809 
810  /* Assert that entity represent a value code */
811  pips_assert("it is a code", value_code_p(entity_initial(module)));
812 
814  MAP(ENTITY, var,
815  {
816  debug(2, "Prettyprinter declaration initialisation for variable :",st_entity_local_name(var));
817  if (consider_this_entity(var))
818  {
819  string old = result;
820  string svar = st_declaration_comment(var);
821  result = strdup(concatenate(old, !first && !lastsep? separator: "",
822  svar, lastsep? separator: "", NULL));
823  free(old);
824  free(svar);
825  first = false;
826  }
827  },code_declarations(c));
828  return result;
829 }
static string st_declaration_comment(entity var)
Return a string representing Smalltalk declaration initialisation for entity (constant or variable) v...

References code_declarations, concatenate(), debug(), ENTITY, entity_initial, free(), MAP, module, pips_assert, st_declaration_comment(), st_entity_local_name(), strdup(), value_code, and value_code_p.

Referenced by smalltalk_code_string().

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

◆ st_declarations_init()

static string st_declarations_init ( entity  module,
bool(*)(entity consider_this_entity,
string  separator,
bool  lastsep 
)
static

Return string representing variables or constants declaration initialisation written in SmallTalk style.

Assert that entity represent a value code

Definition at line 761 of file print_code_smalltalk.c.

765 {
766  string result = strdup("");
767  code c;
768  bool first = true;
769 
770  /* Assert that entity represent a value code */
771  pips_assert("it is a code", value_code_p(entity_initial(module)));
772 
774  MAP(ENTITY, var,
775  {
776  debug(2, "Prettyprinter declaration initialisation for variable :",st_entity_local_name(var));
777  if (consider_this_entity(var))
778  {
779  string old = result;
780  string svar = st_declaration_init(var);
781  if (svar != NULL) {
782  result = strdup(concatenate(old, !first && !lastsep? separator: "",
783  svar, lastsep? separator: "", NULL));
784  }
785  else {
786  result = strdup(result);
787  }
788  free(old);
789  free(svar);
790  first = false;
791  }
792  },code_declarations(c));
793  return result;
794 }
static string st_declaration_init(entity var)
Return a string representing Smalltalk declaration initialisation for entity (constant or variable) v...

References code_declarations, concatenate(), debug(), ENTITY, entity_initial, free(), MAP, module, pips_assert, st_declaration_init(), st_entity_local_name(), strdup(), value_code, and value_code_p.

Referenced by smalltalk_code_string().

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

◆ st_dim_string()

static string st_dim_string ( string  svar,
list  ldim 
)
static

Return string representing array initialization for variable svar in SMALLTALK.

Definition at line 286 of file print_code_smalltalk.c.

287 {
288  string result = "";
289  int dimensions = 0;
290 
291  dimensions = gen_length(ldim);
292 
293  pips_debug(5,"Dimension : %d \n", dimensions);
294 
295  if (dimensions == 0) {
296  return strdup(result);
297  }
298 
299  else if (dimensions == 1) {
300 
301  dimension dim = DIMENSION(gen_nth(0,ldim));
302 
303  result = strdup(concatenate(svar, SPACE, SETVALUE, SPACE,
304  ARRAY, SPACE,
305  ARRAY_NEW, SPACE,
306  st_dimension_bound_as_string (dim), NULL));
307  return result;
308  }
309 
310  else if (dimensions == 2) {
311 
312  dimension dim = DIMENSION(gen_nth(0,ldim));
313  dimension dim2 = DIMENSION(gen_nth(1,ldim));
314 
315  result = strdup(concatenate(svar, SPACE, SETVALUE, SPACE,
316  ARRAY2D, SPACE,
319  NULL));
320  return result;
321  }
322 
323  else {
324  result = strdup("More than 2-dimensionals arrays not handled !");
325  return result;
326  }
327 }
static string st_dimension_bound_as_string(dimension dim)
Return a string representing dimension bounds of a dimension dim This function automatically convert ...
#define ARRAY2D_NEW2
#define ARRAY2D
#define ARRAY2D_NEW1
#define ARRAY_NEW
#define ARRAY

References ARRAY, ARRAY2D, ARRAY2D_NEW1, ARRAY2D_NEW2, ARRAY_NEW, concatenate(), DIMENSION, gen_length(), gen_nth(), pips_debug, SETVALUE, SPACE, st_dimension_bound_as_string(), and strdup().

Referenced by st_declaration_init().

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

◆ st_dimension_bound_as_string()

static string st_dimension_bound_as_string ( dimension  dim)
static

Return a string representing dimension bounds of a dimension dim This function automatically convert bounds in fortran to bounds starting from 0 by doing upbound = (upper - lower + 1) This function is valid even in case of non-directly-cumputable expressions.

Definition at line 223 of file print_code_smalltalk.c.

223  {
224 
225  intptr_t low, up;
226  string slow = NULL;
227  string sup = NULL;
228  bool low_given_by_expression = false;
229  bool up_given_by_expression = false;
230  string result = strdup(EMPTY);
231 
232  expression elow = dimension_lower(dim);
233  expression eup = dimension_upper(dim);
234 
235  if (expression_integer_value(elow, &low)) {
236  low_given_by_expression = true;
237  }
238  else {
239  low_given_by_expression = false;
240  slow = st_expression(elow);
241  }
242  if (expression_integer_value(eup, &up)) {
243  up_given_by_expression = true;
244  }
245  else {
246  up_given_by_expression = false;
247  sup = st_expression(eup);
248  }
249 
250  if (low_given_by_expression) {
251  if (up_given_by_expression) {
252  pips_debug(5,"up=%"PRIdPTR" low=%"PRIdPTR"\n", up, low);
253  string istr = int2a(up-low+1);
254  result = strdup(concatenate(result, istr, NULL));
255  free(istr);
256  }
257  else {
258  string istr = int2a(low-1);
259  pips_debug(5,"sup=%s low=%"PRIdPTR"\n", sup, low);
260  result = strdup(concatenate(result, sup,"-",istr, NULL));
261  free(istr);
262  }
263  }
264  else {
265  if (up_given_by_expression) {
266  pips_debug(5,"up=%"PRIdPTR" slow=%s\n", up, slow);
267  string istr = int2a(up+1);
268  result = strdup(concatenate(result, istr,"-",
269  OPENBRACE,slow,CLOSEBRACE, NULL));
270  free(istr);
271  }
272  else {
273  pips_debug(5,"sup=%s slow=%s\n", sup, slow);
274  result = strdup(concatenate(result, sup,"-",OPENBRACE,slow,
275  CLOSEBRACE,"+1", NULL));
276  }
277  }
278 
279  return result;
280 }
bool expression_integer_value(expression e, intptr_t *pval)
Definition: eval.c:792
#define dimension_lower(x)
Definition: ri.h:980
#define dimension_upper(x)
Definition: ri.h:982
#define intptr_t
Definition: stdint.in.h:294
#define OPENBRACE
#define CLOSEBRACE

References CLOSEBRACE, concatenate(), dimension_lower, dimension_upper, EMPTY, expression_integer_value(), free(), int2a(), intptr_t, OPENBRACE, pips_debug, st_expression(), and strdup().

Referenced by st_dim_string().

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

◆ st_dimension_reference_as_string()

static string st_dimension_reference_as_string ( dimension  dim,
expression  old_expression 
)
static

Return a string representing dimension reference for a dimension dim and an expression e This function automatically convert bounds in fortran to bounds starting from 0 by doing new_reference = old_reference - lower This function is valid even in case of non-directly-cumputable expressions.

Definition at line 158 of file print_code_smalltalk.c.

158  {
159 
160  intptr_t low, old;
161  string slow = NULL;
162  string sold = NULL;
163  bool low_given_by_expression = false;
164  bool old_given_by_expression = false;
165  string result = strdup(EMPTY);
166 
167  expression elow = dimension_lower(dim);
168  expression eold = old_expression;
169 
170  if (expression_integer_value(elow, &low)) {
171  low_given_by_expression = true;
172  }
173  else {
174  low_given_by_expression = false;
175  slow = st_expression(elow);
176  }
177  if (expression_integer_value(eold, &old)) {
178  old_given_by_expression = true;
179  }
180  else {
181  old_given_by_expression = false;
182  sold = st_expression(eold);
183  }
184 
185  if (low_given_by_expression) {
186  if (old_given_by_expression) {
187  pips_debug(5,"old=%"PRIdPTR" low=%"PRIdPTR"\n", old, low);
188  string istr = int2a(old-low);
189  result = strdup(concatenate(result, istr, NULL));
190  free(istr);
191  }
192  else {
193  pips_debug(5,"sold=%s low=%"PRIdPTR"\n", sold, low);
194  string istr = int2a(low);
195  result = strdup(concatenate(result, sold,"-",istr, NULL));
196  free(istr);
197  }
198  }
199  else {
200  if (old_given_by_expression) {
201  pips_debug(5,"old=%"PRIdPTR" slow=%s\n", old, slow);
202  string istr = int2a(old);
203  result = strdup(concatenate(result, istr,"-",
204  OPENBRACE,slow,CLOSEBRACE, NULL));
205  free(istr);
206  }
207  else {
208  pips_debug(5,"sold=%s slow=%s\n", sold, slow);
209  result = strdup(concatenate(result, sold,"-",OPENBRACE,slow,
210  CLOSEBRACE, NULL));
211  }
212  }
213 
214  return result;
215 }

References CLOSEBRACE, concatenate(), dimension_lower, EMPTY, expression_integer_value(), free(), int2a(), intptr_t, OPENBRACE, pips_debug, st_expression(), and strdup().

Referenced by ppt_assignement(), and st_reference().

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

◆ st_entity_local_name()

static string st_entity_local_name ( entity  var)
static

Return beautified string representing name for entity var.

Delete all the prefixes

Definition at line 93 of file print_code_smalltalk.c.

94 {
95  const char* name;
96 
97  pips_debug(6,"st_entity_local_name was : %s\n",entity_local_name(var));
98 
100  var != get_current_module_entity() &&
103  name = RESULT_NAME;
104  }
105  else
106  {
107  name = entity_local_name(var);
108 
109  /* Delete all the prefixes */
110 
111  if (strstr(name,STRUCT_PREFIX) != NULL)
112  name = strstr(name,STRUCT_PREFIX) + 1;
113  if (strstr(name,UNION_PREFIX) != NULL)
114  name = strstr(name,UNION_PREFIX) + 1;
115  if (strstr(name,ENUM_PREFIX) != NULL)
116  name = strstr(name,ENUM_PREFIX) + 1;
117  if (strstr(name,TYPEDEF_PREFIX) != NULL)
118  name = strstr(name,TYPEDEF_PREFIX) + 1;
119  if (strstr(name,MEMBER_SEP_STRING) != NULL)
120  name = strstr(name,MEMBER_SEP_STRING) + 1;
121  if (strstr(name,MAIN_PREFIX) != NULL)
122  name = strstr(name,MAIN_PREFIX) + 1;
123  }
124  pips_debug(6,"st_entity_local_name is now : %s\n",name);
125  return strdup(name);
126 }
#define TYPEDEF_PREFIX
Definition: naming-local.h:62
#define MAIN_PREFIX
Definition: naming-local.h:32
#define UNION_PREFIX
Definition: naming-local.h:58
#define ENUM_PREFIX
Definition: naming-local.h:60
#define MEMBER_SEP_STRING
Definition: naming-local.h:53
#define STRUCT_PREFIX
Definition: naming-local.h:56

References current_module_is_a_function, entity_local_name(), ENUM_PREFIX, get_current_module_entity(), MAIN_PREFIX, MEMBER_SEP_STRING, pips_debug, RESULT_NAME, same_string_p, strdup(), STRUCT_PREFIX, TYPEDEF_PREFIX, and UNION_PREFIX.

Referenced by ppt_assignement(), st_arguments(), st_call(), st_declaration(), st_declaration_comment(), st_declaration_init(), st_declarations(), st_declarations_comment(), st_declarations_init(), st_header(), st_loop(), st_reference(), and st_statement().

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

◆ st_expression()

static string st_expression ( expression  e)
static

add cast, sizeof here

Definition at line 1644 of file print_code_smalltalk.c.

1645 {
1646  string result = NULL;
1647  syntax s = expression_syntax(e);
1648  switch (syntax_tag(s))
1649  {
1650  case is_syntax_call:
1651  result = st_call(syntax_call(s));
1652  break;
1653  case is_syntax_range:
1654  result = strdup("range not implemented");
1655  break;
1656  case is_syntax_reference:
1657  result = st_reference(syntax_reference(s));
1658  break;
1659  /* add cast, sizeof here */
1660  default:
1661  pips_internal_error("unexpected syntax tag");
1662  }
1663  return result;
1664 }
static string st_call(call c)
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a ...

References expression_syntax, is_syntax_call, is_syntax_range, is_syntax_reference, pips_internal_error, st_call(), st_reference(), strdup(), syntax_call, syntax_reference, and syntax_tag.

Referenced by ppt_assignement(), ppt_binary(), ppt_unary(), ppt_unary_post(), st_dimension_bound_as_string(), st_dimension_reference_as_string(), st_forloop(), st_loop(), st_test(), and st_whileloop().

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

◆ st_forloop()

static string st_forloop ( forloop  f)
static

This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a For-Loop Statement (I don't know how to specify in fortran !!!)

Definition at line 1502 of file print_code_smalltalk.c.

1503 {
1504  string result, loopbody;
1505  string body = st_statement(forloop_body(f));
1507  string cond = st_expression(forloop_condition(f));
1508  string inc = st_expression(forloop_increment(f));
1509  result = strdup(concatenate("for (", init, ";",cond,";",inc,") {" NL,
1510  body, "}" NL, NULL));
1511 
1512  loopbody = strdup(concatenate(OPENBRACKET, cond, CLOSEBRACKET, SPACE,
1514  body, inc,
1515  STSEMICOLON, CLOSEBRACKET, NULL));
1516 
1517 
1518  result = strdup(concatenate(init, loopbody, STSEMICOLON, NULL));
1519 
1520  free(loopbody);
1521  free(inc);
1522  free(cond);
1523  free(init);
1524  free(body);
1525  return result;
1526 }
static int init
Maximal value set for Fortran 77.
Definition: entity.c:320
#define forloop_initialization(x)
Definition: ri.h:1366
#define forloop_increment(x)
Definition: ri.h:1370
#define forloop_condition(x)
Definition: ri.h:1368
#define forloop_body(x)
Definition: ri.h:1372
#define ST_WHILETRUE

References CLOSEBRACKET, concatenate(), f(), forloop_body, forloop_condition, forloop_increment, forloop_initialization, free(), init, NL, OPENBRACKET, SPACE, st_expression(), st_statement(), ST_WHILETRUE, strdup(), and STSEMICOLON.

Referenced by st_statement().

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

◆ st_header()

static string st_header ( entity  module)
static

Generate header for SMALLTALK module.

Generates the arguments declarations

Definition at line 834 of file print_code_smalltalk.c.

835 {
836  string result, svar, args;
837 
838  pips_assert("it is a function", type_functional_p(entity_type(module)));
839 
841 
842  /* Generates the arguments declarations */
843  args = st_arguments(module,
844  argument_p,
845  SPACE,
846  true);
847 
848  result = strdup(concatenate(svar, SPACE, args, NL,
849  COMMENT, "Automatically generated with PIPS", COMMENT,
850  NL, NULL));
851 
852  return result;
853 }
static bool argument_p(entity e)
This function return a bool indicating if related entity e represents an argument.
static string st_arguments(entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep)
Return string representing arguments declaration written in SmallTalk style.

References argument_p(), COMMENT, concatenate(), entity_type, module, NL, pips_assert, SPACE, st_arguments(), st_entity_local_name(), strdup(), and type_functional_p.

Referenced by smalltalk_code_string().

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

◆ st_loop()

static string st_loop ( loop  l)
static

This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Loop Statement (DO...ENDDO)

Definition at line 1423 of file print_code_smalltalk.c.

1424 {
1425  string result, initialisation, loopbody, incrementation;
1426  string body = st_statement(loop_body(l));
1427  string index = st_entity_local_name(loop_index(l));
1428  range r = loop_range(l);
1429  string low = st_expression(range_lower(r));
1430  string up = st_expression(range_upper(r));
1431  string inc = st_expression(range_increment(r));
1432  intptr_t incasint;
1433 
1434  initialisation = strdup(concatenate(index, SPACE, SETVALUE, SPACE, low, STSEMICOLON, NULL));
1435 
1436  if (expression_integer_value(range_increment(r), &incasint)) {
1437  string istr;
1438  if (incasint >= 0) {
1439  istr = int2a(incasint);
1440  inc = strdup(concatenate(ST_PLUS, SPACE,
1441  istr, NULL));
1442  }
1443  else {
1444  istr = int2a(-incasint);
1445  inc = strdup(concatenate(ST_MINUS, SPACE,
1446  istr, NULL));
1447  }
1448  free(istr);
1449  }
1450  else {
1451  inc = strdup(concatenate(ST_PLUS, SPACE,
1452  st_expression(range_increment(r)), NULL));
1453  }
1454 
1455  incrementation = strdup(concatenate(index, SPACE, SETVALUE, SPACE, index, SPACE, inc, NULL));
1456 
1457  loopbody = strdup(concatenate(OPENBRACKET, index, SPACE, ST_LE,
1458  SPACE, up, CLOSEBRACKET, SPACE,
1460  body, incrementation,
1461  STSEMICOLON, CLOSEBRACKET, NULL));
1462 
1463 
1464  result = strdup(concatenate(initialisation, loopbody, STSEMICOLON, NULL));
1465 
1466  free(initialisation);
1467  free(incrementation);
1468  free(loopbody);
1469  free(body);
1470  free(low);
1471  free(up);
1472  free(index);
1473  return result;
1474 }
#define loop_body(x)
Definition: ri.h:1644
#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 loop_range(x)
Definition: ri.h:1642
#define loop_index(x)
Definition: ri.h:1640
#define ST_PLUS
#define ST_LE
#define ST_MINUS

References CLOSEBRACKET, concatenate(), expression_integer_value(), free(), int2a(), intptr_t, loop_body, loop_index, loop_range, NL, OPENBRACKET, range_increment, range_lower, range_upper, SETVALUE, SPACE, st_entity_local_name(), st_expression(), ST_LE, ST_MINUS, ST_PLUS, st_statement(), ST_WHILETRUE, strdup(), and STSEMICOLON.

Referenced by st_statement().

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

◆ st_reference()

static string st_reference ( reference  r)
static

This function return a string representation of a reference r.

A reference is an array element, considering non-array variables (scalar variables) are 0-dimension arrays elements. We must here differently manage scalar, 1-D arrays (using SmallTalk Array class) and 2-D arrays (using SmallTalk Array2D).

NB: in Fortran, the indexes are reversed

This is a scalar variable, no need to manage array indices

Definition at line 1577 of file print_code_smalltalk.c.

1578 {
1579  string result = strdup(EMPTY), svar;
1580 
1581  entity var = reference_variable(r);
1582  type t = entity_type(var);
1583  variable v = type_variable(t);
1584  list ldim = variable_dimensions(v);
1585  bool pr, pr1, pr2;
1586 
1588 
1589  if (gen_length(ldim) == 0) {
1590 
1591  /* This is a scalar variable, no need to manage array indices */
1592  result = strdup(st_entity_local_name(var));
1593  free(svar);
1594  return result;
1595  }
1596 
1597  else if (gen_length(ldim) == 1) {
1598 
1599  dimension dim = DIMENSION(gen_nth(0,ldim));
1602 
1603  dim = DIMENSION(gen_nth(0,ldim));
1604 
1605  result = strdup(concatenate(OPENPAREN, svar, SPACE, ARRAY_AT, SPACE,
1606  pr? OPENPAREN: EMPTY,
1608  pr? CLOSEPAREN: EMPTY,
1609  CLOSEPAREN, NULL));
1610  }
1611 
1612  else if (gen_length(ldim) == 2) {
1613 
1614  dimension dim1 = DIMENSION(gen_nth(0,ldim));
1616  dimension dim2 = DIMENSION(gen_nth(1,ldim));
1620 
1621  result = strdup(concatenate(OPENPAREN, svar,
1623  pr1? OPENPAREN: EMPTY,
1625  pr1? CLOSEPAREN: EMPTY,
1627  pr2? OPENPAREN: EMPTY,
1629  pr2? CLOSEPAREN: EMPTY,
1630  CLOSEPAREN, NULL));
1631  }
1632 
1633  else {
1634 
1635  result = strdup(concatenate(COMMENT, "Arrays more than 2D are not handled !",
1636  COMMENT, NULL));
1637  }
1638 
1639  free(svar);
1640  return result;
1641 
1642 }
#define ARRAY2D_AT_AT_1
#define ARRAY2D_AT_AT_2
#define ARRAY_AT

References ARRAY2D_AT_AT_1, ARRAY2D_AT_AT_2, ARRAY_AT, CLOSEPAREN, COMMENT, concatenate(), DIMENSION, EMPTY, entity_type, EXPRESSION, expression_needs_parenthesis_p(), free(), gen_length(), gen_nth(), OPENPAREN, reference_indices, reference_variable, SPACE, st_dimension_reference_as_string(), st_entity_local_name(), strdup(), type_variable, and variable_dimensions.

Referenced by ppt_assignement(), and st_expression().

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

◆ st_sequence()

static string st_sequence ( sequence  seq)
static

This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Sequence Statement (an ordered set of sequential statements)

Definition at line 1400 of file print_code_smalltalk.c.

1401 {
1402  string result = strdup(EMPTY);
1403  MAP(STATEMENT, s,
1404  {
1405  string oldresult = result;
1406  string current = st_statement(s);
1407  if (current != NULL) {
1408  result = strdup(concatenate(oldresult, current, NULL));
1409  }
1410  else {
1411  result = strdup(oldresult);
1412  }
1413  free(current);
1414  free(oldresult);
1415  }, sequence_statements(seq));
1416  return result;
1417 }
#define sequence_statements(x)
Definition: ri.h:2360
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
static size_t current
Definition: string.c:115

References concatenate(), current, EMPTY, free(), MAP, sequence_statements, st_statement(), STATEMENT, and strdup().

Referenced by st_statement().

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

◆ st_statement()

static string st_statement ( statement  s)
static

This method returns Smalltalk-like string representation (pretty-print) for a statement s.

nstructured u = instruction_unstructured(i);

tatement g = instruction_goto(i);

add switch, forloop break, continue, return instructions here

Definition at line 1264 of file print_code_smalltalk.c.

1265 {
1266  string result;
1269  ifdebug(3) {
1270  printf("\nCurrent statement : \n");
1271  print_statement(s);
1272  }
1273  switch (instruction_tag(i))
1274  {
1275  case is_instruction_test:
1276  {
1277  test t = instruction_test(i);
1278  pips_debug(2, "Instruction TEST\n");
1279  result = st_test(t);
1280  break;
1281  }
1283  {
1284  sequence seq = instruction_sequence(i);
1285  pips_debug(2, "Instruction SEQUENCE\n");
1286  result = st_sequence(seq);
1287  break;
1288  }
1289  case is_instruction_loop:
1290  {
1291  loop l = instruction_loop(i);
1292  pips_debug(2, "Instruction LOOP\n");
1293  result = st_loop(l);
1294  break;
1295  }
1297  {
1299  pips_debug(2, "Instruction WHILELOOP\n");
1300  result = st_whileloop(w);
1301  break;
1302  }
1304  {
1306  pips_debug(2, "Instruction FORLOOP\n");
1307  result = st_forloop(f);
1308  break;
1309  }
1310  case is_instruction_call:
1311  {
1312  string scall = st_call(instruction_call(i));
1313  pips_debug(2, "Instruction CALL\n");
1314  result = strdup(concatenate(scall, STSEMICOLON, NULL));
1315  break;
1316  }
1318  {
1319  /*unstructured u = instruction_unstructured(i);*/
1320  pips_debug(2, "Instruction UNSTRUTURED\n");
1321  result = strdup(concatenate(COMMENT,
1322  "UNSTRUCTURED: Instruction not implementable in SMALLTALK",
1323  COMMENT, NL, NULL));
1324  break;
1325  }
1326  case is_instruction_goto:
1327  {
1328  /*statement g = instruction_goto(i);*/
1329  pips_debug(2, "Instruction GOTO\n");
1330  result = strdup(concatenate(COMMENT,
1331  "GOTO: Instruction not implementable in SMALLTALK",
1332  COMMENT, NL, NULL));
1333  break;
1334  }
1335  /* add switch, forloop break, continue, return instructions here*/
1336  default:
1337  pips_user_warning("Instruction NOT IMPLEMENTED\n");
1338  result = strdup(concatenate(COMMENT, " Instruction not implemented" NL, NULL));
1339  break;
1340  }
1341 
1342  if (!ENDP(l))
1343  {
1344  string decl = "";
1345  MAP(ENTITY, var,
1346  {
1347  string svar;
1348  debug(2, "\n In block declaration for variable :",st_entity_local_name(var));
1349  svar = st_declaration(var);
1350  decl = strdup(concatenate(decl, svar, STSEMICOLON, NULL));
1351  free(svar);
1352  },l);
1353  result = strdup(concatenate(decl,result,NULL));
1354  }
1355 
1356  return result;
1357 }
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define pips_user_warning
Definition: misc-local.h:146
static string st_whileloop(whileloop w)
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a ...
static string st_sequence(sequence seq)
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a ...
static string st_loop(loop l)
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a ...
static string st_test(test t)
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a ...
static string st_forloop(forloop f)
This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a ...
#define instruction_loop(x)
Definition: ri.h:1520
@ is_instruction_goto
Definition: ri.h:1473
@ is_instruction_unstructured
Definition: ri.h:1475
@ is_instruction_whileloop
Definition: ri.h:1472
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_sequence
Definition: ri.h:1469
@ is_instruction_forloop
Definition: ri.h:1477
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511
#define instruction_sequence(x)
Definition: ri.h:1514
#define instruction_forloop(x)
Definition: ri.h:1538
#define instruction_whileloop(x)
Definition: ri.h:1523
#define statement_instruction(x)
Definition: ri.h:2458
#define instruction_call(x)
Definition: ri.h:1529
#define instruction_test(x)
Definition: ri.h:1517

References COMMENT, concatenate(), debug(), ENDP, ENTITY, f(), free(), ifdebug, instruction_call, instruction_forloop, instruction_loop, instruction_sequence, instruction_tag, instruction_test, instruction_whileloop, is_instruction_call, is_instruction_forloop, is_instruction_goto, is_instruction_loop, is_instruction_sequence, is_instruction_test, is_instruction_unstructured, is_instruction_whileloop, MAP, NL, pips_debug, pips_user_warning, print_statement(), printf(), st_call(), st_declaration(), st_entity_local_name(), st_forloop(), st_loop(), st_sequence(), st_test(), st_whileloop(), statement_declarations, statement_instruction, strdup(), and STSEMICOLON.

Referenced by smalltalk_code_string(), st_forloop(), st_loop(), st_sequence(), st_test(), and st_whileloop().

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

◆ st_test()

static string st_test ( test  t)
static

This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a Test Statement (IF/THEN/ELSE)

Definition at line 1363 of file print_code_smalltalk.c.

1364 {
1365  string result;
1366  bool no_false;
1367  string cond, strue, sfalse;
1368 
1369  cond = st_expression(test_condition(t));
1370  strue = st_statement(test_true(t));
1371  no_false = empty_statement_p(test_false(t));
1372 
1373  sfalse = no_false? NULL: st_statement(test_false(t));
1374 
1375  if (no_false) {
1376  result = strdup(concatenate(OPENPAREN, cond, CLOSEPAREN, NL,
1377  ST_IFTRUE, SPACE, OPENBRACKET, NL, strue,
1379  NULL));
1380  }
1381  else {
1382  result = strdup(concatenate(OPENPAREN, cond, CLOSEPAREN, NL,
1383  ST_IFTRUE, SPACE, OPENBRACKET, NL, strue,
1384  CLOSEBRACKET, NL,
1385  ST_IFFALSE, SPACE, OPENBRACKET, NL, sfalse,
1387  NULL));
1388  }
1389  free(cond);
1390  free(strue);
1391  if (sfalse) free(sfalse);
1392  return result;
1393 }
bool empty_statement_p(statement)
Test if a statement is empty.
Definition: statement.c:391
#define test_false(x)
Definition: ri.h:2837
#define test_true(x)
Definition: ri.h:2835
#define test_condition(x)
Definition: ri.h:2833
#define ST_IFFALSE
#define ST_IFTRUE

References CLOSEBRACKET, CLOSEPAREN, concatenate(), empty_statement_p(), free(), NL, OPENBRACKET, OPENPAREN, SPACE, st_expression(), ST_IFFALSE, ST_IFTRUE, st_statement(), strdup(), STSEMICOLON, test_condition, test_false, and test_true.

Referenced by st_statement().

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

◆ st_whileloop()

static string st_whileloop ( whileloop  w)
static

This method returns Smalltalk-like string representation (pretty-print) for a statement s which is a While-Loop Statement (DO WHILE...ENDDO)

valuation eval = whileloop_evaluation(w);

Definition at line 1480 of file print_code_smalltalk.c.

1481 {
1482  string result;
1483  string body = st_statement(whileloop_body(w));
1484  string cond = st_expression(whileloop_condition(w));
1485  /*evaluation eval = whileloop_evaluation(w);*/
1486 
1487  result = strdup(concatenate(OPENBRACKET, cond, CLOSEBRACKET, SPACE,
1489  body,
1490  CLOSEBRACKET, STSEMICOLON, NULL));
1491 
1492  free(cond);
1493  free(body);
1494  return result;
1495 }
#define whileloop_body(x)
Definition: ri.h:3162
#define whileloop_condition(x)
Definition: ri.h:3160

References CLOSEBRACKET, concatenate(), free(), NL, OPENBRACKET, SPACE, st_expression(), st_statement(), ST_WHILETRUE, strdup(), STSEMICOLON, whileloop_body, and whileloop_condition.

Referenced by st_statement().

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

◆ variable_p()

static bool variable_p ( entity  e)
static

This function return a bool indicating if related entity e represents a variable.

Definition at line 668 of file print_code_smalltalk.c.

669 {
670  storage s = entity_storage(e);
671  return type_variable_p(entity_type(e)) &&
672  (storage_ram_p(s) || storage_return_p(s));
673 }
#define storage_ram_p(x)
Definition: ri.h:2519
#define storage_return_p(x)
Definition: ri.h:2516

References entity_storage, entity_type, storage_ram_p, storage_return_p, and type_variable_p.

Referenced by smalltalk_code_string().

+ Here is the caller graph for this function:

Variable Documentation

◆ intrinsic_to_smalltalk

struct s_ppt intrinsic_to_smalltalk[]
static

This data structure encodes the differents intrinsic allowing to convert fortran code to smalltalk code.

Definition at line 1131 of file print_code_smalltalk.c.

Referenced by get_ppt().