Skip to content

Commit 53cbbf0

Browse files
authored
Merge pull request #3162 from ntrel/expr-tweaks
[expression.dd] Improve formatting
2 parents b6725b2 + b3a3ad8 commit 53cbbf0

File tree

1 file changed

+78
-38
lines changed

1 file changed

+78
-38
lines changed

spec/expression.dd

Lines changed: 78 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ $(SPEC_S Expressions,
44

55
$(HEADERNAV_TOC)
66

7+
$(H2 $(LEGACY_LNAME2 Expression, expression, Expressions))
8+
9+
$(GRAMMAR
10+
$(GNAME Expression):
11+
$(GLINK CommaExpression)
12+
)
13+
714
$(P An expression is a sequence of operators and operands that specifies an evaluation.
815
The syntax, order of evaluation, and semantics of expressions are as follows.)
916

@@ -41,7 +48,7 @@ $(LI built-in unary operators `+` (when applied to an lvalue), `*`, `++` (prefix
4148
$(LI built-in indexing operator `[]` (but not the slicing operator);)
4249
$(LI built-in assignment binary operators, i.e. `=`, `+=`, `*=`, `/=`, `%=`, `&=`, `|=`, `^=`, `~=`,
4350
`<<=`, `>>=`, `>>>=`, and `^^=`;)
44-
$(LI the ternary operator $(I e) `?` $(I e$(SUBSCRIPT 1)) `:` $(I e$(SUBSCRIPT 2)) under the following
51+
$(LI the $(GLINK ConditionalExpression) operator $(I e) `?` $(I e$(SUBSCRIPT 1)) `:` $(I e$(SUBSCRIPT 2)) under the following
4552
circumstances:)
4653
$(OL
4754
$(LI $(I e$(SUBSCRIPT 1)) and $(I e$(SUBSCRIPT 2)) are lvalues of the same type; OR)
@@ -172,7 +179,7 @@ $(P Note: An intuition behind these rules is that destructors of temporaries are
172179
expression and in reverse order of construction, with the exception that the right-hand side of
173180
`&&` and `||` are considered their own full expressions even when part of larger expressions.)
174181

175-
$(P Note: The ternary expression $(I e$(SUBSCRIPT 1) ? e$(SUBSCRIPT 2) : e$(SUBSCRIPT 3)) is not
182+
$(P Note: The $(GLINK ConditionalExpression) $(I e$(SUBSCRIPT 1) ? e$(SUBSCRIPT 2) : e$(SUBSCRIPT 3)) is not
176183
a special case although it evaluates expressions conditionally: $(I e$(SUBSCRIPT 1)) and one of
177184
$(I e$(SUBSCRIPT 2)) and $(I e$(SUBSCRIPT 3)) may create temporaries. Their destructors are inserted
178185
to the end of the full expression in the reverse order of creation.)
@@ -218,12 +225,9 @@ Following their destruction, `S(5)` and `S(6)` are constructed in lexical order.
218225
destroyed at the end of the full expression, but right at the end of the `&&` expression.
219226
Consequently, the destruction of `S(6)` and `S(5)` is carried before that of `S(2)` and `S(1)`.
220227

221-
$(H2 $(LEGACY_LNAME2 Expression, expression, Expressions))
228+
$(H2 $(LNAME2 comma_expression, Comma Expression))
222229

223230
$(GRAMMAR
224-
$(GNAME Expression):
225-
$(GLINK CommaExpression)
226-
227231
$(GNAME CommaExpression):
228232
$(GLINK AssignExpression)
229233
$(GSELF CommaExpression) $(D ,) $(GLINK AssignExpression)
@@ -371,7 +375,11 @@ $(GNAME ConditionalExpression):
371375
test ? a = b : (c = 2);
372376
---
373377

374-
$(H2 $(LNAME2 oror_expressions, OrOr Expressions))
378+
$(H2 $(LNAME2 logical_expressions, Logical Expressions))
379+
380+
$(DDOC_SEE_ALSO $(GLINK UnaryExpression) for `!expr`.)
381+
382+
$(H3 $(LNAME2 oror_expressions, OrOr Expressions))
375383

376384
$(GRAMMAR
377385
$(GNAME OrOrExpression):
@@ -399,7 +407,7 @@ $(GNAME OrOrExpression):
399407
expression is the right operand converted to type $(D bool).
400408
)
401409

402-
$(H2 $(LNAME2 andand_expressions, AndAnd Expressions))
410+
$(H3 $(LNAME2 andand_expressions, AndAnd Expressions))
403411

404412
$(GRAMMAR
405413
$(GNAME AndAndExpression):
@@ -429,11 +437,13 @@ $(GNAME AndAndExpression):
429437

430438
$(H2 $(LNAME2 bitwise_expressions, Bitwise Expressions))
431439

432-
$(P Bit wise expressions perform a bitwise operation on their operands.
440+
$(P Bit wise expressions perform a
441+
$(LINK2 https://en.wikipedia.org/wiki/Bitwise_operation, bitwise operation) on their operands.
433442
Their operands must be integral types.
434443
First, the $(USUAL_ARITHMETIC_CONVERSIONS) are done. Then, the bitwise
435444
operation is done.
436445
)
446+
$(DDOC_SEE_ALSO $(GLINK ShiftExpression), $(GLINK ComplementExpression))
437447

438448
$(H3 $(LNAME2 or_expressions, Or Expressions))
439449

@@ -731,9 +741,10 @@ $(GNAME ShiftExpression):
731741
by the right operand's value.
732742
)
733743

734-
$(P $(D <)$(D <) is a left shift.
735-
$(D >)$(D >) is a signed right shift.
736-
$(D >)$(D >)$(D >) is an unsigned right shift.
744+
$(UL
745+
$(LI $(D <)$(D <) is a left shift.)
746+
$(LI $(D >)$(D >) is a signed right shift.)
747+
$(LI $(D >)$(D >)$(D >) is an unsigned right shift.)
737748
)
738749

739750
$(P It's illegal to shift by the same or more bits than the size of the
@@ -759,11 +770,25 @@ $(GNAME AddExpression):
759770
$(USUAL_ARITHMETIC_CONVERSIONS).
760771
)
761772

773+
$(P If both operands are of integral types and an overflow or underflow
774+
occurs in the computation, wrapping will happen. For example:)
775+
$(UL
776+
$(LI $(D uint.max + 1 == uint.min))
777+
$(LI $(D uint.min - 1 == uint.max))
778+
$(LI $(D int.max + 1 == int.min))
779+
$(LI $(D int.min - 1 == int.max))
780+
)
781+
762782
$(P If either operand is a floating point type, the other is implicitly
763783
converted to floating point and they are brought to a common type
764784
via the $(USUAL_ARITHMETIC_CONVERSIONS).
765785
)
766786

787+
$(P Add expressions for floating point operands are not associative.
788+
)
789+
790+
$(H3 $(LNAME2 pointer_arithmetic, Pointer Arithmetic))
791+
767792
$(P If the operator is $(D +) or $(D -), and
768793
the first operand is a pointer, and the second is an integral type,
769794
the resulting type is the type of the first operand, and the resulting
@@ -789,14 +814,7 @@ $(GNAME AddExpression):
789814
The type of the result is $(D ptrdiff_t).
790815
)
791816

792-
$(P If both operands are of integral types and an overflow or underflow
793-
occurs in the computation, wrapping will happen. For example,
794-
$(D uint.max + 1 == uint.min), $(D uint.min - 1 == uint.max),
795-
$(D int.max + 1 == int.min), and $(D int.min - 1 == int.max).
796-
)
797-
798-
$(P Add expressions for floating point operands are not associative.
799-
)
817+
$(P $(GLINK IndexExpression) can also be used with a pointer.)
800818

801819
$(H2 $(LNAME2 cat_expressions, Cat Expressions))
802820

@@ -833,6 +851,8 @@ $(GNAME MulExpression):
833851
into the integral type.
834852
)
835853

854+
$(H3 $(LNAME2 division, Division))
855+
836856
$(P For integral operands of the $(D /) and $(D %) operators,
837857
the quotient rounds towards zero and the remainder has the
838858
same sign as the dividend.
@@ -853,10 +873,12 @@ $(GNAME MulExpression):
853873
can be used to check for them and select a defined behavior.
854874
)
855875

856-
$(P For floating point operands, the * and / operations correspond
857-
to the IEEE 754 floating point equivalents. % is not the same as
858-
the IEEE 754 remainder. For example, 15.0 % 10.0 == 5.0, whereas
859-
for IEEE 754, remainder(15.0,10.0) == -5.0.
876+
$(H3 $(LNAME2 mul_floating, Floating Point))
877+
878+
$(P For floating point operands, the `*` and `/` operations correspond
879+
to the IEEE 754 floating point equivalents. `%` is not the same as
880+
the IEEE 754 remainder. For example, `15.0 % 10.0 == 5.0`, whereas
881+
for IEEE 754, `remainder(15.0,10.0) == -5.0`.
860882
)
861883

862884
$(P Mul expressions for floating point operands are not associative.
@@ -879,6 +901,17 @@ $(GNAME UnaryExpression):
879901
$(GLINK PowExpression)
880902
)
881903

904+
$(TABLE
905+
$(THEAD Operator, Description)
906+
$(TROW `&`, Take memory address of an $(RELATIVE_LINK2 .define-lvalue, lvalue) - see $(DDSUBLINK arrays, pointer, pointers))
907+
$(TROW `++`, Increment before use - see $(RELATIVE_LINK2 order-of-evaluation, order of evaluation))
908+
$(TROW `--`, Decrement before use)
909+
$(TROW `*`, Dereference/indirection - typically for pointers)
910+
$(TROW `-`, Negative)
911+
$(TROW `+`, Positive)
912+
$(TROW `!`, Logical NOT)
913+
)
914+
882915
$(H3 $(LNAME2 complement_expressions, Complement Expressions))
883916

884917
$(GRAMMAR
@@ -916,6 +949,20 @@ $(GNAME ArgumentList):
916949
collected heap (default) or using a class or struct specific allocator.
917950
)
918951

952+
$(DDOC_DEPRECATED If $(I AllocatorArguments) is provided, then
953+
the $(I ArgumentList) is passed to the class or struct specific
954+
$(DDSUBLINK spec/class, allocators, allocator function) after the size argument.
955+
)
956+
957+
$(P If a $(I NewExpression) is used as an initializer for
958+
a function local variable with $(D scope) storage class,
959+
and the $(I ArgumentList) to $(D new) is empty, then
960+
the instance is allocated on the stack rather than the heap
961+
or using the class specific allocator.
962+
)
963+
964+
$(H3 $(LNAME2 new_multidimensional, Multidimensional Arrays))
965+
919966
$(P To allocate multidimensional arrays, the declaration reads
920967
in the same order as the prefix array declaration order.)
921968

@@ -953,26 +1000,13 @@ $(GNAME ArgumentList):
9531000
}
9541001
-----------
9551002

956-
$(P If there is a $(D new $(LPAREN)) $(GLINK ArgumentList) $(D $(RPAREN)),
957-
then
958-
those arguments are passed to the class or struct specific
959-
$(DDSUBLINK spec/class, allocators, allocator function) after the size argument.
960-
)
961-
962-
$(P If a $(I NewExpression) is used as an initializer for
963-
a function local variable with $(D scope) storage class,
964-
and the $(GLINK ArgumentList) to $(D new) is empty, then
965-
the instance is allocated on the stack rather than the heap
966-
or using the class specific allocator.
967-
)
968-
9691003
$(H3 $(LNAME2 delete_expressions, Delete Expressions))
9701004

9711005
$(GRAMMAR
9721006
$(GNAME DeleteExpression):
9731007
$(D delete) $(GLINK UnaryExpression)
9741008
)
975-
$(P NOTE: `delete` has been deprecated. Instead, please use $(REF1 destroy, object)
1009+
$(DDOC_DEPRECATED `delete` has been deprecated. Instead, please use $(REF1 destroy, object)
9761010
if feasible, or $(REF __delete, core, memory) as a last resort.)
9771011

9781012
$(P If the $(I UnaryExpression) is a class object reference, and
@@ -1228,6 +1262,12 @@ $(GNAME PostfixExpression):
12281262
$(GLINK SliceExpression)
12291263
)
12301264

1265+
$(TABLE
1266+
$(THEAD Operator, Description)
1267+
$(TROW `++`, Increment after use - see $(RELATIVE_LINK2 order-of-evaluation, order of evaluation))
1268+
$(TROW `--`, Decrement after use)
1269+
)
1270+
12311271
$(H2 $(LNAME2 index_expressions, Index Expressions))
12321272

12331273
$(GRAMMAR

0 commit comments

Comments
 (0)