|
|
|
|
%{
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* bootscanner.l
|
|
|
|
|
* a lexical scanner for the bootstrap parser
|
|
|
|
|
*
|
|
|
|
|
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
|
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* IDENTIFICATION
|
|
|
|
|
* src/backend/bootstrap/bootscanner.l
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
|
|
#include "access/attnum.h"
|
|
|
|
|
#include "access/htup.h"
|
|
|
|
|
#include "access/itup.h"
|
|
|
|
|
#include "access/tupdesc.h"
|
|
|
|
|
#include "bootstrap/bootstrap.h"
|
|
|
|
|
#include "catalog/pg_am.h"
|
|
|
|
|
#include "catalog/pg_attribute.h"
|
|
|
|
|
#include "catalog/pg_class.h"
|
|
|
|
|
#include "nodes/nodes.h"
|
|
|
|
|
#include "nodes/parsenodes.h"
|
|
|
|
|
#include "nodes/pg_list.h"
|
|
|
|
|
#include "nodes/primnodes.h"
|
|
|
|
|
#include "parser/scansup.h"
|
|
|
|
|
#include "rewrite/prs2lock.h"
|
|
|
|
|
#include "storage/block.h"
|
|
|
|
|
#include "storage/fd.h"
|
|
|
|
|
#include "storage/itemptr.h"
|
|
|
|
|
#include "storage/off.h"
|
|
|
|
|
#include "utils/rel.h"
|
|
|
|
|
|
|
|
|
|
/* Not needed now that this file is compiled as part of bootparse. */
|
|
|
|
|
/* #include "bootparse.h" */
|
|
|
|
|
|
|
|
|
|
/* LCOV_EXCL_START */
|
|
|
|
|
|
|
|
|
|
/* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
|
|
|
|
|
#undef fprintf
|
Improve handling of ereport(ERROR) and elog(ERROR).
In commit 71450d7fd6c7cf7b3e38ac56e363bff6a681973c, we added code to inform
suitably-intelligent compilers that ereport() doesn't return if the elevel
is ERROR or higher. This patch extends that to elog(), and also fixes a
double-evaluation hazard that the previous commit created in ereport(),
as well as reducing the emitted code size.
The elog() improvement requires the compiler to support __VA_ARGS__, which
should be available in just about anything nowadays since it's required by
C99. But our minimum language baseline is still C89, so add a configure
test for that.
The previous commit assumed that ereport's elevel could be evaluated twice,
which isn't terribly safe --- there are already counterexamples in xlog.c.
On compilers that have __builtin_constant_p, we can use that to protect the
second test, since there's no possible optimization gain if the compiler
doesn't know the value of elevel. Otherwise, use a local variable inside
the macros to prevent double evaluation. The local-variable solution is
inferior because (a) it leads to useless code being emitted when elevel
isn't constant, and (b) it increases the optimization level needed for the
compiler to recognize that subsequent code is unreachable. But it seems
better than not teaching non-gcc compilers about unreachability at all.
Lastly, if the compiler has __builtin_unreachable(), we can use that
instead of abort(), resulting in a noticeable code savings since no
function call is actually emitted. However, it seems wise to do this only
in non-assert builds. In an assert build, continue to use abort(), so that
the behavior will be predictable and debuggable if the "impossible"
happens.
These changes involve making the ereport and elog macros emit do-while
statement blocks not just expressions, which forces small changes in
a few call sites.
Andres Freund, Tom Lane, Heikki Linnakangas
13 years ago
|
|
|
#define fprintf(file, fmt, msg) fprintf_to_ereport(fmt, msg)
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
fprintf_to_ereport(const char *fmt, const char *msg)
|
|
|
|
|
{
|
|
|
|
|
ereport(ERROR, (errmsg_internal("%s", msg)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int yyline = 1; /* line number for error reporting */
|
|
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
%option 8bit
|
|
|
|
|
%option never-interactive
|
|
|
|
|
%option nodefault
|
|
|
|
|
%option noinput
|
|
|
|
|
%option nounput
|
|
|
|
|
%option noyywrap
|
|
|
|
|
%option warn
|
|
|
|
|
%option prefix="boot_yy"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
D [0-9]
|
|
|
|
|
oct \\{D}{D}{D}
|
|
|
|
|
id ([A-Za-z0-9_]|{oct}|\-)+
|
|
|
|
|
sid \"([^\"])*\"
|
|
|
|
|
arrayid [A-Za-z0-9_]+\[{D}*\]
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
open { return OPEN; }
|
|
|
|
|
|
|
|
|
|
close { return XCLOSE; }
|
|
|
|
|
|
|
|
|
|
create { return XCREATE; }
|
|
|
|
|
|
|
|
|
|
OID { return OBJ_ID; }
|
|
|
|
|
bootstrap { return XBOOTSTRAP; }
|
|
|
|
|
"shared_relation" { return XSHARED_RELATION; }
|
|
|
|
|
"without_oids" { return XWITHOUT_OIDS; }
|
|
|
|
|
"rowtype_oid" { return XROWTYPE_OID; }
|
|
|
|
|
_null_ { return NULLVAL; }
|
|
|
|
|
|
|
|
|
|
insert { return INSERT_TUPLE; }
|
|
|
|
|
|
|
|
|
|
"," { return COMMA; }
|
|
|
|
|
"=" { return EQUALS; }
|
|
|
|
|
"(" { return LPAREN; }
|
|
|
|
|
")" { return RPAREN; }
|
|
|
|
|
|
|
|
|
|
[\n] { yyline++; }
|
|
|
|
|
[\t] ;
|
|
|
|
|
" " ;
|
|
|
|
|
|
|
|
|
|
^\#[^\n]* ; /* drop everything after "#" for comments */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"declare" { return XDECLARE; }
|
|
|
|
|
"build" { return XBUILD; }
|
|
|
|
|
"indices" { return INDICES; }
|
|
|
|
|
"unique" { return UNIQUE; }
|
|
|
|
|
"index" { return INDEX; }
|
|
|
|
|
"on" { return ON; }
|
|
|
|
|
"using" { return USING; }
|
|
|
|
|
"toast" { return XTOAST; }
|
|
|
|
|
"FORCE" { return XFORCE; }
|
|
|
|
|
"NOT" { return XNOT; }
|
|
|
|
|
"NULL" { return XNULL; }
|
|
|
|
|
|
|
|
|
|
{arrayid} {
|
|
|
|
|
yylval.str = MapArrayTypeName(yytext);
|
|
|
|
|
return ID;
|
|
|
|
|
}
|
|
|
|
|
{id} {
|
|
|
|
|
yylval.str = scanstr(yytext);
|
|
|
|
|
return ID;
|
|
|
|
|
}
|
|
|
|
|
{sid} {
|
|
|
|
|
yytext[strlen(yytext)-1] = '\0'; /* strip off quotes */
|
|
|
|
|
yylval.str = scanstr(yytext+1);
|
|
|
|
|
yytext[strlen(yytext)] = '"'; /* restore quotes */
|
|
|
|
|
return ID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
. {
|
|
|
|
|
elog(ERROR, "syntax error at line %d: unexpected character \"%s\"", yyline, yytext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
/* LCOV_EXCL_STOP */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
yyerror(const char *message)
|
|
|
|
|
{
|
|
|
|
|
elog(ERROR, "%s at line %d", message, yyline);
|
|
|
|
|
}
|