Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 1 | /* -*- c++ -*- */ |
2 | /* |
||
3 | * Copyright © 2010 Intel Corporation |
||
4 | * |
||
5 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
6 | * copy of this software and associated documentation files (the "Software"), |
||
7 | * to deal in the Software without restriction, including without limitation |
||
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
9 | * and/or sell copies of the Software, and to permit persons to whom the |
||
10 | * Software is furnished to do so, subject to the following conditions: |
||
11 | * |
||
12 | * The above copyright notice and this permission notice (including the next |
||
13 | * paragraph) shall be included in all copies or substantial portions of the |
||
14 | * Software. |
||
15 | * |
||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||
22 | * DEALINGS IN THE SOFTWARE. |
||
23 | */ |
||
24 | |||
25 | #pragma once |
||
26 | #ifndef GLSL_SYMBOL_TABLE |
||
27 | #define GLSL_SYMBOL_TABLE |
||
28 | |||
29 | #include |
||
30 | |||
31 | extern "C" { |
||
32 | #include "program/symbol_table.h" |
||
33 | } |
||
34 | #include "ir.h" |
||
35 | #include "glsl_types.h" |
||
36 | |||
37 | class symbol_table_entry; |
||
38 | |||
39 | /** |
||
40 | * Facade class for _mesa_symbol_table |
||
41 | * |
||
42 | * Wraps the existing \c _mesa_symbol_table data structure to enforce some |
||
43 | * type safe and some symbol table invariants. |
||
44 | */ |
||
45 | struct glsl_symbol_table { |
||
46 | private: |
||
47 | static void |
||
48 | _glsl_symbol_table_destructor (glsl_symbol_table *table) |
||
49 | { |
||
50 | table->~glsl_symbol_table(); |
||
51 | } |
||
52 | |||
53 | public: |
||
54 | /* Callers of this ralloc-based new need not call delete. It's |
||
55 | * easier to just ralloc_free 'ctx' (or any of its ancestors). */ |
||
56 | static void* operator new(size_t size, void *ctx) |
||
57 | { |
||
58 | void *table; |
||
59 | |||
60 | table = ralloc_size(ctx, size); |
||
61 | assert(table != NULL); |
||
62 | |||
63 | ralloc_set_destructor(table, (void (*)(void*)) _glsl_symbol_table_destructor); |
||
64 | |||
65 | return table; |
||
66 | } |
||
67 | |||
68 | /* If the user *does* call delete, that's OK, we will just |
||
69 | * ralloc_free in that case. Here, C++ will have already called the |
||
70 | * destructor so tell ralloc not to do that again. */ |
||
71 | static void operator delete(void *table) |
||
72 | { |
||
73 | ralloc_set_destructor(table, NULL); |
||
74 | ralloc_free(table); |
||
75 | } |
||
76 | |||
77 | glsl_symbol_table(); |
||
78 | ~glsl_symbol_table(); |
||
79 | |||
80 | /* In 1.10, functions and variables have separate namespaces. */ |
||
81 | bool separate_function_namespace; |
||
82 | |||
83 | void push_scope(); |
||
84 | void pop_scope(); |
||
85 | |||
86 | /** |
||
87 | * Determine whether a name was declared at the current scope |
||
88 | */ |
||
89 | bool name_declared_this_scope(const char *name); |
||
90 | |||
91 | /** |
||
92 | * \name Methods to add symbols to the table |
||
93 | * |
||
94 | * There is some temptation to rename all these functions to \c add_symbol |
||
95 | * or similar. However, this breaks symmetry with the getter functions and |
||
96 | * reduces the clarity of the intention of code that uses these methods. |
||
97 | */ |
||
98 | /*@{*/ |
||
99 | bool add_variable(ir_variable *v); |
||
100 | bool add_type(const char *name, const glsl_type *t); |
||
101 | bool add_type_ast(const char *name, const class ast_type_specifier *t); |
||
102 | bool add_function(ir_function *f); |
||
103 | bool add_interface(const char *name, const glsl_type *i, |
||
104 | enum ir_variable_mode mode); |
||
105 | /*@}*/ |
||
106 | |||
107 | /** |
||
108 | * Add an function at global scope without checking for scoping conflicts. |
||
109 | */ |
||
110 | void add_global_function(ir_function *f); |
||
111 | |||
112 | /** |
||
113 | * \name Methods to get symbols from the table |
||
114 | */ |
||
115 | /*@{*/ |
||
116 | ir_variable *get_variable(const char *name); |
||
117 | const glsl_type *get_type(const char *name); |
||
118 | const class ast_type_specifier *get_type_ast(const char *name); |
||
119 | ir_function *get_function(const char *name); |
||
120 | const glsl_type *get_interface(const char *name, |
||
121 | enum ir_variable_mode mode); |
||
122 | /*@}*/ |
||
123 | |||
124 | private: |
||
125 | symbol_table_entry *get_entry(const char *name); |
||
126 | |||
127 | struct _mesa_symbol_table *table; |
||
128 | void *mem_ctx; |
||
129 | }; |
||
130 | |||
131 | #endif /* GLSL_SYMBOL_TABLE */ |