Skip to content

Commit 2db6c0f

Browse files
authored
Merge pull request #1880 from czgdp1807/allocs
Add ``Allocatable`` and ``Array`` types
2 parents bc632d5 + 99cb99f commit 2db6c0f

File tree

226 files changed

+18448
-17350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

226 files changed

+18448
-17350
lines changed

src/libasr/ASR.asdl

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ symbol
111111
identifier proc_name, symbol proc, abi abi, bool is_deferred)
112112
| AssociateBlock(symbol_table symtab, identifier name, stmt* body)
113113
| Block(symbol_table symtab, identifier name, stmt* body)
114+
| Requirement(symbol_table symtab, identifier name, identifier* args)
115+
| Template(symbol_table symtab, identifier name, identifier* args)
114116

115-
storage_type = Default | Save | Parameter | Allocatable
117+
storage_type = Default | Save | Parameter
116118
access = Public | Private
117119
intent = Local | In | Out | InOut | ReturnVar | Unspecified
118120
deftype = Implementation | Interface
@@ -317,6 +319,7 @@ expr
317319
| EnumValue(expr v, ttype enum_type, ttype type, expr? value)
318320
| OverloadedCompare(expr left, cmpop op, expr right, ttype type, expr? value, expr overloaded)
319321
| OverloadedBinOp(expr left, binop op, expr right, ttype type, expr? value, expr overloaded)
322+
| OverloadedUnaryMinus(expr arg, ttype type, expr? value, expr overloaded)
320323
| Cast(expr arg, cast_kind kind, ttype type, expr? value)
321324
| ComplexRe(expr arg, ttype type, expr? value)
322325
| ComplexIm(expr arg, ttype type, expr? value)
@@ -362,24 +365,26 @@ expr
362365
-- integer, so we also use kind=4 for the default logical.)
363366

364367
ttype
365-
= Integer(int kind, dimension* dims)
366-
| UnsignedInteger(int kind, dimension* dims)
367-
| Real(int kind, dimension* dims)
368-
| Complex(int kind, dimension* dims)
369-
| Character(int kind, int len, expr? len_expr, dimension* dims)
370-
| Logical(int kind, dimension* dims)
368+
= Integer(int kind)
369+
| UnsignedInteger(int kind)
370+
| Real(int kind)
371+
| Complex(int kind)
372+
| Character(int kind, int len, expr? len_expr)
373+
| Logical(int kind)
371374
| Set(ttype type)
372375
| List(ttype type)
373376
| Tuple(ttype* type)
374-
| Struct(symbol derived_type, dimension* dims)
375-
| Enum(symbol enum_type, dimension *dims)
376-
| Union(symbol union_type, dimension *dims)
377-
| Class(symbol class_type, dimension* dims)
377+
| Struct(symbol derived_type)
378+
| Enum(symbol enum_type)
379+
| Union(symbol union_type)
380+
| Class(symbol class_type)
378381
| Dict(ttype key_type, ttype value_type)
379382
| Pointer(ttype type)
383+
| Allocatable(ttype type)
380384
| Const(ttype type)
381385
| CPtr()
382-
| TypeParameter(identifier param, dimension* dims)
386+
| TypeParameter(identifier param)
387+
| Array(ttype type, dimension* dims)
383388
| FunctionType(ttype* arg_types, ttype? return_var_type,
384389
abi abi, deftype deftype, string? bindc_name, bool elemental,
385390
bool pure, bool module, bool inline, bool static, ttype* type_params,

src/libasr/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ set(SRC
4444
pass/class_constructor.cpp
4545
pass/arr_slice.cpp
4646
pass/print_arr.cpp
47+
pass/print_struct_type.cpp
4748
pass/print_list_tuple.cpp
4849
pass/pass_utils.cpp
4950
pass/unused_functions.cpp

src/libasr/asdl_cpp.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def visitModule(self, mod):
417417
self.emit("private:")
418418
self.emit(" Struct& self() { return static_cast<Struct&>(*this); }")
419419
self.emit("public:")
420-
self.emit(" SymbolTable* current_scope;")
420+
self.emit(" SymbolTable* current_scope=nullptr;")
421421
self.emit(" void transform_stmts(ASR::stmt_t **&m_body, size_t &n_body) {")
422422
self.emit(" for (size_t i = 0; i < n_body; i++) {", 1)
423423
self.emit(" self().visit_stmt(*m_body[i]);", 1)
@@ -527,7 +527,7 @@ def visitModule(self, mod):
527527
self.emit(" Struct& self() { return static_cast<Struct&>(*this); }")
528528
self.emit("public:")
529529
self.emit(" ASR::expr_t** current_expr;")
530-
self.emit(" SymbolTable* current_scope;")
530+
self.emit(" SymbolTable* current_scope=nullptr;")
531531
self.emit("")
532532
self.emit(" void call_replacer() {}")
533533
self.emit(" void transform_stmts(ASR::stmt_t **&m_body, size_t &n_body) {")
@@ -1295,6 +1295,11 @@ def visitField(self, field):
12951295
self.emit(" current_expr = &(x->m_%s[i].m_start);" % (field.name), level)
12961296
self.emit(" self().replace_expr(x->m_%s[i].m_start);"%(field.name), level)
12971297
self.emit(" current_expr = current_expr_copy_%d;" % (self.current_expr_copy_variable_count), level)
1298+
elif field.type == "expr":
1299+
self.emit(" ASR::expr_t** current_expr_copy_%d = current_expr;" % (self.current_expr_copy_variable_count), level)
1300+
self.emit(" current_expr = &(x->m_%s[i]);" % (field.name), level)
1301+
self.emit(" self().replace_expr(x->m_%s[i]);"%(field.name), level)
1302+
self.emit(" current_expr = current_expr_copy_%d;" % (self.current_expr_copy_variable_count), level)
12981303
self.current_expr_copy_variable_count += 1
12991304
self.emit("}", level)
13001305
else:

src/libasr/asr_scopes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ void SymbolTable::move_symbols_from_global_scope(Allocator &al,
152152
ASR::ExternalSymbol_t *es = ASR::down_cast<ASR::ExternalSymbol_t>(a.second);
153153
mod_dependencies.push_back(al, es->m_module_name);
154154
es->m_parent_symtab = module_scope;
155-
ASR::symbol_t *s = ASRUtils::symbol_get_past_external(a.second);
156-
LCOMPILERS_ASSERT(s);
155+
LCOMPILERS_ASSERT(ASRUtils::symbol_get_past_external(a.second));
157156
module_scope->add_symbol(a.first, (ASR::symbol_t *) es);
158157
syms.push_back(al, s2c(al, a.first));
159158
break;

0 commit comments

Comments
 (0)