OSDN Git Service

Trivial clean-ups to ast_type_specifier(int) constructor
[android-x86/external-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       : 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       "sampler3D",
82       "samplerCube",
83       "sampler1DShadow",
84       "sampler2DShadow",
85       "samplerCubeShadow",
86       "sampler1DArray",
87       "sampler2DArray",
88       "sampler1DArrayShadow",
89       "sampler2DArrayShadow",
90       "isampler1D",
91       "isampler2D",
92       "isampler3D",
93       "isamplerCube",
94       "isampler1DArray",
95       "isampler2DArray",
96       "usampler1D",
97       "usampler2D",
98       "usampler3D",
99       "usamplerCube",
100       "usampler1DArray",
101       "usampler2DArray",
102
103       NULL, /* ast_struct */
104       NULL  /* ast_type_name */
105    };
106
107    type_name = names[specifier];
108 }