diff --git a/lix/libexpr/symbol-table.hh b/lix/libexpr/symbol-table.hh index a38fb59d2..a5e23c864 100644 --- a/lix/libexpr/symbol-table.hh +++ b/lix/libexpr/symbol-table.hh @@ -169,4 +169,81 @@ public: } }; +/** + * NixSymbolTable extends the generic SymbolTable with pre-filled symbol constants for + * all well-known symbol names used in the Nix language. + * Besides the convenience aspect, this also improves performances as it does not require a table lookup for + * these very commonly used symbols. + */ +class NixSymbolTable : public SymbolTable +{ +public: + /* So it turns out that in C++, not only all identifiers starting with `__` are reserved, but also + * all identifiers *containing* `__`. However, given our prefix and the usage of triple underscores + * we are exceedingly unlikely to ever accidentally hit an actual identifier collision, and given that + * we are using custom types such a collision would almost certainly blow up with a loud bang and not + * cause any silent failure. We can always easily change to a different (likely worse) naming convention + * for our identifiers should we ever run into such a case. + */ + // NOLINTBEGIN(bugprone-reserved-identifier) + /* Magic primops */ + const Symbol sym___sub = create("__sub"); + const Symbol sym___lessThan = create("__lessThan"); + const Symbol sym___mul = create("__mul"); + const Symbol sym___div = create("__div"); + const Symbol sym___findFile = create("__findFile"); + const Symbol sym___nixPath = create("__nixPath"); + /* Parser keywords */ + const Symbol sym_or = create("or"); + const Symbol sym_body = create("body"); /* ancient let */ + /* __pos */ + const Symbol sym_file = create("file"); + const Symbol sym_line = create("line"); + const Symbol sym_column = create("column"); + /* Evaluator magic attrs */ + const Symbol sym___overrides = create("__overrides"); + const Symbol sym___functor = create("__functor"); + const Symbol sym___toString = create("__toString"); + /* Symbols for primops/builtins */ + const Symbol sym_path = create("path"); // builtins.getContext + const Symbol sym_prefix = create("prefix"); // builtins.findFile + const Symbol sym_startSet = create("startSet"); // builtins.genericClosure + const Symbol sym_operator = create("operator"); // builtins.genericClosure + const Symbol sym_key = create("key"); // builtins.genericClosure + const Symbol sym_right = create("right"); // builtins.partition + const Symbol sym_wrong = create("wrong"); // builtins.partition + /* Derivation magic attrs */ + const Symbol sym___ignoreNulls = create("__ignoreNulls"); + const Symbol sym___structuredAttrs = create("__structuredAttrs"); + const Symbol sym___contentAddressed = create("__contentAddressed"); + const Symbol sym___impure = create("__impure"); + /* Derivation */ + const Symbol sym_outPath = create("outPath"); + const Symbol sym_drvPath = create("drvPath"); + const Symbol sym_meta = create("meta"); + const Symbol sym_outputs = create("outputs"); + const Symbol sym_outputName = create("outputName"); + const Symbol sym_allowedReferences = create("allowedReferences"); + const Symbol sym_allowedRequisites = create("allowedRequisites"); + const Symbol sym_disallowedReferences = create("disallowedReferences"); + const Symbol sym_disallowedRequisites = create("disallowedRequisites"); + const Symbol sym_maxSize = create("maxSize"); + const Symbol sym_maxClosureSize = create("maxClosureSize"); + const Symbol sym_builder = create("builder"); + const Symbol sym_args = create("args"); + const Symbol sym_outputHash = create("outputHash"); + const Symbol sym_outputHashAlgo = create("outputHashAlgo"); + const Symbol sym_outputHashMode = create("outputHashMode"); + const Symbol sym_recurseForDerivations = create("recurseForDerivations"); + const Symbol sym_outputSpecified = create("outputSpecified"); + /* Flakes */ + const Symbol sym_description = create("description"); + const Symbol sym_self = create("self"); + /* Various uses */ + const Symbol sym_name = create("name"); // Derivation name, name value pair, ... + const Symbol sym_value = create("value"); // builtins.tryEval, name value pair, ... + const Symbol sym_system = create("system"); // Derivation, user env, ... + const Symbol sym_type = create("type"); + // NOLINTEND(bugprone-reserved-identifier) +}; }