Skip to content

Commit bdb1d2e

Browse files
author
Quirin Schroll
committed
Replace BasicType by PrimaryType mostly
1 parent 8501a0e commit bdb1d2e

File tree

8 files changed

+68
-159
lines changed

8 files changed

+68
-159
lines changed

spec/class.dd

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,12 @@ $(GNAME ClassDeclaration):
3232
$(GLINK2 template, ClassTemplateDeclaration)
3333

3434
$(GNAME BaseClassList):
35-
$(D :) $(GLINK SuperClassOrInterface)
36-
$(D :) $(GLINK SuperClassOrInterface) $(D ,) $(GLINK Interfaces)
35+
$(D :) $(GLINK BasicType)
36+
$(D :) $(GLINK BasicType) $(D ,) $(GLINK BasicTypes)
3737

38-
$(GNAME SuperClassOrInterface):
39-
$(GLINK2 type, BasicType)
40-
41-
$(GNAME Interfaces):
42-
$(GLINK Interface)
43-
$(GLINK Interface) $(D ,) $(GSELF Interfaces)
44-
45-
$(GNAME Interface):
46-
$(GLINK2 type, BasicType)
38+
$(GNAME BasicTypes):
39+
$(GLINK BasicType)
40+
$(GLINK BasicType) $(D ,) $(GSELF BasicTypes)
4741
)
4842

4943
$(P A class consists of:)

spec/declaration.dd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $(H3 $(LNAME2 variable-declarations, Variable Declarations))
4141

4242
$(GRAMMAR
4343
$(GNAME VarDeclarations):
44-
$(GLINK StorageClasses)$(OPT) $(GLINK2 type, BasicType) $(GLINK2 type, TypeSuffixes)$(OPT) $(GLINK IdentifierInitializers) $(D ;)
44+
$(GLINK StorageClasses)$(OPT) $(GLINK2 type, PrimaryType) $(GLINK2 type, TypeSuffixes)$(OPT) $(GLINK IdentifierInitializers) $(D ;)
4545
$(GLINK AutoDeclaration)
4646

4747
$(GNAME IdentifierInitializers): $(LEGACY_LNAME2 Declarators, DeclaratorIdentifierList)
@@ -334,8 +334,8 @@ $(H2 $(LNAME2 alias, Alias Declarations))
334334

335335
$(GRAMMAR
336336
$(GNAME AliasDeclaration):
337-
$(D alias) $(GLINK StorageClasses)$(OPT) $(GLINK2 type, BasicType) $(GLINK2 type, TypeSuffixes)$(OPT) $(GLINK Identifiers) $(D ;)
338-
$(D alias) $(GLINK StorageClasses)$(OPT) $(GLINK2 type, BasicType) $(GLINK2 function, FuncDeclarator) $(D ;)
337+
$(D alias) $(GLINK StorageClasses)$(OPT) $(GLINK2 type, PrimaryType) $(GLINK2 type, TypeSuffixes)$(OPT) $(GLINK Identifiers) $(D ;)
338+
$(D alias) $(GLINK StorageClasses)$(OPT) $(GLINK2 type, PrimaryType) $(GLINK2 function, FuncDeclarator) $(D ;)
339339
$(D alias) $(GLINK AliasAssignments) $(D ;)
340340

341341
$(GNAME Identifiers):
@@ -397,8 +397,8 @@ void foo(myint m) { ... } // error, multiply defined function foo
397397
alias abc = foo.bar; // is it a type or a symbol?
398398
--------------------
399399

400-
$(BEST_PRACTICE Other than when aliasing simple basic type names,
401-
type alias names should be Capitalized.)
400+
$(BEST_PRACTICE When aliasing types other than built-in ones,
401+
alias names should be Capitalized.)
402402

403403
$(H3 $(LNAME2 alias-symbol, Symbol Aliases))
404404

@@ -690,7 +690,7 @@ $(GRAMMAR
690690
$(GNAME AliasReassignment):
691691
$(GLINK_LEX Identifier) $(D =) $(GLINK StorageClasses)$(OPT) $(GLINK2 type, Type)
692692
$(GLINK_LEX Identifier) $(D =) $(GLINK2 expression, FunctionLiteral)
693-
$(GLINK_LEX Identifier) $(D =) $(GLINK StorageClasses)$(OPT) $(GLINK2 type, BasicType) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT)
693+
$(GLINK_LEX Identifier) $(D =) $(GLINK StorageClasses)$(OPT) $(GLINK2 type, PrimaryType) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT)
694694
)
695695

696696
$(P An alias declaration inside a template can be reassigned a new value.)

spec/expression.dd

Lines changed: 39 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,15 @@ $(GLINK OrOrExpression) (`||`), such that $(I expr) is a subexpression of $(I sc
9696
---
9797
((f() * 2 && g()) + 1) || h()
9898
---
99-
$(P The smallest short-circuit expression
100-
of the subexpression `f() * 2` above is `f() * 2 && g()`. Example:)
99+
The smallest short-circuit expression
100+
of the subexpression `f() * 2` above is `f() * 2 && g()`. Example:
101101
---
102102
(f() && g()) + h()
103103
---
104-
$(P The subexpression `h()` above has no smallest short-circuit expression.)
105-
104+
The subexpression `h()` above has no smallest short-circuit expression.
106105

107106
$(H2 $(LNAME2 order-of-evaluation, Order Of Evaluation))
108107

109-
$(BEST_PRACTICE Even when the order of evaluation is well-defined, writing code that
110-
depends on it is rarely recommended.)
111-
112-
$(H3 $(LNAME2 order-increment, Increment and Decrement))
113-
114108
$(P Built-in prefix unary expressions `++` and `--` are evaluated as if lowered (rewritten) to
115109
$(RELATIVE_LINK2 assignment_operator_expressions, assignments) as follows:)
116110

@@ -135,21 +129,6 @@ $(TABLE
135129
$(P Therefore, the result of postfix
136130
`++` and `--` is an rvalue just before the side effect has been effected.)
137131

138-
$(SPEC_RUNNABLE_EXAMPLE_RUN
139-
---
140-
int i = 0;
141-
assert(++i == 1);
142-
assert(i++ == 1);
143-
assert(i == 2);
144-
145-
int* p = [1, 2].ptr;
146-
assert(*p++ == 1);
147-
assert(*p == 2);
148-
---
149-
)
150-
151-
$(H3 $(LNAME2 order-binary, Binary Expressions))
152-
153132
$(P Binary expressions except for $(GLINK AssignExpression), $(GLINK OrOrExpression), and
154133
$(GLINK AndAndExpression) are evaluated in lexical order (left-to-right). Example:)
155134

@@ -166,24 +145,14 @@ first. Then, $(GLINK OrOrExpression) evaluates its right-hand side if and only i
166145
side does not evaluate to nonzero. $(GLINK AndAndExpression) evaluates its right-hand side if and
167146
only if its left-hand side evaluates to nonzero.)
168147

169-
$(IMPLEMENTATION_DEFINED The order of evaluation of the operands of $(GLINK AssignExpression).)
170-
171-
$(H3 $(LNAME2 order-conditional, Conditional Expressions))
172-
173148
$(P $(GLINK ConditionalExpression) evaluates its left-hand side argument
174149
first. Then, if the result is nonzero, the second operand is evaluated. Otherwise, the third operand
175150
is evaluated.)
176151

177-
$(H3 $(LNAME2 order-calls, Function Calls))
178-
179152
$(P Calls to functions with `extern(D)` $(DDSUBLINK spec/attribute, linkage, linkage) (which is
180-
the default linkage) are evaluated in the following order:)
181-
1. If necessary, the address of the
182-
function to call is evaluated (e.g. in the case of a computed function pointer or delegate).
183-
1. Arguments are evaluated left to right.
184-
1. Transfer of execution is passed to the function.
185-
186-
$(P Example calling a $(DDSUBLINK spec/function, function-pointers, function pointer):)
153+
the default linkage) are evaluated in the following order: first, if necessary, the address of the
154+
function to call is evaluated (e.g. in the case of a computed function pointer or delegate). Then,
155+
arguments are evaluated left to right. Finally, transfer is passed to the function. Example:)
187156

188157
$(SPEC_RUNNABLE_EXAMPLE_RUN
189158
---
@@ -204,8 +173,14 @@ fun()(f1(), f3(f2()), f4());
204173
---
205174
)
206175

207-
$(IMPLEMENTATION_DEFINED The order of evaluation of function arguments for functions with linkage other than `extern(D)`.)
176+
$(IMPLEMENTATION_DEFINED
177+
$(OL
178+
$(LI The order of evaluation of the operands of $(GLINK AssignExpression).)
179+
$(LI The order of evaluation of function arguments for functions with linkage other than `extern (D)`.)
180+
))
208181

182+
$(BEST_PRACTICE Even though the order of evaluation is well-defined, writing code that
183+
depends on it is rarely recommended.)
209184

210185
$(H2 $(LNAME2 temporary-lifetime, Lifetime of Temporaries))
211186

@@ -300,29 +275,11 @@ $(GNAME CommaExpression):
300275
)
301276

302277
$(P The left operand of the $(D ,) is evaluated, then the right operand
303-
is evaluated.
304-
In C, the result of a comma expression is the result of the right operand.
305-
In D, using the result of a comma expression isn't allowed.
306-
Consequently a comma expression is only useful when each operand has
307-
a side effect.
278+
is evaluated. The type of the expression is the type of the right
279+
operand, and the result is the result of the right operand.
280+
Using the result of comma expressions isn't allowed.
308281
)
309282

310-
$(SPEC_RUNNABLE_EXAMPLE_RUN
311-
---
312-
int x, y;
313-
// expression statement
314-
x = 1, y = 1;
315-
// evaluate a comma expression at the end of each loop iteration
316-
for (; y < 10; x++, y *= 2)
317-
writefln("%s, %s", x, y);
318-
---
319-
)
320-
$(RATIONALE The comma expression has been used unintentionally, either by
321-
bracket nesting mistakes or when users expect a sequence of arguments instead
322-
of a single expression. Those bugs can be hard to detect in code review.
323-
Disallowing use of the result turns those bugs into errors.)
324-
325-
326283
$(H2 $(LNAME2 assign_expressions, Assign Expressions))
327284

328285
$(GRAMMAR
@@ -1644,7 +1601,7 @@ $(GNAME PostfixExpression):
16441601
$(GSELF PostfixExpression) $(D ++)
16451602
$(GSELF PostfixExpression) $(D --)
16461603
$(GSELF PostfixExpression) $(D $(LPAREN)) $(GLINK NamedArgumentList)$(OPT) $(D $(RPAREN))
1647-
$(GLINK2 type, TypeCtors)$(OPT) $(GLINK2 type, BasicType) $(D $(LPAREN)) $(GLINK NamedArgumentList)$(OPT) $(D $(RPAREN))
1604+
$(GLINK2 type, PrimaryType) $(D $(LPAREN)) $(GLINK NamedArgumentList)$(OPT) $(D $(RPAREN))
16481605
$(GSELF PostfixExpression) $(GLINK IndexOperation)
16491606
$(GSELF PostfixExpression) $(GLINK SliceOperation)
16501607
)
@@ -1656,8 +1613,6 @@ $(TABLE
16561613
* Access a $(DDLINK spec/property, Properties, property) of a type or expression.
16571614
* Access a member of a module, package, aggregate type or instance, enum
16581615
or template instance.
1659-
* Dereference a $(DDSUBLINK spec/struct, struct-pointer, pointer to a struct/union)
1660-
instance and access a member of it.
16611616
* Call a free function using $(DDSUBLINK spec/function, pseudo-member, UFCS).
16621617
)
16631618
$(TROW `.` *NewExpression*, Instantiate a $(DDSUBLINK spec/class, nested-explicit,
@@ -2203,12 +2158,8 @@ $(H4 $(LNAME2 array-literal-heap, GC Allocation))
22032158
$(P An array literal is not GC allocated if:)
22042159

22052160
* It initializes or assigns to a static array.
2206-
* It is an argument to a $(DDSUBLINK spec/function, scope-parameters, `scope`
2207-
function parameter).
2208-
* It initializes a $(DDSUBLINK spec/attribute, scope, `scope`) slice (`-preview=dip1000`
2209-
$(LINK2 $(ROOT_DIR)changelog/2.102.0.html#dmd.scope-array-on-stack,
2210-
is required for this)).
2211-
* It is used on one side of an $(GLINK EqualExpression) or $(GLINK RelExpression).
2161+
* It initializes a $(DDSUBLINK spec/attribute, scope, `scope`) slice.
2162+
* It is used on one side of a $(GLINK EqualExpression) or $(GLINK RelExpression).
22122163
* It is immediately $(RELATIVE_LINK2 index_operations, indexed) and used as an rvalue.
22132164
* It is used as a `foreach` aggregate where the element variable is not `ref`.
22142165

@@ -2323,15 +2274,12 @@ $(H3 $(LNAME2 function_literals, Function Literals))
23232274

23242275
$(GRAMMAR
23252276
$(GNAME FunctionLiteral):
2326-
$(D function) $(GLINK RefOrAutoRef)$(OPT) $(GLINK BasicTypeWithSuffixes)$(OPT) $(GLINK ParameterWithAttributes)$(OPT) $(GLINK FunctionLiteralBody)
2327-
$(D delegate) $(GLINK RefOrAutoRef)$(OPT) $(GLINK BasicTypeWithSuffixes)$(OPT) $(GLINK ParameterWithMemberAttributes)$(OPT) $(GLINK FunctionLiteralBody)
2277+
$(D function) $(GLINK RefOrAutoRef)$(OPT) $(GLINK SuffixedPrimaryType)$(OPT) $(GLINK ParameterWithAttributes)$(OPT) $(GLINK FunctionLiteralBody)
2278+
$(D delegate) $(GLINK RefOrAutoRef)$(OPT) $(GLINK SuffixedPrimaryType)$(OPT) $(GLINK ParameterWithMemberAttributes)$(OPT) $(GLINK FunctionLiteralBody)
23282279
$(GLINK RefOrAutoRef)$(OPT) $(GLINK ParameterWithMemberAttributes) $(GLINK FunctionLiteralBody)
23292280
$(GLINK2 statement, BlockStatement)
23302281
$(IDENTIFIER) $(D =>) $(GLINK AssignExpression)
23312282

2332-
$(GNAME BasicTypeWithSuffixes):
2333-
$(GLINK2 type, BasicType) $(GLINK2 type, TypeSuffixes)$(OPT)
2334-
23352283
$(GNAME ParameterWithAttributes):
23362284
$(GLINK2 function, Parameters) $(GLINK2 function, FunctionAttributes)$(OPT)
23372285

@@ -2345,6 +2293,9 @@ $(GNAME FunctionLiteralBody):
23452293
$(GNAME RefOrAutoRef):
23462294
$(D ref)
23472295
$(D auto ref)
2296+
2297+
$(GNAME SuffixedPrimaryType):
2298+
$(GLINK2 type, SuffixedPrimaryType) $(GLINK2 type, TypeSuffixes)$(OPT)
23482299
)
23492300

23502301
$(P $(I FunctionLiteral)s enable embedding anonymous functions
@@ -2748,30 +2699,11 @@ $(H4 $(LNAME2 assert-ct, Compile-time Evaluation))
27482699
Compile Time Function Execution (CTFE) is not attempted.
27492700
)
27502701

2751-
$(P This allows the compiler to suppress an error when there is a
2752-
missing return statement:)
2753-
2754-
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
2755-
---
2756-
int f(int x)
2757-
{
2758-
if (x > 0)
2759-
{
2760-
return 5 / x;
2761-
}
2762-
assert(0);
2763-
// no need to use a dummy return statement here
2764-
}
2765-
---
2766-
)
2767-
27682702
$(P The implementation may handle the case of the first $(I AssignExpression) evaluating to `false`
27692703
at compile time differently - even when other `assert`s are ignored,
27702704
it may still generate a $(D HLT) instruction or equivalent.
27712705
)
27722706

2773-
$(RATIONALE Halting the program prevents undefined behaviour from occurring.)
2774-
27752707
$(P See also: $(DDSUBLINK spec/version, static-assert, `static assert`).)
27762708

27772709
$(H4 $(LNAME2 assert-message, Assert Message))
@@ -2788,7 +2720,7 @@ $(H4 $(LNAME2 assert-message, Assert Message))
27882720
}
27892721
----
27902722

2791-
$(P When compiled and run, typically it will produce the message:)
2723+
$(P When compiled and run, it will produce the message:)
27922724

27932725
$(CONSOLE [email protected](3) an error message)
27942726

@@ -2861,52 +2793,38 @@ $(GNAME NewExpression):
28612793
collected) heap by default.
28622794
)
28632795

2864-
$(P `new T` constructs an instance of type `T` and default-initializes it.
2865-
The result's type is:)
2866-
* `T` when `T` is a reference type (e.g. classes,
2867-
$(DDSUBLINK spec/hash-map, construction_and_ref_semantic, associative arrays))
2868-
* `T*` when `T` is a value type (e.g. basic types, structs)
2796+
$(P The `new` *Type* form constructs an instance of a type and default-initializes it.)
2797+
$(P The *Type(NamedArgumentList)* form allows passing either a single initializer
2798+
of the same type, or multiple arguments for more complex types.
2799+
For class types, *NamedArgumentList* is passed to the class constructor.
2800+
For a dynamic array, the argument sets the initial array length.
2801+
For multidimensional dynamic arrays, each argument corresponds to
2802+
an initial length (see $(RELATIVE_LINK2 new_multidimensional, below)).)
28692803

28702804
$(SPEC_RUNNABLE_EXAMPLE_RUN
28712805
---
28722806
int* i = new int;
2873-
assert(*i == 0); // int.init
2874-
2875-
Object o = new Object;
2876-
//int[] a = new int[]; // error, need length argument
2877-
---
2878-
)
2879-
$(P The $(INLINE_GRAMMAR *Type(NamedArgumentList)*) form allows passing either a single initializer
2880-
of the same type, or multiple arguments for more complex types:)
2881-
2882-
* For class and struct types, *NamedArgumentList* is passed to the constructor.
2883-
* For a dynamic array, the argument sets the initial array length.
2884-
* For multidimensional dynamic arrays, each argument corresponds to
2885-
an initial length (see $(RELATIVE_LINK2 new_multidimensional, below)).
2886-
2887-
$(SPEC_RUNNABLE_EXAMPLE_RUN
2888-
---
2889-
int* i = new int(5);
2807+
assert(*i == 0);
2808+
i = new int(5);
28902809
assert(*i == 5);
28912810

2811+
Object o = new Object;
28922812
Exception e = new Exception("info");
2893-
assert(e.msg == "info");
28942813

2895-
int[] a = new int[](2);
2814+
auto a = new int[](2);
28962815
assert(a.length == 2);
2897-
a = new int[2]; // same, see below
28982816
---
28992817
)
29002818

2901-
$(P The $(INLINE_GRAMMAR *Type[AssignExpression]*) form allocates a dynamic array with
2819+
$(P The *Type[AssignExpression]* form allocates a dynamic array with
29022820
length equal to *AssignExpression*.
2903-
It is preferred to use the $(INLINE_GRAMMAR *Type(NamedArgumentList)*) form when allocating
2821+
It is preferred to use the *Type(NamedArgumentList)* form when allocating
29042822
dynamic arrays instead, as it is more general.)
29052823

29062824
$(NOTE It is not possible to allocate a static array directly with
29072825
`new` (only by using a type alias).)
29082826

2909-
$(P The result is a $(DDSUBLINK spec/const3, unique-expressions, unique expression)
2827+
$(P The result is a $(DDSUBLINK const3, unique-expressions, unique expression)
29102828
which can implicitly convert to other qualifiers:)
29112829

29122830
---

spec/function.dd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $(H2 $(LNAME2 grammar, Function Declarations))
88

99
$(GRAMMAR
1010
$(GNAME FuncDeclaration):
11-
$(GLINK2 declaration, StorageClasses)$(OPT) $(GLINK2 type, BasicType) $(GLINK FuncDeclarator) $(GLINK FunctionBody)
11+
$(GLINK2 declaration, StorageClasses)$(OPT) $(GLINK2 type, PrimaryType) $(GLINK FuncDeclarator) $(GLINK FunctionBody)
1212
$(GLINK AutoFuncDeclaration)
1313

1414
$(GNAME AutoFuncDeclaration):
@@ -48,7 +48,7 @@ $(GNAME Parameter):
4848
$(GLINK ParameterDeclaration) $(D =) $(ASSIGNEXPRESSION) $(D ...)
4949

5050
$(GNAME ParameterDeclaration):
51-
$(GLINK ParameterAttributes)$(OPT) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator)
51+
$(GLINK ParameterAttributes)$(OPT) $(GLINK2 type, PrimaryType) $(GLINK2 declaration, Declarator)
5252
$(GLINK ParameterAttributes)$(OPT) $(GLINK2 type, Type)
5353

5454
$(GNAME ParameterAttributes):

spec/simd.dd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ $(HEADERNAV_TOC)
99
Vector types are a fixed array of floating or integer types, and
1010
vector operations operate simultaneously on them.)
1111

12-
$(P Specialized $(GLINK2 type, Vector) types provide access to them.)
12+
$(P Specialized $(D __vector$(LPAREN)$(GLINK2 type, Type)$(RPAREN)) types provide access to them.)
1313

14-
$(P The $(GLINK2 type, VectorBaseType) must be a $(DDSUBLINK spec/arrays, static-arrays, Static Array).
15-
The $(GNAME VectorElementType) is the unqualified element type of the
14+
$(P The type argument to $(D __vector) must be a $(DDSUBLINK spec/arrays, static-arrays, Static Array).
15+
The element type is the unqualified element type of the
1616
static array.
1717
The dimension of the static array is the number
1818
of elements in the vector.

0 commit comments

Comments
 (0)