polserver/pol-core/bscript/compiler/analyzer/Variables.h
Eric Swanson 9bbc0518f8
Compiler rewrite: add global variables (#241)
Adds support for var statements at the global level.

Adds:
- analyzer/Variables: keeps track of the variables in scope (either local or global).
- ast/Identifier: AST node for an identifier.
  - The optimizer will replace constant identifiers with their constant value (in a later commit).
  - The semantic analyzer will set the variable field for local or global variable identifiers.
- ast/VarStatement: AST node for a var statement.
  - A single var statement will generate one VarStatement per variable declared.
- model/Variable: Describes a variable, including its index within its scope.
2020-08-25 00:57:03 -07:00

44 lines
998 B
C++

#ifndef POLSERVER_VARIABLES_H
#define POLSERVER_VARIABLES_H
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "clib/maputil.h"
#include "compiler/model/VariableScope.h"
#include "compiler/model/WarnOn.h"
namespace Pol::Bscript::Compiler
{
class Report;
class SourceLocation;
class Variable;
class Variables
{
public:
Variables( VariableScope, Report& );
std::shared_ptr<Variable> create( const std::string& name, unsigned block_depth,
WarnOn, const SourceLocation& );
std::shared_ptr<Variable> find( const std::string& name ) const;
const std::vector<std::string>& get_names() const;
unsigned count() const;
private:
const VariableScope scope;
Report& report;
typedef std::map<std::string, std::shared_ptr<Variable>, Clib::ci_cmp_pred> VariableMap;
VariableMap variables_by_name;
std::vector<std::string> names_by_index;
};
} // namespace Pol::Bscript::Compiler
#endif // POLSERVER_SCRIPTVARIABLES_H