1bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick/* 2bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * Copyright © 2010 Intel Corporation 3bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * 4bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * Permission is hereby granted, free of charge, to any person obtaining a 5bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * copy of this software and associated documentation files (the "Software"), 6bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * to deal in the Software without restriction, including without limitation 7bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * and/or sell copies of the Software, and to permit persons to whom the 9bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * Software is furnished to do so, subject to the following conditions: 10bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * 11bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * The above copyright notice and this permission notice (including the next 12bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * paragraph) shall be included in all copies or substantial portions of the 13bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * Software. 14bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * 15bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick * DEALINGS IN THE SOFTWARE. 22bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick */ 23bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick 24bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick#include "ast.h" 253d6012303c3ce24c75d209267e6914f706d025c5Eric Anholtextern "C" { 2631747155ea3a24190277b125bd188ac8689af719Aras Pranckevicius#include "program/symbol_table.h" 273d6012303c3ce24c75d209267e6914f706d025c5Eric Anholt} 28bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick 29bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanickvoid 30bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanickast_type_specifier::print(void) const 31bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick{ 32eb7a71dea78152142b456f29e4881c4d3aeb56b6Eric Anholt if (structure) { 33bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick structure->print(); 347f9d30974317a4050fb8990ce1a3eebbb190483aIan Romanick } else { 357f9d30974317a4050fb8990ce1a3eebbb190483aIan Romanick printf("%s ", type_name); 36bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick } 37bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick 38bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick if (is_array) { 39bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick printf("[ "); 40bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick 41bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick if (array_size) { 42bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick array_size->print(); 43bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick } 44bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick 45bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick printf("] "); 46bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick } 47bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick} 48bbddcb3092dbb80081d9d4d183cd7b6f3804b1d8Ian Romanick 4928527ed557923aecff5d3b88e5d7776f04389547Kenneth Graunkebool 5028527ed557923aecff5d3b88e5d7776f04389547Kenneth Graunkeast_fully_specified_type::has_qualifiers() const 5128527ed557923aecff5d3b88e5d7776f04389547Kenneth Graunke{ 52e24d35a5b59ca1e75b69a32db6294787378a963fIan Romanick return this->qualifier.flags.i != 0; 5328527ed557923aecff5d3b88e5d7776f04389547Kenneth Graunke} 540e2f8936c8ef872cb464e54a9f09ae0324487147Chad Versace 55605aacc67d73db0926e0046a90a07fcd93a2d613Chad Versacebool ast_type_qualifier::has_interpolation() const 56605aacc67d73db0926e0046a90a07fcd93a2d613Chad Versace{ 57605aacc67d73db0926e0046a90a07fcd93a2d613Chad Versace return this->flags.q.smooth 58605aacc67d73db0926e0046a90a07fcd93a2d613Chad Versace || this->flags.q.flat 59605aacc67d73db0926e0046a90a07fcd93a2d613Chad Versace || this->flags.q.noperspective; 60605aacc67d73db0926e0046a90a07fcd93a2d613Chad Versace} 61605aacc67d73db0926e0046a90a07fcd93a2d613Chad Versace 620e2f8936c8ef872cb464e54a9f09ae0324487147Chad Versaceconst char* 630e2f8936c8ef872cb464e54a9f09ae0324487147Chad Versaceast_type_qualifier::interpolation_string() const 640e2f8936c8ef872cb464e54a9f09ae0324487147Chad Versace{ 650e2f8936c8ef872cb464e54a9f09ae0324487147Chad Versace if (this->flags.q.smooth) 660e2f8936c8ef872cb464e54a9f09ae0324487147Chad Versace return "smooth"; 670e2f8936c8ef872cb464e54a9f09ae0324487147Chad Versace else if (this->flags.q.flat) 680e2f8936c8ef872cb464e54a9f09ae0324487147Chad Versace return "flat"; 690e2f8936c8ef872cb464e54a9f09ae0324487147Chad Versace else if (this->flags.q.noperspective) 700e2f8936c8ef872cb464e54a9f09ae0324487147Chad Versace return "noperspective"; 710e2f8936c8ef872cb464e54a9f09ae0324487147Chad Versace else 720e2f8936c8ef872cb464e54a9f09ae0324487147Chad Versace return NULL; 730e2f8936c8ef872cb464e54a9f09ae0324487147Chad Versace} 74551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt 75551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholtbool 76551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholtast_type_qualifier::merge_qualifier(YYLTYPE *loc, 77551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt _mesa_glsl_parse_state *state, 78551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt ast_type_qualifier q) 79551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt{ 80551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt ast_type_qualifier ubo_mat_mask; 81551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt ubo_mat_mask.flags.i = 0; 82551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt ubo_mat_mask.flags.q.row_major = 1; 83551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt ubo_mat_mask.flags.q.column_major = 1; 84551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt 85551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt ast_type_qualifier ubo_layout_mask; 86551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt ubo_layout_mask.flags.i = 0; 87551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt ubo_layout_mask.flags.q.std140 = 1; 88551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt ubo_layout_mask.flags.q.packed = 1; 89551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt ubo_layout_mask.flags.q.shared = 1; 90551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt 91551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt /* Uniform block layout qualifiers get to overwrite each 92551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt * other (rightmost having priority), while all other 93551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt * qualifiers currently don't allow duplicates. 94551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt */ 95551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt 96551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt if ((this->flags.i & q.flags.i & ~(ubo_mat_mask.flags.i | 97551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt ubo_layout_mask.flags.i)) != 0) { 98551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt _mesa_glsl_error(loc, state, 99551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt "duplicate layout qualifiers used\n"); 100551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt return false; 101551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt } 102551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt 103551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt if ((q.flags.i & ubo_mat_mask.flags.i) != 0) 104551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt this->flags.i &= ~ubo_mat_mask.flags.i; 105551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt if ((q.flags.i & ubo_layout_mask.flags.i) != 0) 106551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt this->flags.i &= ~ubo_layout_mask.flags.i; 107551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt 108551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt this->flags.i |= q.flags.i; 109551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt 110551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt if (q.flags.q.explicit_location) 111551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt this->location = q.location; 112551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt 113551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt if (q.flags.q.explicit_index) 114551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt this->index = q.index; 115551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt 116551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt return true; 117551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt} 118551bdf25bc4e57bea51c54da7e31c44c507e6c9fEric Anholt 119