Ensure that ast_type always has type_name set
[mesa.git] / ast_type.cpp
1 /*
2 * Copyright © 2010 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include <cstdio>
25 #include "ast.h"
26 #include "symbol_table.h"
27
28 void
29 ast_type_specifier::print(void) const
30 {
31 if (type_specifier == ast_struct) {
32 structure->print();
33 } else {
34 printf("%s ", type_name);
35 }
36
37 if (is_array) {
38 printf("[ ");
39
40 if (array_size) {
41 array_size->print();
42 }
43
44 printf("] ");
45 }
46 }
47
48 ast_type_specifier::ast_type_specifier(int specifier)
49 {
50 static const char *const names[] = {
51 "void",
52 "float",
53 "int",
54 "uint",
55 "bool",
56 "vec2",
57 "vec3",
58 "vec4",
59 "bvec2",
60 "bvec3",
61 "bvec4",
62 "ivec2",
63 "ivec3",
64 "ivec4",
65 "uvec2",
66 "uvec3",
67 "uvec4",
68 "mat2",
69 "mat2x3",
70 "mat2x4",
71 "mat3x2",
72 "mat3",
73 "mat3x4",
74 "mat4x2",
75 "mat4x3",
76 "mat4",
77 "sampler1D",
78 "sampler2D",
79 "sampler3D",
80 "samplerCube",
81 "sampler1DShadow",
82 "sampler2DShadow",
83 "samplerCubeShadow",
84 "sampler1DArray",
85 "sampler2DArray",
86 "sampler1DArrayShadow",
87 "sampler2DArrayShadow",
88 "isampler1D",
89 "isampler2D",
90 "isampler3D",
91 "isamplerCube",
92 "isampler1DArray",
93 "isampler2DArray",
94 "usampler1D",
95 "usampler2D",
96 "usampler3D",
97 "usamplerCube",
98 "usampler1DArray",
99 "usampler2DArray",
100
101 NULL, /* ast_struct */
102 NULL /* ast_type_name */
103 };
104
105 type_specifier = ast_types(specifier);
106 type_name = names[specifier];
107 }