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

Go to the source code of this file.

Functions

bool entity_allocatable_p (entity e)
 Check if an entity is an allocatable. More...
 
bool expression_allocatable_data_access_p (expression e)
 Check if an expression is a reference to an allocatable array. More...
 
expression get_allocatable_data_expr (entity e)
 This function produce an expression that is an access to the array inside the allocatable structure. More...
 
entity get_allocatable_data_entity (entity e)
 Get the entity inside the struct corresponding to the array, mostly for correct prettyprint. More...
 

Function Documentation

◆ entity_allocatable_p()

bool entity_allocatable_p ( entity  e)

Check if an entity is an allocatable.

allocatable.c

Definition at line 72 of file allocatable.c.

72  {
73  type t = entity_type(e);
74  if(!type_variable_p(t)) {
75  return false;
76  }
77  variable v = type_variable(t);
79  return false;
80  }
81  entity allocatable_struct = basic_derived(variable_basic(v));
82 
83  if(!same_stringn_p(entity_local_name(allocatable_struct),
85  sizeof(STRUCT_PREFIX ALLOCATABLE_PREFIX)-1)) {
86  return false;
87  }
88 
89  return true;
90 }
#define same_stringn_p(a, b, c)
Definition: misc-local.h:199
#define STRUCT_PREFIX
Definition: naming-local.h:56
#define ALLOCATABLE_PREFIX
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 basic_derived(x)
Definition: ri.h:640
#define type_variable(x)
Definition: ri.h:2949
#define basic_derived_p(x)
Definition: ri.h:638
#define entity_type(x)
Definition: ri.h:2792
#define type_variable_p(x)
Definition: ri.h:2947
#define variable_basic(x)
Definition: ri.h:3120

References ALLOCATABLE_PREFIX, basic_derived, basic_derived_p, entity_local_name(), entity_type, same_stringn_p, STRUCT_PREFIX, type_variable, type_variable_p, and variable_basic.

Referenced by expression_allocatable_data_access_p(), get_allocatable_data_entity(), get_allocatable_data_expr(), and gfc2pips_expr2expression().

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

◆ expression_allocatable_data_access_p()

bool expression_allocatable_data_access_p ( expression  e)

Check if an expression is a reference to an allocatable array.

Definition at line 95 of file allocatable.c.

95  {
96  // This must be a call
97  if(!expression_call_p(e)) {
98  return false;
99  }
100 
101  entity field_call = call_function(expression_call(e));
102  list args_list = call_arguments(expression_call(e));
103 
104  // This must be a call to "." and we must have args
105  if(!ENTITY_FIELD_P(field_call) || ENDP(args_list)) {
106  return false;
107  }
108 
109  // Check that we deal with an allocatable
110  expression allocatable_exp = CAR(args_list).e;
111  entity allocatable =
112  reference_variable(expression_reference(allocatable_exp));
113  if(!entity_allocatable_p(allocatable)) {
114  return false;
115  } else {
116  pips_assert("Allocatable shouldn't have any indices !",
117  ENDP(reference_indices(expression_reference(allocatable_exp))));
118  }
119 
120  // Check that it is the data field
121  expression field_exp = CAR(CDR(args_list)).e;
122  pips_assert("Allocatable field shouldn't have any indices !",
124  entity field = reference_variable(expression_reference(field_exp));
130  strlen(ALLOCATABLE_UBOUND_PREFIX))) {
131  return false;
132  }
133 
134  return true;
135 }
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#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
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define ALLOCATABLE_UBOUND_PREFIX
#define ENTITY_FIELD_P(e)
C data structure and pointer management.
#define ALLOCATABLE_LBOUND_PREFIX
bool entity_allocatable_p(entity e)
Check if an entity is an allocatable.
Definition: allocatable.c:72
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
bool expression_call_p(expression e)
Definition: expression.c:415
call expression_call(expression e)
Definition: expression.c:445
reference expression_reference(expression e)
Short cut, meaningful only if expression_reference_p(e) holds.
Definition: expression.c:1832
#define call_function(x)
Definition: ri.h:709
#define reference_variable(x)
Definition: ri.h:2326
#define reference_indices(x)
Definition: ri.h:2328
#define call_arguments(x)
Definition: ri.h:711
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References ALLOCATABLE_LBOUND_PREFIX, ALLOCATABLE_UBOUND_PREFIX, call_arguments, call_function, CAR, CDR, ENDP, entity_allocatable_p(), ENTITY_FIELD_P, entity_user_name(), expression_call(), expression_call_p(), expression_reference(), pips_assert, reference_indices, reference_variable, and same_stringn_p.

Referenced by ensure_comment_consistency().

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

◆ get_allocatable_data_entity()

entity get_allocatable_data_entity ( entity  e)

Get the entity inside the struct corresponding to the array, mostly for correct prettyprint.

Definition at line 157 of file allocatable.c.

157  {
158  pips_assert("Entity isn't an allocatable", entity_allocatable_p(e));
159 
160  // Get the data field inside the allocatable struct
162  entity allocatable_struct = basic_derived(variable_basic(v));
163  entity data_field = CAR(type_struct(entity_type(allocatable_struct))).e;
164  return data_field;
165 }
#define type_struct(x)
Definition: ri.h:2964

References basic_derived, CAR, entity_allocatable_p(), entity_type, pips_assert, type_struct, type_variable, and variable_basic.

Referenced by get_allocatable_data_expr(), and text_entity_declaration().

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

◆ get_allocatable_data_expr()

expression get_allocatable_data_expr ( entity  e)

This function produce an expression that is an access to the array inside the allocatable structure.

Definition at line 141 of file allocatable.c.

141  {
142  pips_assert("Entity isn't an allocatable", entity_allocatable_p(e));
143 
144  entity data_field = get_allocatable_data_entity(e);
145 
146  // Construct the expression e.data
149  entity_to_expression(data_field));
150 
151 }
#define FIELD_OPERATOR_NAME
Definition: ri-util-local.h:91
entity get_allocatable_data_entity(entity e)
Get the entity inside the struct corresponding to the array, mostly for correct prettyprint.
Definition: allocatable.c:157
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
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

References CreateIntrinsic(), entity_allocatable_p(), entity_to_expression(), FIELD_OPERATOR_NAME, get_allocatable_data_entity(), MakeBinaryCall(), and pips_assert.

Referenced by gfc2pips_expr2expression().

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