pl_gram.c
来自「postgresql8.3.4源码,开源数据库」· C语言 代码 · 共 2,193 行 · 第 1/5 页
C
2,193 行
conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow ("parser stack overflow", &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; }#else /* no yyoverflow */# ifndef YYSTACK_RELOCATE goto yyoverflowlab;# else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) goto yyoverflowlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { short *yyss1 = yyss; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) goto yyoverflowlab; YYSTACK_RELOCATE (yyss); YYSTACK_RELOCATE (yyvs);# undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); }# endif#endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; YYDPRINTF ((stderr, "Stack size increased to %lu\n", (unsigned long int) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); goto yybackup;/*-----------.| yybackup. |`-----------*/yybackup:/* Do appropriate processing given the current state. *//* Read a lookahead token if we need one and don't already have one. *//* yyresume: */ /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; if (yyn == YYPACT_NINF) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; } if (yychar <= YYEOF) { yychar = yytoken = YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } else { yytoken = YYTRANSLATE (yychar); YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc); } /* If the proper action on seeing token YYTOKEN is to reduce or to detect an error, take that action. */ yyn += yytoken; if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) goto yydefault; yyn = yytable[yyn]; if (yyn <= 0) { if (yyn == 0 || yyn == YYTABLE_NINF) goto yyerrlab; yyn = -yyn; goto yyreduce; } if (yyn == YYFINAL) YYACCEPT; /* Shift the lookahead token. */ YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken])); /* Discard the token being shifted unless it is eof. */ if (yychar != YYEOF) yychar = YYEMPTY; *++yyvsp = yylval; /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; yystate = yyn; goto yynewstate;/*-----------------------------------------------------------.| yydefault -- do the default action for the current state. |`-----------------------------------------------------------*/yydefault: yyn = yydefact[yystate]; if (yyn == 0) goto yyerrlab; goto yyreduce;/*-----------------------------.| yyreduce -- Do a reduction. |`-----------------------------*/yyreduce: /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: `$$ = $1'. Otherwise, the following line sets YYVAL to garbage. This behavior is undocumented and Bison users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ yyval = yyvsp[1-yylen]; YY_REDUCE_PRINT (yyn); switch (yyn) { case 2:#line 227 "gram.y" { yylval.program = (PLpgSQL_stmt_block *)yyvsp[-1].stmt; } break; case 3:#line 231 "gram.y" { yylval.program = (PLpgSQL_stmt_block *)yyvsp[-1].stmt; } break; case 8:#line 245 "gram.y" { plpgsql_DumpExecTree = true; } break; case 11:#line 255 "gram.y" { PLpgSQL_stmt_block *new; new = palloc0(sizeof(PLpgSQL_stmt_block)); new->cmd_type = PLPGSQL_STMT_BLOCK; new->lineno = yyvsp[-4].ival; new->label = yyvsp[-6].declhdr.label; new->n_initvars = yyvsp[-6].declhdr.n_initvars; new->initvarnos = yyvsp[-6].declhdr.initvarnos; new->body = yyvsp[-3].list; new->exceptions = yyvsp[-2].exception_block; check_labels(yyvsp[-6].declhdr.label, yyvsp[0].str); plpgsql_ns_pop(); yyval.stmt = (PLpgSQL_stmt *)new; } break; case 12:#line 277 "gram.y" { plpgsql_ns_setlocal(false); yyval.declhdr.label = yyvsp[0].str; yyval.declhdr.n_initvars = 0; yyval.declhdr.initvarnos = NULL; } break; case 13:#line 284 "gram.y" { plpgsql_ns_setlocal(false); yyval.declhdr.label = yyvsp[-1].str; yyval.declhdr.n_initvars = 0; yyval.declhdr.initvarnos = NULL; } break; case 14:#line 291 "gram.y" { plpgsql_ns_setlocal(false); if (yyvsp[0].str != NULL) yyval.declhdr.label = yyvsp[0].str; else yyval.declhdr.label = yyvsp[-2].str; /* Remember variables declared in decl_stmts */ yyval.declhdr.n_initvars = plpgsql_add_initdatums(&(yyval.declhdr.initvarnos)); } break; case 15:#line 303 "gram.y" { /* Forget any variables created before block */ plpgsql_add_initdatums(NULL); /* Make variable names be local to block */ plpgsql_ns_setlocal(true); } break; case 16:#line 312 "gram.y" { yyval.str = yyvsp[0].str; } break; case 17:#line 314 "gram.y" { yyval.str = yyvsp[0].str; } break; case 18:#line 318 "gram.y" { yyval.str = yyvsp[-2].str; } break; case 19:#line 320 "gram.y" { yyval.str = NULL; } break; case 20:#line 322 "gram.y" { yyval.str = NULL; } break; case 21:#line 326 "gram.y" { PLpgSQL_variable *var; var = plpgsql_build_variable(yyvsp[-4].varname.name, yyvsp[-4].varname.lineno, yyvsp[-2].dtype, true); if (yyvsp[-3].boolean) { if (var->dtype == PLPGSQL_DTYPE_VAR) ((PLpgSQL_var *) var)->isconst = yyvsp[-3].boolean; else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("row or record variable cannot be CONSTANT"))); } if (yyvsp[-1].boolean) { if (var->dtype == PLPGSQL_DTYPE_VAR) ((PLpgSQL_var *) var)->notnull = yyvsp[-1].boolean; else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("row or record variable cannot be NOT NULL"))); } if (yyvsp[0].expr != NULL) { if (var->dtype == PLPGSQL_DTYPE_VAR) ((PLpgSQL_var *) var)->default_val = yyvsp[0].expr; else ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("default value for row or record variable is not supported"))); } } break; case 22:#line 360 "gram.y" { plpgsql_ns_additem(yyvsp[-1].nsitem->itemtype, yyvsp[-1].nsitem->itemno, yyvsp[-4].varname.name); } break; case 23:#line 365 "gram.y" { plpgsql_ns_rename(yyvsp[-3].str, yyvsp[-1].str); } break; case 24:#line 369 "gram.y" { plpgsql_ns_push(yyvsp[-2].varname.name); } break; case 25:#line 371 "gram.y" { PLpgSQL_var *new; PLpgSQL_expr *curname_def; char buf[1024]; char *cp1; char *cp2; /* pop local namespace for cursor args */ plpgsql_ns_pop(); new = (PLpgSQL_var *) plpgsql_build_variable(yyvsp[-6].varname.name, yyvsp[-6].varname.lineno, plpgsql_build_datatype(REFCURSOROID, -1), true); curname_def = palloc0(sizeof(PLpgSQL_expr)); curname_def->dtype = PLPGSQL_DTYPE_EXPR; strcpy(buf, "SELECT "); cp1 = new->refname; cp2 = buf + strlen(buf); /* * Don't trust standard_conforming_strings here; * it might change before we use the string. */ if (strchr(cp1, '\\') != NULL) *cp2++ = ESCAPE_STRING_SYNTAX; *cp2++ = '\''; while (*cp1) { if (SQL_STR_DOUBLE(*cp1, true)) *cp2++ = *cp1; *cp2++ = *cp1++; } strcpy(cp2, "'::refcursor"); curname_def->query = pstrdup(buf); new->default_val = curname_def; new->cursor_explicit_expr = yyvsp[0].expr; if (yyvsp[-2].row == NULL) new->cursor_explicit_argrow = -1; else new->cursor_explicit_argrow = yyvsp[-2].row->rowno; new->cursor_options = CURSOR_OPT_FAST_PLAN | yyvsp[-5].ival; } break; case 26:#line 420 "gram.y" { yyval.ival = 0; } break; case 27:#line 424 "gram.y" { yyval.ival = CURSOR_OPT_NO_SCROLL; } break; case 28:#line 428 "gram.y" { yyval.ival = CURSOR_OPT_SCROLL; } break; case 29:#line 434 "gram.y" { PLpgSQL_expr *query; plpgsql_ns_setlocal(false); query = read_sql_stmt(""); plpgsql_ns_setlocal(true); yyval.expr = query; } break; case 30:#line 446 "gram.y" { yyval.row = NULL; } break; case 31:#line 450 "gram.y" { PLpgSQL_row *new; int i; ListCell *l; new = palloc0(sizeof(PLpgSQL_row)); new->dtype = PLPGSQL_DTYPE_ROW; new->lineno = plpgsql_scanner_lineno(); new->rowtupdesc = NULL; new->nfields = list_length(yyvsp[-1].list); new->fieldnames = palloc(new->nfields * sizeof(char *)); new->varnos = palloc(new->nfields * sizeof(int)); i = 0; foreach (l, yyvsp[-1].list) { PLpgSQL_variable *arg = (PLpgSQL_variable *) lfirst(l); new->fieldnames[i] = arg->refname; new->varnos[i] = arg->dno; i++; } list_free(yyvsp[-1].list);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?