annotate gen/utils.h @ 1351:8d501abecd24

Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Thu, 14 May 2009 17:20:17 +0200
parents ec1d9dc1d32a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
1 #ifndef __LDC_GEN_UTILS_H__
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
2 #define __LDC_GEN_UTILS_H__
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
3
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
4 #include "root.h"
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
5
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
6 /// Very simple templated iterator for DMD ArrayS.
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
7 template<class C>
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
8 struct ArrayIter
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
9 {
1262
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
10 Array* array;
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
11 size_t index;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
12
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
13 ArrayIter(Array& arr, size_t idx = 0)
1262
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
14 : array(&arr), index(idx)
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
15 { }
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
16 ArrayIter(Array* arr, size_t idx = 0)
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
17 : array(arr), index(idx)
1262
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
18 { assert(arr && "null array"); }
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
19
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
20 ArrayIter<C>& operator=(const Array& arr)
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
21 {
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
22 array = &arr;
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
23 index = 0;
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
24 return *this;
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
25 }
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
26 ArrayIter<C>& operator=(const Array* arr)
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
27 {
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
28 assert(arr && "null array");
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
29 array = arr;
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
30 index = 0;
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
31 return *this;
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
32 }
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
33
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
34 bool done()
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
35 {
1262
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
36 return index >= array->dim;
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
37 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
38 bool more()
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
39 {
1262
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
40 return index < array->dim;
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
41 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
42
1262
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
43 C* get() {
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
44 return static_cast<C*>(array->data[index]);
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
45 }
1262
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
46 C* operator->() {
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
47 return get();
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
48 }
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
49 C* operator*() {
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
50 return get();
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
51 }
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
52
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
53 void next()
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
54 {
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
55 ++index;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
56 }
1262
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
57
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
58 bool operator==(const ArrayIter<C>& other) {
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
59 return &array->data[index] == &other.array->data[other.index];
ec1d9dc1d32a Fixed struct default initializers.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1228
diff changeset
60 }
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
61 };
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
62
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
63 // some aliases
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
64 typedef ArrayIter<Dsymbol> DsymbolIter;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
65 typedef ArrayIter<FuncDeclaration> FuncDeclarationIter;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
66 typedef ArrayIter<VarDeclaration> VarDeclarationIter;
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
67
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
68 #endif