@@ -1169,7 +1169,9 @@ class ExprBaseReplacerVisitor(ASDLVisitor):
1169
1169
1170
1170
def __init__ (self , stream , data ):
1171
1171
self .replace_expr = []
1172
+ self .replace_ttype = []
1172
1173
self .is_expr = False
1174
+ self .is_ttype = False
1173
1175
self .is_product = False
1174
1176
self .current_expr_copy_variable_count = 0
1175
1177
super (ExprBaseReplacerVisitor , self ).__init__ (stream , data )
@@ -1195,16 +1197,32 @@ def visitModule(self, mod):
1195
1197
self .replace_expr .append (("" , 0 ))
1196
1198
self .replace_expr .append ((" switch(x->type) {" , 1 ))
1197
1199
1200
+ self .replace_ttype .append ((" void replace_ttype(ASR::ttype_t* x) {" , 0 ))
1201
+ self .replace_ttype .append ((" if( !x ) {" , 1 ))
1202
+ self .replace_ttype .append ((" return ;" , 2 ))
1203
+ self .replace_ttype .append ((" }" , 1 ))
1204
+ self .replace_ttype .append (("" , 0 ))
1205
+ self .replace_ttype .append ((" switch(x->type) {" , 1 ))
1206
+
1198
1207
super (ExprBaseReplacerVisitor , self ).visitModule (mod )
1199
1208
1200
1209
self .replace_expr .append ((" default: {" , 2 ))
1201
- self .replace_expr .append ((' LCOMPILERS_ASSERT_MSG(false, "Duplication of " + std::to_string(x->type) + " expression is not supported yet.");' , 3 ))
1210
+ self .replace_expr .append ((' LCOMPILERS_ASSERT_MSG(false, "Replacement in " + std::to_string(x->type) + " expression is not supported yet.");' , 3 ))
1202
1211
self .replace_expr .append ((" }" , 2 ))
1203
1212
self .replace_expr .append ((" }" , 1 ))
1204
1213
self .replace_expr .append (("" , 0 ))
1205
1214
self .replace_expr .append ((" }" , 0 ))
1215
+
1216
+ self .replace_ttype .append ((" default: {" , 2 ))
1217
+ self .replace_ttype .append ((' LCOMPILERS_ASSERT_MSG(false, "Replacement in " + std::to_string(x->type) + " type is not supported yet.");' , 3 ))
1218
+ self .replace_ttype .append ((" }" , 2 ))
1219
+ self .replace_ttype .append ((" }" , 1 ))
1220
+ self .replace_ttype .append (("" , 0 ))
1221
+ self .replace_ttype .append ((" }" , 0 ))
1206
1222
for line , level in self .replace_expr :
1207
1223
self .emit (line , level = level )
1224
+ for line , level in self .replace_ttype :
1225
+ self .emit (line , level = level )
1208
1226
self .emit ("" )
1209
1227
self .emit ("};" )
1210
1228
@@ -1215,7 +1233,8 @@ def visitType(self, tp):
1215
1233
1216
1234
def visitSum (self , sum , * args ):
1217
1235
self .is_expr = args [0 ] == 'expr'
1218
- if self .is_expr :
1236
+ self .is_ttype = args [0 ] == 'ttype'
1237
+ if self .is_expr or self .is_ttype :
1219
1238
for tp in sum .types :
1220
1239
self .visit (tp , * args )
1221
1240
@@ -1239,12 +1258,21 @@ def make_visitor(self, name, fields):
1239
1258
self .replace_expr .append ((" self().replace_%s(down_cast<ASR::%s_t>(x));" % (name , name ), 3 ))
1240
1259
self .replace_expr .append ((" break;" , 3 ))
1241
1260
self .replace_expr .append ((" }" , 2 ))
1261
+ elif self .is_ttype :
1262
+ self .replace_ttype .append ((" case ASR::ttypeType::%s: {" % name , 2 ))
1263
+ self .replace_ttype .append ((" self().replace_%s(down_cast<ASR::%s_t>(x));" % (name , name ), 3 ))
1264
+ self .replace_ttype .append ((" break;" , 3 ))
1265
+ self .replace_ttype .append ((" }" , 2 ))
1242
1266
self .emit ("}" , 1 )
1243
1267
self .emit ("" )
1244
1268
1245
1269
def visitField (self , field ):
1246
1270
arguments = None
1247
- if field .type == "expr" or field .type == "symbol" or field .type == "call_arg" :
1271
+ if (field .type == "expr" or
1272
+ field .type == "symbol" or
1273
+ field .type == "call_arg" or
1274
+ field .type == "ttype" or
1275
+ field .type == "dimension" ):
1248
1276
level = 2
1249
1277
if field .seq :
1250
1278
self .used = True
@@ -1257,15 +1285,29 @@ def visitField(self, field):
1257
1285
self .emit (" current_expr = current_expr_copy_%d;" % (self .current_expr_copy_variable_count ), level + 1 )
1258
1286
self .emit (" }" , level )
1259
1287
self .current_expr_copy_variable_count += 1
1288
+ elif field .type == "dimension" :
1289
+ self .emit (" ASR::expr_t** current_expr_copy_%d = current_expr;" % (self .current_expr_copy_variable_count ), level )
1290
+ self .emit (" current_expr = &(x->m_%s[i].m_length);" % (field .name ), level )
1291
+ self .emit (" self().replace_expr(x->m_%s[i].m_length);" % (field .name ), level )
1292
+ self .emit (" current_expr = current_expr_copy_%d;" % (self .current_expr_copy_variable_count ), level )
1293
+ self .current_expr_copy_variable_count += 1
1294
+ self .emit (" ASR::expr_t** current_expr_copy_%d = current_expr;" % (self .current_expr_copy_variable_count ), level )
1295
+ self .emit (" current_expr = &(x->m_%s[i].m_start);" % (field .name ), level )
1296
+ self .emit (" self().replace_expr(x->m_%s[i].m_start);" % (field .name ), level )
1297
+ self .emit (" current_expr = current_expr_copy_%d;" % (self .current_expr_copy_variable_count ), level )
1298
+ self .current_expr_copy_variable_count += 1
1260
1299
self .emit ("}" , level )
1261
1300
else :
1262
1301
if field .type != "symbol" :
1263
1302
self .used = True
1264
- self .emit ("ASR::expr_t** current_expr_copy_%d = current_expr;" % (self .current_expr_copy_variable_count ), level )
1265
- self .emit ("current_expr = &(x->m_%s);" % (field .name ), level )
1266
- self .emit ("self().replace_%s(x->m_%s);" % (field .type , field .name ), level )
1267
- self .emit ("current_expr = current_expr_copy_%d;" % (self .current_expr_copy_variable_count ), level )
1268
- self .current_expr_copy_variable_count += 1
1303
+ if field .type == "ttype" :
1304
+ self .emit ("self().replace_%s(x->m_%s);" % (field .type , field .name ), level )
1305
+ else :
1306
+ self .emit ("ASR::expr_t** current_expr_copy_%d = current_expr;" % (self .current_expr_copy_variable_count ), level )
1307
+ self .emit ("current_expr = &(x->m_%s);" % (field .name ), level )
1308
+ self .emit ("self().replace_%s(x->m_%s);" % (field .type , field .name ), level )
1309
+ self .emit ("current_expr = current_expr_copy_%d;" % (self .current_expr_copy_variable_count ), level )
1310
+ self .current_expr_copy_variable_count += 1
1269
1311
1270
1312
class StmtBaseReplacerVisitor (ASDLVisitor ):
1271
1313
0 commit comments