aboutsummaryrefslogtreecommitdiffstats
path: root/src/vhdl/sem_expr.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2018-09-08 07:04:46 +0200
committerTristan Gingold <tgingold@free.fr>2018-09-08 07:04:46 +0200
commit409a39f4b2afa0f527ee4cb2732bef719ce5a5b9 (patch)
treece4fb62e6c10ec71c75520a3f4b09ec4e240520d /src/vhdl/sem_expr.adb
parent5cd3de469b95342dc20e883e8387ff59a752b7e9 (diff)
downloadghdl-409a39f4b2afa0f527ee4cb2732bef719ce5a5b9.tar.gz
ghdl-409a39f4b2afa0f527ee4cb2732bef719ce5a5b9.tar.bz2
ghdl-409a39f4b2afa0f527ee4cb2732bef719ce5a5b9.zip
sem_expr: minor refactoring (for aggregates).
Diffstat (limited to 'src/vhdl/sem_expr.adb')
-rw-r--r--src/vhdl/sem_expr.adb93
1 files changed, 51 insertions, 42 deletions
diff --git a/src/vhdl/sem_expr.adb b/src/vhdl/sem_expr.adb
index 89acf1afe..b5b579090 100644
--- a/src/vhdl/sem_expr.adb
+++ b/src/vhdl/sem_expr.adb
@@ -3058,6 +3058,55 @@ package body Sem_Expr is
type Array_Aggr_Info_Arr is array (Natural range <>) of Array_Aggr_Info;
+ procedure Sem_Array_Aggregate_Elements
+ (Aggr : Iir;
+ A_Type : Iir;
+ Expr_Staticness : in out Iir_Staticness;
+ Info : in out Array_Aggr_Info)
+ is
+ Element_Type : constant Iir := Get_Element_Subtype (A_Type);
+ El : Iir;
+ Expr : Iir;
+ El_Staticness : Iir_Staticness;
+ Assoc_Chain : Iir;
+ begin
+ -- LRM93 7.3.2.2:
+ -- the expression of each element association must be of the
+ -- element type.
+ Assoc_Chain := Get_Association_Choices_Chain (Aggr);
+
+ El := Assoc_Chain;
+ while El /= Null_Iir loop
+ if not Get_Same_Alternative_Flag (El) then
+ Expr := Get_Associated_Expr (El);
+ Expr := Sem_Expression (Expr, Element_Type);
+ if Expr /= Null_Iir then
+ El_Staticness := Get_Expr_Staticness (Expr);
+ Expr := Eval_Expr_If_Static (Expr);
+ Set_Associated_Expr (El, Expr);
+
+ if not Is_Static_Construct (Expr) then
+ Set_Aggregate_Expand_Flag (Aggr, False);
+ end if;
+
+ if not Eval_Is_In_Bound (Expr, Element_Type)
+ then
+ Info.Has_Bound_Error := True;
+ Warning_Msg_Sem (Warnid_Runtime_Error, +Expr,
+ "element is out of the bounds");
+ end if;
+
+ Expr_Staticness := Min (Expr_Staticness, El_Staticness);
+
+ Info.Nbr_Assocs := Info.Nbr_Assocs + 1;
+ else
+ Info.Error := True;
+ end if;
+ end if;
+ El := Get_Chain (El);
+ end loop;
+ end Sem_Array_Aggregate_Elements;
+
-- Analyze an array aggregate AGGR of *base type* A_TYPE.
-- The type of the array is computed into A_SUBTYPE.
-- DIM is the dimension index in A_TYPE.
@@ -3366,52 +3415,12 @@ package body Sem_Expr is
if Dim = Get_Nbr_Elements (Index_List) then
-- A type has been found for AGGR, analyze AGGR as if it was
-- an aggregate with a subtype (and not a string).
-
if Get_Kind (Aggr) /= Iir_Kind_Aggregate then
-- Nothing to do for a string.
return;
+ else
+ Sem_Array_Aggregate_Elements (Aggr, A_Type, Expr_Staticness, Info);
end if;
-
- -- LRM93 7.3.2.2:
- -- the expression of each element association must be of the
- -- element type.
- declare
- Element_Type : constant Iir := Get_Element_Subtype (A_Type);
- El : Iir;
- Expr : Iir;
- El_Staticness : Iir_Staticness;
- begin
- El := Assoc_Chain;
- while El /= Null_Iir loop
- if not Get_Same_Alternative_Flag (El) then
- Expr := Get_Associated_Expr (El);
- Expr := Sem_Expression (Expr, Element_Type);
- if Expr /= Null_Iir then
- El_Staticness := Get_Expr_Staticness (Expr);
- Expr := Eval_Expr_If_Static (Expr);
- Set_Associated_Expr (El, Expr);
-
- if not Is_Static_Construct (Expr) then
- Set_Aggregate_Expand_Flag (Aggr, False);
- end if;
-
- if not Eval_Is_In_Bound (Expr, Element_Type)
- then
- Info.Has_Bound_Error := True;
- Warning_Msg_Sem (Warnid_Runtime_Error, +Expr,
- "element is out of the bounds");
- end if;
-
- Expr_Staticness := Min (Expr_Staticness, El_Staticness);
-
- Info.Nbr_Assocs := Info.Nbr_Assocs + 1;
- else
- Info.Error := True;
- end if;
- end if;
- El := Get_Chain (El);
- end loop;
- end;
else
-- A sub-aggregate: recurse.
declare