!ASIS Issue #027 !topic Corresponding_Name_Definition !reference ASIS !from Sergey Rybin 97-01-12 !keywords Corresponding_Name_Definition !discussion Below there are several comments on Asis.Expressions.Corresponding_Name_Definition function, the comments are "embadded" in the documentation of the function ------------------------------------------------------------------------------ -- Section 17.6 function Corresponding_Name_Definition ------------------------------------------------------------------------------ function Corresponding_Name_Definition (Reference : in Asis.Expression) return Asis.Defining_Name; ------------------------------------------------------------------------------ -- Reference - Specifies an expression to query -- -- Returns the defining_identifier, defining_character_literal, -- defining_operator_symbol, or defining_program_unit_name from the -- declaration of the referenced entity. -- -- - Record component references, return the defining_name of the -- record discriminant or component_declaration. For derived types, the -- result will be an Is_Part_Of_Implicit structural (syntactic) -- component from the declaration of the parent type definition. -- -- - References to implicit operators and inherited subprograms will return -- an Is_Part_Of_Implicit defining name for the operation. The -- Enclosing_Element of the name is an implicit declaration for the -- operation. The Enclosing_Element of the declaration is the associated -- derived_type_definition. -- -- - References to formal parameters given in calls to inherited subprograms -- will return an Is_Part_Of_Implicit defining name for the -- Parameter_Specification from the inherited subprogram specification. -- -- - References to visible components of instantiated generic packages will -- return a name from the expanded generic specification instance. -- -- - References, within expanded generic instances, that refer to other -- components of the same, or an enclosing, expanded generic instance, -- return a name from the appropriate expanded specification or body -- instance. -- -- Returns a Nil_Element if the reference is to an implicitly declared -- element for which the implementation does not provide declarations and -- defining_name elements. -- -- The Enclosing_Element of a non-Nil result is either a Declaration or a -- Statement. -- -- Appropriate Expression_Kinds: -- An_Identifier -- An_Operator_Symbol -- A_Character_Literal -- An_Enumeration_Literal -- -- Returns Element_Kinds: -- Not_An_Element -- A_Defining_Name -- --|IP Implementation Permissions: --|IP --|IP Some implementations do not represent all forms of implicit --|IP declarations such that elements representing them can be easily --|IP provided. An implementation can choose whether or not to construct --|IP and provide artificial declarations for implicitly declared elements. --|IP --|IR Implementation Requirements: --|IR -- Raises Asis_Inappropriate_Element, with a Status of Value_Error, if passed -- a reference that does not have a declaration: -- -- - a reference to an attribute_designator. Attributes are defined, but -- have no implicit or explicit declarations. -- -- - a name argument from a pragma identifier that does not actually -- reference a declared object. A contrived example of such an argument -- would be: -- -- pragma Should_I_Check ( Really => Yes ); -- -- In this example, the name Yes has no declaration. Comments: ======== 1. The RM-defined term for "Yes" is "an identifier specific to a pragma". (RM 2.8(10)); 2. In this example Really also has no declaration. So pragma_argument_identifier should also be mentioned here -- -- Raises Asis_Inappropriate_Element, with a Status of Data_Error, if passed -- a portion of a pragma that was "ignored" by the compiler and which does -- not have (sufficient) semantic information for a proper return result -- to be computed. For example, -- -- pragma I_Am_Ignored (Foof); Comments: ======== 3. Consider pragma I_Am_Ignored (Param => Foof) ^ ^ | | Data_Error Data_Error or Value_Error? I would suggest Value_Error. -- -- The "Foof" expression would be An_Identifier but would raise this exception -- if passed to Corresponding_Name_Definition if the pragma was ignored -- or unprocessed. -- -- Raises Asis_Inappropriate_Element, with a Status of Use_Error, if passed -- a portion of a pragma that is an ambiguous reference to more than one -- entity. For example, -- -- pragma Inline ("+"); -- Inlines all "+" operators -- -- The "+" expression would be An_Operator_Symbol but would raise this -- exception if it actually referenced more than one "+" operator. In this -- case, the Corresponding_Name_Definition_List query can be used to obtain a -- list of referenced entities. -- Comments: ======== 4. This "+" expression should for sure be classified as An_Operator_Symbol. But what about its further classification - should it be A_Plus_Operator or A_Unary_Plus_Operator? This question has the direct relation to the query under consideration, and also to the queries Asis.Elements.Pragma_Argument_Associations and Asis.Expressions.Actual_Parameter - to apply Corresponding_Name_Definition to this "+" expression, one should get this "+" before by applying Pragma_Argument_Associations to the whole A_Pragma Element and then by applying Actual_Parameter to the result of Pragma_Argument_Associations, so the question is - how should this "+" be classified as if Asis.Elements.Operator_Kind function? 5. The documentation actually says, that Corresponding_Name_Definition should set three different Error Status values if passed inappropriate Element: Value_Error, Data_Error and Use_Error. But the last two are defined in Asis.Errors only for Contexts and Compilation Units: Use_Error, -- Context/unit not use/open-able Data_Error, -- Context/unit bad/invalid/corrupt !resolution Accepted. !date 97-03-25 !Notes The text was changed to read as follows in ASIS version 2.0.M, subclause 17.6: --|IR Implementation Requirements: --|IR -- Raises Asis_Inappropriate_Element, with a Status of Value_Error, if passed -- a reference that does not have a declaration: -- -- - a reference to an attribute_designator. Attributes are defined, but -- have no implicit or explicit declarations; -- -- - an identifier which syntactically is placed before "=>" in a -- pragma_argument_association which has the form of a named association; -- such an identifier can never have a declaration; -- -- - an identifier specific to a pragma (Reference Manual, 2.8(10)); -- -- pragma Should_I_Check ( Really => Yes ); -- -- In this example, both the names Really and Yes have no declaration. -- -- Raises Asis_Inappropriate_Element, with a Status of Value_Error, if passed -- a portion of a pragma that was "ignored" by the compiler and which does -- not have (sufficient) semantic information for a proper return result -- to be computed. For example, -- -- pragma I_Am_Ignored (Foof); -- -- The "Foof" expression would be An_Identifier but would raise this exception -- if passed to Corresponding_Name_Definition if the pragma was ignored -- or unprocessed. -- -- Raises Asis_Inappropriate_Element, with a Status of Falue_Error, if passed -- a portion of a pragma that is an ambiguous reference to more than one -- entity. For example, -- -- pragma Inline ("+"); -- Inlines all "+" operators -- -- The "+" expression would be An_Operator_Symbol but would raise this -- exception if it referenced more than one "+" operator. In this -- case, the Corresponding_Name_Definition_List query can be used to obtain a -- list of referenced entities. -- ---------------------------------------------------------------------------------------