101e04c3fSmrg/* -*- c++ -*- */ 201e04c3fSmrg/* 301e04c3fSmrg * Copyright © 2010 Intel Corporation 401e04c3fSmrg * 501e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 601e04c3fSmrg * copy of this software and associated documentation files (the "Software"), 701e04c3fSmrg * to deal in the Software without restriction, including without limitation 801e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 901e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the 1001e04c3fSmrg * Software is furnished to do so, subject to the following conditions: 1101e04c3fSmrg * 1201e04c3fSmrg * The above copyright notice and this permission notice (including the next 1301e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the 1401e04c3fSmrg * Software. 1501e04c3fSmrg * 1601e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1701e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1801e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1901e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2001e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2101e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 2201e04c3fSmrg * DEALINGS IN THE SOFTWARE. 2301e04c3fSmrg */ 2401e04c3fSmrg 2501e04c3fSmrg#ifndef GLSL_SYMBOL_TABLE 2601e04c3fSmrg#define GLSL_SYMBOL_TABLE 2701e04c3fSmrg 2801e04c3fSmrg#include <new> 2901e04c3fSmrg 3001e04c3fSmrg#include "program/symbol_table.h" 3101e04c3fSmrg#include "ir.h" 3201e04c3fSmrg 3301e04c3fSmrgclass symbol_table_entry; 3401e04c3fSmrgstruct glsl_type; 3501e04c3fSmrg 3601e04c3fSmrg/** 3701e04c3fSmrg * Facade class for _mesa_symbol_table 3801e04c3fSmrg * 3901e04c3fSmrg * Wraps the existing \c _mesa_symbol_table data structure to enforce some 4001e04c3fSmrg * type safe and some symbol table invariants. 4101e04c3fSmrg */ 4201e04c3fSmrgstruct glsl_symbol_table { 4301e04c3fSmrg DECLARE_RALLOC_CXX_OPERATORS(glsl_symbol_table) 4401e04c3fSmrg 4501e04c3fSmrg glsl_symbol_table(); 4601e04c3fSmrg ~glsl_symbol_table(); 4701e04c3fSmrg 4801e04c3fSmrg /* In 1.10, functions and variables have separate namespaces. */ 4901e04c3fSmrg bool separate_function_namespace; 5001e04c3fSmrg 5101e04c3fSmrg void push_scope(); 5201e04c3fSmrg void pop_scope(); 5301e04c3fSmrg 5401e04c3fSmrg /** 5501e04c3fSmrg * Determine whether a name was declared at the current scope 5601e04c3fSmrg */ 5701e04c3fSmrg bool name_declared_this_scope(const char *name); 5801e04c3fSmrg 5901e04c3fSmrg /** 6001e04c3fSmrg * \name Methods to add symbols to the table 6101e04c3fSmrg * 6201e04c3fSmrg * There is some temptation to rename all these functions to \c add_symbol 6301e04c3fSmrg * or similar. However, this breaks symmetry with the getter functions and 6401e04c3fSmrg * reduces the clarity of the intention of code that uses these methods. 6501e04c3fSmrg */ 6601e04c3fSmrg /*@{*/ 6701e04c3fSmrg bool add_variable(ir_variable *v); 6801e04c3fSmrg bool add_type(const char *name, const glsl_type *t); 6901e04c3fSmrg bool add_function(ir_function *f); 7001e04c3fSmrg bool add_interface(const char *name, const glsl_type *i, 7101e04c3fSmrg enum ir_variable_mode mode); 7201e04c3fSmrg bool add_default_precision_qualifier(const char *type_name, int precision); 7301e04c3fSmrg /*@}*/ 7401e04c3fSmrg 7501e04c3fSmrg /** 7601e04c3fSmrg * Add an function at global scope without checking for scoping conflicts. 7701e04c3fSmrg */ 7801e04c3fSmrg void add_global_function(ir_function *f); 7901e04c3fSmrg 8001e04c3fSmrg /** 8101e04c3fSmrg * \name Methods to get symbols from the table 8201e04c3fSmrg */ 8301e04c3fSmrg /*@{*/ 8401e04c3fSmrg ir_variable *get_variable(const char *name); 8501e04c3fSmrg const glsl_type *get_type(const char *name); 8601e04c3fSmrg ir_function *get_function(const char *name); 8701e04c3fSmrg const glsl_type *get_interface(const char *name, 8801e04c3fSmrg enum ir_variable_mode mode); 8901e04c3fSmrg int get_default_precision_qualifier(const char *type_name); 9001e04c3fSmrg /*@}*/ 9101e04c3fSmrg 9201e04c3fSmrg /** 9301e04c3fSmrg * Disable a previously-added variable so that it no longer appears to be 9401e04c3fSmrg * in the symbol table. This is necessary when gl_PerVertex is redeclared, 9501e04c3fSmrg * to ensure that previously-available built-in variables are no longer 9601e04c3fSmrg * available. 9701e04c3fSmrg */ 9801e04c3fSmrg void disable_variable(const char *name); 9901e04c3fSmrg 10001e04c3fSmrg /** 10101e04c3fSmrg * Replaces the variable in the entry by the new variable. 10201e04c3fSmrg */ 10301e04c3fSmrg void replace_variable(const char *name, ir_variable *v); 10401e04c3fSmrg 10501e04c3fSmrgprivate: 10601e04c3fSmrg symbol_table_entry *get_entry(const char *name); 10701e04c3fSmrg 10801e04c3fSmrg struct _mesa_symbol_table *table; 10901e04c3fSmrg void *mem_ctx; 11001e04c3fSmrg void *linalloc; 11101e04c3fSmrg}; 11201e04c3fSmrg 11301e04c3fSmrg#endif /* GLSL_SYMBOL_TABLE */ 114