Skip to content

Commit

Permalink
nixd/Sema: const-correctness for the Lowering class
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Sep 20, 2023
1 parent 5c3dfdc commit cb890d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions nixd/include/nixd/Sema/Lowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ struct Lowering {
std::vector<syntax::Diagnostic> &Diags;
EvalContext &Ctx;

nix::Expr *lower(syntax::Node *Root);
nix::ExprLambda *lowerFunction(syntax::Function *Fn);
nix::Expr *lower(const syntax::Node *Root);
nix::ExprLambda *lowerFunction(const syntax::Function *Fn);
nix::Formal lowerFormal(const syntax::Formal &Formal);
nix::AttrPath lowerAttrPath(const syntax::AttrPath &Path);
nix::ExprAttrs *lowerBinds(const syntax::Binds &Binds);
Expand Down
14 changes: 7 additions & 7 deletions nixd/lib/Sema/Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ nix::Formal Lowering::lowerFormal(const syntax::Formal &Formal) {
return F;
}

nix::ExprLambda *Lowering::lowerFunction(syntax::Function *Fn) {
nix::ExprLambda *Lowering::lowerFunction(const syntax::Function *Fn) {
// Implementation note:
// The official parser does this in the semantic action, and we deferred it
// here, as a part of the progressive lowering process.
Expand Down Expand Up @@ -218,37 +218,37 @@ nix::ExprAttrs *Lowering::lowerBinds(const syntax::Binds &Binds) {
return Builder.finish();
}

nix::Expr *Lowering::lower(nixd::syntax::Node *Root) {
nix::Expr *Lowering::lower(const nixd::syntax::Node *Root) {
if (!Root)
return nullptr;

switch (Root->getKind()) {
case Node::NK_Function: {
auto *Fn = dynamic_cast<syntax::Function *>(Root);
auto *Fn = dynamic_cast<const syntax::Function *>(Root);
return lowerFunction(Fn);
}
case Node::NK_Assert: {
auto *Assert = dynamic_cast<syntax::Assert *>(Root);
auto *Assert = dynamic_cast<const syntax::Assert *>(Root);
auto *Cond = lower(Assert->Cond);
auto *Body = lower(Assert->Body);
auto *NixAssert =
Ctx.Pool.record(new nix::ExprAssert(Assert->Range.Begin, Cond, Body));
return NixAssert;
}
case Node::NK_With: {
auto *With = dynamic_cast<syntax::With *>(Root);
auto *With = dynamic_cast<const syntax::With *>(Root);
auto *Attrs = lower(With->Attrs);
auto *Body = lower(With->Body);
auto *NixWith =
Ctx.Pool.record(new nix::ExprWith(With->Range.Begin, Attrs, Body));
return NixWith;
}
case Node::NK_Binds: {
auto *Binds = dynamic_cast<syntax::Binds *>(Root);
auto *Binds = dynamic_cast<const syntax::Binds *>(Root);
return lowerBinds(*Binds);
}
case Node::NK_AttrSet: {
auto *AttrSet = dynamic_cast<syntax::AttrSet *>(Root);
auto *AttrSet = dynamic_cast<const syntax::AttrSet *>(Root);
assert(AttrSet->AttrBinds && "null AttrBinds of the AttrSet!");
nix::ExprAttrs *Binds = lowerBinds(*AttrSet->AttrBinds);
Binds->recursive = AttrSet->Recursive;
Expand Down

0 comments on commit cb890d0

Please sign in to comment.