mirror of
https://github.com/PashaBibko/LX.git
synced 2026-04-03 17:39:02 +00:00
Changed how scopes work
Also added logging and GenIR functions for VariableDeclaration
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// Lexer foward declares fstream components so we can use them here //
|
||||
#include <Lexer.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <memory>
|
||||
|
||||
// Foward declares STD stuff that is passed around //
|
||||
@@ -30,6 +30,7 @@ namespace LX::AST
|
||||
|
||||
NUMBER_LITERAL,
|
||||
OPERATION,
|
||||
VARIABLE_DECLARATION,
|
||||
|
||||
// Control flow Nodes //
|
||||
|
||||
@@ -81,18 +82,6 @@ namespace LX
|
||||
class Scope
|
||||
{
|
||||
public:
|
||||
// Struct to store all the info of a variable (excluding name as that is stored in the map) //
|
||||
struct __declspec(novtable) Variable final
|
||||
{
|
||||
// Default constructor //
|
||||
Variable() {}
|
||||
|
||||
// Will hold the type as part of the type here //
|
||||
|
||||
// The value of the variable //
|
||||
llvm::Value* val = nullptr;
|
||||
};
|
||||
|
||||
// Error thrown if the user tried to create a variable that already existed //
|
||||
struct __declspec(novtable) VariableAlreadyExists final {};
|
||||
|
||||
@@ -105,17 +94,14 @@ namespace LX
|
||||
{}
|
||||
|
||||
// Gets a variable from the scope by it's name //
|
||||
Variable* GetVarOfName(const std::string& name);
|
||||
bool DoesVarExist(const std::string& name);
|
||||
|
||||
// Creates a variable of the given name, returns nullptr if a variable with that name already exists //
|
||||
Variable* CreateVar(const std::string& name);
|
||||
// Creates a variable of the given name //
|
||||
void CreateVar(const std::string& name);
|
||||
|
||||
private:
|
||||
// Base logic for getting a variable by it's name without any error checking //
|
||||
Variable* GetVarOfNameImpl(const std::string& name);
|
||||
|
||||
// Holds all the variables in the scope (excluding ones owned by the children //
|
||||
std::unordered_map<std::string, Variable> m_LocalVariables;
|
||||
std::unordered_set<std::string> m_LocalVariables;
|
||||
|
||||
// Holds a section of the scope, for example the variables created in a while loop //
|
||||
std::unique_ptr<Scope> m_Child;
|
||||
|
||||
Reference in New Issue
Block a user