1b8e80941Smrg/* -*- c++ -*- */
2b8e80941Smrg/*
3b8e80941Smrg * Copyright © 2010 Intel Corporation
4b8e80941Smrg *
5b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6b8e80941Smrg * copy of this software and associated documentation files (the "Software"),
7b8e80941Smrg * to deal in the Software without restriction, including without limitation
8b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the
10b8e80941Smrg * Software is furnished to do so, subject to the following conditions:
11b8e80941Smrg *
12b8e80941Smrg * The above copyright notice and this permission notice (including the next
13b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the
14b8e80941Smrg * Software.
15b8e80941Smrg *
16b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22b8e80941Smrg * DEALINGS IN THE SOFTWARE.
23b8e80941Smrg */
24b8e80941Smrg
25b8e80941Smrg#ifndef GLSL_SYMBOL_TABLE
26b8e80941Smrg#define GLSL_SYMBOL_TABLE
27b8e80941Smrg
28b8e80941Smrg#include <new>
29b8e80941Smrg
30b8e80941Smrg#include "program/symbol_table.h"
31b8e80941Smrg#include "ir.h"
32b8e80941Smrg
33b8e80941Smrgclass symbol_table_entry;
34b8e80941Smrgstruct glsl_type;
35b8e80941Smrg
36b8e80941Smrg/**
37b8e80941Smrg * Facade class for _mesa_symbol_table
38b8e80941Smrg *
39b8e80941Smrg * Wraps the existing \c _mesa_symbol_table data structure to enforce some
40b8e80941Smrg * type safe and some symbol table invariants.
41b8e80941Smrg */
42b8e80941Smrgstruct glsl_symbol_table {
43b8e80941Smrg   DECLARE_RALLOC_CXX_OPERATORS(glsl_symbol_table)
44b8e80941Smrg
45b8e80941Smrg   glsl_symbol_table();
46b8e80941Smrg   ~glsl_symbol_table();
47b8e80941Smrg
48b8e80941Smrg   /* In 1.10, functions and variables have separate namespaces. */
49b8e80941Smrg   bool separate_function_namespace;
50b8e80941Smrg
51b8e80941Smrg   void push_scope();
52b8e80941Smrg   void pop_scope();
53b8e80941Smrg
54b8e80941Smrg   /**
55b8e80941Smrg    * Determine whether a name was declared at the current scope
56b8e80941Smrg    */
57b8e80941Smrg   bool name_declared_this_scope(const char *name);
58b8e80941Smrg
59b8e80941Smrg   /**
60b8e80941Smrg    * \name Methods to add symbols to the table
61b8e80941Smrg    *
62b8e80941Smrg    * There is some temptation to rename all these functions to \c add_symbol
63b8e80941Smrg    * or similar.  However, this breaks symmetry with the getter functions and
64b8e80941Smrg    * reduces the clarity of the intention of code that uses these methods.
65b8e80941Smrg    */
66b8e80941Smrg   /*@{*/
67b8e80941Smrg   bool add_variable(ir_variable *v);
68b8e80941Smrg   bool add_type(const char *name, const glsl_type *t);
69b8e80941Smrg   bool add_function(ir_function *f);
70b8e80941Smrg   bool add_interface(const char *name, const glsl_type *i,
71b8e80941Smrg                      enum ir_variable_mode mode);
72b8e80941Smrg   bool add_default_precision_qualifier(const char *type_name, int precision);
73b8e80941Smrg   /*@}*/
74b8e80941Smrg
75b8e80941Smrg   /**
76b8e80941Smrg    * Add an function at global scope without checking for scoping conflicts.
77b8e80941Smrg    */
78b8e80941Smrg   void add_global_function(ir_function *f);
79b8e80941Smrg
80b8e80941Smrg   /**
81b8e80941Smrg    * \name Methods to get symbols from the table
82b8e80941Smrg    */
83b8e80941Smrg   /*@{*/
84b8e80941Smrg   ir_variable *get_variable(const char *name);
85b8e80941Smrg   const glsl_type *get_type(const char *name);
86b8e80941Smrg   ir_function *get_function(const char *name);
87b8e80941Smrg   const glsl_type *get_interface(const char *name,
88b8e80941Smrg                                  enum ir_variable_mode mode);
89b8e80941Smrg   int get_default_precision_qualifier(const char *type_name);
90b8e80941Smrg   /*@}*/
91b8e80941Smrg
92b8e80941Smrg   /**
93b8e80941Smrg    * Disable a previously-added variable so that it no longer appears to be
94b8e80941Smrg    * in the symbol table.  This is necessary when gl_PerVertex is redeclared,
95b8e80941Smrg    * to ensure that previously-available built-in variables are no longer
96b8e80941Smrg    * available.
97b8e80941Smrg    */
98b8e80941Smrg   void disable_variable(const char *name);
99b8e80941Smrg
100b8e80941Smrg   /**
101b8e80941Smrg    * Replaces the variable in the entry by the new variable.
102b8e80941Smrg    */
103b8e80941Smrg   void replace_variable(const char *name, ir_variable *v);
104b8e80941Smrg
105b8e80941Smrgprivate:
106b8e80941Smrg   symbol_table_entry *get_entry(const char *name);
107b8e80941Smrg
108b8e80941Smrg   struct _mesa_symbol_table *table;
109b8e80941Smrg   void *mem_ctx;
110b8e80941Smrg   void *linalloc;
111b8e80941Smrg};
112b8e80941Smrg
113b8e80941Smrg#endif /* GLSL_SYMBOL_TABLE */
114