compresses multiple consecutive REMOVE clauses into a single REMOVE clause
| 200 | |
| 201 | // compresses multiple consecutive REMOVE clauses into a single REMOVE clause |
| 202 | static void _replace_remove_clause |
| 203 | ( |
| 204 | cypher_astnode_t *root, // ast root |
| 205 | cypher_astnode_t **clauses, // clause being replaced |
| 206 | int scope_start, // beginning of scope |
| 207 | int scope_end, // ending of scope |
| 208 | replace_func replace // replace function pointer |
| 209 | ) { |
| 210 | uint count = array_len(clauses); |
| 211 | |
| 212 | struct cypher_input_range range = cypher_astnode_range(clauses[0]); |
| 213 | cypher_astnode_t **items = array_new(cypher_astnode_t *, count); |
| 214 | |
| 215 | for (uint i = 0; i < count; i++) { |
| 216 | uint nitems = cypher_ast_remove_nitems(clauses[i]); |
| 217 | for(uint j = 0; j < nitems; j++) { |
| 218 | const cypher_astnode_t *item = |
| 219 | cypher_ast_remove_get_item(clauses[i], j); |
| 220 | array_append(items, cypher_ast_clone(item)); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | // build the replacement clause |
| 225 | cypher_astnode_t *new_clause = |
| 226 | cypher_ast_remove(items, array_len(items), items, array_len(items), |
| 227 | range); |
| 228 | |
| 229 | // replace original clause with fully populated one |
| 230 | replace(root, new_clause, scope_start, scope_end); |
| 231 | |
| 232 | array_free(items); |
| 233 | } |
| 234 | |
| 235 | // tries to compress clauses of a query or a foreach clause |
| 236 | // returns true if a rewrite occurred |
no test coverage detected