Tizen 2.0 Release
[profile/ivi/osmesa.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       "sampler1DShadow",
87       "sampler2DShadow",
88       "sampler2DRectShadow",
89       "samplerCubeShadow",
90       "sampler1DArray",
91       "sampler2DArray",
92       "sampler1DArrayShadow",
93       "sampler2DArrayShadow",
94       "isampler1D",
95       "isampler2D",
96       "isampler3D",
97       "isamplerCube",
98       "isampler1DArray",
99       "isampler2DArray",
100       "usampler1D",
101       "usampler2D",
102       "usampler3D",
103       "usamplerCube",
104       "usampler1DArray",
105       "usampler2DArray",
106
107       NULL, /* ast_struct */
108       NULL  /* ast_type_name */
109    };
110
111    type_name = names[specifier];
112 }
113
114 bool
115 ast_fully_specified_type::has_qualifiers() const
116 {
117    return this->qualifier.flags.i != 0;
118 }
119
120 bool ast_type_qualifier::has_interpolation() const
121 {
122    return this->flags.q.smooth
123           || this->flags.q.flat
124           || this->flags.q.noperspective;
125 }
126
127 const char*
128 ast_type_qualifier::interpolation_string() const
129 {
130    if (this->flags.q.smooth)
131       return "smooth";
132    else if (this->flags.q.flat)
133       return "flat";
134    else if (this->flags.q.noperspective)
135       return "noperspective";
136    else
137       return NULL;
138 }