fix(3p/nix): inherit Expr from gc, make parser state traceable
The parser contained vectors, and the primary parser state, that were not participating in GC tracing. Change-Id: Ie198592cd7acffd390e3e2ae9595138b56416838 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1706 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in> Reviewed-by: glittershark <grfn@gws.fyi>
This commit is contained in:
parent
42bdaacca6
commit
906f5c1d2d
4 changed files with 56 additions and 40 deletions
51
third_party/nix/src/libexpr/parser.y
vendored
51
third_party/nix/src/libexpr/parser.y
vendored
|
|
@ -14,6 +14,29 @@
|
|||
%code requires {
|
||||
#define YY_NO_INPUT 1 // disable unused yyinput features
|
||||
#include "libexpr/parser.hh"
|
||||
|
||||
// Allow GC tracing of YY-allocated structures
|
||||
#define YYMALLOC GC_MALLOC_UNCOLLECTABLE
|
||||
#define YYFREE GC_FREE
|
||||
#define YYREALLOC GC_REALLOC
|
||||
|
||||
struct YYSTYPE : public gc {
|
||||
union {
|
||||
nix::Expr * e;
|
||||
nix::ExprList * list;
|
||||
nix::ExprAttrs * attrs;
|
||||
nix::Formals * formals;
|
||||
nix::Formal * formal;
|
||||
nix::NixInt n;
|
||||
nix::NixFloat nf;
|
||||
const char * id; // !!! -> Symbol
|
||||
char * path;
|
||||
char * uri;
|
||||
nix::AttrNameVector * attrNames;
|
||||
nix::VectorExprs * string_parts;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
%{
|
||||
|
|
@ -40,22 +63,6 @@ void yyerror(YYLTYPE* loc, yyscan_t scanner, ParseData* data,
|
|||
|
||||
%}
|
||||
|
||||
%union {
|
||||
// !!! We're probably leaking stuff here.
|
||||
nix::Expr * e;
|
||||
nix::ExprList * list;
|
||||
nix::ExprAttrs * attrs;
|
||||
nix::Formals * formals;
|
||||
nix::Formal * formal;
|
||||
nix::NixInt n;
|
||||
nix::NixFloat nf;
|
||||
const char * id; // !!! -> Symbol
|
||||
char * path;
|
||||
char * uri;
|
||||
std::vector<nix::AttrName> * attrNames;
|
||||
std::vector<nix::Expr *> * string_parts;
|
||||
}
|
||||
|
||||
%type <e> start expr expr_function expr_if expr_op
|
||||
%type <e> expr_app expr_select expr_simple
|
||||
%type <list> expr_list
|
||||
|
|
@ -138,7 +145,7 @@ expr_op
|
|||
| expr_op UPDATE expr_op { $$ = new ExprOpUpdate(CUR_POS, $1, $3); }
|
||||
| expr_op '?' attrpath { $$ = new ExprOpHasAttr($1, *$3); }
|
||||
| expr_op '+' expr_op
|
||||
{ $$ = new ExprConcatStrings(CUR_POS, false, new std::vector<Expr *>({$1, $3})); }
|
||||
{ $$ = new ExprConcatStrings(CUR_POS, false, new nix::VectorExprs({$1, $3})); }
|
||||
| expr_op '-' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.Create("__sub")), $1), $3); }
|
||||
| expr_op '*' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.Create("__mul")), $1), $3); }
|
||||
| expr_op '/' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.Create("__div")), $1), $3); }
|
||||
|
|
@ -208,9 +215,9 @@ string_parts
|
|||
string_parts_interpolated
|
||||
: string_parts_interpolated STR { $$ = $1; $1->push_back($2); }
|
||||
| string_parts_interpolated DOLLAR_CURLY expr '}' { $$ = $1; $1->push_back($3); }
|
||||
| DOLLAR_CURLY expr '}' { $$ = new std::vector<Expr *>; $$->push_back($2); }
|
||||
| DOLLAR_CURLY expr '}' { $$ = new nix::VectorExprs; $$->push_back($2); }
|
||||
| STR DOLLAR_CURLY expr '}' {
|
||||
$$ = new std::vector<Expr *>;
|
||||
$$ = new nix::VectorExprs;
|
||||
$$->push_back($1);
|
||||
$$->push_back($3);
|
||||
}
|
||||
|
|
@ -219,7 +226,7 @@ string_parts_interpolated
|
|||
ind_string_parts
|
||||
: ind_string_parts IND_STR { $$ = $1; $1->push_back($2); }
|
||||
| ind_string_parts DOLLAR_CURLY expr '}' { $$ = $1; $1->push_back($3); }
|
||||
| { $$ = new std::vector<Expr *>; }
|
||||
| { $$ = new nix::VectorExprs; }
|
||||
;
|
||||
|
||||
binds
|
||||
|
|
@ -276,9 +283,9 @@ attrpath
|
|||
$$->push_back(AttrName($3));
|
||||
}
|
||||
}
|
||||
| attr { $$ = new std::vector<AttrName>; $$->push_back(AttrName(data->symbols.Create($1))); }
|
||||
| attr { $$ = new nix::AttrNameVector; $$->push_back(AttrName(data->symbols.Create($1))); }
|
||||
| string_attr
|
||||
{ $$ = new std::vector<AttrName>;
|
||||
{ $$ = new nix::AttrNameVector;
|
||||
ExprString *str = dynamic_cast<ExprString *>($1);
|
||||
if (str) {
|
||||
$$->push_back(AttrName(str->s));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue