From af24481deb31a2bfa1466bfc9d97a26f3bf14208 Mon Sep 17 00:00:00 2001 From: XL_up <3066352084@qq.com> Date: Mon, 28 Aug 2023 23:11:58 +0800 Subject: [PATCH] Update parser.cpp --- src/common/backend/parser/parser.cpp | 36 +++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/common/backend/parser/parser.cpp b/src/common/backend/parser/parser.cpp index d91fb17cc..d7541e831 100644 --- a/src/common/backend/parser/parser.cpp +++ b/src/common/backend/parser/parser.cpp @@ -9,7 +9,6 @@ * the grammar are "raw" parsetrees that still need to be analyzed by * analyze.c and related files. * - * * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * @@ -40,15 +39,15 @@ static void resetCreateFuncFlag() /* * raw_parser - * Given a query in string form, do lexical and grammatical analysis. + * Given a query in string form, do lexical and grammatical analysis. * * Returns a list of raw (un-analyzed) parse trees. */ List* raw_parser(const char* str, List** query_string_locationlist) { - core_yyscan_t yyscanner; - base_yy_extra_type yyextra; - int yyresult; + core_yyscan_t yyscanner; + base_yy_extra_type yyextra; // An intermediate variable that holds the returned syntax tree. + int yyresult; // The calling result of base_yyparse(). /* reset u_sess->parser_cxt.stmt_contains_operator_plus */ resetOperatorPlusFlag(); @@ -58,7 +57,7 @@ List* raw_parser(const char* str, List** query_string_locationlist) /* reset u_sess->parser_cxt.isCreateFuncOrProc */ resetCreateFuncFlag(); - + /* initialize the flex scanner */ yyscanner = scanner_init(str, &yyextra.core_yy_extra, ScanKeywords, NumScanKeywords); @@ -89,6 +88,7 @@ List* raw_parser(const char* str, List** query_string_locationlist) } } + // Returns the generated syntax tree. return yyextra.parsetree; } @@ -127,7 +127,7 @@ List* raw_parser(const char* str, List** query_string_locationlist) * words. Furthermore it's not clear how to do it without re-introducing * scanner backtrack, which would cost more performance than this filter * layer does. - * + * * The filter also provides a convenient place to translate between * the core_YYSTYPE and YYSTYPE representations (which are really the * same thing anyway, but notationally they're different). @@ -489,8 +489,8 @@ int base_yylex(YYSTYPE* lvalp, YYLTYPE* llocp, core_yyscan_t yyscanner) /* * @Description: Check whether its a empty query with only comments and semicolon. - * @Param query_string: the query need check. - * @retrun:true or false. + * @Param[IN] query_string: the query need check. + * @return:the bool value of the check result. */ static bool is_empty_query(char* query_string) { @@ -513,6 +513,7 @@ static bool is_empty_query(char* query_string) end_comment_postion = strstr(query_string, end_comment); query_string = end_comment_postion + 2; while (isspace((unsigned char)*query_string)) { + // Trim the spaces after comments. query_string++; } } @@ -537,11 +538,12 @@ static bool is_empty_query(char* query_string) char** get_next_snippet( char** query_string_single, const char* query_string, List* query_string_locationlist, int* stmt_num) { - int query_string_location_start = 0; - int query_string_location_end = -1; - char* query_string_single_p = NULL; - int single_query_string_len = 0; - + int query_string_location_start = 0; // The starting position of the query statement. + int query_string_location_end = -1; // The ending position of the query statement. + char* query_string_single_p = NULL; // An intermediate variable used to copy the string. + int single_query_string_len = 0; // The length of the query statement. + + // Count the number of query statements. int stmt_count = list_length(query_string_locationlist); /* Malloc memory for single query here just for the first time. */ @@ -558,11 +560,13 @@ char** get_next_snippet( * Notice : The locationlist only store the end postion of each single query but not any * start postion. */ + // Calculate the starting position of the specified query statement. if (*stmt_num == 0) { query_string_location_start = 0; } else { query_string_location_start = list_nth_int(query_string_locationlist, *stmt_num - 1) + 1; } + // Calculate the ending position of the specified query statement. query_string_location_end = list_nth_int(query_string_locationlist, (*stmt_num)++); /* Malloc memory for each single query string. */ @@ -583,10 +587,10 @@ char** get_next_snippet( */ if (is_empty_query(query_string_single[*stmt_num - 1])) { continue; - } else { + } else { // The obtained query statement is not a null query, exit the loop, and return this statement. break; } } return query_string_single; -} +} \ No newline at end of file