glsl/pp: Fix macro formal argument parsing, more descriptive error msgs.
[mesa.git] / src / glsl / pp / sl_pp_dict.c
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 "sl_pp_context.h"
29 #include "sl_pp_dict.h"
30
31
32 #define ADD_NAME_STR(CTX, NAME, STR)\
33 do {\
34 (CTX)->dict.NAME = sl_pp_context_add_unique_str((CTX), (STR));\
35 if ((CTX)->dict.NAME == -1) {\
36 return -1;\
37 }\
38 } while (0)
39
40 #define ADD_NAME(CTX, NAME) ADD_NAME_STR(CTX, NAME, #NAME)
41
42
43 int
44 sl_pp_dict_init(struct sl_pp_context *context)
45 {
46 ADD_NAME(context, all);
47 ADD_NAME_STR(context, _GL_ARB_draw_buffers, "GL_ARB_draw_buffers");
48 ADD_NAME_STR(context, _GL_ARB_texture_rectangle, "GL_ARB_texture_rectangle");
49
50 ADD_NAME(context, require);
51 ADD_NAME(context, enable);
52 ADD_NAME(context, warn);
53 ADD_NAME(context, disable);
54
55 ADD_NAME(context, defined);
56
57 ADD_NAME_STR(context, ___LINE__, "__LINE__");
58 ADD_NAME_STR(context, ___FILE__, "__FILE__");
59 ADD_NAME_STR(context, ___VERSION__, "__VERSION__");
60
61 ADD_NAME(context, optimize);
62 ADD_NAME(context, debug);
63
64 ADD_NAME(context, off);
65 ADD_NAME(context, on);
66
67 ADD_NAME(context, define);
68 ADD_NAME(context, elif);
69 ADD_NAME_STR(context, _else, "else");
70 ADD_NAME(context, endif);
71 ADD_NAME(context, error);
72 ADD_NAME(context, extension);
73 ADD_NAME_STR(context, _if, "if");
74 ADD_NAME(context, ifdef);
75 ADD_NAME(context, ifndef);
76 ADD_NAME(context, line);
77 ADD_NAME(context, pragma);
78 ADD_NAME(context, undef);
79
80 ADD_NAME(context, version);
81
82 ADD_NAME_STR(context, _0, "0");
83 ADD_NAME_STR(context, _1, "1");
84
85 return 0;
86 }