polserver/pol-core/bscript/compiler/analyzer/LocalVariableScopes.h
Eric Swanson 64503c2866
var statements in program blocks (#256)
Adds:
- analyzer/LocalVariableScope: tracks local variables created within a given scope.
  - Instantiated on the stack during semantic analysis, this registers itself with LocalVariableScopes during construction and deregisters itself during destruction.
  - Detects unused variables during deregistration
- analyzer/LocalVariableScopes: this is what LocalVariableScope registers with.
  - keeps track of the stack of local scopes.
  - can provide the current local scope, for var statements.

Other notes:

"Shadowed" variables: this is when a variable in one scope hides a variable in another, like so:
    var a := 2;
    if (a)
        var a := 3;
        a := 4;
    endif
    print(a); // still 2
"debug_variables": We'll use these later when writing debug files.
2020-08-30 01:32:38 -07:00

30 lines
575 B
C++

#ifndef POLSERVER_LOCALVARIABLESCOPES_H
#define POLSERVER_LOCALVARIABLESCOPES_H
#include <vector>
namespace Pol::Bscript::Compiler
{
class LocalVariableScope;
class Report;
class Variables;
class LocalVariableScopes
{
public:
LocalVariableScopes( Variables& locals, Report& report );
LocalVariableScope* current_local_scope();
private:
friend class LocalVariableScope;
Variables& local_variables;
std::vector<LocalVariableScope*> local_variable_scopes;
Report& report;
};
} // namespace Pol::Bscript::Compiler
#endif // POLSERVER_LOCALVARIABLESCOPES_H