| 394 | } |
| 395 | |
| 396 | AST *AST_Build |
| 397 | ( |
| 398 | cypher_parse_result_t *parse_result |
| 399 | ) { |
| 400 | AST *ast = rm_malloc(sizeof(AST)); |
| 401 | |
| 402 | ast->free_root = false; |
| 403 | ast->ref_count = rm_malloc(sizeof(uint)); |
| 404 | ast->parse_result = parse_result; |
| 405 | ast->referenced_entities = NULL; |
| 406 | ast->params_parse_result = NULL; |
| 407 | ast->anot_ctx_collection = AST_AnnotationCtxCollection_New(); |
| 408 | |
| 409 | *(ast->ref_count) = 1; |
| 410 | |
| 411 | // retrieve the AST root node from a parsed query |
| 412 | const cypher_astnode_t *statement = _AST_parse_result_root(parse_result); |
| 413 | |
| 414 | // we are parsing with the CYPHER_PARSE_ONLY_STATEMENTS flag, |
| 415 | // and double-checking this in AST validations |
| 416 | ASSERT(cypher_astnode_type(statement) == CYPHER_AST_STATEMENT); |
| 417 | ast->root = cypher_ast_statement_get_body(statement); |
| 418 | |
| 419 | // empty queries should be captured by AST validations |
| 420 | ASSERT(ast->root); |
| 421 | |
| 422 | // set thread-local AST |
| 423 | QueryCtx_SetAST(ast); |
| 424 | |
| 425 | // augment the AST with annotations for naming entities |
| 426 | // and populating WITH/RETURN * projections |
| 427 | AST_Enrich(ast); |
| 428 | |
| 429 | return ast; |
| 430 | } |
| 431 | |
| 432 | AST *AST_NewSegment |
| 433 | ( |