MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / tm_invocation_parse

Function tm_invocation_parse

src/mcp/test_impact.c:783–839  ·  view source on GitHub ↗

C macro argument commas are shielded by parentheses, not by brackets, * braces or template angle brackets. The lexer handles comments and ordinary * literals as units. Unsupported raw/spliced text latches the shared flag. * Return 1=parsed, 0=malformed, -1=allocation/counter failure. */

Source from the content-addressed store, hash-verified

781 * literals as units. Unsupported raw/spliced text latches the shared flag.
782 * Return 1=parsed, 0=malformed, -1=allocation/counter failure. */
783static int tm_invocation_parse(tm_scan_t *sc, tm_lex_t at, tm_invocation_t *invocation) {
784 tm_tok_t tok;
785 tm_next(&at, &tok);
786 if (!tm_tok_punct(&tok, '('))
787 return 0;
788 int depth = 0;
789 tm_argument_t arg = {0};
790 for (;;) {
791 tm_next(&at, &tok);
792 if (tok.kind == TM_TOK_EOF || tok.kind == TM_TOK_DIRECTIVE)
793 return 0;
794 if (tm_tok_punct(&tok, ')') && depth == 0) {
795 if ((arg.has_token || invocation->count) && !tm_argument_append(invocation, &arg))
796 return -1;
797 invocation->after = at;
798 return 1;
799 }
800 if (tm_tok_punct(&tok, ',') && depth == 0) {
801 if (!tm_argument_append(invocation, &arg))
802 return -1;
803 memset(&arg, 0, sizeof(arg));
804 continue;
805 }
806 /* Consuming an outer invocation must not hide another configured
807 * invocation in an unselected argument. We cannot infer expansion or
808 * execution of that inner call, so these rows cannot justify omission. */
809 if (tok.kind == TM_TOK_IDENT) {
810 for (int i = 0; i < tm_rule_count(sc); i++) {
811 int declaration;
812 const cbm_test_declaration_t *rule = tm_rule(sc, i, &declaration);
813 bool perf;
814 if (!tm_rule_matches(sc, rule, &tok, &perf))
815 continue;
816 tm_lex_t ahead = at;
817 tm_tok_t next;
818 tm_next(&ahead, &next);
819 if (tm_tok_punct(&next, '('))
820 tm_scan_mapping(sc, CBM_TEST_MODEL_MAPPING_UNSUPPORTED_FORM, declaration,
821 tok.line);
822 }
823 }
824 if (!arg.has_token) {
825 arg.first = tok;
826 arg.has_token = true;
827 arg.single_identifier = tok.kind == TM_TOK_IDENT;
828 } else {
829 arg.single_identifier = false;
830 }
831 if (tm_tok_punct(&tok, '(')) {
832 if (depth == INT_MAX)
833 return -1;
834 depth++;
835 } else if (tm_tok_punct(&tok, ')')) {
836 depth--;
837 }
838 }
839}
840

Callers 1

tm_descriptor_identFunction · 0.85

Calls 7

tm_nextFunction · 0.85
tm_tok_punctFunction · 0.85
tm_argument_appendFunction · 0.85
tm_rule_countFunction · 0.85
tm_ruleFunction · 0.85
tm_rule_matchesFunction · 0.85
tm_scan_mappingFunction · 0.85

Tested by

no test coverage detected