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

Function tf_object_get

src/pipeline/pass_terraform.c:1501–1529  ·  view source on GitHub ↗

The value of `key` in an object expression (keys bare or quoted). */

Source from the content-addressed store, hash-verified

1499
1500/* The value of `key` in an object expression (keys bare or quoted). */
1501static TSNode tf_object_get(const char *src, TSNode expr, const char *key) {
1502 TSNode n = expr;
1503 while ((tf_type(n, "expression") || tf_type(n, "collection_value")) &&
1504 ts_node_named_child_count(n) > 0) {
1505 n = ts_node_named_child(n, 0);
1506 }
1507 for (uint32_t i = 0; tf_type(n, "object") && i < ts_node_named_child_count(n); i++) {
1508 TSNode el = ts_node_named_child(n, i);
1509 if (!tf_type(el, "object_elem")) {
1510 continue;
1511 }
1512 TSNode k = ts_node_child_by_field_name(el, "key", sizeof("key") - SKIP_ONE);
1513 char text[CBM_SZ_64];
1514 bool named = tf_literal(src, k, text, sizeof(text));
1515 if (!named) {
1516 TSNode id = k;
1517 while ((tf_type(id, "expression") || tf_type(id, "variable_expr")) &&
1518 ts_node_named_child_count(id) > 0) {
1519 id = ts_node_named_child(id, 0);
1520 }
1521 named = tf_type(id, "identifier") && tf_text_is(src, id, key);
1522 text[0] = '\0';
1523 }
1524 if ((named && !text[0]) || (text[0] && strcmp(text, key) == 0)) {
1525 return ts_node_child_by_field_name(el, "val", sizeof("val") - SKIP_ONE);
1526 }
1527 }
1528 return (TSNode){0};
1529}
1530
1531/* The expression of attribute `key` in a block body, or a null node. */
1532static TSNode tf_body_attr(const char *src, TSNode body, const char *key) {

Callers 1

tf_k8s_blockFunction · 0.85

Calls 3

tf_typeFunction · 0.85
tf_literalFunction · 0.85
tf_text_isFunction · 0.85

Tested by

no test coverage detected