tries to compress clauses of a query or a foreach clause returns true if a rewrite occurred
| 235 | // tries to compress clauses of a query or a foreach clause |
| 236 | // returns true if a rewrite occurred |
| 237 | static bool _compress_clauses |
| 238 | ( |
| 239 | const cypher_astnode_t *node // node containing clauses to compress |
| 240 | ) { |
| 241 | bool rewritten = false; |
| 242 | |
| 243 | cypher_astnode_type_t type = cypher_astnode_type(node); |
| 244 | |
| 245 | ASSERT(type == CYPHER_AST_QUERY || type == CYPHER_AST_FOREACH); |
| 246 | |
| 247 | cypher_astnode_t **clauses = array_new(cypher_astnode_t *, 0); |
| 248 | // is the node representing a FOREACH clause |
| 249 | uint clause_count = 0; |
| 250 | replace_func replace_func = NULL; |
| 251 | get_clause_func get_clause = NULL; |
| 252 | // use appropriate function to get a positioned clause |
| 253 | if(type == CYPHER_AST_FOREACH) { |
| 254 | get_clause = cypher_ast_foreach_get_clause; |
| 255 | clause_count = cypher_ast_foreach_nclauses(node); |
| 256 | replace_func = cypher_ast_foreach_replace_clauses; |
| 257 | } else { |
| 258 | get_clause = cypher_ast_query_get_clause; |
| 259 | replace_func = cypher_ast_query_replace_clauses; |
| 260 | clause_count = cypher_ast_query_nclauses(node); |
| 261 | } |
| 262 | |
| 263 | for(uint i = 0; i < clause_count; i++) { |
| 264 | const cypher_astnode_t *clause = get_clause(node, i); |
| 265 | cypher_astnode_type_t t = cypher_astnode_type(clause); |
| 266 | |
| 267 | // try compressing the inner-clauses of foreach clause and call subquery |
| 268 | if(t == CYPHER_AST_FOREACH) { |
| 269 | rewritten |= _compress_clauses(clause); |
| 270 | continue; |
| 271 | } else if(t == CYPHER_AST_CALL_SUBQUERY) { |
| 272 | rewritten |= |
| 273 | _compress_clauses(cypher_ast_call_subquery_get_query(clause)); |
| 274 | continue; |
| 275 | } |
| 276 | |
| 277 | // check compressibility, move on if not compressible |
| 278 | if(!is_compressible(clause, t)) { |
| 279 | continue; |
| 280 | } |
| 281 | |
| 282 | //---------------------------------------------------------------------- |
| 283 | // collect clauses of the same type as current clause |
| 284 | //---------------------------------------------------------------------- |
| 285 | |
| 286 | for (uint j = i; j < clause_count; j++) { |
| 287 | clause = get_clause(node, j); |
| 288 | cypher_astnode_type_t t2 = cypher_astnode_type(clause); |
| 289 | if(t2 != t || !is_compressible(clause, t2)) { |
| 290 | break; |
| 291 | } |
| 292 | array_append(clauses, (cypher_astnode_t *)clause); |
| 293 | } |
| 294 |
no test coverage detected