/* * Copyright (C) 2014 Patrick Mours * SPDX-License-Identifier: BSD-3-Clause */ #pragma once #include "effect_module.hpp" #include #include // Used for symbol lookup table namespace reshadefx { /// /// A scope encapsulating symbols. /// struct scope { std::string name; uint32_t level, namespace_level; }; /// /// Enumeration of all possible symbol types. /// enum class symbol_type { invalid, variable, constant, function, intrinsic, structure, }; /// /// A single symbol in the symbol table. /// struct symbol { symbol_type op = symbol_type::invalid; uint32_t id = 0; reshadefx::type type = {}; reshadefx::constant constant = {}; const reshadefx::function_info *function = nullptr; }; struct scoped_symbol : symbol { struct scope scope; // Store scope together with symbol data }; /// /// A symbol table managing a list of scopes and symbols. /// class symbol_table { public: symbol_table(); /// /// Enters a new scope as child of the current one. /// void enter_scope(); /// /// Enters a new namespace as child of the current one. /// void enter_namespace(const std::string &name); /// /// Leaves the current scope and enter the parent one. /// void leave_scope(); /// /// Leaves the current namespace and enter the parent one. /// void leave_namespace(); /// /// Gets the current scope the symbol table operates in. /// const scope ¤t_scope() const { return _current_scope; } /// /// Inserts an new symbol in the symbol table. /// Returns if a symbol by that name and type already exists. /// bool insert_symbol(const std::string &name, const symbol &symbol, bool global = false); /// /// Looks for an existing symbol with the specified . /// scoped_symbol find_symbol(const std::string &name) const; scoped_symbol find_symbol(const std::string &name, const scope &scope, bool exclusive) const; /// /// Searches for the best function or intrinsic overload matching the argument list. /// bool resolve_function_call(const std::string &name, const std::vector &args, const scope &scope, symbol &data, bool &ambiguous) const; private: scope _current_scope; // Lookup table from name to matching symbols std::unordered_map> _symbol_stack; }; }