glsl: add support for GL_OES_EGL_image_external
[profile/ivi/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 "ast.h"
25 extern "C" {
26 #include "program/symbol_table.h"
27 }
28
29 void
30 ast_type_specifier::print(void) const
31 {
32    if (type_specifier == ast_struct) {
33       structure->print();
34    } else {
35       printf("%s ", type_name);
36    }
37
38    if (is_array) {
39       printf("[ ");
40
41       if (array_size) {
42          array_size->print();
43       }
44
45       printf("] ");
46    }
47 }
48
49 ast_type_specifier::ast_type_specifier(int specifier)
50       : type_specifier(ast_types(specifier)), type_name(NULL), structure(NULL),
51         is_array(false), array_size(NULL), precision(ast_precision_none),
52         is_precision_statement(false)
53 {
54    static const char *const names[] = {
55       "void",
56       "float",
57       "int",
58       "uint",
59       "bool",
60       "vec2",
61       "vec3",
62       "vec4",
63       "bvec2",
64       "bvec3",
65       "bvec4",
66       "ivec2",
67       "ivec3",
68       "ivec4",
69       "uvec2",
70       "uvec3",
71       "uvec4",
72       "mat2",
73       "mat2x3",
74       "mat2x4",
75       "mat3x2",
76       "mat3",
77       "mat3x4",
78       "mat4x2",
79       "mat4x3",
80       "mat4",
81       "sampler1D",
82       "sampler2D",
83       "sampler2DRect",
84       "sampler3D",
85       "samplerCube",
86       "samplerExternalOES",
87       "sampler1DShadow",
88       "sampler2DShadow",
89       "sampler2DRectShadow",
90       "samplerCubeShadow",
91       "sampler1DArray",
92       "sampler2DArray",
93       "sampler1DArrayShadow",
94       "sampler2DArrayShadow",
95       "isampler1D",
96       "isampler2D",
97       "isampler3D",
98       "isamplerCube",
99       "isampler1DArray",
100       "isampler2DArray",
101       "usampler1D",
102       "usampler2D",
103       "usampler3D",
104       "usamplerCube",
105       "usampler1DArray",
106       "usampler2DArray",
107
108       NULL, /* ast_struct */
109       NULL  /* ast_type_name */
110    };
111
112    type_name = names[specifier];
113 }
114
115 bool
116 ast_fully_specified_type::has_qualifiers() const
117 {
118    return this->qualifier.flags.i != 0;
119 }
120
121 bool ast_type_qualifier::has_interpolation() const
122 {
123    return this->flags.q.smooth
124           || this->flags.q.flat
125           || this->flags.q.noperspective;
126 }
127
128 const char*
129 ast_type_qualifier::interpolation_string() const
130 {
131    if (this->flags.q.smooth)
132       return "smooth";
133    else if (this->flags.q.flat)
134       return "flat";
135    else if (this->flags.q.noperspective)
136       return "noperspective";
137    else
138       return NULL;
139 }