aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2022-08-10 22:05:38 +0200
committerTristan Gingold <tgingold@free.fr>2022-08-10 22:05:38 +0200
commit003d45ec12c0d533a3ec37126ea6a6bb5efcb9ff (patch)
tree065546ec80a385e5a76d5707d767b8dfa493214f /src
parent4d14b77ce02b89b1a22718ce607b16d823d95c74 (diff)
downloadghdl-003d45ec12c0d533a3ec37126ea6a6bb5efcb9ff.tar.gz
ghdl-003d45ec12c0d533a3ec37126ea6a6bb5efcb9ff.tar.bz2
ghdl-003d45ec12c0d533a3ec37126ea6a6bb5efcb9ff.zip
vhdl-sem_names: factorize code for element attribute
Diffstat (limited to 'src')
-rw-r--r--src/vhdl/vhdl-sem_names.adb66
1 files changed, 10 insertions, 56 deletions
diff --git a/src/vhdl/vhdl-sem_names.adb b/src/vhdl/vhdl-sem_names.adb
index 455640779..dc7c0ab60 100644
--- a/src/vhdl/vhdl-sem_names.adb
+++ b/src/vhdl/vhdl-sem_names.adb
@@ -2018,11 +2018,16 @@ 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);
return Res;
+ when Iir_Kind_Element_Attribute =>
+ Set_Base_Name (Res, Res);
+ Set_Name_Staticness (Res, Get_Name_Staticness (Get_Prefix (Res)));
+ Set_Type_Staticness (Res, Get_Type_Staticness (Get_Type (Res)));
+ Free_Iir (Name);
+ return Res;
when Iir_Kind_Simple_Name_Attribute
| Iir_Kind_Path_Name_Attribute
| Iir_Kind_Instance_Name_Attribute =>
@@ -3779,6 +3784,9 @@ package body Vhdl.Sem_Names is
Res := Create_Iir (Iir_Kind_Ascending_Array_Attribute);
-- FIXME: Error if ambiguous
Res_Type := Boolean_Type_Definition;
+ when Name_Element =>
+ Res := Create_Iir (Iir_Kind_Element_Attribute);
+ Res_Type := Get_Element_Subtype (Prefix_Type);
when others =>
raise Internal_Error;
end case;
@@ -3826,60 +3834,6 @@ 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);
- Attr_Subtype := Get_Element_Subtype (Attr_Type);
- else
- Attr_Type := Is_Type_Name (Prefix_Name);
- if Attr_Type /= Null_Iir then
- Attr_Subtype := Get_Element_Subtype (Attr_Type);
- else
- Error_Msg_Sem (+Attr, "prefix must denote an object or a type");
- Attr_Subtype := Create_Error_Type (Attr);
- end if;
- end if;
-
- if False and then 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.
- -- NO, it isn't. The prefix can be a type.
- if False and then 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
@@ -4520,7 +4474,7 @@ package body Vhdl.Sem_Names is
when Name_Element =>
if Flags.Vhdl_Std >= Vhdl_08 then
- Res := Sem_Element_Attribute (Attr);
+ Res := Sem_Array_Attribute_Name (Attr);
else
Res := Sem_User_Attribute (Attr);
end if;