aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2016-10-11 00:52:18 -0500
committerTao Bao2016-10-13 01:29:59 -0500
commit39119ad8ecd00a9c19fb173c78cb4a8d22a4540a (patch)
treeb7c6d625baefc3521fe46c794d8d82fe99535229 /edify/parser.yy
parent19bb05dfc7a148dc4fc4ce744e5cfd013949497a (diff)
downloadplatform-bootable-recovery-39119ad8ecd00a9c19fb173c78cb4a8d22a4540a.tar.gz
platform-bootable-recovery-39119ad8ecd00a9c19fb173c78cb4a8d22a4540a.tar.xz
platform-bootable-recovery-39119ad8ecd00a9c19fb173c78cb4a8d22a4540a.zip
edify: Some clean-ups to libedify.
- Remove dead declarations in expr.h: SetError(), GetError(), ClearError(). - Remove the declaration of Build() out of expr.h. - Use std::unordered_map to implement RegisterFunction() and FindFunction(); kill FinishRegistration(). - Add a testcase for calling unknown functions. Test: mmma bootable/recovery; recovery_component_test passes. Change-Id: I9af6825ae677f92b22d716a4a5682f58522af03b
Diffstat (limited to 'edify/parser.yy')
-rw-r--r--edify/parser.yy29
1 files changed, 24 insertions, 5 deletions
diff --git a/edify/parser.yy b/edify/parser.yy
index 098a6370..58a8dec6 100644
--- a/edify/parser.yy
+++ b/edify/parser.yy
@@ -33,6 +33,25 @@ struct yy_buffer_state;
33void yy_switch_to_buffer(struct yy_buffer_state* new_buffer); 33void yy_switch_to_buffer(struct yy_buffer_state* new_buffer);
34struct yy_buffer_state* yy_scan_string(const char* yystr); 34struct yy_buffer_state* yy_scan_string(const char* yystr);
35 35
36// Convenience function for building expressions with a fixed number
37// of arguments.
38static Expr* Build(Function fn, YYLTYPE loc, size_t count, ...) {
39 va_list v;
40 va_start(v, count);
41 Expr* e = static_cast<Expr*>(malloc(sizeof(Expr)));
42 e->fn = fn;
43 e->name = "(operator)";
44 e->argc = count;
45 e->argv = static_cast<Expr**>(malloc(count * sizeof(Expr*)));
46 for (size_t i = 0; i < count; ++i) {
47 e->argv[i] = va_arg(v, Expr*);
48 }
49 va_end(v);
50 e->start = loc.start;
51 e->end = loc.end;
52 return e;
53}
54
36%} 55%}
37 56
38%locations 57%locations
@@ -70,7 +89,7 @@ input: expr { *root = $1; }
70; 89;
71 90
72expr: STRING { 91expr: STRING {
73 $$ = reinterpret_cast<Expr*>(malloc(sizeof(Expr))); 92 $$ = static_cast<Expr*>(malloc(sizeof(Expr)));
74 $$->fn = Literal; 93 $$->fn = Literal;
75 $$->name = $1; 94 $$->name = $1;
76 $$->argc = 0; 95 $$->argc = 0;
@@ -91,9 +110,9 @@ expr: STRING {
91| IF expr THEN expr ENDIF { $$ = Build(IfElseFn, @$, 2, $2, $4); } 110| IF expr THEN expr ENDIF { $$ = Build(IfElseFn, @$, 2, $2, $4); }
92| IF expr THEN expr ELSE expr ENDIF { $$ = Build(IfElseFn, @$, 3, $2, $4, $6); } 111| IF expr THEN expr ELSE expr ENDIF { $$ = Build(IfElseFn, @$, 3, $2, $4, $6); }
93| STRING '(' arglist ')' { 112| STRING '(' arglist ')' {
94 $$ = reinterpret_cast<Expr*>(malloc(sizeof(Expr))); 113 $$ = static_cast<Expr*>(malloc(sizeof(Expr)));
95 $$->fn = FindFunction($1); 114 $$->fn = FindFunction($1);
96 if ($$->fn == NULL) { 115 if ($$->fn == nullptr) {
97 char buffer[256]; 116 char buffer[256];
98 snprintf(buffer, sizeof(buffer), "unknown function \"%s\"", $1); 117 snprintf(buffer, sizeof(buffer), "unknown function \"%s\"", $1);
99 yyerror(root, error_count, buffer); 118 yyerror(root, error_count, buffer);
@@ -113,12 +132,12 @@ arglist: /* empty */ {
113} 132}
114| expr { 133| expr {
115 $$.argc = 1; 134 $$.argc = 1;
116 $$.argv = reinterpret_cast<Expr**>(malloc(sizeof(Expr*))); 135 $$.argv = static_cast<Expr**>(malloc(sizeof(Expr*)));
117 $$.argv[0] = $1; 136 $$.argv[0] = $1;
118} 137}
119| arglist ',' expr { 138| arglist ',' expr {
120 $$.argc = $1.argc + 1; 139 $$.argc = $1.argc + 1;
121 $$.argv = reinterpret_cast<Expr**>(realloc($$.argv, $$.argc * sizeof(Expr*))); 140 $$.argv = static_cast<Expr**>(realloc($$.argv, $$.argc * sizeof(Expr*)));
122 $$.argv[$$.argc-1] = $3; 141 $$.argv[$$.argc-1] = $3;
123} 142}
124; 143;