ast_type.cpp revision 0e2f8936c8ef872cb464e54a9f09ae0324487147
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"
26extern "C" {
27#include "program/symbol_table.h"
28}
29
30void
31ast_type_specifier::print(void) const
32{
33   if (type_specifier == ast_struct) {
34      structure->print();
35   } else {
36      printf("%s ", type_name);
37   }
38
39   if (is_array) {
40      printf("[ ");
41
42      if (array_size) {
43	 array_size->print();
44      }
45
46      printf("] ");
47   }
48}
49
50ast_type_specifier::ast_type_specifier(int specifier)
51      : type_specifier(ast_types(specifier)), type_name(NULL), structure(NULL),
52	is_array(false), array_size(NULL), precision(ast_precision_high)
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
114bool
115ast_fully_specified_type::has_qualifiers() const
116{
117   return this->qualifier.flags.i != 0;
118}
119
120const char*
121ast_type_qualifier::interpolation_string() const
122{
123   if (this->flags.q.smooth)
124      return "smooth";
125   else if (this->flags.q.flat)
126      return "flat";
127   else if (this->flags.q.noperspective)
128      return "noperspective";
129   else
130      return NULL;
131}
132