KSeExpr 4.0.4.0
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.
 ~ExprVarEnv ()=default
 ExprVarEnv (ExprVarEnv &&)=default
ExprVarEnvoperator= (ExprVarEnv &&)=default
void resetAndSetParent (ExprVarEnv *parent)
 Resets the scope (deletes all variables) and sets parent.
ExprLocalFunctionNodefindFunction (const std::string &name)
 Find a function by name (recursive to parents)
ExprLocalVarfind (const std::string &name)
 Find a variable name by name (recursive to parents)
ExprLocalVar const * lookup (const std::string &name) const
 Find a const variable reference name by name (recursive to parents)
void addFunction (const std::string &name, ExprLocalFunctionNode *prototype)
 Add a function.
void add (const std::string &name, std::unique_ptr< ExprLocalVar > var)
 Add a variable refernece.
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.
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)
std::vector< std::vector< std::pair< std::string, ExprLocalVarPhi * > > > _mergedVariables
 Keep track of all merged variables in.
ExprVarEnv_parent {nullptr}
 Parent variable environment has all variablesf rom previou scope (for lookup)

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

References ExprVarEnv().

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, and _parent.

◆ codegenMerges()

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

References LLVM_BASE.

◆ 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, and _parent.

Referenced by 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, and _parent.

Referenced by 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, and _parent.

◆ 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.

◆ 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(), ExprVarEnv(), and find().

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

◆ operator=() [1/2]

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

References ExprVarEnv().

◆ operator=() [2/2]

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

References ExprVarEnv().

◆ 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, and ExprVarEnv().

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: