58 std::vector<const ExprVar *> Uses;
64 : Syntax(Syntax), Source(Source) {}
67 : Uses(std::move(Uses)), Syntax(Syntax), Source(Source) {}
69 [[nodiscard]]
const Node *
syntax()
const {
return Syntax; }
71 [[nodiscard]]
const std::vector<const ExprVar *> &
uses()
const {
85 using DefMap = std::map<std::string, std::shared_ptr<Definition>>;
88 const std::shared_ptr<EnvNode> Parent;
96 : Parent(std::move(Parent)), Defs(std::move(Defs)), Syntax(Syntax) {}
104 return Syntax && Syntax->
kind() == Node::NK_ExprWith;
109 [[nodiscard]]
bool isLive()
const;
123 std::shared_ptr<const Definition>
Def;
126 using ToDefMap = std::map<const Node *, std::shared_ptr<Definition>>;
127 using EnvMap = std::map<const Node *, std::shared_ptr<EnvNode>>;
130 std::vector<Diagnostic> &Diags;
132 std::map<const Node *, std::shared_ptr<Definition>>
141 void lookupVar(
const ExprVar &Var,
const std::shared_ptr<EnvNode> &Env);
143 std::shared_ptr<EnvNode> dfsAttrs(
const SemaAttrs &SA,
144 const std::shared_ptr<EnvNode> &Env,
148 void emitEnvLivenessWarning(
const std::shared_ptr<EnvNode> &NewEnv);
150 void dfsDynamicAttrs(
const std::vector<Attribute> &DynamicAttrs,
151 const std::shared_ptr<EnvNode> &Env);
154 void dfs(
const ExprLambda &Lambda,
const std::shared_ptr<EnvNode> &Env);
155 void dfs(
const ExprAttrs &Attrs,
const std::shared_ptr<EnvNode> &Env);
156 void dfs(
const ExprLet &Let,
const std::shared_ptr<EnvNode> &Env);
157 void dfs(
const ExprWith &With,
const std::shared_ptr<EnvNode> &Env);
159 void dfs(
const Node &Root,
const std::shared_ptr<EnvNode> &Env);
161 void trivialDispatch(
const Node &Root,
const std::shared_ptr<EnvNode> &Env);
163 std::map<const ExprVar *, LookupResult> Results;
175 if (!Results.contains(&Var))
177 return Results.at(&Var);
193 if (ToDef.contains(&N))
194 return ToDef.at(&N).get();
void usedBy(const ExprVar &User)
Definition(const Node *Syntax, DefinitionSource Source)
const Node * syntax() const
Definition(std::vector< const ExprVar * > Uses, const Node *Syntax, DefinitionSource Source)
DefinitionSource source() const
const std::vector< const ExprVar * > & uses() const
DefinitionSource
"Source" information so we can know where the def comes from.
@ DS_Rec
From recursive attribute set. e.g. rec { }.
@ DS_LambdaArg
From ambda arg e.g. a: a + 1.
@ DS_LambdaNoArg_Formal
From lambda (noarg) formal, e.g. { a }: a + 1.
@ DS_Builtin
Builtin names.
@ DS_LambdaWithArg_Arg
From lambda (with @arg) arg, e.g. a in { foo }@a: foo + 1
@ DS_With
From with <expr>;.
@ DS_LambdaWithArg_Formal
From lambda (with @arg) formal, e.g. foo in { foo }@a: foo + 1
@ DS_Let
From let ... in ...
A set of variable definitions, which may inherit parent environment.
const Node * syntax() const
Where this node comes from.
std::map< std::string, std::shared_ptr< Definition > > DefMap
EnvNode(std::shared_ptr< EnvNode > Parent, DefMap Defs, const Node *Syntax)
const DefMap & defs() const
Attribute set after deduplication.
const EnvNode * env(const Node *N) const
std::map< const Node *, std::shared_ptr< Definition > > ToDefMap
const Definition * toDef(const Node &N) const
Get definition record for some name.
std::map< const Node *, std::shared_ptr< EnvNode > > EnvMap
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.
VariableLookupAnalysis(std::vector< Diagnostic > &Diags)
std::shared_ptr< const Definition > Def