aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAnselmo95 <anselmo.alberto95@gmail.com>2021-04-02 20:39:48 +0200
committertgingold <tgingold@users.noreply.github.com>2021-04-03 12:01:30 +0200
commit800656a30c2385b591766281cbc35de1582ce8f5 (patch)
treeeddc4f4ffbcf8cd0d79f2ec312566316bcb99e73 /src
parentc33f41e4612347d1fcbb9a37bc82249d7b8366eb (diff)
downloadghdl-800656a30c2385b591766281cbc35de1582ce8f5.tar.gz
ghdl-800656a30c2385b591766281cbc35de1582ce8f5.tar.bz2
ghdl-800656a30c2385b591766281cbc35de1582ce8f5.zip
Add base support for the attribue element in vhdl 08
Diffstat (limited to 'src')
-rw-r--r--src/vhdl/vhdl-prints.adb2
-rw-r--r--src/vhdl/vhdl-sem_names.adb59
-rw-r--r--src/vhdl/vhdl-utils.adb6
-rw-r--r--src/vhdl/vhdl-utils.ads3
4 files changed, 70 insertions, 0 deletions
diff --git a/src/vhdl/vhdl-prints.adb b/src/vhdl/vhdl-prints.adb
index 8fb03bf8e..6016c23e2 100644
--- a/src/vhdl/vhdl-prints.adb
+++ b/src/vhdl/vhdl-prints.adb
@@ -4893,6 +4893,8 @@ package body Vhdl.Prints is
Disp_Name_Attribute (Ctxt, Expr, Name_Base);
when Iir_Kind_Subtype_Attribute =>
Disp_Name_Attribute (Ctxt, Expr, Name_Subtype);
+ when Iir_Kind_Element_Attribute =>
+ Disp_Name_Attribute (Ctxt, Expr, Name_Element);
when Iir_Kind_Type_Declaration
| Iir_Kind_Subtype_Declaration
| Iir_Kind_Unit_Declaration
diff --git a/src/vhdl/vhdl-sem_names.adb b/src/vhdl/vhdl-sem_names.adb
index 957eb54ce..4548c8175 100644
--- a/src/vhdl/vhdl-sem_names.adb
+++ b/src/vhdl/vhdl-sem_names.adb
@@ -2004,6 +2004,7 @@ package body Vhdl.Sem_Names is
return Res;
when Iir_Kinds_Type_Attribute
| Iir_Kind_Subtype_Attribute
+ | Iir_Kind_Element_Attribute
| Iir_Kind_Base_Attribute =>
pragma Assert (Get_Kind (Name) = Iir_Kind_Attribute_Name);
Free_Iir (Name);
@@ -3733,6 +3734,57 @@ package body Vhdl.Sem_Names is
return Res;
end Sem_Subtype_Attribute;
+ -- For 'Element
+ function Sem_Element_Attribute (Attr : Iir_Attribute_Name) return Iir
+ is
+ Prefix_Name : Iir;
+ Attr_Type : Iir;
+ Attr_Subtype : Iir;
+ Res : Iir;
+ begin
+ Prefix_Name := Get_Prefix (Attr);
+ Prefix_Name := Finish_Sem_Name (Prefix_Name);
+ Set_Prefix (Attr, Prefix_Name);
+
+ -- LRM08 16.2 Predefined attributes
+ -- Prefix: Any prefix A that is appropriate for an array object, or an
+ -- alias thereof, or that denotes an array subtype
+ if (Get_Kind (Get_Base_Name (Prefix_Name))
+ in Iir_Kinds_Object_Declaration)
+ then
+ Attr_Type := Get_Type (Prefix_Name);
+ elsif (Get_Kind (Get_Base_Name (Prefix_Name))
+ in Iir_Kinds_Type_Declaration)
+ then
+ Attr_Type := Get_Type (Get_Base_Name (Prefix_Name));
+ else
+ Error_Msg_Sem (+Attr, "prefix must denote an object or a type");
+ end if;
+
+ if False and not Is_Array_Type (Attr_Type) then
+ Error_Msg_Sem (+Attr, "prefix must denote an array");
+ end if;
+
+ -- The type defined by 'element is always constrained. Create
+ -- a subtype if it is not.
+ Attr_Subtype := Get_Element_Subtype (Attr_Type);
+ if False and not Is_Fully_Constrained_Type (Attr_Subtype) then
+ Attr_Subtype :=
+ Sem_Types.Build_Constrained_Subtype (Attr_Subtype, Attr);
+ end if;
+
+ Res := Create_Iir (Iir_Kind_Element_Attribute);
+ Location_Copy (Res, Attr);
+ Set_Prefix (Res, Prefix_Name);
+ Set_Type (Res, Attr_Subtype);
+
+ Set_Base_Name (Res, Res);
+ Set_Name_Staticness (Res, Get_Name_Staticness (Prefix_Name));
+ Set_Type_Staticness (Res, Get_Type_Staticness (Attr_Subtype));
+
+ return Res;
+ end Sem_Element_Attribute;
+
-- For 'Across or 'Through
function Sem_Nature_Type_Attribute (Attr : Iir_Attribute_Name) return Iir
is
@@ -4371,6 +4423,13 @@ package body Vhdl.Sem_Names is
Res := Sem_User_Attribute (Attr);
end if;
+ when Name_Element =>
+ if Flags.Vhdl_Std >= Vhdl_08 then
+ Res := Sem_Element_Attribute (Attr);
+ else
+ Res := Sem_User_Attribute (Attr);
+ end if;
+
when Name_Across
| Name_Through =>
if Flags.AMS_Vhdl then
diff --git a/src/vhdl/vhdl-utils.adb b/src/vhdl/vhdl-utils.adb
index f34be5aeb..35cf51ed8 100644
--- a/src/vhdl/vhdl-utils.adb
+++ b/src/vhdl/vhdl-utils.adb
@@ -1039,6 +1039,11 @@ package body Vhdl.Utils is
return Get_Nature_Declarator (Def) = Null_Iir;
end Is_Anonymous_Nature_Definition;
+ function Is_Array_Type (Def : Iir) return Boolean is
+ begin
+ return Get_Kind (Def) in Iir_Kinds_Array_Type_Definition;
+ end Is_Array_Type;
+
function Is_Fully_Constrained_Type (Def : Iir) return Boolean is
begin
return Get_Kind (Def) not in Iir_Kinds_Composite_Type_Definition
@@ -1194,6 +1199,7 @@ package body Vhdl.Utils is
when Iir_Kinds_Subtype_Definition =>
return Ind;
when Iir_Kind_Subtype_Attribute
+ | Iir_Kind_Element_Attribute
| Iir_Kind_Across_Attribute
| Iir_Kind_Through_Attribute =>
return Get_Type (Ind);
diff --git a/src/vhdl/vhdl-utils.ads b/src/vhdl/vhdl-utils.ads
index 3696405e0..4d78640eb 100644
--- a/src/vhdl/vhdl-utils.ads
+++ b/src/vhdl/vhdl-utils.ads
@@ -175,6 +175,9 @@ package Vhdl.Utils is
-- Return TRUE iff DEF is a fully constrained type (or subtype) definition.
function Is_Fully_Constrained_Type (Def : Iir) return Boolean;
+ -- Return TRUE iff DEF is an array type (or subtype) definition.
+ function Is_Array_Type (Def : Iir) return Boolean;
+
-- Return True iff OBJ can be the target of an aggregate with an others
-- choice (cf LRM08 9.3.3.3).
-- Return True iff object or member of it is declared to be a fully