Mercurial > projects > ldc
annotate tango/tango/core/Vararg.d @ 264:a9dae3da4e87 trunk
[svn r285] Fixed D -> bool LLVM helper for floating point values.
Changed the way D-style varargs are passed, now each param should be aligned to size_t.sizeof.
author | lindquist |
---|---|
date | Sat, 14 Jun 2008 17:28:13 +0200 |
parents | a27941d00351 |
children |
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 { |
264
a9dae3da4e87
[svn r285] Fixed D -> bool LLVM helper for floating point values.
lindquist
parents:
144
diff
changeset
|
39 // size_t size = T.sizeof > size_t.sizeof ? size_t.sizeof : T.sizeof; |
a9dae3da4e87
[svn r285] Fixed D -> bool LLVM helper for floating point values.
lindquist
parents:
144
diff
changeset
|
40 // va_list vptmp = cast(va_list)((cast(size_t)vp + size - 1) & ~(size - 1)); |
a9dae3da4e87
[svn r285] Fixed D -> bool LLVM helper for floating point values.
lindquist
parents:
144
diff
changeset
|
41 // vp = vptmp + T.sizeof; |
a9dae3da4e87
[svn r285] Fixed D -> bool LLVM helper for floating point values.
lindquist
parents:
144
diff
changeset
|
42 // return *cast(T*)vptmp; |
a9dae3da4e87
[svn r285] Fixed D -> bool LLVM helper for floating point values.
lindquist
parents:
144
diff
changeset
|
43 T* arg = cast(T*) vp; |
a9dae3da4e87
[svn r285] Fixed D -> bool LLVM helper for floating point values.
lindquist
parents:
144
diff
changeset
|
44 vp = cast(va_list) ( cast(void*) vp + ( ( T.sizeof + size_t.sizeof - 1 ) & ~( size_t.sizeof - 1 ) ) ); |
a9dae3da4e87
[svn r285] Fixed D -> bool LLVM helper for floating point values.
lindquist
parents:
144
diff
changeset
|
45 return *arg; |
144
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
46 } |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
132
diff
changeset
|
47 } |
132 | 48 else |
49 { | |
50 /** | |
51 * The base vararg list type. | |
52 */ | |
53 alias void* va_list; | |
54 | |
55 | |
56 template va_start( T ) | |
57 { | |
58 /** | |
59 * This function initializes the supplied argument pointer for subsequent | |
60 * use by va_arg and va_end. | |
61 * | |
62 * Params: | |
63 * ap = The argument pointer to initialize. | |
64 * paramn = The identifier of the rightmost parameter in the function | |
65 * parameter list. | |
66 */ | |
67 void va_start( out va_list ap, inout T parmn ) | |
68 { | |
69 ap = cast(va_list) ( cast(void*) &parmn + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) ); | |
70 } | |
71 } | |
72 | |
73 | |
74 template va_arg( T ) | |
75 { | |
76 /** | |
77 * This function returns the next argument in the sequence referenced by | |
78 * the supplied argument pointer. The argument pointer will be adjusted | |
79 * to point to the next arggument in the sequence. | |
80 * | |
81 * Params: | |
82 * ap = The argument pointer. | |
83 * | |
84 * Returns: | |
85 * The next argument in the sequence. The result is undefined if ap | |
86 * does not point to a valid argument. | |
87 */ | |
88 T va_arg( inout va_list ap ) | |
89 { | |
90 T arg = *cast(T*) ap; | |
91 ap = cast(va_list) ( cast(void*) ap + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) ); | |
92 return arg; | |
93 } | |
94 } | |
95 | |
96 | |
97 /** | |
98 * This function cleans up any resources allocated by va_start. It is | |
99 * currently a no-op and exists mostly for syntax compatibility with | |
100 * the variadric argument functions for C. | |
101 * | |
102 * Params: | |
103 * ap = The argument pointer. | |
104 */ | |
105 void va_end( va_list ap ) | |
106 { | |
107 | |
108 } | |
109 | |
110 | |
111 /** | |
112 * This function copied the argument pointer src to dst. | |
113 * | |
114 * Params: | |
115 * src = The source pointer. | |
116 * dst = The destination pointer. | |
117 */ | |
118 void va_copy( out va_list dst, va_list src ) | |
119 { | |
120 dst = src; | |
121 } | |
122 } |