Mercurial > projects > ldc
annotate tango/tango/core/Vararg.d @ 144:a27941d00351 trunk
[svn r149] fixed: a bunch of D-style variadics problems.
fixed: GotoDefaultStatement implemented.
fixed: some other minor bugs.
author | lindquist |
---|---|
date | Sat, 26 Jan 2008 17:13:22 +0100 |
parents | 1700239cab2e |
children | a9dae3da4e87 |
rev | line source |
---|---|
132 | 1 /** |
2 * The vararg module is intended to facilitate vararg manipulation in D. | |
3 * It should be interface compatible with the C module "stdarg," and the | |
4 * two modules may share a common implementation if possible (as is done | |
5 * here). | |
6 * | |
7 * Copyright: Public Domain | |
8 * License: Public Domain | |
9 * Authors: Hauke Duden, Walter Bright | |
10 */ | |
11 module tango.core.Vararg; | |
12 | |
13 | |
14 version( GNU ) | |
15 { | |
16 public import std.stdarg; | |
17 } | |
144
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
18 else version( LLVMDC ) |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
19 { |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
20 /** |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
21 * The base vararg list type. |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
22 */ |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
23 alias void* va_list; |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
24 |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
25 /** |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
26 * This function returns the next argument in the sequence referenced by |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
27 * the supplied argument pointer. The argument pointer will be adjusted |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
28 * to point to the next arggument in the sequence. |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
29 * |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
30 * Params: |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
31 * vp = The argument pointer. |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
32 * |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
33 * Returns: |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
34 * The next argument in the sequence. The result is undefined if vp |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
35 * does not point to a valid argument. |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
36 */ |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
37 T va_arg(T)(ref va_list vp) |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
38 { |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
39 size_t size = T.sizeof > size_t.sizeof ? size_t.sizeof : T.sizeof; |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
40 va_list vptmp = cast(va_list)((cast(size_t)vp + size - 1) & ~(size - 1)); |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
41 vp = vptmp + T.sizeof; |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
42 return *cast(T*)vptmp; |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
43 } |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
44 } |
132 | 45 else |
46 { | |
47 /** | |
48 * The base vararg list type. | |
49 */ | |
50 alias void* va_list; | |
51 | |
52 | |
53 template va_start( T ) | |
54 { | |
55 /** | |
56 * This function initializes the supplied argument pointer for subsequent | |
57 * use by va_arg and va_end. | |
58 * | |
59 * Params: | |
60 * ap = The argument pointer to initialize. | |
61 * paramn = The identifier of the rightmost parameter in the function | |
62 * parameter list. | |
63 */ | |
64 void va_start( out va_list ap, inout T parmn ) | |
65 { | |
66 ap = cast(va_list) ( cast(void*) &parmn + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) ); | |
67 } | |
68 } | |
69 | |
70 | |
71 template va_arg( T ) | |
72 { | |
73 /** | |
74 * This function returns the next argument in the sequence referenced by | |
75 * the supplied argument pointer. The argument pointer will be adjusted | |
76 * to point to the next arggument in the sequence. | |
77 * | |
78 * Params: | |
79 * ap = The argument pointer. | |
80 * | |
81 * Returns: | |
82 * The next argument in the sequence. The result is undefined if ap | |
83 * does not point to a valid argument. | |
84 */ | |
85 T va_arg( inout va_list ap ) | |
86 { | |
87 T arg = *cast(T*) ap; | |
88 ap = cast(va_list) ( cast(void*) ap + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) ); | |
89 return arg; | |
90 } | |
91 } | |
92 | |
93 | |
94 /** | |
95 * This function cleans up any resources allocated by va_start. It is | |
96 * currently a no-op and exists mostly for syntax compatibility with | |
97 * the variadric argument functions for C. | |
98 * | |
99 * Params: | |
100 * ap = The argument pointer. | |
101 */ | |
102 void va_end( va_list ap ) | |
103 { | |
104 | |
105 } | |
106 | |
107 | |
108 /** | |
109 * This function copied the argument pointer src to dst. | |
110 * | |
111 * Params: | |
112 * src = The source pointer. | |
113 * dst = The destination pointer. | |
114 */ | |
115 void va_copy( out va_list dst, va_list src ) | |
116 { | |
117 dst = src; | |
118 } | |
119 } |