[Home] [Prev] [Next] [Index]
8.5 Renaming Declarations
8.5 Renaming Declarations
- 1
- A renaming declaration declares another name for an entity.
- 2
- renaming_declaration ::=
identifier : type_mark renames
object_name;
| identifier : exception
renames
exception_name;
| package
identifier renames
package_name;
| subprogram_specification renames
subprogram_or_entry_name;
- 3
- The elaboration of a renaming declaration evaluates the name that follows the reserved word
renames
and thereby determines the entity denoted by this name (the renamed entity). At any point where a renaming declaration is visible, the identifier, or operator symbol of this declaration denotes the renamed entity.
- 4
- The first form of renaming declaration is used for the renaming of objects. The renamed entity must be an object of the base type of the type mark. The properties of the renamed object are not affected by the renaming declaration. In particular, its value and whether or not it is a constant are unaffected; similarly, the constraints that apply to an object are not affected by renaming (any constraint implied by the type mark of the renaming declaration is ignored). The renaming declaration is legal only if exactly one object has this type and can be denoted by the object name.
- 5
- The following restrictions apply to the renaming of a subcomponent that depends on discriminants of a variable. The renaming is not allowed if the subtype of the variable, as defined in a corresponding object declaration, component declaration, or component subtype indication, is an unconstrained type; or if the variable is a generic formal object (of mode
in out
). Similarly if the variable is a formal parameter, the renaming is not allowed if the type mark given in the parameter specification denotes an nconstrained type whose discriminants have default expressions.
- 6
- The second form of renaming declaration is used for the renaming of exceptions; the third form, for the renaming of packages.
- 7
- The last form of renaming declaration is used for the renaming of subprograms and entries. The renamed subprogram or entry and the subprogram specification given in the renaming declaration must have the same parameter and result type profile (see 6.6). The renaming declaration is legal only if exactly one visible subprogram or entry satisfies the above requirements and can be denoted by the given subprogram or entry name. In addition, parameter modes must be identical for formal parameters that are at the same parameter position.
- 8
- The subtypes of the parameters and result (if any) of a renamed subprogram or entry are not affected by renaming. These subtypes are those given in the original subprogram declaration, generic instantiation, or entry declaration (not those of the renaming declaration); even for calls that use the new name. On the other hand, a renaming declaration can introduce parameter names and default expressions that differ from those of the renamed subprogram; named associations of calls with the new subprogram name must use the new parameter name; calls with the old subprogram name must use the old parameter names.
- 9
- A procedure can only be renamed as a procedure. Either of a function or operator can be renamed as either of a function or operator; for renaming as an operator, the subprogram specification given in the renaming declaration is subject to the rules given in section 6.7 for operator declarations. Enumeration literals can be renamed as functions; similarly, attributes defined as functions (such as SUCC and PRED) can be renamed as functions. An entry can only be renamed as a procedure; the new name is only allowed to appear in contexts that allow a procedure name. An entry of a family can be renamed, but an entry family cannot be renamed as a whole.
- 10
- Examples:
declare
L : PERSON renames
LEFTMOST_PERSON; -- see 3.8.1
begin
L.AGE := L.AGE + 1;
end
;
FULL : exception
renames
TABLE_MANAGER.TABLE_FULL; -- see 7.5
package
TM renames
TABLE_MANAGER;
function
REAL_PLUS(LEFT, RIGHT : REAL ) return
REAL renames
"+";
function
INT_PLUS
(LEFT, RIGHT : INTEGER) return
INTEGER renames
"+";
function
ROUGE return
COLOR renames
RED; -- see 3.5.1
function
ROT return
COLOR renames
RED;
function
ROSSO return
COLOR renames
ROUGE;
function
NEXT(X : COLOR) return
COLOR renames
COLOR'SUCC;
-- see 3.5.5
- 11
- Example of a renaming declaration with new parameter names:
function
"*" (X,Y : VECTOR) return
REAL renames
DOT_PRODUCT; --
see 6.1
- 12
- Example of a renaming declaration with a new default expression:
function
MINIMUM(L : LINK := HEAD) return
CELL renames
MIN_CELL;
-- see 6.1
- Notes:
- 13
- Renaming may be used to resolve name conflicts and to act as a shorthand. Renaming with a different identifier or operator symbol does not hide the old name; the new name and the old name need not be visible at the same points. The attributes POS and VAL cannot be renamed since the corresponding specifications cannot be written; the same holds for the predefined multiplying operators with a universal_fixed result.
- 14
- Calls with the new name of a renamed entry are procedure call statements and are not allowed at places where the syntax requires an entry call statement in conditional and timed entry calls; similarly, the COUNT attribute is not available for the new name.
- 15
- A task object that is declared by an object declaration can be renamed as an object. However, a single task cannot be renamed since the corresponding task type is anonymous. For similar reasons, an object of an anonymous array type cannot be renamed. No syntactic form exists for renaming a generic unit.
- 16
- A subtype can be used to achieve the effect of renaming a type (including a task type) as in
subtype
MODE is
TEXT_IO.FILE_MODE;
- 17
- References:

- allow 1.6

- attribute 4.1.4

- base type 3.3

- conditional entry call 9.7.2

- constant 3.2.1

- constrained subtype 3.3

- constraint 3.3

- declaration 3.1

- default expression 6.1

- depend on a discriminant 3.7.1

- discriminant 3.7.1

- elaboration 3.1

- elaboration 3.9

- entry 9.5

- entry call 9.5

- entry call statement 9.5

- entry declaration 9.5

- entry family 9.5

- enumeration literal 3.5.1

- evaluation of a name 4.1

- exception 11

- formal parameter 6.1

- function 6.5

- identifier 2.3

- legal 1.6

- mode 6.1

- name 4.1

- object 3.2

- object declaration 3.2

- operator 6.7

- operator declaration 6.7

- operator symbol 6.1

- package 7

- parameter 6.2

- parameter specification 6.1

- procedure 6.1

- procedure call statement 6.4

- reserved word 2.9

- subcomponent 3.3

- subprogram 6

- subprogram call 6.4

- subprogram declaration 6.1

- subprogram specification 6.1

- subtype 3.3.2

- task object 9.2

- timed entry call 9.7.3

- type 3.3

- type mark 3.3.2

- variable 3.2.1

- visibility 8.3
[Home] [Prev] [Next] [Index]
documentation@rational.com
Copyright © 1993-2000, Rational Software Corporation. All rights
reserved.