From 1deda7216985707b3386b4c305eca21dda1ebd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Th=C3=A9venoux?= Date: Mon, 9 Oct 2023 14:41:58 +0200 Subject: [PATCH] Factorize float type definitions/constraints RangeSpec equation --- ada/ast.py | 52 +++++++++++++--------------------------------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/ada/ast.py b/ada/ast.py index 6e180c5a2..466d34008 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -8199,15 +8199,7 @@ def xref_equation(): Entity.delta.sub_equation, Entity.delta.matches_expected_type, - # Expressions from the range specification are expected to be of - # any real type, the types need not be the same. - Entity.range.then( - lambda r: - Entity.universal_real_bind(r.range.expected_type_var) - & r.range.sub_equation - & r.range.matches_expected_type, - default_val=LogicTrue() - ) + If(Self.range.is_null, LogicTrue(), Entity.range.sub_equation) ) @langkit_property(memoized=True) @@ -8267,15 +8259,7 @@ def xref_equation(): Entity.digits.sub_equation, Entity.digits.matches_expected_type, - # Expressions from the range specification are expected to be of - # any real type, the types need not be the same. - Entity.range.then( - lambda r: - Entity.universal_real_bind(r.range.expected_type_var) - & r.range.sub_equation - & r.range.matches_expected_type, - default_val=LogicTrue() - ) + If(Self.range.is_null, LogicTrue(), Entity.range.sub_equation) ) @langkit_property(memoized=True) @@ -8394,16 +8378,7 @@ def xref_equation(): Entity.universal_int_bind(Entity.digits.expected_type_var), Entity.digits.sub_equation, Entity.digits.matches_expected_type, - - # Expressions from the range specification are expected to be of - # any real type, the types need not be the same. - Entity.range.then( - lambda r: - Entity.universal_real_bind(r.range.expected_type_var) - & r.range.sub_equation - & r.range.matches_expected_type, - default_val=LogicTrue() - ) + If(Self.range.is_null, LogicTrue(), Entity.range.sub_equation) ) @@ -8425,16 +8400,7 @@ def xref_equation(): Entity.universal_real_bind(Entity.delta.expected_type_var), Entity.delta.sub_equation, Entity.delta.matches_expected_type, - - # Expressions from the range specification are expected to be of - # any real type, the types need not be the same. - Entity.range.then( - lambda r: - Entity.universal_real_bind(r.range.expected_type_var) - & r.range.sub_equation - & r.range.matches_expected_type, - default_val=LogicTrue() - ) + If(Self.range.is_null, LogicTrue(), Entity.range.sub_equation) ) @@ -22521,7 +22487,7 @@ class RangeSpec(AdaNode): range = Field(type=Expr) xref_stop_resolution = Property(Self.parent.is_a(ComponentClause)) - xref_equation = Property(Entity.range.xref_equation & If( + xref_equation = Property(Entity.range.xref_equation & Cond( # Ada RM says that for component clauses and signed int type # definitions, the expected type is any integer type. Self.parent.is_a(ComponentClause, SignedIntTypeDef), @@ -22529,6 +22495,14 @@ class RangeSpec(AdaNode): Self.universal_int_bind(Self.range.expected_type_var) & Entity.range.matches_expected_type, + # In the following cases, expressions from the range specification are + # expected to be of any real type, the types need not be the same. + Self.parent.is_a(DeltaConstraint, DigitsConstraint, + OrdinaryFixedPointDef, DecimalFixedPointDef), + + Self.universal_real_bind(Self.range.expected_type_var) + & Entity.range.matches_expected_type, + LogicTrue() ))