gfc_symbol *sym, *dt_sym;
gfc_intrinsic_op op;
match m;
+ gfc_access access = (st == ST_PUBLIC) ? ACCESS_PUBLIC : ACCESS_PRIVATE;
if (gfc_match (" ::") == MATCH_NO && gfc_match_space () == MATCH_NO)
goto done;
if (m == MATCH_NO)
goto syntax;
if (m == MATCH_ERROR)
- return MATCH_ERROR;
+ goto done;
switch (type)
{
&& sym->attr.flavor == FL_UNKNOWN)
sym->attr.flavor = FL_PROCEDURE;
- if (!gfc_add_access (&sym->attr,
- (st == ST_PUBLIC)
- ? ACCESS_PUBLIC : ACCESS_PRIVATE,
- sym->name, NULL))
- return MATCH_ERROR;
+ if (!gfc_add_access (&sym->attr, access, sym->name, NULL))
+ goto done;
if (sym->attr.generic && (dt_sym = gfc_find_dt_in_generic (sym))
- && !gfc_add_access (&dt_sym->attr,
- (st == ST_PUBLIC)
- ? ACCESS_PUBLIC : ACCESS_PRIVATE,
- sym->name, NULL))
- return MATCH_ERROR;
+ && !gfc_add_access (&dt_sym->attr, access, sym->name, NULL))
+ goto done;
break;
{
gfc_intrinsic_op other_op;
- gfc_current_ns->operator_access[op] =
- (st == ST_PUBLIC) ? ACCESS_PUBLIC : ACCESS_PRIVATE;
+ gfc_current_ns->operator_access[op] = access;
/* Handle the case if there is another op with the same
function, for INTRINSIC_EQ vs. INTRINSIC_EQ_OS and so on. */
other_op = gfc_equivalent_op (op);
if (other_op != INTRINSIC_NONE)
- gfc_current_ns->operator_access[other_op] =
- (st == ST_PUBLIC) ? ACCESS_PUBLIC : ACCESS_PRIVATE;
-
+ gfc_current_ns->operator_access[other_op] = access;
}
else
{
if (uop->access == ACCESS_UNKNOWN)
{
- uop->access = (st == ST_PUBLIC)
- ? ACCESS_PUBLIC : ACCESS_PRIVATE;
+ uop->access = access;
}
else
{
{
gfc_symbol *sym;
match m;
+ char c;
+
+ /* PROTECTED has already been seen, but must be followed by whitespace
+ or ::. */
+ c = gfc_peek_ascii_char ();
+ if (!gfc_is_whitespace (c) && c != ':')
+ return MATCH_NO;
if (!gfc_current_ns->proc_name
|| gfc_current_ns->proc_name->attr.flavor != FL_MODULE)
}
+ gfc_match (" ::");
+
if (!gfc_notify_std (GFC_STD_F2003, "PROTECTED statement at %C"))
return MATCH_ERROR;
- if (gfc_match (" ::") == MATCH_NO && gfc_match_space () == MATCH_NO)
- {
- return MATCH_ERROR;
- }
-
+ /* PROTECTED has an entity-list. */
if (gfc_match_eos () == MATCH_YES)
goto syntax;
match
gfc_match_private (gfc_statement *st)
{
+ gfc_state_data *prev;
+ char c;
if (gfc_match ("private") != MATCH_YES)
return MATCH_NO;
- if (gfc_current_state () != COMP_MODULE
- && !(gfc_current_state () == COMP_DERIVED
- && gfc_state_stack->previous
- && gfc_state_stack->previous->state == COMP_MODULE)
- && !(gfc_current_state () == COMP_DERIVED_CONTAINS
- && gfc_state_stack->previous && gfc_state_stack->previous->previous
- && gfc_state_stack->previous->previous->state == COMP_MODULE))
- {
- gfc_error ("PRIVATE statement at %C is only allowed in the "
- "specification part of a module");
- return MATCH_ERROR;
- }
-
- if (gfc_current_state () == COMP_DERIVED)
+ /* Try matching PRIVATE without an access-list. */
+ if (gfc_match_eos () == MATCH_YES)
{
- if (gfc_match_eos () == MATCH_YES)
+ prev = gfc_state_stack->previous;
+ if (gfc_current_state () != COMP_MODULE
+ && !(gfc_current_state () == COMP_DERIVED
+ && prev && prev->state == COMP_MODULE)
+ && !(gfc_current_state () == COMP_DERIVED_CONTAINS
+ && prev->previous && prev->previous->state == COMP_MODULE))
{
- *st = ST_PRIVATE;
- return MATCH_YES;
+ gfc_error ("PRIVATE statement at %C is only allowed in the "
+ "specification part of a module");
+ return MATCH_ERROR;
}
- gfc_syntax_error (ST_PRIVATE);
- return MATCH_ERROR;
+ *st = ST_PRIVATE;
+ return MATCH_YES;
}
- if (gfc_match_eos () == MATCH_YES)
+ /* At this point, PRIVATE must be followed by whitespace or ::. */
+ c = gfc_peek_ascii_char ();
+ if (!gfc_is_whitespace (c) && c != ':')
+ return MATCH_NO;
+
+ prev = gfc_state_stack->previous;
+ if (gfc_current_state () != COMP_MODULE
+ && !(gfc_current_state () == COMP_DERIVED
+ && prev && prev->state == COMP_MODULE)
+ && !(gfc_current_state () == COMP_DERIVED_CONTAINS
+ && prev->previous && prev->previous->state == COMP_MODULE))
{
- *st = ST_PRIVATE;
- return MATCH_YES;
+ gfc_error ("PRIVATE statement at %C is only allowed in the "
+ "specification part of a module");
+ return MATCH_ERROR;
}
*st = ST_ATTR_DECL;
match
gfc_match_public (gfc_statement *st)
{
+ char c;
if (gfc_match ("public") != MATCH_YES)
return MATCH_NO;
+ /* Try matching PUBLIC without an access-list. */
+ if (gfc_match_eos () == MATCH_YES)
+ {
+ if (gfc_current_state () != COMP_MODULE)
+ {
+ gfc_error ("PUBLIC statement at %C is only allowed in the "
+ "specification part of a module");
+ return MATCH_ERROR;
+ }
+
+ *st = ST_PUBLIC;
+ return MATCH_YES;
+ }
+
+ /* At this point, PUBLIC must be followed by whitespace or ::. */
+ c = gfc_peek_ascii_char ();
+ if (!gfc_is_whitespace (c) && c != ':')
+ return MATCH_NO;
+
if (gfc_current_state () != COMP_MODULE)
{
gfc_error ("PUBLIC statement at %C is only allowed in the "
return MATCH_ERROR;
}
- if (gfc_match_eos () == MATCH_YES)
- {
- *st = ST_PUBLIC;
- return MATCH_YES;
- }
-
*st = ST_ATTR_DECL;
return access_attr_decl (ST_PUBLIC);
}