about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2020-08-21T02·29+0100
committertazjin <mail@tazj.in>2020-08-21T03·55+0000
commit1443298657156107704b5d9fcfa7356ee8fa8789 (patch)
tree3c4009acabdc90799d11084dbe5df58f39b90beb /third_party/nix/src/libexpr
parent7edbe59c6c70cd085fc68c4317c3a71a40ac21e5 (diff)
style(tvix): Add missing braces in expressions r/1703
The previous clang-tidy invocation missed some header files, which has
now been rectified.

Change-Id: I31547754fbf52f439dc7aeefb08ab90bd50c4156
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1831
Reviewed-by: glittershark <grfn@gws.fyi>
Tested-by: BuildkiteCI
Diffstat (limited to 'third_party/nix/src/libexpr')
-rw-r--r--third_party/nix/src/libexpr/parser.cc25
-rw-r--r--third_party/nix/src/libexpr/parser.hh6
-rw-r--r--third_party/nix/src/libexpr/primops/context.cc13
-rw-r--r--third_party/nix/src/libexpr/primops/fetchGit.cc25
-rw-r--r--third_party/nix/src/libexpr/primops/fetchMercurial.cc15
-rw-r--r--third_party/nix/src/libexpr/primops/fromTOML.cc26
6 files changed, 68 insertions, 42 deletions
diff --git a/third_party/nix/src/libexpr/parser.cc b/third_party/nix/src/libexpr/parser.cc
index 29d31661c896..756fdfa12819 100644
--- a/third_party/nix/src/libexpr/parser.cc
+++ b/third_party/nix/src/libexpr/parser.cc
@@ -85,9 +85,10 @@ void addAttr(ExprAttrs* attrs, AttrPath& attrPath, Expr* e, const Pos& pos) {
 }
 
 void addFormal(const Pos& pos, Formals* formals, const Formal& formal) {
-  if (formals->argNames.find(formal.name) != formals->argNames.end())
+  if (formals->argNames.find(formal.name) != formals->argNames.end()) {
     throw ParseError(format("duplicate formal function argument '%1%' at %2%") %
                      formal.name % pos);
+  }
   formals->formals.push_front(formal);
   formals->argNames.insert(formal.name);
 }
@@ -117,9 +118,9 @@ Expr* stripIndentation(const Pos& pos, SymbolTable& symbols, VectorExprs& es) {
     }
     for (size_t j = 0; j < e->s.size(); ++j) {
       if (atStartOfLine) {
-        if (e->s[j] == ' ')
+        if (e->s[j] == ' ') {
           curIndent++;
-        else if (e->s[j] == '\n') {
+        } else if (e->s[j] == '\n') {
           /* Empty line, doesn't influence minimum
              indentation. */
           curIndent = 0;
@@ -154,7 +155,9 @@ Expr* stripIndentation(const Pos& pos, SymbolTable& symbols, VectorExprs& es) {
     for (size_t j = 0; j < e->s.size(); ++j) {
       if (atStartOfLine) {
         if (e->s[j] == ' ') {
-          if (curDropped++ >= minIndent) s2 += e->s[j];
+          if (curDropped++ >= minIndent) {
+            s2 += e->s[j];
+          }
         } else if (e->s[j] == '\n') {
           curDropped = 0;
           s2 += e->s[j];
@@ -197,8 +200,9 @@ Path resolveExprPath(Path path) {
      path references work. */
   struct stat st;
   while (true) {
-    if (lstat(path.c_str(), &st))
+    if (lstat(path.c_str(), &st)) {
       throw SysError(format("getting status of '%1%'") % path);
+    }
     if (!S_ISLNK(st.st_mode)) {
       break;
     }
@@ -206,7 +210,9 @@ Path resolveExprPath(Path path) {
   }
 
   /* If `path' refers to a directory, append `/default.nix'. */
-  if (S_ISDIR(st.st_mode)) path = canonPath(path + "/default.nix");
+  if (S_ISDIR(st.st_mode)) {
+    path = canonPath(path + "/default.nix");
+  }
 
   return path;
 }
@@ -259,13 +265,14 @@ Path EvalState::findFile(SearchPath& searchPath, const std::string& path,
                          const Pos& pos) {
   for (auto& i : searchPath) {
     std::string suffix;
-    if (i.first.empty())
+    if (i.first.empty()) {
       suffix = "/" + path;
-    else {
+    } else {
       auto s = i.first.size();
       if (path.compare(0, s, i.first) != 0 ||
-          (path.size() > s && path[s] != '/'))
+          (path.size() > s && path[s] != '/')) {
         continue;
+      }
       suffix = path.size() == s ? "" : "/" + std::string(path, s);
     }
     auto r = resolveSearchPathElem(i);
diff --git a/third_party/nix/src/libexpr/parser.hh b/third_party/nix/src/libexpr/parser.hh
index a79e2cad281f..70b5450b5aa8 100644
--- a/third_party/nix/src/libexpr/parser.hh
+++ b/third_party/nix/src/libexpr/parser.hh
@@ -79,16 +79,18 @@ static Expr* unescapeStr(SymbolTable& symbols, const char* s, size_t length) {
         t += '\r';
       } else if (c == 't') {
         t += '\t';
-      } else
+      } else {
         t += c;
+      }
     } else if (c == '\r') {
       /* Normalise CR and CR/LF into LF. */
       t += '\n';
       if (*s == '\n') {
         s++;
       } /* cr/lf */
-    } else
+    } else {
       t += c;
+    }
   }
   return new ExprString(symbols.Create(t));
 }
diff --git a/third_party/nix/src/libexpr/primops/context.cc b/third_party/nix/src/libexpr/primops/context.cc
index 841a45c61c03..fb8879ead16d 100644
--- a/third_party/nix/src/libexpr/primops/context.cc
+++ b/third_party/nix/src/libexpr/primops/context.cc
@@ -97,12 +97,13 @@ static void prim_getContext(EvalState& state, const Pos& pos, Value** args,
           ContextInfo{isPath, isAllOutputs,
                       output.empty() ? Strings{} : Strings{std::move(output)}});
     } else {
-      if (isPath)
+      if (isPath) {
         iter->second.path = true;
-      else if (isAllOutputs)
+      } else if (isAllOutputs) {
         iter->second.allOutputs = true;
-      else
+      } else {
         iter->second.outputs.emplace_back(std::move(output));
+      }
     }
   }
 
@@ -116,8 +117,9 @@ static void prim_getContext(EvalState& state, const Pos& pos, Value** args,
     if (info.second.path) {
       mkBool(*state.allocAttr(infoVal, sPath), true);
     }
-    if (info.second.allOutputs)
+    if (info.second.allOutputs) {
       mkBool(*state.allocAttr(infoVal, sAllOutputs), true);
+    }
     if (!info.second.outputs.empty()) {
       auto& outputsVal = *state.allocAttr(infoVal, state.sOutputs);
       state.mkList(outputsVal, info.second.outputs.size());
@@ -147,9 +149,10 @@ static void prim_appendContext(EvalState& state, const Pos& pos, Value** args,
   auto sAllOutputs = state.symbols.Create("allOutputs");
   for (const auto& attr_iter : *args[1]->attrs) {
     const Attr* i = &attr_iter.second;  // TODO(tazjin): get rid of this
-    if (!state.store->isStorePath(i->name))
+    if (!state.store->isStorePath(i->name)) {
       throw EvalError("Context key '%s' is not a store path, at %s", i->name,
                       i->pos);
+    }
     if (!settings.readOnlyMode) {
       state.store->ensurePath(i->name);
     }
diff --git a/third_party/nix/src/libexpr/primops/fetchGit.cc b/third_party/nix/src/libexpr/primops/fetchGit.cc
index 2b2ca476cbbb..72b498d30b3e 100644
--- a/third_party/nix/src/libexpr/primops/fetchGit.cc
+++ b/third_party/nix/src/libexpr/primops/fetchGit.cc
@@ -30,8 +30,9 @@ std::regex revRegex("^[0-9a-fA-F]{40}$");
 GitInfo exportGit(ref<Store> store, const std::string& uri,
                   std::optional<std::string> ref, std::string rev,
                   const std::string& name) {
-  if (evalSettings.pureEval && rev == "")
+  if (evalSettings.pureEval && rev == "") {
     throw Error("in pure evaluation mode, 'fetchGit' requires a Git revision");
+  }
 
   if (!ref && rev == "" && absl::StartsWith(uri, "/") &&
       pathExists(uri + "/.git")) {
@@ -90,8 +91,9 @@ GitInfo exportGit(ref<Store> store, const std::string& uri,
     ref = "HEAD"s;
   }
 
-  if (rev != "" && !std::regex_match(rev, revRegex))
+  if (rev != "" && !std::regex_match(rev, revRegex)) {
     throw Error("invalid Git revision '%s'", rev);
+  }
 
   deletePath(getCacheDir() + "/nix/git");
 
@@ -104,10 +106,11 @@ GitInfo exportGit(ref<Store> store, const std::string& uri,
   }
 
   Path localRefFile;
-  if (ref->compare(0, 5, "refs/") == 0)
+  if (ref->compare(0, 5, "refs/") == 0) {
     localRefFile = cacheDir + "/" + *ref;
-  else
+  } else {
     localRefFile = cacheDir + "/refs/heads/" + *ref;
+  }
 
   bool doFetch;
   time_t now = time(0);
@@ -226,22 +229,24 @@ static void prim_fetchGit(EvalState& state, const Pos& pos, Value** args,
     for (auto& attr_iter : *args[0]->attrs) {
       auto& attr = attr_iter.second;
       std::string n(attr.name);
-      if (n == "url")
+      if (n == "url") {
         url =
             state.coerceToString(*attr.pos, *attr.value, context, false, false);
-      else if (n == "ref")
+      } else if (n == "ref") {
         ref = state.forceStringNoCtx(*attr.value, *attr.pos);
-      else if (n == "rev")
+      } else if (n == "rev") {
         rev = state.forceStringNoCtx(*attr.value, *attr.pos);
-      else if (n == "name")
+      } else if (n == "name") {
         name = state.forceStringNoCtx(*attr.value, *attr.pos);
-      else
+      } else {
         throw EvalError("unsupported argument '%s' to 'fetchGit', at %s",
                         attr.name, *attr.pos);
+      }
     }
 
-    if (url.empty())
+    if (url.empty()) {
       throw EvalError(format("'url' argument required, at %1%") % pos);
+    }
 
   } else {
     url = state.coerceToString(pos, *args[0], context, false, false);
diff --git a/third_party/nix/src/libexpr/primops/fetchMercurial.cc b/third_party/nix/src/libexpr/primops/fetchMercurial.cc
index df42b6d94884..13dc61766fe0 100644
--- a/third_party/nix/src/libexpr/primops/fetchMercurial.cc
+++ b/third_party/nix/src/libexpr/primops/fetchMercurial.cc
@@ -28,10 +28,11 @@ std::regex commitHashRegex("^[0-9a-fA-F]{40}$");
 
 HgInfo exportMercurial(ref<Store> store, const std::string& uri,
                        std::string rev, const std::string& name) {
-  if (evalSettings.pureEval && rev == "")
+  if (evalSettings.pureEval && rev == "") {
     throw Error(
         "in pure evaluation mode, 'fetchMercurial' requires a Mercurial "
         "revision");
+  }
 
   if (rev == "" && absl::StartsWith(uri, "/") && pathExists(uri + "/.hg")) {
     bool clean = runProgram("hg", true,
@@ -199,20 +200,22 @@ static void prim_fetchMercurial(EvalState& state, const Pos& pos, Value** args,
     for (auto& attr_iter : *args[0]->attrs) {
       auto& attr = attr_iter.second;
       std::string n(attr.name);
-      if (n == "url")
+      if (n == "url") {
         url =
             state.coerceToString(*attr.pos, *attr.value, context, false, false);
-      else if (n == "rev")
+      } else if (n == "rev") {
         rev = state.forceStringNoCtx(*attr.value, *attr.pos);
-      else if (n == "name")
+      } else if (n == "name") {
         name = state.forceStringNoCtx(*attr.value, *attr.pos);
-      else
+      } else {
         throw EvalError("unsupported argument '%s' to 'fetchMercurial', at %s",
                         attr.name, *attr.pos);
+      }
     }
 
-    if (url.empty())
+    if (url.empty()) {
       throw EvalError(format("'url' argument required, at %1%") % pos);
+    }
 
   } else {
     url = state.coerceToString(pos, *args[0], context, false, false);
diff --git a/third_party/nix/src/libexpr/primops/fromTOML.cc b/third_party/nix/src/libexpr/primops/fromTOML.cc
index 389ac080677a..e3d2a4940769 100644
--- a/third_party/nix/src/libexpr/primops/fromTOML.cc
+++ b/third_party/nix/src/libexpr/primops/fromTOML.cc
@@ -30,10 +30,12 @@ static void prim_fromTOML(EvalState& state, const Pos& pos, Value** args,
         if (auto i2 = i.second->as_table_array()) {
           size_t size2 = i2->get().size();
           state.mkList(v2, size2);
-          for (size_t j = 0; j < size2; ++j)
+          for (size_t j = 0; j < size2; ++j) {
             visit(*((*v2.list)[j] = state.allocValue()), i2->get()[j]);
-        } else
+          }
+        } else {
           visit(v2, i.second);
+        }
       }
     }
 
@@ -42,8 +44,9 @@ static void prim_fromTOML(EvalState& state, const Pos& pos, Value** args,
 
       state.mkList(v, size);
 
-      for (size_t i = 0; i < size; ++i)
+      for (size_t i = 0; i < size; ++i) {
         visit(*((*v.list)[i] = state.allocValue()), t2->get()[i]);
+      }
     }
 
     // Handle cases like 'a = [[{ a = true }]]', which IMHO should be
@@ -55,25 +58,28 @@ static void prim_fromTOML(EvalState& state, const Pos& pos, Value** args,
 
       state.mkList(v, size);
 
-      for (size_t j = 0; j < size; ++j)
+      for (size_t j = 0; j < size; ++j) {
         visit(*((*v.list)[j] = state.allocValue()), t2->get()[j]);
+      }
     }
 
     else if (t->is_value()) {
-      if (auto val = t->as<int64_t>())
+      if (auto val = t->as<int64_t>()) {
         mkInt(v, val->get());
-      else if (auto val = t->as<NixFloat>())
+      } else if (auto val = t->as<NixFloat>()) {
         mkFloat(v, val->get());
-      else if (auto val = t->as<bool>())
+      } else if (auto val = t->as<bool>()) {
         mkBool(v, val->get());
-      else if (auto val = t->as<std::string>())
+      } else if (auto val = t->as<std::string>()) {
         mkString(v, val->get());
-      else
+      } else {
         throw EvalError("unsupported value type in TOML");
+      }
     }
 
-    else
+    else {
       abort();
+    }
   };
 
   try {