2010-03-19 11:42:45 -07:00
|
|
|
/* -*- c++ -*- */
|
|
|
|
/*
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#ifndef GLSL_SYMBOL_TABLE
|
|
|
|
#define GLSL_SYMBOL_TABLE
|
|
|
|
|
2010-06-23 15:47:04 -07:00
|
|
|
#include <new>
|
|
|
|
|
2010-06-24 17:08:53 -07:00
|
|
|
extern "C" {
|
2010-07-26 17:47:59 -07:00
|
|
|
#include "program/symbol_table.h"
|
2010-06-24 17:08:53 -07:00
|
|
|
}
|
2010-03-19 11:42:45 -07:00
|
|
|
#include "ir.h"
|
|
|
|
#include "glsl_types.h"
|
|
|
|
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
class symbol_table_entry;
|
|
|
|
|
2010-03-19 11:42:45 -07:00
|
|
|
/**
|
|
|
|
* Facade class for _mesa_symbol_table
|
|
|
|
*
|
|
|
|
* Wraps the existing \c _mesa_symbol_table data structure to enforce some
|
|
|
|
* type safe and some symbol table invariants.
|
|
|
|
*/
|
2010-08-14 15:35:57 +01:00
|
|
|
struct glsl_symbol_table {
|
2010-03-19 15:34:13 -07:00
|
|
|
private:
|
2010-06-23 15:47:04 -07:00
|
|
|
static int
|
|
|
|
_glsl_symbol_table_destructor (glsl_symbol_table *table)
|
|
|
|
{
|
|
|
|
table->~glsl_symbol_table();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-19 11:42:45 -07:00
|
|
|
public:
|
2010-06-23 15:47:04 -07:00
|
|
|
/* Callers of this talloc-based new need not call delete. It's
|
|
|
|
* easier to just talloc_free 'ctx' (or any of its ancestors). */
|
|
|
|
static void* operator new(size_t size, void *ctx)
|
|
|
|
{
|
|
|
|
void *table;
|
|
|
|
|
|
|
|
table = talloc_size(ctx, size);
|
|
|
|
assert(table != NULL);
|
|
|
|
|
|
|
|
talloc_set_destructor(table, (int (*)(void*)) _glsl_symbol_table_destructor);
|
|
|
|
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the user *does* call delete, that's OK, we will just
|
|
|
|
* talloc_free in that case. Here, C++ will have already called the
|
|
|
|
* destructor so tell talloc not to do that again. */
|
|
|
|
static void operator delete(void *table)
|
|
|
|
{
|
|
|
|
talloc_set_destructor(table, NULL);
|
|
|
|
talloc_free(table);
|
|
|
|
}
|
|
|
|
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
glsl_symbol_table();
|
|
|
|
~glsl_symbol_table();
|
2010-03-19 11:42:45 -07:00
|
|
|
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
unsigned int language_version;
|
2010-03-19 11:42:45 -07:00
|
|
|
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
void push_scope();
|
|
|
|
void pop_scope();
|
2010-03-19 11:42:45 -07:00
|
|
|
|
2010-03-19 15:37:01 -07:00
|
|
|
/**
|
|
|
|
* Determine whether a name was declared at the current scope
|
|
|
|
*/
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
bool name_declared_this_scope(const char *name);
|
2010-03-19 15:37:01 -07:00
|
|
|
|
2010-03-19 11:42:45 -07:00
|
|
|
/**
|
|
|
|
* \name Methods to add symbols to the table
|
|
|
|
*
|
|
|
|
* There is some temptation to rename all these functions to \c add_symbol
|
|
|
|
* or similar. However, this breaks symmetry with the getter functions and
|
|
|
|
* reduces the clarity of the intention of code that uses these methods.
|
|
|
|
*/
|
|
|
|
/*@{*/
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
bool add_variable(const char *name, ir_variable *v);
|
|
|
|
bool add_type(const char *name, const glsl_type *t,
|
|
|
|
ir_function *constructor = NULL);
|
|
|
|
bool add_function(const char *name, ir_function *f);
|
2010-03-19 11:42:45 -07:00
|
|
|
/*@}*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \name Methods to get symbols from the table
|
|
|
|
*/
|
|
|
|
/*@{*/
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
ir_variable *get_variable(const char *name);
|
|
|
|
const glsl_type *get_type(const char *name);
|
2010-08-25 17:10:16 -07:00
|
|
|
ir_function *get_function(const char *name, bool return_constructors = true);
|
2010-03-19 11:42:45 -07:00
|
|
|
/*@}*/
|
|
|
|
|
|
|
|
private:
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
symbol_table_entry *get_entry(const char *name);
|
|
|
|
|
2010-03-19 11:42:45 -07:00
|
|
|
struct _mesa_symbol_table *table;
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
void *mem_ctx;
|
2010-03-19 11:42:45 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GLSL_SYMBOL_TABLE */
|