MCPcopy Create free account
hub / github.com/ElementsProject/lightning / tok_take_enum

Function tok_take_enum

ccan/ccan/cdump/cdump.c:532–608  ·  view source on GitHub ↗

enum ... */

Source from the content-addressed store, hash-verified

530
531/* enum ... */
532static bool tok_take_enum(struct parse_state *ps)
533{
534 size_t n = 0;
535 struct cdump_type *e;
536 const char *name;
537
538 name = tok_take_ident(ps->defs, &ps->toks);
539 if (!name) {
540 complain(ps, "Expected enum name");
541 return false;
542 }
543
544 e = get_type(ps->defs, CDUMP_ENUM, name);
545
546 /* Duplicate name? */
547 if (type_defined(e)) {
548 complain(ps, "enum already defined");
549 return false;
550 }
551
552 /* CDUMP() */
553 if (!tok_maybe_take_cdump_note(e, ps, &e->note))
554 return false;
555
556 if (!tok_ignore_attribute(ps))
557 return false;
558
559 if (!tok_take_if(&ps->toks, "{")) {
560 complain(ps, "Expected { after enum name");
561 return false;
562 }
563
564 e->u.enum_vals = tal_arr(e, struct cdump_enum_val, n);
565 do {
566 struct cdump_enum_val *v;
567
568 /* GCC extension: comma and end of enum */
569 if (tok_is(&ps->toks, "}"))
570 break;
571
572 tal_resize(&e->u.enum_vals, n+1);
573 v = &e->u.enum_vals[n++];
574
575 v->name = tok_take_ident(e, &ps->toks);
576 if (!v->name) {
577 complain(ps, "Expected enum value name");
578 return false;
579 }
580
581 /* CDUMP() */
582 if (!tok_maybe_take_cdump_note(e->u.enum_vals, ps, &v->note))
583 return false;
584
585 if (tok_take_if(&ps->toks, "=")) {
586 v->value = tok_take_until(e, &ps->toks, ",}");
587 if (!v->value) {
588 complain(ps, "Expected , or } to end value");
589 return false;

Callers 1

cdump_extractFunction · 0.85

Calls 9

tok_take_identFunction · 0.85
complainFunction · 0.85
get_typeFunction · 0.85
type_definedFunction · 0.85
tok_ignore_attributeFunction · 0.85
tok_take_ifFunction · 0.85
tok_isFunction · 0.85
tok_take_untilFunction · 0.85

Tested by

no test coverage detected