~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/mesa/shader/slang/Include/Common.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
//Copyright (C) 2002-2005  3Dlabs Inc. Ltd.
3
 
//All rights reserved.
4
 
//
5
 
//Redistribution and use in source and binary forms, with or without
6
 
//modification, are permitted provided that the following conditions
7
 
//are met:
8
 
//
9
 
//    Redistributions of source code must retain the above copyright
10
 
//    notice, this list of conditions and the following disclaimer.
11
 
//
12
 
//    Redistributions in binary form must reproduce the above
13
 
//    copyright notice, this list of conditions and the following
14
 
//    disclaimer in the documentation and/or other materials provided
15
 
//    with the distribution.
16
 
//
17
 
//    Neither the name of 3Dlabs Inc. Ltd. nor the names of its
18
 
//    contributors may be used to endorse or promote products derived
19
 
//    from this software without specific prior written permission.
20
 
//
21
 
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
 
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
 
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24
 
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
 
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
 
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
 
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
 
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
 
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
 
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
 
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
 
//POSSIBILITY OF SUCH DAMAGE.
33
 
//
34
 
 
35
 
#ifndef _COMMON_INCLUDED_
36
 
#define _COMMON_INCLUDED_
37
 
 
38
 
#ifdef _WIN32
39
 
    #include <basetsd.h>
40
 
#elif defined (solaris)
41
 
    #include <sys/int_types.h>
42
 
    #define UINT_PTR uintptr_t
43
 
#else
44
 
    #include <stdint.h>
45
 
    #define UINT_PTR uintptr_t
46
 
#endif
47
 
 
48
 
/* windows only pragma */
49
 
#ifdef _MSC_VER
50
 
    #pragma warning(disable : 4786) // Don't warn about too long identifiers
51
 
    #pragma warning(disable : 4514) // unused inline method
52
 
    #pragma warning(disable : 4201) // nameless union
53
 
#endif
54
 
 
55
 
//
56
 
// Doing the push and pop below for warnings does not leave the warning state
57
 
// the way it was.  This seems like a defect in the compiler.  We would like
58
 
// to do this, but since it does not work correctly right now, it is turned
59
 
// off.
60
 
//
61
 
//??#pragma warning(push, 3)
62
 
 
63
 
        #include <set>
64
 
    #include <vector>
65
 
    #include <map>
66
 
    #include <list>
67
 
    #include <string>
68
 
    #include <stdio.h>
69
 
 
70
 
//??#pragma warning(pop)
71
 
 
72
 
typedef int TSourceLoc;
73
 
 
74
 
#include <assert.h>
75
 
#include "PoolAlloc.h"
76
 
 
77
 
//
78
 
// Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme.
79
 
//
80
 
#define POOL_ALLOCATOR_NEW_DELETE(A)                                  \
81
 
    void* operator new(size_t s) { return (A).allocate(s); }          \
82
 
    void* operator new(size_t, void *_Where) { return (_Where); }     \
83
 
    void operator delete(void*) { }                                   \
84
 
    void operator delete(void *, void *) { }                          \
85
 
    void* operator new[](size_t s) { return (A).allocate(s); }        \
86
 
    void* operator new[](size_t, void *_Where) { return (_Where);       } \
87
 
    void operator delete[](void*) { }                                 \
88
 
    void operator delete[](void *, void *) { }
89
 
 
90
 
#ifdef _M_AMD64
91
 
//
92
 
// The current version of STL that comes with the PSDK (as required for the AMD64 compiler)
93
 
// has a very old version of the STL which is very out of date.  As a result, various additions needed
94
 
// making to it to get the compilers compiling!
95
 
//
96
 
 
97
 
//
98
 
// A new version of the Map template class - the operator[] now returns the correct type reference
99
 
//
100
 
template <class _K, class _Ty, class _Pr = std::less<_K>, class _A = std::allocator<_Ty> >
101
 
class TBaseMap : public std::map <_K, _Ty, _Pr, _A >
102
 
{
103
 
public :
104
 
        _Ty& operator[] (const _K& _Kv)
105
 
        {
106
 
                iterator _P = insert(value_type(_Kv, _Ty())).first;
107
 
                return ((*_P).second); 
108
 
        }
109
 
        
110
 
        explicit TBaseMap(const _Pr& _Pred = _Pr(), const _A& _Al = _A())
111
 
                : std::map<_K, _Ty, _Pr, _A >(_Pred, _Al) {};
112
 
 
113
 
 
114
 
};
115
 
 
116
 
//
117
 
// A new version of the List template class - the begin function now checks for NULL to eliminate access violations
118
 
//
119
 
template <class _Ty, class _A = std::allocator<_Ty> >
120
 
class TBaseList : public std::list <_Ty, _A >
121
 
{
122
 
public :
123
 
        iterator begin()
124
 
        {
125
 
                return (iterator(_Head == 0 ? 0 : _Acc::_Next(_Head))); 
126
 
        }
127
 
        
128
 
        const_iterator begin() const
129
 
        {
130
 
                return (const_iterator(_Head == 0 ? 0 : _Acc::_Next(_Head))); 
131
 
        }
132
 
        
133
 
        // 
134
 
        // These are required - apparently!
135
 
        //
136
 
        explicit TBaseList(const _A& _Al = _A()) 
137
 
                : std::list<_Ty, _A >(_Al) {};
138
 
        explicit TBaseList(size_type _N, const _Ty& _V = _Ty(), const _A& _Al = _A())
139
 
                : std::list<_Ty, _A >(N, _V, _Al) {};
140
 
 
141
 
};
142
 
 
143
 
//
144
 
// A new version of the set class - this defines the required insert method
145
 
//
146
 
template<class _K, class _Pr = std::less<_K>, class _A = std::allocator<_K> >
147
 
class TBaseSet : public std::set <_K, _Pr, _A>
148
 
{
149
 
public :
150
 
 
151
 
        //
152
 
        // This method wasn't defined
153
 
        //
154
 
        template<class _Iter>
155
 
        void insert(_Iter _First, _Iter _Last)
156
 
        {       // insert [_First, _Last)
157
 
                for (; _First != _Last; ++_First)
158
 
                        this->insert(*_First);
159
 
        }
160
 
        
161
 
        // 
162
 
        // These methods were not resolved if I declared the previous method??
163
 
        //
164
 
        _Pairib insert(const value_type& _X)
165
 
        {
166
 
                _Imp::_Pairib _Ans = _Tr.insert(_X);
167
 
                return (_Pairib(_Ans.first, _Ans.second)); 
168
 
        }
169
 
        
170
 
        iterator insert(iterator _P, const value_type& _X)
171
 
        {
172
 
                return (_Tr.insert((_Imp::iterator&)_P, _X)); 
173
 
        }
174
 
        
175
 
        void insert(_It _F, _It _L)
176
 
        {
177
 
                for (; _F != _L; ++_F)
178
 
                        _Tr.insert(*_F); 
179
 
        }
180
 
 
181
 
};
182
 
 
183
 
#else
184
 
 
185
 
#define TBaseMap std::map
186
 
#define TBaseList std::list
187
 
#define TBaseSet std::set
188
 
 
189
 
#endif //_M_AMD64
190
 
 
191
 
//
192
 
// Pool version of string.
193
 
//
194
 
typedef pool_allocator<char> TStringAllocator;
195
 
typedef std::basic_string <char, std::char_traits<char>, TStringAllocator > TString;
196
 
inline TString* NewPoolTString(const char* s)
197
 
{
198
 
        void* memory = GlobalPoolAllocator.allocate(sizeof(TString));
199
 
        return new(memory) TString(s);
200
 
}
201
 
 
202
 
//
203
 
// Pool allocator versions of vectors, lists, and maps
204
 
//
205
 
template <class T> class TVector : public std::vector<T, pool_allocator<T> > {
206
 
public:
207
 
    typedef typename std::vector<T, pool_allocator<T> >::size_type size_type;
208
 
    TVector() : std::vector<T, pool_allocator<T> >() {}
209
 
    TVector(const pool_allocator<T>& a) : std::vector<T, pool_allocator<T> >(a) {}
210
 
    TVector(size_type i): std::vector<T, pool_allocator<T> >(i) {}
211
 
};
212
 
 
213
 
template <class T> class TList   : public TBaseList  <T, pool_allocator<T> > {
214
 
public:
215
 
    typedef typename TBaseList<T, pool_allocator<T> >::size_type size_type;
216
 
    TList() : TBaseList<T, pool_allocator<T> >() {}
217
 
    TList(const pool_allocator<T>& a) : TBaseList<T, pool_allocator<T> >(a) {}
218
 
    TList(size_type i): TBaseList<T, pool_allocator<T> >(i) {}
219
 
};
220
 
 
221
 
// This is called TStlSet, because TSet is taken by an existing compiler class.
222
 
template <class T, class CMP> class TStlSet : public std::set<T, CMP, pool_allocator<T> > {
223
 
    // No pool allocator versions of constructors in std::set.
224
 
};
225
 
 
226
 
 
227
 
template <class K, class D, class CMP = std::less<K> > class TMap :
228
 
    public TBaseMap<K, D, CMP, pool_allocator<std::pair<K, D> > > {
229
 
public:
230
 
    typedef pool_allocator<std::pair <K, D> > tAllocator;
231
 
 
232
 
    TMap() : TBaseMap<K, D, CMP, tAllocator >() {}
233
 
/*
234
 
    TMap(const tAllocator& a) : TBaseMap<K, D, CMP, tAllocator >(key_compare(), a) {}
235
 
*/
236
 
    TMap(const tAllocator& a) : TBaseMap<K, D, CMP, tAllocator >() {}
237
 
};
238
 
 
239
 
//
240
 
// Persistent string memory.  Should only be used for strings that survive
241
 
// across compiles/links.
242
 
//
243
 
typedef std::basic_string<char> TPersistString;
244
 
 
245
 
//
246
 
// templatized min and max functions.
247
 
//
248
 
template <class T> T Min(const T a, const T b) { return a < b ? a : b; }
249
 
template <class T> T Max(const T a, const T b) { return a > b ? a : b; }
250
 
 
251
 
//
252
 
// Create a TString object from an integer.
253
 
//
254
 
inline const TString String(const int i, const int base = 10)
255
 
{
256
 
    char text[16];     // 32 bit ints are at most 10 digits in base 10
257
 
    
258
 
    #ifdef _WIN32
259
 
        itoa(i, text, base);
260
 
    #else
261
 
        // we assume base 10 for all cases
262
 
        sprintf(text, "%d", i);
263
 
    #endif
264
 
 
265
 
    return text;
266
 
}
267
 
 
268
 
const unsigned int SourceLocLineMask = 0xffff;
269
 
const unsigned int SourceLocStringShift = 16;
270
 
 
271
 
__inline TPersistString FormatSourceLoc(const TSourceLoc loc)
272
 
{
273
 
    char locText[64];
274
 
 
275
 
    int string = loc >> SourceLocStringShift;
276
 
    int line = loc & SourceLocLineMask;
277
 
 
278
 
    if (line)
279
 
        sprintf(locText, "%d:%d", string, line);
280
 
    else
281
 
        sprintf(locText, "%d:? ", string);
282
 
 
283
 
    return TPersistString(locText);
284
 
}
285
 
typedef TMap<TString, TString> TPragmaTable;
286
 
typedef TMap<TString, TString>::tAllocator TPragmaTableAllocator;
287
 
 
288
 
#endif // _COMMON_INCLUDED_