aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2015-05-11 00:56:39 +0200
committerTristan Gingold <tgingold@free.fr>2015-05-11 00:56:39 +0200
commitc89a5680b88cf17056595d48e67fc28ba18f6910 (patch)
treeb07b49d08e0725559f118da36d989815d6d5d190 /src
parent358323160ff607b668539f8e4a8d3f2156ad9e37 (diff)
downloadghdl-c89a5680b88cf17056595d48e67fc28ba18f6910.tar.gz
ghdl-c89a5680b88cf17056595d48e67fc28ba18f6910.tar.bz2
ghdl-c89a5680b88cf17056595d48e67fc28ba18f6910.zip
Fix use of condition operator in case of overload.
Fix ticket 50.
Diffstat (limited to 'src')
-rw-r--r--src/vhdl/sem_expr.adb47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/vhdl/sem_expr.adb b/src/vhdl/sem_expr.adb
index 95642236e..341e7f73a 100644
--- a/src/vhdl/sem_expr.adb
+++ b/src/vhdl/sem_expr.adb
@@ -132,8 +132,7 @@ package body Sem_Expr is
return Get_Common_Basetype (Left, Right) /= Null_Iir;
end Are_Basetypes_Compatible;
- function Are_Types_Compatible (Left: Iir; Right: Iir)
- return Boolean is
+ function Are_Types_Compatible (Left: Iir; Right: Iir) return Boolean is
begin
return Get_Common_Basetype (Get_Base_Type (Left),
Get_Base_Type (Right)) /= Null_Iir;
@@ -4247,19 +4246,49 @@ package body Sem_Expr is
-- context including the expression, then the condition operator is
-- not applied.
- -- GHDL: what does the second alternative mean ? Any example ?
-
Res := Sem_Expression_Ov (Cond, Null_Iir);
if Res = Null_Iir then
+ -- Error occured.
return Res;
end if;
- if not Is_Overloaded (Res)
- and then Get_Base_Type (Get_Type (Res)) = Boolean_Type_Definition
- then
- Check_Read (Res);
- return Res;
+ if not Is_Overloaded (Res) then
+ -- Only one result. Operator "??" is not applied if the result
+ -- is of type boolean.
+ if Are_Types_Compatible (Get_Type (Res), Boolean_Type_Definition)
+ then
+ Check_Read (Res);
+ return Res;
+ end if;
+ else
+ -- Many interpretations.
+ declare
+ El : Iir;
+ Res_List : constant Iir_List :=
+ Get_Overload_List (Get_Type (Res));
+ Nbr_Booleans : Natural;
+ begin
+ Nbr_Booleans := 0;
+
+ -- Extract boolean interpretations.
+ for I in Natural loop
+ El := Get_Nth_Element (Res_List, I);
+ exit when El = Null_Iir;
+ if Are_Types_Compatible (El, Boolean_Type_Definition) then
+ Nbr_Booleans := Nbr_Booleans + 1;
+ end if;
+ end loop;
+
+ if Nbr_Booleans >= 1 then
+ -- There is one or more boolean interpretations: keep them.
+ -- In case of multiple boolean interpretations, an error
+ -- message will be generated.
+ Res := Sem_Expression_Ov (Cond, Boolean_Type_Definition);
+ Check_Read (Res);
+ return Res;
+ end if;
+ end;
end if;
-- LRM08 9.2.9