KSeExpr  4.0.4.0
Public Member Functions | Protected Member Functions | Private Types | Private Attributes | List of all members
KSeExpr::ExprVarEnv Class Reference

Variable scope for tracking variable lookup. More...

#include <ExprEnv.h>

Public Member Functions

 ExprVarEnv ()=default
 Create a scope with no parent. More...
 
 ~ExprVarEnv ()=default
 
 ExprVarEnv (ExprVarEnv &&)=default
 
ExprVarEnvoperator= (ExprVarEnv &&)=default
 
void resetAndSetParent (ExprVarEnv *parent)
 Resets the scope (deletes all variables) and sets parent. More...
 
ExprLocalFunctionNodefindFunction (const std::string &name)
 Find a function by name (recursive to parents) More...
 
ExprLocalVarfind (const std::string &name)
 Find a variable name by name (recursive to parents) More...
 
ExprLocalVar const * lookup (const std::string &name) const
 Find a const variable reference name by name (recursive to parents) More...
 
void addFunction (const std::string &name, ExprLocalFunctionNode *prototype)
 Add a function. More...
 
void add (const std::string &name, std::unique_ptr< ExprLocalVar > var)
 Add a variable refernece. More...
 
size_t mergeBranches (const ExprType &type, ExprVarEnv &env1, ExprVarEnv &env2)
 Add all variables into scope by name, but modify their lifetimes to the given type's lifetime. More...
 
LLVM_VALUE codegenMerges (LLVM_BUILDER, int) LLVM_BASE
 
std::vector< std::pair< std::string, ExprLocalVarPhi * > > & merge (size_t index)
 

Protected Member Functions

 ExprVarEnv (ExprVarEnv &other)
 
ExprVarEnvoperator= (const ExprVarEnv &other)
 

Private Types

using VarDictType = std::map< std::string, std::unique_ptr< ExprLocalVar > >
 
using FuncDictType = std::map< std::string, ExprLocalFunctionNode * >
 

Private Attributes

VarDictType _map
 
FuncDictType _functions
 
std::vector< std::unique_ptr< ExprLocalVar > > shadowedVariables
 Variables that have been superceded (and thus are inaccessible) More...
 
std::vector< std::vector< std::pair< std::string, ExprLocalVarPhi * > > > _mergedVariables
 Keep track of all merged variables in. More...
 
ExprVarEnv_parent {nullptr}
 Parent variable environment has all variablesf rom previou scope (for lookup) More...
 

Detailed Description

Variable scope for tracking variable lookup.

Definition at line 119 of file ExprEnv.h.

Member Typedef Documentation

◆ FuncDictType

using KSeExpr::ExprVarEnv::FuncDictType = std::map<std::string, ExprLocalFunctionNode *>
private

Definition at line 124 of file ExprEnv.h.

◆ VarDictType

using KSeExpr::ExprVarEnv::VarDictType = std::map<std::string, std::unique_ptr<ExprLocalVar> >
private

Definition at line 122 of file ExprEnv.h.

Constructor & Destructor Documentation

◆ ExprVarEnv() [1/3]

KSeExpr::ExprVarEnv::ExprVarEnv ( ExprVarEnv other)
protected

◆ ExprVarEnv() [2/3]

KSeExpr::ExprVarEnv::ExprVarEnv ( )
default

Create a scope with no parent.

◆ ~ExprVarEnv()

KSeExpr::ExprVarEnv::~ExprVarEnv ( )
default

◆ ExprVarEnv() [3/3]

KSeExpr::ExprVarEnv::ExprVarEnv ( ExprVarEnv &&  )
default

Member Function Documentation

◆ add()

void KSeExpr::ExprVarEnv::add ( const std::string &  name,
std::unique_ptr< ExprLocalVar var 
)

Add a variable refernece.

Definition at line 63 of file ExprEnv.cpp.

References _map, and shadowedVariables.

Referenced by mergeBranches(), and KSeExpr::ExprAssignNode::prep().

◆ addFunction()

void KSeExpr::ExprVarEnv::addFunction ( const std::string &  name,
ExprLocalFunctionNode prototype 
)

Add a function.

Definition at line 49 of file ExprEnv.cpp.

References _functions, _parent, and addFunction().

Referenced by addFunction().

◆ codegenMerges()

LLVM_VALUE KSeExpr::ExprVarEnv::codegenMerges ( LLVM_BUILDER  ,
int   
)

◆ find()

ExprLocalVar * KSeExpr::ExprVarEnv::find ( const std::string &  name)

Find a variable name by name (recursive to parents)

Definition at line 17 of file ExprEnv.cpp.

References _map, _parent, and find().

Referenced by find(), mergeBranches(), and KSeExpr::ExprVarNode::prep().

◆ findFunction()

ExprLocalFunctionNode * KSeExpr::ExprVarEnv::findFunction ( const std::string &  name)

Find a function by name (recursive to parents)

Definition at line 28 of file ExprEnv.cpp.

References _functions, _parent, and findFunction().

Referenced by findFunction(), and KSeExpr::ExprFuncNode::prep().

◆ lookup()

ExprLocalVar const * KSeExpr::ExprVarEnv::lookup ( const std::string &  name) const

Find a const variable reference name by name (recursive to parents)

Definition at line 39 of file ExprEnv.cpp.

References _map, _parent, and lookup().

Referenced by lookup().

◆ merge()

std::vector<std::pair<std::string, ExprLocalVarPhi *> >& KSeExpr::ExprVarEnv::merge ( size_t  index)
inline

Definition at line 171 of file ExprEnv.h.

References _mergedVariables.

Referenced by KSeExpr::ExprIfThenElseNode::buildInterpreter().

◆ mergeBranches()

size_t KSeExpr::ExprVarEnv::mergeBranches ( const ExprType type,
ExprVarEnv env1,
ExprVarEnv env2 
)

Add all variables into scope by name, but modify their lifetimes to the given type's lifetime.

Checks if each branch shares the same items and the same types!

For each thing in env1 see if env2 has an entry

For each thing in env2 see if env1 has an entry

Definition at line 74 of file ExprEnv.cpp.

References _map, _mergedVariables, add(), and find().

Referenced by KSeExpr::ExprIfThenElseNode::prep().

◆ operator=() [1/2]

ExprVarEnv& KSeExpr::ExprVarEnv::operator= ( const ExprVarEnv other)
protected

◆ operator=() [2/2]

ExprVarEnv& KSeExpr::ExprVarEnv::operator= ( ExprVarEnv &&  )
default

◆ resetAndSetParent()

void KSeExpr::ExprVarEnv::resetAndSetParent ( ExprVarEnv parent)

Resets the scope (deletes all variables) and sets parent.

Definition at line 12 of file ExprEnv.cpp.

References _parent.

Referenced by KSeExpr::ExprLocalFunctionNode::prep().

Member Data Documentation

◆ _functions

FuncDictType KSeExpr::ExprVarEnv::_functions
private

Definition at line 125 of file ExprEnv.h.

Referenced by addFunction(), and findFunction().

◆ _map

VarDictType KSeExpr::ExprVarEnv::_map
private

Definition at line 123 of file ExprEnv.h.

Referenced by add(), find(), lookup(), and mergeBranches().

◆ _mergedVariables

std::vector<std::vector<std::pair<std::string, ExprLocalVarPhi *> > > KSeExpr::ExprVarEnv::_mergedVariables
private

Keep track of all merged variables in.

Definition at line 132 of file ExprEnv.h.

Referenced by merge(), and mergeBranches().

◆ _parent

ExprVarEnv* KSeExpr::ExprVarEnv::_parent {nullptr}
private

Parent variable environment has all variablesf rom previou scope (for lookup)

Definition at line 135 of file ExprEnv.h.

Referenced by addFunction(), find(), findFunction(), lookup(), and resetAndSetParent().

◆ shadowedVariables

std::vector<std::unique_ptr<ExprLocalVar> > KSeExpr::ExprVarEnv::shadowedVariables
private

Variables that have been superceded (and thus are inaccessible)

Definition at line 129 of file ExprEnv.h.

Referenced by add().


The documentation for this class was generated from the following files: