~ubuntu-branches/ubuntu/natty/mesa/natty-proposed

« back to all changes in this revision

Viewing changes to src/glsl/pp/sl_pp_macro.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Hooker, Robert Hooker, Christopher James Halse Rogers
  • Date: 2010-09-14 08:55:40 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100914085540-m4fpl0hdjlfd4jgz
Tags: 7.9~git20100909-0ubuntu1
[ Robert Hooker ]
* New upstream git snapshot up to commit 94118fe2d4b1e5 (LP: #631413)
* New features include ATI HD5xxx series support in r600, and a vastly
  improved glsl compiler.
* Remove pre-generated .pc's, use the ones generated at build time
  instead.
* Remove all references to mesa-utils now that its no longer shipped
  with the mesa source.
* Disable the experimental ARB_fragment_shader option by default on
  i915, it exposes incomplete functionality that breaks KDE compositing
  among other things. It can be enabled via driconf still. (LP: #628930).

[ Christopher James Halse Rogers ]
* debian/patches/04_osmesa_version.diff:
  - Refresh for new upstream
* Bugs fixed in this release:
  - Fixes severe rendering corruption in Unity on radeon (LP: #628727,
    LP: #596292, LP: #599741, LP: #630315, LP: #613694, LP: #599741).
  - Also fixes rendering in gnome-shell (LP: #578619).
  - Flickering in OpenGL apps on radeon (LP: #626943, LP: #610541).
  - Provides preliminary support for new intel chips (LP: #601052).
* debian/rules:
  - Update configure flags to match upstream reshuffling.
  - Explicitly remove gallium DRI drivers that we don't want to ship.
* Update debian/gbp.conf for this Maverick-specific packaging
* libegl1-mesa-dri-x11,kms: There are no longer separate kms or x11 drivers
  for EGL, libegl1-mesa-drivers now contains a single driver that provides
  both backends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**************************************************************************
2
 
 * 
3
 
 * Copyright 2009 VMware, Inc.
4
 
 * All Rights Reserved.
5
 
 * 
6
 
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 
 * copy of this software and associated documentation files (the
8
 
 * "Software"), to deal in the Software without restriction, including
9
 
 * without limitation the rights to use, copy, modify, merge, publish,
10
 
 * distribute, sub license, and/or sell copies of the Software, and to
11
 
 * permit persons to whom the Software is furnished to do so, subject to
12
 
 * the following conditions:
13
 
 * 
14
 
 * The above copyright notice and this permission notice (including the
15
 
 * next paragraph) shall be included in all copies or substantial portions
16
 
 * of the Software.
17
 
 * 
18
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
 
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21
 
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22
 
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
 
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
 
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
 
 * 
26
 
 **************************************************************************/
27
 
 
28
 
#include <stdlib.h>
29
 
#include <stdio.h>
30
 
#include <string.h>
31
 
#include "sl_pp_context.h"
32
 
#include "sl_pp_public.h"
33
 
#include "sl_pp_macro.h"
34
 
#include "sl_pp_process.h"
35
 
 
36
 
 
37
 
static void
38
 
_macro_init(struct sl_pp_macro *macro)
39
 
{
40
 
   macro->name = -1;
41
 
   macro->num_args = -1;
42
 
   macro->arg = NULL;
43
 
   macro->body = NULL;
44
 
}
45
 
 
46
 
struct sl_pp_macro *
47
 
sl_pp_macro_new(void)
48
 
{
49
 
   struct sl_pp_macro *macro;
50
 
 
51
 
   macro = calloc(1, sizeof(struct sl_pp_macro));
52
 
   if (macro) {
53
 
      _macro_init(macro);
54
 
   }
55
 
   return macro;
56
 
}
57
 
 
58
 
static void
59
 
_macro_destroy(struct sl_pp_macro *macro)
60
 
{
61
 
   struct sl_pp_macro_formal_arg *arg = macro->arg;
62
 
 
63
 
   while (arg) {
64
 
      struct sl_pp_macro_formal_arg *next_arg = arg->next;
65
 
 
66
 
      free(arg);
67
 
      arg = next_arg;
68
 
   }
69
 
 
70
 
   free(macro->body);
71
 
}
72
 
 
73
 
void
74
 
sl_pp_macro_free(struct sl_pp_macro *macro)
75
 
{
76
 
   while (macro) {
77
 
      struct sl_pp_macro *next_macro = macro->next;
78
 
 
79
 
      _macro_destroy(macro);
80
 
      free(macro);
81
 
      macro = next_macro;
82
 
   }
83
 
}
84
 
 
85
 
void
86
 
sl_pp_macro_reset(struct sl_pp_macro *macro)
87
 
{
88
 
   _macro_destroy(macro);
89
 
   _macro_init(macro);
90
 
}
91
 
 
92
 
static int
93
 
_out_number(struct sl_pp_context *context,
94
 
            struct sl_pp_process_state *state,
95
 
            unsigned int number)
96
 
{
97
 
   char buf[32];
98
 
   struct sl_pp_token_info ti;
99
 
 
100
 
   sprintf(buf, "%u", number);
101
 
 
102
 
   ti.token = SL_PP_UINT;
103
 
   ti.data._uint = sl_pp_context_add_unique_str(context, buf);
104
 
   if (sl_pp_process_out(state, &ti)) {
105
 
      strcpy(context->error_msg, "out of memory");
106
 
      return -1;
107
 
   }
108
 
 
109
 
   return 0;
110
 
}
111
 
 
112
 
int
113
 
sl_pp_macro_expand(struct sl_pp_context *context,
114
 
                   struct sl_pp_token_buffer *tokens,
115
 
                   struct sl_pp_macro *local,
116
 
                   struct sl_pp_process_state *state,
117
 
                   enum sl_pp_macro_expand_behaviour behaviour)
118
 
{
119
 
   int mute = (behaviour == sl_pp_macro_expand_mute);
120
 
   struct sl_pp_token_info input;
121
 
   int macro_name;
122
 
   struct sl_pp_macro *macro = NULL;
123
 
   struct sl_pp_macro *actual_arg = NULL;
124
 
   unsigned int j;
125
 
 
126
 
   if (sl_pp_token_buffer_get(tokens, &input)) {
127
 
      return -1;
128
 
   }
129
 
 
130
 
   if (input.token != SL_PP_IDENTIFIER) {
131
 
      strcpy(context->error_msg, "expected an identifier");
132
 
      return -1;
133
 
   }
134
 
 
135
 
   macro_name = input.data.identifier;
136
 
 
137
 
   /* First look for predefined macros.
138
 
    */
139
 
 
140
 
   if (macro_name == context->dict.___LINE__) {
141
 
      if (!mute && _out_number(context, state, context->line)) {
142
 
         return -1;
143
 
      }
144
 
      return 0;
145
 
   }
146
 
   if (macro_name == context->dict.___FILE__) {
147
 
      if (!mute && _out_number(context, state, context->file)) {
148
 
         return -1;
149
 
      }
150
 
      return 0;
151
 
   }
152
 
   if (macro_name == context->dict.___VERSION__) {
153
 
      if (!mute && _out_number(context, state, 110)) {
154
 
         return -1;
155
 
      }
156
 
      return 0;
157
 
   }
158
 
 
159
 
   for (j = 0; j < context->num_predefined; j++) {
160
 
      if (macro_name == context->predefined[j].name) {
161
 
         if (!mute) {
162
 
            struct sl_pp_token_info ti;
163
 
 
164
 
            ti.token = SL_PP_UINT;
165
 
            ti.data._uint = context->predefined[j].value;
166
 
            if (sl_pp_process_out(state, &ti)) {
167
 
               strcpy(context->error_msg, "out of memory");
168
 
               return -1;
169
 
            }
170
 
         }
171
 
         return 0;
172
 
      }
173
 
   }
174
 
 
175
 
   /* Replace extension names with 1.
176
 
    */
177
 
   for (j = 0; j < context->num_extensions; j++) {
178
 
      if (macro_name == context->extensions[j].name) {
179
 
         if (!mute && _out_number(context, state, 1)) {
180
 
            return -1;
181
 
         }
182
 
         return 0;
183
 
      }
184
 
   }
185
 
 
186
 
   if (local) {
187
 
      for (macro = local; macro; macro = macro->next) {
188
 
         if (macro->name == macro_name) {
189
 
            break;
190
 
         }
191
 
      }
192
 
   }
193
 
 
194
 
   if (!macro) {
195
 
      for (macro = context->macro; macro; macro = macro->next) {
196
 
         if (macro->name == macro_name) {
197
 
            break;
198
 
         }
199
 
      }
200
 
   }
201
 
 
202
 
   if (!macro) {
203
 
      if (behaviour == sl_pp_macro_expand_unknown_to_0) {
204
 
         if (_out_number(context, state, 0)) {
205
 
            strcpy(context->error_msg, "out of memory");
206
 
            return -1;
207
 
         }
208
 
      } else if (!mute) {
209
 
         if (sl_pp_process_out(state, &input)) {
210
 
            strcpy(context->error_msg, "out of memory");
211
 
            return -1;
212
 
         }
213
 
      }
214
 
      return 0;
215
 
   }
216
 
 
217
 
   if (macro->num_args >= 0) {
218
 
      if (sl_pp_token_buffer_skip_white(tokens, &input)) {
219
 
         return -1;
220
 
      }
221
 
      if (input.token != SL_PP_LPAREN) {
222
 
         strcpy(context->error_msg, "expected `('");
223
 
         return -1;
224
 
      }
225
 
      if (sl_pp_token_buffer_skip_white(tokens, &input)) {
226
 
         return -1;
227
 
      }
228
 
      sl_pp_token_buffer_unget(tokens, &input);
229
 
   }
230
 
 
231
 
   if (macro->num_args > 0) {
232
 
      struct sl_pp_macro_formal_arg *formal_arg = macro->arg;
233
 
      struct sl_pp_macro **pmacro = &actual_arg;
234
 
 
235
 
      for (j = 0; j < (unsigned int)macro->num_args; j++) {
236
 
         struct sl_pp_process_state arg_state;
237
 
         int done = 0;
238
 
         unsigned int paren_nesting = 0;
239
 
         struct sl_pp_token_info eof;
240
 
 
241
 
         memset(&arg_state, 0, sizeof(arg_state));
242
 
 
243
 
         while (!done) {
244
 
            if (sl_pp_token_buffer_get(tokens, &input)) {
245
 
               goto fail_arg;
246
 
            }
247
 
            switch (input.token) {
248
 
            case SL_PP_WHITESPACE:
249
 
               break;
250
 
 
251
 
            case SL_PP_COMMA:
252
 
               if (!paren_nesting) {
253
 
                  if (j < (unsigned int)macro->num_args - 1) {
254
 
                     done = 1;
255
 
                  } else {
256
 
                     strcpy(context->error_msg, "too many actual macro arguments");
257
 
                     goto fail_arg;
258
 
                  }
259
 
               } else {
260
 
                  if (sl_pp_process_out(&arg_state, &input)) {
261
 
                     strcpy(context->error_msg, "out of memory");
262
 
                     goto fail_arg;
263
 
                  }
264
 
               }
265
 
               break;
266
 
 
267
 
            case SL_PP_LPAREN:
268
 
               paren_nesting++;
269
 
               if (sl_pp_process_out(&arg_state, &input)) {
270
 
                  goto oom_arg;
271
 
               }
272
 
               break;
273
 
 
274
 
            case SL_PP_RPAREN:
275
 
               if (!paren_nesting) {
276
 
                  if (j == (unsigned int)macro->num_args - 1) {
277
 
                     done = 1;
278
 
                  } else {
279
 
                     strcpy(context->error_msg, "too few actual macro arguments");
280
 
                     goto fail_arg;
281
 
                  }
282
 
               } else {
283
 
                  paren_nesting--;
284
 
                  if (sl_pp_process_out(&arg_state, &input)) {
285
 
                     goto oom_arg;
286
 
                  }
287
 
               }
288
 
               break;
289
 
 
290
 
            case SL_PP_IDENTIFIER:
291
 
               sl_pp_token_buffer_unget(tokens, &input);
292
 
               if (sl_pp_macro_expand(context, tokens, local, &arg_state, sl_pp_macro_expand_normal)) {
293
 
                  goto fail_arg;
294
 
               }
295
 
               break;
296
 
 
297
 
            case SL_PP_EOF:
298
 
               strcpy(context->error_msg, "too few actual macro arguments");
299
 
               goto fail_arg;
300
 
 
301
 
            default:
302
 
               if (sl_pp_process_out(&arg_state, &input)) {
303
 
                  goto oom_arg;
304
 
               }
305
 
            }
306
 
         }
307
 
 
308
 
         eof.token = SL_PP_EOF;
309
 
         if (sl_pp_process_out(&arg_state, &eof)) {
310
 
            goto oom_arg;
311
 
         }
312
 
 
313
 
         *pmacro = sl_pp_macro_new();
314
 
         if (!*pmacro) {
315
 
            goto oom_arg;
316
 
         }
317
 
 
318
 
         (**pmacro).name = formal_arg->name;
319
 
         (**pmacro).body = arg_state.out;
320
 
 
321
 
         formal_arg = formal_arg->next;
322
 
         pmacro = &(**pmacro).next;
323
 
 
324
 
         continue;
325
 
 
326
 
oom_arg:
327
 
         strcpy(context->error_msg, "out of memory");
328
 
fail_arg:
329
 
         free(arg_state.out);
330
 
         goto fail;
331
 
      }
332
 
   }
333
 
 
334
 
   /* Right paren for non-empty argument list has already been eaten. */
335
 
   if (macro->num_args == 0) {
336
 
      if (sl_pp_token_buffer_skip_white(tokens, &input)) {
337
 
         goto fail;
338
 
      }
339
 
      if (input.token != SL_PP_RPAREN) {
340
 
         strcpy(context->error_msg, "expected `)'");
341
 
         goto fail;
342
 
      }
343
 
   }
344
 
 
345
 
   /* XXX: This is all wrong, we should be ungetting all tokens
346
 
    *      back to the main token buffer.
347
 
    */
348
 
   {
349
 
      struct sl_pp_token_buffer buffer;
350
 
 
351
 
      /* Seek to the end.
352
 
       */
353
 
      for (j = 0; macro->body[j].token != SL_PP_EOF; j++) {
354
 
      }
355
 
      j++;
356
 
 
357
 
      /* Create a context-less token buffer since we are not going to underrun
358
 
       * its internal buffer.
359
 
       */
360
 
      if (sl_pp_token_buffer_init(&buffer, NULL)) {
361
 
         strcpy(context->error_msg, "out of memory");
362
 
         goto fail;
363
 
      }
364
 
 
365
 
      /* Unget the tokens in reverse order so later they will be fetched correctly.
366
 
       */
367
 
      for (; j > 0; j--) {
368
 
         sl_pp_token_buffer_unget(&buffer, &macro->body[j - 1]);
369
 
      }
370
 
 
371
 
      /* Expand.
372
 
       */
373
 
      for (;;) {
374
 
         struct sl_pp_token_info input;
375
 
 
376
 
         sl_pp_token_buffer_get(&buffer, &input);
377
 
         switch (input.token) {
378
 
         case SL_PP_NEWLINE:
379
 
            if (sl_pp_process_out(state, &input)) {
380
 
               strcpy(context->error_msg, "out of memory");
381
 
               sl_pp_token_buffer_destroy(&buffer);
382
 
               goto fail;
383
 
            }
384
 
            break;
385
 
 
386
 
         case SL_PP_IDENTIFIER:
387
 
            sl_pp_token_buffer_unget(&buffer, &input);
388
 
            if (sl_pp_macro_expand(context, &buffer, actual_arg, state, behaviour)) {
389
 
               sl_pp_token_buffer_destroy(&buffer);
390
 
               goto fail;
391
 
            }
392
 
            break;
393
 
 
394
 
         case SL_PP_EOF:
395
 
            sl_pp_token_buffer_destroy(&buffer);
396
 
            sl_pp_macro_free(actual_arg);
397
 
            return 0;
398
 
 
399
 
         default:
400
 
            if (!mute) {
401
 
               if (sl_pp_process_out(state, &input)) {
402
 
                  strcpy(context->error_msg, "out of memory");
403
 
                  sl_pp_token_buffer_destroy(&buffer);
404
 
                  goto fail;
405
 
               }
406
 
            }
407
 
         }
408
 
      }
409
 
   }
410
 
 
411
 
fail:
412
 
   sl_pp_macro_free(actual_arg);
413
 
   return -1;
414
 
}