nixd
Loading...
Searching...
No Matches
PrimOpsInfoGen.cpp
Go to the documentation of this file.
1#include <nix/expr/eval.hh>
2#include <nix/expr/primops.hh>
3
4#include <iostream>
5
6int main(int argc, char **argv) {
7 std::freopen(argv[1], "w", stdout);
8 nix::initGC();
9 // Generate .cpp file that inject all primops into a custom vector.
10 // This is used by the language server to provide documentation,
11 // but omit the implementation of primops.
12 std::cout << "#include <nixf/Sema/PrimOpInfo.h>" << "\n\n";
13 std::cout << "std::map<std::string, nixf::PrimOpInfo> nixf::PrimOpsInfo = {"
14 << '\n';
15 for (const auto &PrimOp : nix::RegisterPrimOp::primOps()) {
16 std::cout << " {" << "\"" << PrimOp.name << "\", {\n";
17
18 // .args
19 std::cout << " .Args = {";
20 for (size_t I = 0; I < PrimOp.args.size(); ++I) {
21 std::cout << "\"" << PrimOp.args[I] << "\"";
22 if (I + 1 < PrimOp.args.size()) {
23 std::cout << ", ";
24 }
25 }
26 std::cout << "},\n";
27
28 // .arity
29 std::cout << " .Arity = " << PrimOp.arity << ",\n";
30
31 // .doc
32 std::cout << " .Doc = R\"xabc(" << (PrimOp.doc ? PrimOp.doc : "")
33 << ")xabc\",\n";
34
35 // .internal
36 std::cout << " .Internal = " << (PrimOp.internal ? "true" : "false")
37 << ",\n";
38
39 std::cout << " }},\n";
40 }
41 std::cout << "};\n";
42 return 0;
43}
int main(int argc, char **argv)