Path: blob/21.2-virgl/src/compiler/glsl/glsl_symbol_table.h
4545 views
/* -*- c++ -*- */1/*2* Copyright © 2010 Intel Corporation3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21* DEALINGS IN THE SOFTWARE.22*/2324#ifndef GLSL_SYMBOL_TABLE25#define GLSL_SYMBOL_TABLE2627#include <new>2829#include "program/symbol_table.h"30#include "ir.h"3132class symbol_table_entry;33struct glsl_type;3435/**36* Facade class for _mesa_symbol_table37*38* Wraps the existing \c _mesa_symbol_table data structure to enforce some39* type safe and some symbol table invariants.40*/41struct glsl_symbol_table {42DECLARE_RALLOC_CXX_OPERATORS(glsl_symbol_table)4344glsl_symbol_table();45~glsl_symbol_table();4647/* In 1.10, functions and variables have separate namespaces. */48bool separate_function_namespace;4950void push_scope();51void pop_scope();5253/**54* Determine whether a name was declared at the current scope55*/56bool name_declared_this_scope(const char *name);5758/**59* \name Methods to add symbols to the table60*61* There is some temptation to rename all these functions to \c add_symbol62* or similar. However, this breaks symmetry with the getter functions and63* reduces the clarity of the intention of code that uses these methods.64*/65/*@{*/66bool add_variable(ir_variable *v);67bool add_type(const char *name, const glsl_type *t);68bool add_function(ir_function *f);69bool add_interface(const char *name, const glsl_type *i,70enum ir_variable_mode mode);71bool add_default_precision_qualifier(const char *type_name, int precision);72/*@}*/7374/**75* Add an function at global scope without checking for scoping conflicts.76*/77void add_global_function(ir_function *f);7879/**80* \name Methods to get symbols from the table81*/82/*@{*/83ir_variable *get_variable(const char *name);84const glsl_type *get_type(const char *name);85ir_function *get_function(const char *name);86const glsl_type *get_interface(const char *name,87enum ir_variable_mode mode);88int get_default_precision_qualifier(const char *type_name);89/*@}*/9091/**92* Disable a previously-added variable so that it no longer appears to be93* in the symbol table. This is necessary when gl_PerVertex is redeclared,94* to ensure that previously-available built-in variables are no longer95* available.96*/97void disable_variable(const char *name);9899/**100* Replaces the variable in the entry by the new variable.101*/102void replace_variable(const char *name, ir_variable *v);103104private:105symbol_table_entry *get_entry(const char *name);106107struct _mesa_symbol_table *table;108void *mem_ctx;109void *linalloc;110};111112#endif /* GLSL_SYMBOL_TABLE */113114115