@@ -103,6 +103,13 @@ static inline ASR::ttype_t* symbol_type(const ASR::symbol_t *f)
103
103
case ASR::symbolType::EnumType: {
104
104
return ASR::down_cast<ASR::EnumType_t>(f)->m_type ;
105
105
}
106
+ case ASR::symbolType::ExternalSymbol: {
107
+ return symbol_type (ASRUtils::symbol_get_past_external (f));
108
+ }
109
+ case ASR::symbolType::Function: {
110
+ return ASRUtils::expr_type (
111
+ ASR::down_cast<ASR::Function_t>(f)->m_return_var );
112
+ }
106
113
default : {
107
114
throw LCompilersException (" Cannot return type of, " +
108
115
std::to_string (f->type ) + " symbol." );
@@ -175,6 +182,52 @@ static inline ASR::abiType expr_abi(ASR::expr_t* e) {
175
182
}
176
183
}
177
184
185
+ static inline char *symbol_name (const ASR::symbol_t *f)
186
+ {
187
+ switch (f->type ) {
188
+ case ASR::symbolType::Program: {
189
+ return ASR::down_cast<ASR::Program_t>(f)->m_name ;
190
+ }
191
+ case ASR::symbolType::Module: {
192
+ return ASR::down_cast<ASR::Module_t>(f)->m_name ;
193
+ }
194
+ case ASR::symbolType::Function: {
195
+ return ASR::down_cast<ASR::Function_t>(f)->m_name ;
196
+ }
197
+ case ASR::symbolType::GenericProcedure: {
198
+ return ASR::down_cast<ASR::GenericProcedure_t>(f)->m_name ;
199
+ }
200
+ case ASR::symbolType::StructType: {
201
+ return ASR::down_cast<ASR::StructType_t>(f)->m_name ;
202
+ }
203
+ case ASR::symbolType::EnumType: {
204
+ return ASR::down_cast<ASR::EnumType_t>(f)->m_name ;
205
+ }
206
+ case ASR::symbolType::UnionType: {
207
+ return ASR::down_cast<ASR::UnionType_t>(f)->m_name ;
208
+ }
209
+ case ASR::symbolType::Variable: {
210
+ return ASR::down_cast<ASR::Variable_t>(f)->m_name ;
211
+ }
212
+ case ASR::symbolType::ExternalSymbol: {
213
+ return ASR::down_cast<ASR::ExternalSymbol_t>(f)->m_name ;
214
+ }
215
+ case ASR::symbolType::ClassProcedure: {
216
+ return ASR::down_cast<ASR::ClassProcedure_t>(f)->m_name ;
217
+ }
218
+ case ASR::symbolType::CustomOperator: {
219
+ return ASR::down_cast<ASR::CustomOperator_t>(f)->m_name ;
220
+ }
221
+ case ASR::symbolType::AssociateBlock: {
222
+ return ASR::down_cast<ASR::AssociateBlock_t>(f)->m_name ;
223
+ }
224
+ case ASR::symbolType::Block: {
225
+ return ASR::down_cast<ASR::Block_t>(f)->m_name ;
226
+ }
227
+ default : throw LCompilersException (" Not implemented" );
228
+ }
229
+ }
230
+
178
231
static inline std::string type_to_str (const ASR::ttype_t *t)
179
232
{
180
233
switch (t->type ) {
@@ -206,7 +259,7 @@ static inline std::string type_to_str(const ASR::ttype_t *t)
206
259
return " list" ;
207
260
}
208
261
case ASR::ttypeType::Struct: {
209
- return " derived type " ;
262
+ return ASRUtils::symbol_name (ASR::down_cast<ASR::Struct_t>(t)-> m_derived_type ) ;
210
263
}
211
264
case ASR::ttypeType::Union: {
212
265
return " union" ;
@@ -267,52 +320,6 @@ static inline ASR::expr_t* expr_value(ASR::expr_t *f)
267
320
return ASR::expr_value0 (f);
268
321
}
269
322
270
- static inline char *symbol_name (const ASR::symbol_t *f)
271
- {
272
- switch (f->type ) {
273
- case ASR::symbolType::Program: {
274
- return ASR::down_cast<ASR::Program_t>(f)->m_name ;
275
- }
276
- case ASR::symbolType::Module: {
277
- return ASR::down_cast<ASR::Module_t>(f)->m_name ;
278
- }
279
- case ASR::symbolType::Function: {
280
- return ASR::down_cast<ASR::Function_t>(f)->m_name ;
281
- }
282
- case ASR::symbolType::GenericProcedure: {
283
- return ASR::down_cast<ASR::GenericProcedure_t>(f)->m_name ;
284
- }
285
- case ASR::symbolType::StructType: {
286
- return ASR::down_cast<ASR::StructType_t>(f)->m_name ;
287
- }
288
- case ASR::symbolType::EnumType: {
289
- return ASR::down_cast<ASR::EnumType_t>(f)->m_name ;
290
- }
291
- case ASR::symbolType::UnionType: {
292
- return ASR::down_cast<ASR::UnionType_t>(f)->m_name ;
293
- }
294
- case ASR::symbolType::Variable: {
295
- return ASR::down_cast<ASR::Variable_t>(f)->m_name ;
296
- }
297
- case ASR::symbolType::ExternalSymbol: {
298
- return ASR::down_cast<ASR::ExternalSymbol_t>(f)->m_name ;
299
- }
300
- case ASR::symbolType::ClassProcedure: {
301
- return ASR::down_cast<ASR::ClassProcedure_t>(f)->m_name ;
302
- }
303
- case ASR::symbolType::CustomOperator: {
304
- return ASR::down_cast<ASR::CustomOperator_t>(f)->m_name ;
305
- }
306
- case ASR::symbolType::AssociateBlock: {
307
- return ASR::down_cast<ASR::AssociateBlock_t>(f)->m_name ;
308
- }
309
- case ASR::symbolType::Block: {
310
- return ASR::down_cast<ASR::Block_t>(f)->m_name ;
311
- }
312
- default : throw LCompilersException (" Not implemented" );
313
- }
314
- }
315
-
316
323
static inline std::pair<char **, size_t > symbol_dependencies (const ASR::symbol_t *f)
317
324
{
318
325
switch (f->type ) {
@@ -1231,6 +1238,8 @@ bool use_overloaded(ASR::expr_t* left, ASR::expr_t* right,
1231
1238
ASR::binopType op, std::string& intrinsic_op_name,
1232
1239
SymbolTable* curr_scope, ASR::asr_t *& asr,
1233
1240
Allocator &al, const Location& loc,
1241
+ std::set<std::string>& current_function_dependencies,
1242
+ Vec<char *>& current_module_dependencies,
1234
1243
const std::function<void (const std::string &, const Location &)> err);
1235
1244
1236
1245
bool is_op_overloaded (ASR::binopType op, std::string& intrinsic_op_name,
@@ -1240,6 +1249,8 @@ bool use_overloaded(ASR::expr_t* left, ASR::expr_t* right,
1240
1249
ASR::cmpopType op, std::string& intrinsic_op_name,
1241
1250
SymbolTable* curr_scope, ASR::asr_t *& asr,
1242
1251
Allocator &al, const Location& loc,
1252
+ std::set<std::string>& current_function_dependencies,
1253
+ Vec<char *>& current_module_dependencies,
1243
1254
const std::function<void (const std::string &, const Location &)> err);
1244
1255
1245
1256
bool is_op_overloaded (ASR::cmpopType op, std::string& intrinsic_op_name,
@@ -1248,6 +1259,8 @@ bool is_op_overloaded(ASR::cmpopType op, std::string& intrinsic_op_name,
1248
1259
bool use_overloaded_assignment (ASR::expr_t * target, ASR::expr_t * value,
1249
1260
SymbolTable* curr_scope, ASR::asr_t *& asr,
1250
1261
Allocator &al, const Location& loc,
1262
+ std::set<std::string>& current_function_dependencies,
1263
+ Vec<char *>& /* current_module_dependencies*/ ,
1251
1264
const std::function<void (const std::string &, const Location &)> err);
1252
1265
1253
1266
void set_intrinsic (ASR::symbol_t * sym);
@@ -1318,6 +1331,27 @@ static inline bool is_generic(ASR::ttype_t &x) {
1318
1331
}
1319
1332
}
1320
1333
1334
+ static inline bool is_generic_function (ASR::symbol_t *x) {
1335
+ ASR::symbol_t * x2 = symbol_get_past_external (x);
1336
+ switch (x2->type ) {
1337
+ case ASR::symbolType::Function: {
1338
+ ASR::Function_t *func_sym = ASR::down_cast<ASR::Function_t>(x2);
1339
+ return func_sym->n_type_params > 0 && !func_sym->m_is_restriction ;
1340
+ }
1341
+ default : return false ;
1342
+ }
1343
+ }
1344
+
1345
+ static inline bool is_restriction_function (ASR::symbol_t *x) {
1346
+ ASR::symbol_t * x2 = symbol_get_past_external (x);
1347
+ switch (x2->type ) {
1348
+ case ASR::symbolType::Function: {
1349
+ ASR::Function_t *func_sym = ASR::down_cast<ASR::Function_t>(x2);
1350
+ return func_sym->m_is_restriction ;
1351
+ }
1352
+ default : return false ;
1353
+ }
1354
+ }
1321
1355
1322
1356
static inline int get_body_size (ASR::symbol_t * s) {
1323
1357
int n_body = 0 ;
@@ -1678,7 +1712,12 @@ inline bool is_same_type_pointer(ASR::ttype_t* source, ASR::ttype_t* dest) {
1678
1712
source = dest;
1679
1713
dest = temp;
1680
1714
}
1681
- bool res = source->type == ASR::down_cast<ASR::Pointer_t>(dest)->m_type ->type ;
1715
+ dest = ASR::down_cast<ASR::Pointer_t>(dest)->m_type ;
1716
+ if ( (ASR::is_a<ASR::Class_t>(*source) || ASR::is_a<ASR::Struct_t>(*source)) &&
1717
+ (ASR::is_a<ASR::Class_t>(*dest) || ASR::is_a<ASR::Struct_t>(*dest)) ) {
1718
+ return true ;
1719
+ }
1720
+ bool res = source->type == dest->type ;
1682
1721
return res;
1683
1722
}
1684
1723
@@ -1923,12 +1962,15 @@ class ReplaceArgVisitor: public ASR::BaseExprReplacer<ReplaceArgVisitor> {
1923
1962
1924
1963
Vec<ASR::call_arg_t >& orig_args;
1925
1964
1965
+ std::set<std::string>& current_function_dependencies;
1966
+
1926
1967
public:
1927
1968
1928
1969
ReplaceArgVisitor (Allocator& al_, SymbolTable* current_scope_,
1929
- ASR::Function_t* orig_func_, Vec<ASR::call_arg_t >& orig_args_) :
1970
+ ASR::Function_t* orig_func_, Vec<ASR::call_arg_t >& orig_args_,
1971
+ std::set<std::string>& current_function_dependencies_) :
1930
1972
al (al_), current_scope(current_scope_), orig_func(orig_func_),
1931
- orig_args (orig_args_)
1973
+ orig_args (orig_args_), current_function_dependencies(current_function_dependencies_)
1932
1974
{}
1933
1975
1934
1976
void replace_FunctionCall (ASR::FunctionCall_t* x) {
@@ -1984,6 +2026,7 @@ class ReplaceArgVisitor: public ASR::BaseExprReplacer<ReplaceArgVisitor> {
1984
2026
replace_expr (x->m_args [i].m_value );
1985
2027
current_expr = current_expr_copy_;
1986
2028
}
2029
+ current_function_dependencies.insert (std::string (ASRUtils::symbol_name (new_es)));
1987
2030
x->m_name = new_es;
1988
2031
}
1989
2032
0 commit comments