Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7072635

Browse files
committed
Fix parse location tracking for lists that can be empty.
The previous coding of the YYLLOC_DEFAULT macro behaved strangely for emptyproductions, assigning the previous nonterminal's location as the parselocation of the result. The usefulness of that was (at best) debatablealready, but the real problem is that in list-generating nonterminals likeOptFooList: /* EMPTY */ { ... } | OptFooList Foo { ... } ;the initially-identified location would get copied up, so that even anonempty list would be given a bogus parse location. Document how to workaround that, and do so for OptSchemaEltList, so that the error conditionjust added for CREATE SCHEMA IF NOT EXISTS produces a sane error cursor.So far as I can tell, there are currently no other cases where thesituation arises, so we don't need other instances of this coding yet.
1 parent7e389f7 commit7072635

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

‎src/backend/parser/gram.y

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,33 @@
6767
#include"utils/xml.h"
6868

6969

70-
/* Location tracking support --- simpler than bison's default*/
70+
/*
71+
* Location tracking support --- simpler than bison's default, since we only
72+
* want to track the start position not the end position of each nonterminal.
73+
*/
7174
#defineYYLLOC_DEFAULT(Current, Rhs, N) \
7275
do { \
73-
if (N) \
76+
if ((N) >0) \
7477
(Current) = (Rhs)[1]; \
7578
else \
76-
(Current) = (Rhs)[0]; \
79+
(Current) = (-1); \
7780
}while (0)
7881

82+
/*
83+
* The above macro assigns -1 (unknown) as the parse location of any
84+
* nonterminal that was reduced from an empty rule. This is problematic
85+
* for nonterminals defined like
86+
*OptFooList: / * EMPTY * / { ... } | OptFooList Foo { ... } ;
87+
* because we'll set -1 as the location during the first reduction and then
88+
* copy it during each subsequent reduction, leaving us with -1 for the
89+
* location even when the list is not empty. To fix that, do this in the
90+
* action for the nonempty rule(s):
91+
*if (@$ < 0) @$ = @2;
92+
* (Although we have many nonterminals that follow this pattern, we only
93+
* bother with fixing @$ like this when the nonterminal's parse location
94+
* is actually referenced in some rule.)
95+
*/
96+
7997
/*
8098
* Bison doesn't allocate anything that needs to live across parser calls,
8199
* so we can easily have it use palloc instead of malloc. This prevents
@@ -1223,8 +1241,14 @@ OptSchemaName:
12231241
;
12241242

12251243
OptSchemaEltList:
1226-
OptSchemaEltListschema_stmt{$$ = lappend($1,$2); }
1227-
|/* EMPTY*/{$$ = NIL; }
1244+
OptSchemaEltListschema_stmt
1245+
{
1246+
if (@$ <0)/* see comments for YYLLOC_DEFAULT*/
1247+
@$ =@2;
1248+
$$ = lappend($1,$2);
1249+
}
1250+
|/* EMPTY*/
1251+
{$$ = NIL; }
12281252
;
12291253

12301254
/*

‎src/test/regress/expected/namespace.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ CREATE SCHEMA IF NOT EXISTS test_schema_1 -- fail, disallowed
4747
b int UNIQUE
4848
);
4949
ERROR: CREATE SCHEMA IF NOT EXISTS cannot include schema elements
50-
LINE1: CREATE SCHEMA IF NOT EXISTS test_schema_1
51-
^
50+
LINE2: CREATE TABLE abc (
51+
^
5252
DROP SCHEMA test_schema_1 CASCADE;
5353
NOTICE: drop cascades to 2 other objects
5454
DETAIL: drop cascades to table test_schema_1.abc

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp