next up previous
Next: Anonymous classes Up: Scope of a simple Previous: Class and interface declarations

Member declarations

The scope of a member declared or inherited by a class type or interface type is the entire declaration of the class or interface type. A class or interface may also inherit members from other classes or interfaces that it extends:

Scopes[15]:

ATTR TypScopeKey, FldScopeKey, MthScopeKey: DefTableKey;
ATTR TypEnv, FldEnv, MthEnv: Environment;

TREE SYMBOL ClassBody     INHERITS TypeBody END;
TREE SYMBOL InterfaceBody INHERITS TypeBody END;

CLASS SYMBOL TypeBody INHERITS TypExportInhRange, FldExportInhRange,
                               MthExportInhRange END;

RULE: TypeDeclaration ::=
        Modifiers 'class' TypeIdDef Super Interfaces ClassBody  COMPUTE
  ClassBody.TypScopeKey=TypeDeclaration.Type;
  ClassBody.TypGotInh=CONSTITUENTS InheritMembers.TypInheritOk;
  TypeDeclaration.TypEnv=ClassBody.TypEnv;
  TypeDeclaration.TypScopeKey=TypeDeclaration.Type;

  ClassBody.FldScopeKey=TypeDeclaration.Type;
  ClassBody.FldGotInh=CONSTITUENTS InheritMembers.FldInheritOk;
  TypeDeclaration.FldEnv=ClassBody.FldEnv;
  TypeDeclaration.FldScopeKey=TypeDeclaration.Type;

  ClassBody.MthScopeKey=TypeDeclaration.Type;
  ClassBody.MthGotInh=CONSTITUENTS InheritMembers.MthInheritOk;
  TypeDeclaration.MthEnv=ClassBody.MthEnv;
  TypeDeclaration.MthScopeKey=TypeDeclaration.Type;
END;

RULE: TypeDeclaration ::=
        Modifiers 'interface' TypeIdDef Interfaces InterfaceBody COMPUTE
  InterfaceBody.TypScopeKey=TypeDeclaration.Type;
  InterfaceBody.TypGotInh=1;/* FIXME CONSTITUENTS
  InheritMembers.TypInheritOk; */
  TypeDeclaration.TypEnv=InterfaceBody.TypEnv;
  TypeDeclaration.TypScopeKey=TypeDeclaration.Type;

  InterfaceBody.FldScopeKey=TypeDeclaration.Type;
  InterfaceBody.FldGotInh=CONSTITUENTS InheritMembers.FldInheritOk;
  TypeDeclaration.FldEnv=InterfaceBody.FldEnv;
  TypeDeclaration.FldScopeKey=TypeDeclaration.Type;

  InterfaceBody.MthScopeKey=TypeDeclaration.Type;
  InterfaceBody.MthGotInh=CONSTITUENTS InheritMembers.MthInheritOk;
  TypeDeclaration.MthEnv=InterfaceBody.MthEnv;
  TypeDeclaration.MthScopeKey=TypeDeclaration.Type;
END;
This macro is defined in definitions 11, 12, 14, 15, 16, 17, 18, 19, and 20.
This macro is invoked in definition 2.

Array types have a length field that is not explicitly declared:

Scopes[16]:
TREE SYMBOL ArrayType INHERITS FldExportRange COMPUTE
  INH.FldScopeKey=
    ORDER(
      ResetTypeOf(DefineIdn(THIS.FldEnv,MakeName("length")),intType),
      THIS.Type);
END;
This macro is defined in definitions 11, 12, 14, 15, 16, 17, 18, 19, and 20.
This macro is invoked in definition 2.

The inheritances for classes and interfaces can be handled in the same way:

Scopes[17]:
CLASS SYMBOL InheritMembers INHERITS FldInheritScope, MthInheritScope,
                                     TypInheritScope
COMPUTE
  INH.FldInnerScope=INCLUDING TypeDeclaration.FldEnv;
  INH.MthInnerScope=INCLUDING TypeDeclaration.MthEnv;
  INH.TypInnerScope=INCLUDING TypeDeclaration.TypEnv;
  IF(AND(
      NE(INCLUDING TypeDeclaration.Type,objectType),
      OR(
        NOT(THIS.TypInheritOk),
        OR(NOT(THIS.FldInheritOk),NOT(THIS.MthInheritOk)))),
    message(ERROR,"Improper inheritance",0,COORDREF));
END;

TREE SYMBOL Super INHERITS InheritMembers COMPUTE
  SYNT.TypScopeKey=THIS.Type;
  SYNT.FldScopeKey=THIS.Type;
  SYNT.MthScopeKey=THIS.Type;
END;

RULE: Super ::= 'extends' InhName COMPUTE
  Super.Type=InhName.Type;
END;

RULE: Super ::= COMPUTE
  Super.Type=objectType;
END;

TREE SYMBOL InterfaceType INHERITS InheritMembers END;

RULE: InterfaceType ::= InhName COMPUTE
  InterfaceType.TypScopeKey=InhName.Type;
  InterfaceType.FldScopeKey=InhName.Type;
  InterfaceType.MthScopeKey=InhName.Type;
  InterfaceType.Sym=InhName.Sym;
END;

This macro is defined in definitions 11, 12, 14, 15, 16, 17, 18, 19, and 20.
This macro is invoked in definition 2.

Neither fields nor methods have fully-qualified names. Thus there is no need to override the module's computation of their bindings. Method identifiers can be overloaded, however, and therefore we don't want to report an error if one has multiple defining occurrences:

Scopes[18]:

TREE SYMBOL FieldIdDef  INHERITS IdentOcc, FldIdDefScope, MultDefChk END;
TREE SYMBOL MethodIdDef INHERITS IdentOcc, MthIdDefScope             END;
This macro is defined in definitions 11, 12, 14, 15, 16, 17, 18, 19, and 20.
This macro is invoked in definition 2.


next up previous
Next: Anonymous classes Up: Scope of a simple Previous: Class and interface declarations
2008-09-11