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 21, 2023
1 parent 55355c6 commit 4198959
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);
const auto *Fn = dynamic_cast<const syntax::Function *>(Root);
return lowerFunction(Fn);
}
case Node::NK_Assert: {
auto *Assert = dynamic_cast<syntax::Assert *>(Root);
const 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);
const 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);
const auto *Binds = dynamic_cast<const syntax::Binds *>(Root);
return lowerBinds(*Binds);
}
case Node::NK_AttrSet: {
auto *AttrSet = dynamic_cast<syntax::AttrSet *>(Root);
const 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 4198959

Please sign in to comment.