nixd
Loading...
Searching...
No Matches
nixf::VariableLookupAnalysis Class Reference

#include <VariableLookup.h>

Classes

struct  LookupResult

Public Types

enum class  LookupResultKind { Undefined , FromWith , Defined , NoSuchVar }
using ToDefMap = std::map<const Node *, std::shared_ptr<Definition>>
using EnvMap = std::map<const Node *, std::shared_ptr<EnvNode>>

Public Member Functions

 VariableLookupAnalysis (std::vector< Diagnostic > &Diags)
void runOnAST (const Node &Root)
 Perform variable lookup analysis (def-use) on AST.
LookupResult query (const ExprVar &Var) const
 Query the which name/with binds to specific varaible.
const DefinitiontoDef (const Node &N) const
 Get definition record for some name.
const EnvNodeenv (const Node *N) const
std::vector< const ExprWith * > getWithScopes (const ExprVar &Var) const
 Get all with expressions that could provide the binding for a variable.

Detailed Description

Definition at line 112 of file VariableLookup.h.

Member Typedef Documentation

◆ EnvMap

using nixf::VariableLookupAnalysis::EnvMap = std::map<const Node *, std::shared_ptr<EnvNode>>

Definition at line 127 of file VariableLookup.h.

◆ ToDefMap

using nixf::VariableLookupAnalysis::ToDefMap = std::map<const Node *, std::shared_ptr<Definition>>

Definition at line 126 of file VariableLookup.h.

Member Enumeration Documentation

◆ LookupResultKind

Enumerator
Undefined 
FromWith 
Defined 
NoSuchVar 

Definition at line 114 of file VariableLookup.h.

Constructor & Destructor Documentation

◆ VariableLookupAnalysis()

VariableLookupAnalysis::VariableLookupAnalysis ( std::vector< Diagnostic > & Diags)

Definition at line 514 of file VariableLookup.cpp.

Member Function Documentation

◆ env()

const EnvNode * VariableLookupAnalysis::env ( const Node * N) const

Definition at line 517 of file VariableLookup.cpp.

Referenced by nixd::upEnv().

◆ getWithScopes()

std::vector< const ExprWith * > nixf::VariableLookupAnalysis::getWithScopes ( const ExprVar & Var) const
inlinenodiscard

Get all with expressions that could provide the binding for a variable.

For variables resolved from with scopes, multiple enclosing with expressions may potentially provide the binding. This method returns all such with expressions, ordered from innermost to outermost.

This is useful for detecting indirect nested with scenarios where converting an outer with to let/inherit could change semantics.

Parameters
VarThe variable to query.
Returns
A vector of ExprWith pointers representing all with scopes that could provide the variable's binding. Returns an empty vector if the variable is not resolved from a with scope.

Definition at line 223 of file VariableLookup.h.

◆ query()

LookupResult nixf::VariableLookupAnalysis::query ( const ExprVar & Var) const
inlinenodiscard

Query the which name/with binds to specific varaible.

Definition at line 182 of file VariableLookup.h.

References NoSuchVar.

Referenced by nixd::addToFormalsAction(), and nixd::idioms::mkVarSelector().

◆ runOnAST()

void VariableLookupAnalysis::runOnAST ( const Node & Root)

Perform variable lookup analysis (def-use) on AST.

Note
This method should be invoked after any other method called.
The result remains immutable thus it can be shared among threads.

Definition at line 491 of file VariableLookup.cpp.

References nixf::PrimOpsInfo.

Referenced by main().

◆ toDef()

const Definition * nixf::VariableLookupAnalysis::toDef ( const Node & N) const
inlinenodiscard

Get definition record for some name.

For some cases, we need to get "definition" record to find all references to this definition, on AST.

Thus we need to store AST -> Definition There are many pointers on AST, the convention is:

  1. attrname "key" syntax is recorded.

"with" keyword is recorded.

  1. Lambda arguments, record its identifier.

Definition at line 200 of file VariableLookup.h.


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