Skip to content

Commit 0c93178

Browse files
committed
Enable inherited submodule access of private/protected variables from parent
1 parent c3de4d4 commit 0c93178

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

tools/flang1/flang1exe/semsym.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ sym_in_scope(int first, OVCLASS overloadclass, int *paliassym, int *plevel,
224224
} else if (scope->kind == SCOPE_USE &&
225225
(PRIVATEG(sptr) || PRIVATEG(sptrloop))) {
226226
found = TRUE; /* private module variable */
227+
/* private module variables are visible to inherited submodules*/
228+
if (is_used_by_submod(gbl.currsub, sptr))
229+
return sptr;
227230
}
228231
if (!found) { /* not found in 'except' list */
229232
if (STYPEG(sptr) == ST_ALIAS)

tools/flang1/flang1exe/semutil.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,8 +1691,12 @@ mklvalue(SST *stkptr, int stmt_type)
16911691
else
16921692
set_assn(sptr);
16931693
} else if (stmt_type == 1 && !POINTERG(lval ? memsym_of_ast(lval) : sptr)) {
1694-
if (!lval)
1695-
set_assn(sptr);
1694+
if (!lval) {
1695+
/* it's legal for inherited submodules to access protected variables
1696+
defined parent modules, otherwise it's illegal */
1697+
if (!is_used_by_submod(gbl.currsub, sptr))
1698+
set_assn(sptr);
1699+
}
16961700
else
16971701
set_assn(sym_of_ast(lval));
16981702
} else if (stmt_type == 3)

tools/flang1/flang1exe/symtab.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,12 +3344,12 @@ map_initsym(int oldsym, int old_firstosym)
33443344
return 0;
33453345
}
33463346

3347-
/*
3348-
Convert two dollar signs to a hyphen. Especially used for the
3349-
submodule *.mod file renaming:
3350-
ancestor$$submod.mod -> ancestor-submod.mod
3347+
/** \brief Convert two dollar signs to a hyphen. Especially used for the
3348+
submodule *.mod file renaming:
3349+
ancestor$$submod.mod -> ancestor-submod.mod
33513350
*/
3352-
void convert_2dollar_signs_to_hyphen(char *name) {
3351+
void
3352+
convert_2dollar_signs_to_hyphen(char *name) {
33533353
char *p, *q;
33543354
p = q = name;
33553355
while (*q) {
@@ -3362,3 +3362,13 @@ void convert_2dollar_signs_to_hyphen(char *name) {
33623362
*p = *q;
33633363
}
33643364

3365+
/** \brief Used for check whether sym2 used inside the scope of sym1 is defined in
3366+
parent modules (SCOPEG(sym2)) and used by inherited submodules
3367+
ENCLFUNCG(sym1).
3368+
*/
3369+
bool
3370+
is_used_by_submod(SPTR sym1, SPTR sym2) {
3371+
return STYPEG(ENCLFUNCG(sym1)) == ST_MODULE &&
3372+
STYPEG(SCOPEG(sym2)) == ST_MODULE &&
3373+
SCOPEG(sym2) == ANCESTORG(ENCLFUNCG(sym1));
3374+
}

tools/flang1/utils/symtab/symtab.in.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,5 +478,6 @@ typedef enum CMP_INTERFACE_FLAGS {
478478
bool compatible_characteristics(int psptr, int psptr2,
479479
cmp_interface_flags flag);
480480
bool cmp_interfaces_strict(SPTR sym1, SPTR sym2, cmp_interface_flags flag);
481+
bool is_used_by_submod(SPTR sym1, SPTR sym2);
481482

482483
#endif // SYMTAB_H_

tools/flang1/utils/symtab/symtab.n

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ Flags3
473473
.ul
474474
Other Fields
475475
.SE ENCLFUNC w28 SPTR
476-
Symbol table pointer to the enclosing function for
477-
this variable.
476+
Symbol table pointer to the enclosing function (or module) for
477+
this variable (or subprogram).
478478
Zero for variables with
479479
.cw SCOPE
480480
equal to 0.

0 commit comments

Comments
 (0)