Contents | Prev | Next | The T Language Specification, Version 2 Spring 2006 |
CHAPTER 4
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), an array creation expression (§8.8), or a cast operator (§8.12.3).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:
length
,
which is implicitly a member of every array type,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.
A name is used to refer to an entity declared in a program. All names are simple names: a single identifier.
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.
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.
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.
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.
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:
length
, which contains the number of components
of the array (length may be positive or zero), and which always denotes
a value and never a variable.
equals
method inherited from class Object
.
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
A name is syntactically classified as a TypeName in these contexts:
extends
clause in a class declaration
A name is syntactically classified as an ExpressionName in these contexts:
A name is syntactically classified as a MethodName in this context:
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.
The meaning of a name classified as an ExpressionName is determined as follows.
If an expression name consists of a single Identifier, then:
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:
int
,
the length of the array.
If Q.length appears in a context that requires a variable
and not a value, then a compile-time error occurs.
A MethodName can appear only in a method invocation expression. The meaning of a name classified as a MethodName is determined as follows.
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.
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)