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

Go to the source code of this file.

Functions

expression string_to_expression (const char *s, entity module)
 Functions using simultaneously pipsdbm, which is based on strings, and ri-util, which contains basic methods for the objects of the internal representation. More...
 
list string_to_expressions (const char *str, const char *seed, entity module)
 split a string using seed as separator and call string_to_expression on each chunk More...
 

Function Documentation

◆ string_to_expression()

expression string_to_expression ( const char *  s,
entity  module 
)

Functions using simultaneously pipsdbm, which is based on strings, and ri-util, which contains basic methods for the objects of the internal representation.

expressions.c

try to parse s in the context of module module only simple expressions are found

try to find simple expression

unary operators

inary operators

Parameters
moduleodule

Definition at line 50 of file expressions.c.

51 {
53  if(entity_undefined_p(e)) {
54  /* try to find simple expression */
55  /* unary operators */
56  for(const char *iter = s ; *iter ; iter++) {
57  if(isspace(*iter)) continue;
58  if(*iter=='-') {
59  expression etmp = string_to_expression(iter+1, module);
60  if(!expression_undefined_p(etmp)) {
62  etmp);
63  }
64  }
65  }
66 
67  /*binary operators*/
69  for(int i=0; i < (int) (sizeof(seeds)/sizeof(seeds[0])); i++) {
70  char *where = strchr(s,seeds[i][0]);
71  if(where) {
72  char * head = strdup(s);
73  char * tail = head + (where -s) +1 ;
74  head[where-s]='\0';
77  free(head);
79  return MakeBinaryCall(
80  entity_intrinsic(seeds[i]),
81  e0,
82  e1
83  );
84  }
85  else {
86  free_expression(e0);
87  free_expression(e1);
88  }
89  }
90  }
91  return expression_undefined;
92  }
93  else
94  return entity_to_expression(e);
95 }
void free_expression(expression p)
Definition: ri.c:853
void const char const char const int
expression string_to_expression(const char *s, entity module)
Functions using simultaneously pipsdbm, which is based on strings, and ri-util, which contains basic ...
Definition: expressions.c:50
void free(void *)
entity string_to_entity(const char *s, entity module)
very simple conversion from string to expression only handles entities and numeric values at the time...
Definition: naming.c:237
static char * module
Definition: pips.c:74
#define MINUS_OPERATOR_NAME
#define PLUS_OPERATOR_NAME
#define DIVIDE_OPERATOR_NAME
#define UNARY_MINUS_OPERATOR_NAME
#define MULTIPLY_OPERATOR_NAME
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
expression MakeBinaryCall(entity f, expression eg, expression ed)
Creates a call expression to a function with 2 arguments.
Definition: expression.c:354
expression MakeUnaryCall(entity f, expression a)
Creates a call expression to a function with one argument.
Definition: expression.c:342
#define entity_undefined_p(x)
Definition: ri.h:2762
#define expression_undefined
Definition: ri.h:1223
#define expression_undefined_p(x)
Definition: ri.h:1224
char * strdup()

References DIVIDE_OPERATOR_NAME, entity_intrinsic(), entity_to_expression(), entity_undefined_p, expression_undefined, expression_undefined_p, free(), free_expression(), int, MakeBinaryCall(), MakeUnaryCall(), MINUS_OPERATOR_NAME, module, MULTIPLY_OPERATOR_NAME, PLUS_OPERATOR_NAME, strdup(), string_to_entity(), and UNARY_MINUS_OPERATOR_NAME.

Referenced by loop_expansion(), loop_expansion_init(), maxima_simplify(), and string_to_expressions().

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

◆ string_to_expressions()

list string_to_expressions ( const char *  str,
const char *  seed,
entity  module 
)

split a string using seed as separator and call string_to_expression on each chunk

Parameters
strtr
seedeed
moduleodule

Definition at line 98 of file expressions.c.

98  {
99  list strings = strsplit(str,seed);
100  list expressions = NIL;
101  FOREACH(STRING,s,strings) {
103  if(!expression_undefined_p(expr)) {
104  expressions = CONS(EXPRESSION,
105  expr,
106  expressions);
107  }
108  }
109  gen_map(free,strings);
110  gen_free_list(strings);
111  return gen_nreverse(expressions);
112 }
#define STRING(x)
Definition: genC.h:87
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
void gen_map(gen_iter_func_t fp, const list l)
Definition: list.c:172
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#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
list strsplit(const char *, const char *)
Definition: string.c:318
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References CONS, EXPRESSION, expression_undefined_p, FOREACH, free(), gen_free_list(), gen_map(), gen_nreverse(), module, NIL, STRING, string_to_expression(), and strsplit().

Referenced by symbolic_tiling().

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