diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-05-05 05:21:28 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-05-05 05:21:28 +0200 |
commit | e47a1497c12be2d7aeb23716a2f1a1659a3b417e (patch) | |
tree | 08d7e369bc24f5a11d9630efcb1f8389a3025507 /src | |
parent | f96cca00e08340e1cc5cbce8cde7bfe4d5b2c870 (diff) | |
download | ghdl-e47a1497c12be2d7aeb23716a2f1a1659a3b417e.tar.gz ghdl-e47a1497c12be2d7aeb23716a2f1a1659a3b417e.tar.bz2 ghdl-e47a1497c12be2d7aeb23716a2f1a1659a3b417e.zip |
vhdl-sem_expr: improve support of vhdl-08 aggregates. Fix #1282
An element of an aggregate may have an unconstrained length.
Diffstat (limited to 'src')
-rw-r--r-- | src/vhdl/vhdl-sem_expr.adb | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/src/vhdl/vhdl-sem_expr.adb b/src/vhdl/vhdl-sem_expr.adb index 51a6549c8..506bf4290 100644 --- a/src/vhdl/vhdl-sem_expr.adb +++ b/src/vhdl/vhdl-sem_expr.adb @@ -3406,6 +3406,41 @@ package body Vhdl.Sem_Expr is end if; end Sem_Array_Aggregate_Elements; + procedure Sem_Array_Aggregate_Choice_Length + (Choice : Iir; + Len : in out Natural; + Len_Staticness : in out Iir_Staticness) + is + -- Extract length from associated expression. + -- Always has an associated expr, as not named. + Expr : constant Iir := Get_Associated_Expr (Choice); + Expr_Type : constant Iir := Get_Type (Expr); + Expr_Index : Iir; + Index_Staticness : Iir_Staticness; + begin + if Is_Error (Expr_Type) then + return; + end if; + if Get_Constraint_State (Expr_Type) /= Fully_Constrained then + Len_Staticness := None; + return; + end if; + + Expr_Index := Get_Index_Type (Expr_Type, 0); + Index_Staticness := Get_Type_Staticness (Expr_Index); + case Index_Staticness is + when Locally => + Len := Len + Natural + (Eval_Discrete_Type_Length (Expr_Index)); + when Globally | None => + Len_Staticness := Nodes.Min + (Len_Staticness, Index_Staticness); + when Unknown => + -- Must have been caught by Is_Error. + raise Internal_Error; + end case; + end Sem_Array_Aggregate_Choice_Length; + -- 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. @@ -3553,30 +3588,8 @@ package body Vhdl.Sem_Expr is Len := Len + 1; else -- Extract length from associated expression. - declare - -- Always has an associated expr, as not named. - Expr : constant Iir := Get_Associated_Expr (Choice); - Expr_Type : constant Iir := Get_Type (Expr); - Expr_Index : Iir; - Index_Staticness : Iir_Staticness; - begin - if not Is_Error (Expr_Type) then - Expr_Index := Get_Index_Type (Expr_Type, 0); - Index_Staticness := - Get_Type_Staticness (Expr_Index); - case Index_Staticness is - when Locally => - Len := Len + Natural - (Eval_Discrete_Type_Length (Expr_Index)); - when Globally | None => - Len_Staticness := Nodes.Min - (Len_Staticness, Index_Staticness); - when Unknown => - -- Must have been caught by Is_Error. - raise Internal_Error; - end case; - end if; - end; + Sem_Array_Aggregate_Choice_Length + (Choice, Len, Len_Staticness); end if; when Iir_Kind_Choice_By_Others => if not Constrained then |