-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
attribute_subprogram
property on types.
This is basically a refactoring that moves properties around so that the `attribute_subprogram` one can be called on a given `BaseTypeDecl`. It also makes it public so that it can be used outside name resolution.
- Loading branch information
Showing
4 changed files
with
159 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
with Ada.Strings.Text_Buffers; | ||
with Ada.Text_IO; | ||
|
||
procedure Test is | ||
X : Integer := 42; | ||
Y : String := X'Image; | ||
--% typ = node.f_default_expr.f_prefix.p_expression_type | ||
--% subp = typ.p_attribute_subprogram("image") | ||
--% spec = node.f_default_expr.p_called_subp_spec | ||
--% subp.p_subp_spec_or_null() == spec | ||
|
||
package Pkg is | ||
type Custom_Image is null record | ||
with Put_Image => Img; | ||
|
||
procedure Img | ||
(Buffer : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class; | ||
Arg : in Custom_Image); | ||
end Pkg; | ||
|
||
package body Pkg is | ||
procedure Img | ||
(Buffer : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class; | ||
Arg : in Custom_Image) is | ||
begin | ||
null; | ||
end Img; | ||
end Pkg; | ||
|
||
V : Pkg.Custom_Image; | ||
--% typ = node.f_type_expr.p_designated_type_decl | ||
--% subp = typ.p_attribute_subprogram("put_image") | ||
--% non_existant = typ.p_attribute_subprogram("non_existant") | ||
begin | ||
Ada.Text_IO.Put_Line (V'Image); | ||
end Test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Working on node <ObjectDecl ["Y"] test.adb:6:4-6:26> | ||
==================================================== | ||
|
||
Set 'typ' to 'node.f_default_expr.f_prefix.p_expression_type' | ||
Result: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54> | ||
|
||
Set 'subp' to 'typ.p_attribute_subprogram("image")' | ||
Result: <SyntheticSubpDecl [""] __standard:4:3-4:54> | ||
|
||
Set 'spec' to 'node.f_default_expr.p_called_subp_spec' | ||
Result: <SyntheticUnarySpec __standard:4:3-4:54> | ||
|
||
Eval 'subp.p_subp_spec_or_null() == spec' | ||
Result: True | ||
|
||
Working on node <ObjectDecl ["V"] test.adb:30:4-30:25> | ||
====================================================== | ||
|
||
Set 'typ' to 'node.f_type_expr.p_designated_type_decl' | ||
Result: <ConcreteTypeDecl ["Custom_Image"] test.adb:13:7-14:32> | ||
|
||
Set 'subp' to 'typ.p_attribute_subprogram("put_image")' | ||
Result: <SubpDecl ["Img"] test.adb:16:7-18:36> | ||
|
||
Set 'non_existant' to 'typ.p_attribute_subprogram("non_existant")' | ||
Result: None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
driver: inline-playground | ||
input_sources: [test.adb] |