Language Change Specification for Conditional Expressions and/or Operators Proposal

LCS Number: LCS-2016-036a
Version: 7
Date: 27-Feb-2017
Status: Voting
Author: Thomas Preusser
Email: Thomas Preusser
Source Doc: ConditionalExpressions
History Doc: History
Summary: Introduce first-class conditional expressions (baseline version)

Details of Language Change

Modifications are shown in red font. Deletions are striked out.

LRM Section 9.1 General

Edit 36a.1
An expression is a formula that defines the computation of a value.

(Introduce conditional expressions on top of unconditional ones.)

conditional_or_unaffected_expression ::=
  expression_or_unaffected { when condition else expression_or_unaffected } [ when condition ]

expression_or_unaffected ::=
  expression | unaffected 

conditional_expression ::=
  expression { when condition else expression }

expression ::=
  condition_operator primary
| logical_expression

...

primary ::=
  name
| literal
| aggregate
| function_call
| qualified_expression
| type_conversion
| allocator
| ( conditional_expression )

Edit 36a.2
(Move this production from previously 10.2.)

condition ::= expression

Each primary has a value and a type. The only names allowed as primaries are attributes that yield values and names denoting objects or values. In the case of names denoting objects other than objects of file types or protected types, the value of the primary is the value of the object. In the case of names denoting either file objects or objects of protected types, the value of the primary is the entity denoted by the name.

The type of an expression depends only upon the types of its operands and on the operators applied; for an overloaded operand or operator, the determination of the operand type, or the identification of the overloaded operator, depends on the context (see 12.5). For each predefined operator, the operand and result types are given in the following subclause.

Edit 36a.3
(Define semantics of conditional expression - to be inserted before Note 1.)

All of the candidate result expressions in a conditional expression shall have the same base type. The value of a conditional expression is the value of the choice preceding the first condition that evaluates to TRUE, if any. Otherwise, the value is determined from the final, unconditional choice.

Edit 36a.4
Each of the choices in a conditional or unaffected expression either is a candidate result expression of a common base type or consists of the keyword unaffected. For the purpose of evaluation, a conditional or unaffected expression whose last choice has a condition is implicitly completed by a final unconditional choice of unaffected. The conditional or unaffected expression evaluates to the choice preceding the first condition that evaluates to TRUE, if any. Otherwise, the value is determined from the final (possibly implicitly added) unconditional choice.

LRM Section 6.4.2.2 Constant Declarations

Edit 36a.5
A constant declaration declares a constant of the specified type. Such a constant is an explicitly declared constant.

(Allow top-level conditional expressions for value expression.)

constant_declaration ::=
  constant identifier_list : subtype_indication [ := conditional_expression ] ;

LRM Section 6.4.2.3 Signal Declarations

Edit 36a.6
A signal declaration declares a signal of the specified type. Such a signal is an explicitly declared signal.

(Allow top-level conditional expressions for value expression.)

signal_declaration ::=
  signal identifier_list : subtype_indication [ signal_kind ] [ := conditional_expression ] ;

LRM Section 6.4.2.4 Variable Declarations

Edit 36a.7
A variable declaration declares a variable of the specified type. Such a variable is an explicitly declared variable.

(Allow top-level conditional expressions for value expression.)

variable_declaration ::=
  [ shared ] variable identifier_list : subtype_indication [ := conditional_expression ] ;

LRM Section 6.5.2 Interface Object Declarations

Edit 36a.8
An interface object declaration declares an interface object of a specified type. Interface objects include interface constants that appear as generics of a design entity, a component, a block, a package, or a subprogram, or as constant parameters of subprograms; interface signals that appear as ports of a design entity, component, or block, or as signal parameters of subprograms; interface variables that appear as variable parameters of subprograms; interface files that appear as file parameters of subprograms.

interface_object_declaration ::=
  interface_constant_declaration
| interface_signal_declaration
| interface_variable_declaration
| interface_file_declaration

interface_constant_declaration ::=
  [ constant ] identifier_list : [ in ] subtype_indication [ := static_conditional_expression ]

interface_signal_declaration ::=
  [ signal ] identifier_list : [ mode ] subtype_indication [ bus ] [ := static_conditional_expression ]

interface_variable_declaration ::=
  [ variable ] identifier_list : [ mode ] subtype_indication [ := static_conditional_expression ]

interface_file_declaration ::=
  file identifier_list : subtype_indication

LRM Section 6.5.7.1 General

Edit 36a.9
An association list, other than one appearing in an interface package generic map aspect (see 6.5.5), establishes correspondences between formal or local generic, port, or parameter names on the one hand and local or actual names, expressions, subtypes, subprograms, or packages on the other.

association_list ::=
  association_element { , association_element }

...

actual_designator ::=
  [ inertial ] conditional_expression
| signal_name
| variable_name
| file_name
| subtype_indication
| subprogram_name
| instantiated_package_name
| *open*

LRM Section 7.2 Attribute Specification

Edit 36a.10
An attribute specification associates a user-defined attribute with one or more named entities and defines the value of that attribute for those entities. The attribute specification is said to decorate the named entity.

(Allow a conditional expression.)

attribute_specification ::=
  attribute attribute_designator of entity_specification is conditional_expression ;

LRM Section 9.2.9 Condition Operator

Edit 36a.11
(Fix the points of the bullet list.)

In certain circumstances, the condition operator is implicitly applied to an expression that occurs as a condition in any of the following places:

  • After when in a conditional variable assignment statement (see 10.6.3)
  • After when in a conditional or a conditional or unaffected expression (see 9.1)

LRM Section 10.2 Wait Statement

Edit 36a.12
The wait statement causes the suspension of a process statement or a procedure.

(Delete production moved to 9.1.)

condition ::= expression

LRM Section 10.5.2.1 General

Edit 36a.13
(Allow conditional_or_unaffected_expression in grammar production.)

simple_signal_assignment ::=
  simple_waveform_assignment
| simple_force_assignment
| simple_release_assignment

simple_waveform_assignment ::=
  target <= [ delay_mechanism ] waveform ;

simple_force_assignment ::=
  target <= force [ force_mode ] conditional_or_unaffected_expression ;

Edit 36a.14
(Update definition of unaffected semantics.)

It is an error if the pulse rejection limit for any inertially delayed signal assignment statement is either negative or greater than the time expression associated with the first waveform element.

A simple signal assignment of the form

target <= [ delay_mechanism ] unaffected ;

A simple waveform assignment or a simple force assignment that from an expression that evaluates to the special value of unaffected has the same effect as replacing the given assignment with a null statement (not an assignment with a null waveform element).

The right-hand side of a simple force assignment or a simple release assignment may optionally specify a force mode. A force mode consisting of the reserved word in specifies that an effective-value force or an effective-value release is to be scheduled, and a force mode consisting of the reserved word out specifies that a driving-value force or a driving-value release is to be scheduled.

LRM Section 10.5.3 Conditional Signal Assignments

Edit 36a.15
The conditional signal assignment represents an equivalent if statement that assigns values to signals or that forces or releases signals.

Edit 36a.16
(Remove following productions now subsumed by the expression syntax.)

conditional_signal_assignment ::=
  conditional_waveform_assignment
| conditional_force_assignment

conditional_waveform_assignment ::=
  target  <=  [  delay_mechanism  ]  conditional_waveforms  ;

conditional_waveforms ::=
  waveform when condition { else waveform when condition } [ else waveform ]

conditional_force_assignment ::=
target <= force [ force_mode ] conditional_expressions ;

conditional_expressions ::=
expression when condition { else expression when condition } [else expression]

The delay mechanism for a conditional waveform assignment statement is discussed in 10.5.2.1.

...

...
else
    target <= delay_mechanism waveformN;
end if;   _(This is for context.  Keep this part and above.)_ 

Edit 36a.17
(Remove unfolding of signal assignment from a conditional expression into if statements, starting at the end of page 156.)

If the conditional signal assignment is of the form

target <= force
   expression1 when condition1 else
   ...  (This deletes all the force-related productions from the bottom 
      of page 156 through the bottom of 157.)  
else
    target <= force expressionN;
end if;

Edit 36a.18
(Stop deleting, following is context to be kept.)

The characteristics of the target, waveforms, expressions, and conditions in the conditional assignment statement shall be such that the equivalent sequential statement is a legal statement.

LRM Section 10.6.1 General

Edit 36a.19
A variable assignment statement replaces the current value of a variable with a new value specified by an expression. The named variable and the right-hand side expression shall be of the same type.

(Remove conditional assignment now assumed by the conditional expression.)

variable_assignment_statement ::=
  [ label : ] simple_variable_assignment
| [ label : ] conditional_variable_assignment
| [ label : ] selected_variable_assignment

LRM Section 10.6.2.1 Simple Variable Assignments -- General

Edit 36a.20
simple_variable_assignment ::=
  target := conditional_or_unaffected_expression ;

Edit 36a.21
(Insert the description of unaffected for variable assignment at the end of the section.)

An error occurs if the aforementioned subtype checks fail.

A simple variable assignment from an expression that evaluates to the special value of unaffected has the same effect as replacing the given assignment by a null statement (not an assignment of a null value).

LRM Section 10.6.3 Conditional Variable Assignments

Edit 36a.22

(Remove this section entirely, and renumber the later sections accordingly.)

Annex C - Syntax Summary

Edit 36a.23
(Update productions and their references.)

actual_designator ::=
  [ inertial ] conditional_expression [6.5.7.1]
| signal_name
| variable_name
...

Edit 36a.24
attribute_specification ::=
  attribute attribute_designator of entity_specification is conditional_expression ; [7.2]

Edit 36a.25
condition ::= expression [10.29.1]

Edit 36a.26
conditional_expression ::=
  expression { when condition else expression } [9.1]

Edit 36a.27
conditional_or_unaffected_expression ::=
  expression_or_unaffected { when condition else expression_or_unaffected } [ when condition ] [9.1]

Edit 36a.28
conditional_expressions ::=
expression when condition { else expression when condition } [else expression] [10.5.3]

Edit 36a.29
conditional_force_assignment ::=
  target <= force [ force_mode ] conditional_expressions ; [10.5.3]

Edit 36a.30
conditional_signal_assignment ::=
  conditional_waveform_assignment
| conditional_force_assignment
  target  <=  [  delay_mechanism  ]  conditional_waveforms  ; [10.5.3]

Edit 36a.32
conditional_variable_assignment ::=
  target  :=  conditional_expressions ; [10.6.3]

Edit 36a.33
conditional_waveform_assignment ::=
  target  <=  [  delay_mechanism  ]  conditional_waveforms  ; [10.5.3]

Edit 36a.34
constant_declaration ::=
  constant identifier_list : subtype_indication [ := conditional_expression ] ; [6.4.2.2]

Edit 36a.35
expression_or_unaffected ::=
  expression | unaffected  [9.1]

Edit 36a.36
interface_constant_declaration ::=
  [ constant ] identifier_list : [ in ] subtype_indication [ := static_conditional_expression ] [6.5.2]

Edit 36a.37
interface_signal_declaration ::=
  [ signal ] identifier_list : [ mode ] subtype_indication [ bus ] [ := static_conditional_expression ] [6.5.2]

Edit 36a.38
interface_variable_declaration ::=
  [ variable ] identifier_list : [ mode ] subtype_indication [ := static_conditional_expression ] [6.5.2]

Edit 36a.39
primary ::=
  name
...
| ( conditional_expression ) [9.1]

Edit 36a.40
signal_declaration ::=
  signal identifier_list : subtype_indication [ signal_kind ] [ := conditional_expression ] ; [6.4.2.3]

Edit 36a.41
simple_force_assignment ::=
  target <= force [ force_mode ] conditional_or_unaffected_expression ; [10.5.2.1]

Edit 36a.42
simple_variable_assignment ::=
  target := conditional_or_unaffected_expression ; [10.6.2.1]

Edit 36a.43
variable_assignment_statement ::=
  [ label : ] simple_variable_assignment
| [ label : ] conditional_variable_assignment
| [ label : ] selected_variable_assignment [10.6.1]

Edit 36a.44
variable_declaration ::=
[ shared ] variable identifier_list : subtype_indication [ := conditional_expression ] ; [6.4.2.4]

Comments

Topic revision: r67 - 2017-07-23 - 13:08:32 - JimLewis
 
Copyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback