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

Function cdump_extract

ccan/ccan/cdump/cdump.c:648–699  ·  view source on GitHub ↗

Simple LL(1) parser, inspired by Tridge's genstruct.pl. */

Source from the content-addressed store, hash-verified

646
647/* Simple LL(1) parser, inspired by Tridge's genstruct.pl. */
648struct cdump_definitions *cdump_extract(const tal_t *ctx, const char *code,
649 char **complaints)
650{
651 struct parse_state ps;
652 const struct token *toks;
653
654 ps.defs = tal(ctx, struct cdump_definitions);
655 ps.complaints = tal_strdup(ctx, "");
656 ps.code = code;
657
658 strmap_init(&ps.defs->enums);
659 strmap_init(&ps.defs->structs);
660 strmap_init(&ps.defs->unions);
661 tal_add_destructor(ps.defs, destroy_definitions);
662
663 toks = ps.toks = tokenize(ps.defs, code);
664 while (tok_peek(&ps.toks)) {
665 if (!tok_ignore_attribute(&ps))
666 goto fail;
667 if (tok_take_if(&ps.toks, "struct")) {
668 if (!tok_take_conglom(&ps, CDUMP_STRUCT))
669 goto fail;
670 } else if (tok_take_if(&ps.toks, "union")) {
671 if (!tok_take_conglom(&ps, CDUMP_UNION))
672 goto fail;
673 } else if (tok_take_if(&ps.toks, "enum")) {
674 if (!tok_take_enum(&ps))
675 goto fail;
676 } else
677 tok_take_unknown_statement(&ps);
678 }
679
680 /* Now, remove any undefined types! */
681 remove_undefined(&ps.defs->enums);
682 remove_undefined(&ps.defs->structs);
683 remove_undefined(&ps.defs->unions);
684 tal_free(toks);
685
686out:
687 if (streq(ps.complaints, ""))
688 ps.complaints = tal_free(ps.complaints);
689
690 if (complaints)
691 *complaints = ps.complaints;
692 else
693 tal_free(ps.complaints);
694 return ps.defs;
695
696fail:
697 ps.defs = tal_free(ps.defs);
698 goto out;
699}

Callers 9

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 9

tokenizeFunction · 0.85
tok_peekFunction · 0.85
tok_ignore_attributeFunction · 0.85
tok_take_ifFunction · 0.85
tok_take_conglomFunction · 0.85
tok_take_enumFunction · 0.85
remove_undefinedFunction · 0.85
tal_freeFunction · 0.85

Tested by 8

mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68