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