Merge branch 'glsl2-head' into glsl2
[mesa.git] / src / glsl / 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 : type_specifier(ast_types(specifier)), type_name(NULL), structure(NULL),
50 is_array(false), array_size(NULL), precision(ast_precision_high)
51 {
52 static const char *const names[] = {
53 "void",
54 "float",
55 "int",
56 "uint",
57 "bool",
58 "vec2",
59 "vec3",
60 "vec4",
61 "bvec2",
62 "bvec3",
63 "bvec4",
64 "ivec2",
65 "ivec3",
66 "ivec4",
67 "uvec2",
68 "uvec3",
69 "uvec4",
70 "mat2",
71 "mat2x3",
72 "mat2x4",
73 "mat3x2",
74 "mat3",
75 "mat3x4",
76 "mat4x2",
77 "mat4x3",
78 "mat4",
79 "sampler1D",
80 "sampler2D",
81 "sampler2DRect",
82 "sampler3D",
83 "samplerCube",
84 "sampler1DShadow",
85 "sampler2DShadow",
86 "sampler2DRectShadow",
87 "samplerCubeShadow",
88 "sampler1DArray",
89 "sampler2DArray",
90 "sampler1DArrayShadow",
91 "sampler2DArrayShadow",
92 "isampler1D",
93 "isampler2D",
94 "isampler3D",
95 "isamplerCube",
96 "isampler1DArray",
97 "isampler2DArray",
98 "usampler1D",
99 "usampler2D",
100 "usampler3D",
101 "usamplerCube",
102 "usampler1DArray",
103 "usampler2DArray",
104
105 NULL, /* ast_struct */
106 NULL /* ast_type_name */
107 };
108
109 type_name = names[specifier];
110 }