1 // { dg-do compile }
2 // { dg-require-effective-target fpic }
3 // { dg-require-visibility "" }
4 // { dg-options "-fPIC" }
5 /* { dg-additional-options "-Wno-return-type" } */
6
7
8 typedef __SIZE_TYPE__ size_t;
9 extern "C" void *
10 malloc (size_t __size)
11 throw () __attribute__ ((__malloc__));
12 namespace std __attribute__ ((__visibility__ ("default")))
13 {
14 using::size_t;
15 }
16 inline void *operator
new(std::size_t,void * __p)17 new (std::size_t, void *__p)
18 throw ()
19 {
20 return __p;
21 }
22 template < class _T1, class _T2 > struct pair
23 {
24 _T1 first;
25 _T2 second;
pairpair26 pair (const _T1 & __a, const _T2 & __b):first (__a), second (__b)
27 {
28 }
29 template < class _U1, class _U2 >
pairpair30 pair (const pair < _U1, _U2 > &__p):first (__p.first), second (__p.second)
31 {
32 }
33 };
34
35 template < class _T1, class _T2 >
make_pair(_T1 __x,_T2 __y)36 inline pair < _T1, _T2 > make_pair (_T1 __x, _T2 __y)
37 {
38 return pair < _T1, _T2 > (__x, __y);
39 }
40 template < typename _Tp > inline const _Tp &
max(const _Tp & __a,const _Tp & __b)41 max (const _Tp & __a, const _Tp & __b)
42 {
43 }
44 typedef unsigned short int uint16_t;
45 typedef unsigned long int uintptr_t;
46 typedef uint16_t UChar;
47 namespace std __attribute__ ((__visibility__ ("default")))
48 {
49 struct __numeric_limits_base
50 {
51 };
52 template < typename _Tp > struct numeric_limits:public __numeric_limits_base
53 {
maxnumeric_limits54 static _Tp max () throw ()
55 {
56 }
57 };
58 }
59
60 template < typename T > class VectorBufferBase
61 {
62 public:
allocateBuffer(size_t newCapacity)63 void allocateBuffer (size_t newCapacity)
64 {
65 if (newCapacity > std::numeric_limits < size_t >::max () / sizeof (T))
66 *(int *) (uintptr_t) 0xbbadbeef = 0;
67 }
68 };
69
70 template < typename T, size_t inlineCapacity > class VectorBuffer;
71 template < typename T > class VectorBuffer < T, 0 >:private VectorBufferBase <
72 T >
73 {
74 public:
75 typedef VectorBufferBase < T > Base;
76 using Base::allocateBuffer;
77 };
78
79 template < typename T, size_t inlineCapacity = 0 > class Vector
80 {
81 typedef VectorBuffer < T, inlineCapacity > Impl;
82 public:
83 typedef T *iterator;
size()84 size_t size () const
85 {
86 return m_size;
87 }
capacity()88 size_t capacity () const
89 {
90 }
begin()91 iterator begin ()
92 {
93 }
end()94 iterator end ()
95 {
96 return begin () + m_size;
97 }
98 void shrink (size_t size);
99 void reserveCapacity (size_t newCapacity);
clear()100 void clear ()
101 {
102 shrink (0);
103 }
104 template < typename U > void append (const U &);
105 void expandCapacity (size_t newMinCapacity);
106 template < typename U > U * expandCapacity (size_t newMinCapacity, U *);
107 size_t m_size;
108 Impl m_impl;
109 };
110 template < typename T, size_t inlineCapacity >
expandCapacity(size_t newMinCapacity)111 void Vector < T, inlineCapacity >::expandCapacity (size_t newMinCapacity)
112 {
113 reserveCapacity (max
114 (newMinCapacity,
115 max (static_cast < size_t > (16),
116 capacity () + capacity () / 4 + 1)));
117 }
118
119 template < typename T, size_t inlineCapacity >
120 template < typename U >
121 inline U * Vector < T,
expandCapacity(size_t newMinCapacity,U * ptr)122 inlineCapacity >::expandCapacity (size_t newMinCapacity, U * ptr)
123 {
124 expandCapacity (newMinCapacity);
125 }
126 template < typename T, size_t inlineCapacity >
reserveCapacity(size_t newCapacity)127 void Vector < T, inlineCapacity >::reserveCapacity (size_t newCapacity)
128 {
129 m_impl.allocateBuffer (newCapacity);
130 }
131 template < typename T, size_t inlineCapacity >
132 template < typename U >
append(const U & val)133 inline void Vector < T, inlineCapacity >::append (const U & val)
134 {
135 const U *ptr = &val;
136 if (size () == capacity ())
137 ptr = expandCapacity (size () + 1, ptr);
138 new (end ())T (*ptr);
139 }
140
141 class Range;
142 class TextIterator
143 {
144 public:
145 explicit TextIterator (const Range *,
146 bool emitCharactersBetweenAllVisiblePositions =
147 false);
atEnd()148 bool atEnd () const
149 {
150 }
151 void advance ();
length()152 int length () const
153 {
154 }
155 };
156 UChar *
plainTextToMallocAllocatedBuffer(const Range * r,unsigned & bufferLength)157 plainTextToMallocAllocatedBuffer (const Range * r, unsigned &bufferLength)
158 {
159 static const unsigned cMaxSegmentSize = 1 << 16;
160 typedef pair < UChar *, unsigned >TextSegment;
161 Vector < TextSegment > *textSegments = 0;
162 Vector < UChar > textBuffer;
163 for (TextIterator it (r); !it.atEnd (); it.advance ())
164 {
165 if (textBuffer.size ()
166 && textBuffer.size () + it.length () > cMaxSegmentSize)
167 {
168 UChar *newSegmentBuffer =
169 static_cast <
170 UChar * >(malloc (textBuffer.size () * sizeof (UChar)));
171 if (!textSegments)
172 textSegments = new Vector < TextSegment >;
173 textSegments->
174 append (make_pair (newSegmentBuffer, textBuffer.size ()));
175 textBuffer.clear ();
176 }
177 }
178 }
179