forked from dlang/dlang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
D1toD2.dd
104 lines (83 loc) · 2.7 KB
/
D1toD2.dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
Ddoc
$(D_S $(TITLE),
$(P There are many changes to the D programming language that affect
migrating source code from D1 to D2.
This is an outline of changes to look for and a guide to how to modify
the code.
See $(LINK2 features2.html, D 2.0 Enhancements) for a complete list
of changes to the language.
)
$(P This document is incomplete.)
$(UL
$(LI Core Language
$(UL
$(ITEMR new_keywords, New Keywords)
$(ITEMR global_variables, Global Variables)
$(ITEMR static_arrays, Static Arrays are now Value Types)
$(ITEMR immutable_string, String Literals are Immutable)
)
)
$(LI Phobos Library
$(UL
)
)
)
$(ITEM new_keywords, New Keywords)
$(P D2 adds the following keywords:
$(D_KEYWORD pure),
$(D_KEYWORD nothrow),
$(D_KEYWORD shared), and
$(D_KEYWORD immutable).
Any use of them in D1 code must be renamed.
Any variable names starting with two underscores
should be renamed.
)
$(ITEM global_variables, Global Variables)
$(P Global variables are now, by default, stored in thread local
storage. To put them back in global storage, use the $(D_KEYWORD __gshared)
storage class:)
---
int foo = 7; // D1 code
$(B __gshared) int foo = 7; // D2 equivalent
---
$(P Carefully consider whether or not those variables actually should
go into thread local storage, rather than being implicitly shared
among all threads.
)
$(ITEM static_arrays, Static Arrays are now Value Types)
$(P In D1, a static array function parameter is passed by
reference, meaning a pointer to the start of the static array
is passed as an argument.
This means that any changes to the array contents made by the
function will be visible to the function's caller.
In D2, a copy of the whole static
array is passed as an argument. Changes to the array contents by
the function are not visible to the function's caller, as it is
a separate copy.)
$(P To migrate, add the keyword $(D_KEYWORD ref) to the parameter
declaration:)
---
void foo(int[3] array); // D1 code
void foo($(B ref) int[3] array); // D2 equivalent
---
$(ITEM immutable_string, String Literals are Immutable)
$(P String literals in D1 have type $(D char[]), but in D2 they
have type $(D immutable(char)[]), which is aliased for convenience
under the name $(D string). To migrate usually involves doing a
global search replace: )
$(TABLE1
$(TR $(TH from)$(TH to))
$(TR $(TD char[])$(TD string))
$(TR $(TD wchar[])$(TD wstring))
$(TR $(TD dchar[])$(TD dstring))
)
$(P This will take care of most of the issues.
For the rest, where mutable strings are desired, there will
be some work necessary.
)
)
Macros:
TITLE=Migrating D1 Code to D2
WIKI=D1toD2
ITEMR=$(LI $(RELATIVE_LINK2 $1, $+))
ITEM=<hr><h3><a name="$1">$+</a></h3>