Contents | Prev | Next The T Language Specification, Version 2
Spring 2006

CHAPTER 4

Names


Names are used to refer to entities declared in a program (§4.1). A declared entity is a class type, a member (field or method) of a reference type, a parameter (to a method or constructor) or a main block variable.

Names in T programs are simple, consisting of a single identifier (§4.2).

Every declaration that introduces a name has a scope (§4.3), which is the part of the program text within which the declared entity can be referred to by a name.

Reference types (that is, class types and array types) have members (§4.4). A member can be referred to using a qualified name N.x, where N is a variable of a reference type (or this or super) and x is an identifier that names a member of that type, which is either a field or a method.

In determining the meaning of a name (§4.5), the context of the occurrence is used to disambiguate among types, variables, and methods with the same name.

The name of a field, parameter, or main block variable may be used as an expression (§8.2). The name of a method may appear in an expression only as part of a method invocation expression (§8.10). The name of a class type may appear in an expression only as part of a class instance creation expression (§8.7) or an array creation expression (§8.8).

4.1 Declarations

A declaration introduces an entity into a program and includes an identifier that can be used as a name to refer to this entity. A declared entity is one of the following:

Constructors and destructors are also introduced by declarations, but use a name based upon the name of the class in which they are declared rather than introducing a new name.

4.2 Names and Identifiers

A name is used to refer to an entity declared in a program. All names are simple names: a single identifier.

4.3 Scope of a Declaration

The scope of a declaration is the region of the program within which the entity declared by the declaration can be referred to using a name (provided it is visible). A declaration is said to be in scope at a particular point in a program if and only if the declaration's scope includes that point.

These rules imply that declarations of class types need not appear before uses of the types.

4.3.1 Shadowing Declarations

Some declarations may be shadowed in part of their scope by another declaration of the same name, in which case a name cannot be used to refer to the declared entity.

A declaration d of a method parameter or constructor parameter named n shadows the declarations of any fields named n that are in scope at the point where d occurs throughout the scope of d.

A declaration d is said to be visible at point p in a program if the scope of d includes p, and d is not shadowed by any other declaration at p.

Note that shadowing is distinct from hiding. Hiding applies only to members which would otherwise be inherited but are not because of a declaration in a subclass.

4.4 Members and Inheritance

Reference types have members.

This section provides an overview of the members of reference types here, as background for the discussion of the determination of the meaning of names.

4.4.1 The Members of a Class Type

The members of a class type are fields and methods. Members are either declared in the type, or inherited because they are members of a superclass which are not overridden.

The members of a class type are all of the following:

Constructors and destructors are not members.

There is no restriction against a field and a method of a class type having the same name.

A class type may have two or more methods with the same name if the methods have different signatures, that is, if they have different numbers of parameters or different parameter types in at least one parameter position. Such a method member name is said to be overloaded.

A class type may contain a declaration for a method with the same name and the same signature as a method that would otherwise be inherited from a superclass. In this case, the method of the superclass is not inherited. The new declaration is said to override it.

4.4.2 The Members of an Array Type

The members of an array type are specified in §6.5. For convenience, we repeat that specification here.

The members of an array type are the following:

4.5 Determining the Meaning of a Name

The meaning of a name depends on the context in which it is used. The determination of the meaning of a name requires two steps. First, context causes a name syntactically to fall into one of three categories: TypeName, ExpressionName or MethodName. Second, the resulting category then dictates the final determination of the meaning of the name (or a compilation error if the name has no meaning).



TypeName:

    Identifier



ExpressionName:

    Identifier



MethodName:

    Identifier



4.5.1 Syntactic Classification of a Name According to Context

A name is syntactically classified as a TypeName in these contexts:

A name is syntactically classified as an ExpressionName in these contexts:

A name is syntactically classified as a MethodName in this context:

4.5.2 Meaning of Type Names

A type name consists of a single Identifier. The identifier must occur in the scope of a declaration of a type with this name, or a compile-time error occurs.

4.5.3 Meaning of Expression Names

The meaning of a name classified as an ExpressionName is determined as follows.

4.5.3.1 Simple Expression Names

If an expression name consists of a single Identifier, then:

4.5.3.2 Qualified Expression Names

If an expression name is of the form Q.Id, then Q has already been classified as an expression name. Let T be the type of Q:

4.5.4 Meaning of Method Names

A MethodName can appear only in a method invocation expression. The meaning of a name classified as a MethodName is determined as follows.

4.5.4.1 Simple Method Names

If a method name consists of a single Identifier, then Identifier is the method name to be used for method invocation. The Identifier must name at least one method of a class within whose declaration the Identifier appears.

4.5.4.2 Qualified Method Names

If a method name is of the form Q.Id, then Q has already been classified as an expression name. Id is the method name to be used for method invocation. Let T be the type of the expression Q; Id must name at least one method of the type T.


Contents | Prev | Next The T Language Specification, Version 2
Spring 2006

Author(s): John Augros (§4.1-4.5)