Skip to content

implement support for node " N_Expanded_Name" #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sonodtt opened this issue Mar 12, 2019 · 0 comments
Open

implement support for node " N_Expanded_Name" #155

sonodtt opened this issue Mar 12, 2019 · 0 comments

Comments

@sonodtt
Copy link
Contributor

sonodtt commented Mar 12, 2019

Summary: renaming a package variable fails
– currently unsupported:
Var : ET.New_Integer renames ET.External_Var;

This task lies somewhere between "support for renaming" and "support for packages".

Consider the test case below

procedure Declaration_Rename is
A : Integer := 1;
B : Integer;

New_Integer_With_Complicated_Name : Integer := 11;
Simply_Named_Int : Integer renames New_Integer_With_Complicated_Name;
function My_Plus(Left, Right : Integer) return Integer renames "+";

package ET renames External_Types;
– without a 'use' package clause (which would make the package renaming redundant)
– the operator must also be explicitly renamed 
– (this operator is required for the 'pragma Assert'
function "=" (Left, Right: ET.New_Integer) return Boolean renames ET."=";

– currently unsupported. 
Var : ET.New_Integer renames ET.External_Var;

C : ET.New_Integer := 4;
begin
A := A + 1;
B := A + 1;

Var := 5;

pragma Assert (B=3);
pragma Assert (Simply_Named_Int=11);
pragma Assert (My_Plus(A,B)=5);

pragma Assert (C=4);

pragma Assert (Var=4);
end Declaration_Rename;

All operations involving Var (in the example above an assignment statement and equality expression) will cause failure in 'Do_Expression' with report:

12:42 $ gnat2goto declaration_rename.adb
---------At: Do_Expression---------
---------Unknown expression kind---------
N_Expanded_Name "external_var" (Node_Id=2406) (analyzed)
Rewritten: original node = N_Identifier "var" (Node_Id=2547)
Parent = N_Assignment_Statement (Node_Id=2408)
Sloc = 13314 declaration_rename.adb:31:4
Chars = "external_var" (Name_Id=300001456)
Etype = N_Defining_Identifier "new_integer" (Entity_Id=2455)
Prefix = N_Identifier "et" (Node_Id=2546)
Selector_Name = N_Identifier "external_var" (Node_Id=2545)
Entity = N_Defining_Identifier "external_var" (Entity_Id=2465)
Associated_Node = N_Defining_Identifier "external_var" (Entity_Id=2465)
---------At: Do_Expression---------
---------Unknown expression kind---------
N_Expanded_Name "external_var" (Node_Id=2438) (analyzed)
Rewritten: original node = N_Identifier "var" (Node_Id=2589)
Parent = N_Op_Eq "Oeq" (Node_Id=2441)
Sloc = 13477 declaration_rename.adb:39:19
Chars = "external_var" (Name_Id=300001456)
Etype = N_Defining_Identifier "new_integer" (Entity_Id=2455)
Prefix = N_Identifier "et" (Node_Id=2588)
Selector_Name = N_Identifier "external_var" (Node_Id=2587)
Entity = N_Defining_Identifier "external_var" (Entity_Id=2465)
Associated_Node = N_Defining_Identifier "external_var" (Entity_Id=2465)

The issue concerns also getting a fully qualified name:

-------------------
– Expanded Name –
-------------------

– The N_Expanded_Name node is used to represent a selected component
– name that has been resolved to an expanded name. The semantic phase
– replaces N_Selected_Component nodes that represent names by the use
– of this node, leaving the N_Selected_Component node used only when
– the prefix is a record or protected type.

– The fields of the N_Expanded_Name node are layed out identically
– to those of the N_Selected_Component node, allowing conversion of
– an expanded name node to a selected component node to be done
– easily, see Sinfo.CN.Change_Selected_Component_To_Expanded_Name.

– There is no special sprint syntax for an expanded name

– N_Expanded_Name
– Sloc points to the period
– Chars (Name1) copy of Chars field of selector name
– Prefix (Node3)
– Selector_Name (Node2)
– Entity (Node4-Sem)
– Associated_Node (Node4-Sem)
– Has_Private_View (Flag11-Sem) set in generic units.
– Redundant_Use (Flag13-Sem)
– Atomic_Sync_Required (Flag14-Sem)
– plus fields for expression

The prefix here is apparently what we'd need for a FQN, but it is uncertain if just that much will be enough to get it to work;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant