Commit 23db70bf authored by Bruce Momjian's avatar Bruce Momjian

Lex/yacc source cleanup like indent.

parent 319dbfa7
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.4 1996/11/13 20:47:45 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.5 1997/09/08 03:19:50 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -57,10 +57,12 @@ ...@@ -57,10 +57,12 @@
#include "miscadmin.h" #include "miscadmin.h"
#define DO_START { StartTransactionCommand();\ #define DO_START { \
StartTransactionCommand();\
} }
#define DO_END { CommitTransactionCommand();\ #define DO_END { \
CommitTransactionCommand();\
if (!Quiet) { EMITPROMPT; }\ if (!Quiet) { EMITPROMPT; }\
fflush(stdout); \ fflush(stdout); \
} }
...@@ -70,7 +72,8 @@ static Oid objectid; ...@@ -70,7 +72,8 @@ static Oid objectid;
%} %}
%union { %union
{
List *list; List *list;
IndexElem *ielem; IndexElem *ielem;
char *str; char *str;
...@@ -146,18 +149,21 @@ CreateStmt: ...@@ -146,18 +149,21 @@ CreateStmt:
} }
typelist typelist
{ {
if (!Quiet) putchar('\n'); if (!Quiet)
putchar('\n');
DO_END; DO_END;
} }
RPAREN RPAREN
{ {
DO_START; DO_START;
if ($2) { if ($2)
{
extern Relation reldesc; extern Relation reldesc;
TupleDesc tupdesc; TupleDesc tupdesc;
if (reldesc) { if (reldesc)
{
puts("create bootstrap: Warning, open relation"); puts("create bootstrap: Warning, open relation");
puts("exists, closing first"); puts("exists, closing first");
closerel(NULL); closerel(NULL);
...@@ -170,7 +176,9 @@ CreateStmt: ...@@ -170,7 +176,9 @@ CreateStmt:
tupdesc); tupdesc);
if (DebugMode) if (DebugMode)
puts("bootstrap relation created ok"); puts("bootstrap relation created ok");
} else { }
else
{
Oid id; Oid id;
TupleDesc tupdesc; TupleDesc tupdesc;
/* extern Oid heap_create();*/ /* extern Oid heap_create();*/
...@@ -203,7 +211,8 @@ InsertStmt: ...@@ -203,7 +211,8 @@ InsertStmt:
{ {
if (num_tuples_read != numattr) if (num_tuples_read != numattr)
elog(WARN,"incorrect number of values for tuple"); elog(WARN,"incorrect number of values for tuple");
if (reldesc == (Relation)NULL) { if (reldesc == (Relation)NULL)
{
elog(WARN,"must OPEN RELATION before INSERT\n"); elog(WARN,"must OPEN RELATION before INSERT\n");
err_out(); err_out();
} }
...@@ -213,7 +222,8 @@ InsertStmt: ...@@ -213,7 +222,8 @@ InsertStmt:
InsertOneTuple(objectid); InsertOneTuple(objectid);
if (DebugMode) if (DebugMode)
puts("Insert End"); puts("Insert End");
if (!Quiet) { putchar('\n'); } if (!Quiet)
putchar('\n');
DO_END; DO_END;
if (DebugMode) if (DebugMode)
puts("Transaction End"); puts("Transaction End");
...@@ -319,5 +329,3 @@ ident : ...@@ -319,5 +329,3 @@ ident :
ID { $$=yylval.ival; } ID { $$=yylval.ival; }
; ;
%% %%
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.6 1997/01/10 20:16:26 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.7 1997/09/08 03:19:53 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.42 1997/09/04 13:24:25 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.43 1997/09/08 03:19:57 momjian Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -71,7 +71,8 @@ static Node *makeA_Expr(int oper, char *opname, Node *lexpr, Node *rexpr); ...@@ -71,7 +71,8 @@ static Node *makeA_Expr(int oper, char *opname, Node *lexpr, Node *rexpr);
%} %}
%union { %union
{
double dval; double dval;
int ival; int ival;
char chr; char chr;
...@@ -407,8 +408,7 @@ OptDefault: DEFAULT default_expr ...@@ -407,8 +408,7 @@ OptDefault: DEFAULT default_expr
char *defval; char *defval;
defval = (char*) palloc (deflen + 1); defval = (char*) palloc (deflen + 1);
memcpy (defval, memcpy (defval, parseString + DefaultStartPosition,
parseString + DefaultStartPosition,
deflen); deflen);
defval[deflen] = 0; defval[deflen] = 0;
$$ = defval; $$ = defval;
...@@ -456,21 +456,19 @@ default_expr: AexprConst ...@@ -456,21 +456,19 @@ default_expr: AexprConst
| AexprConst TYPECAST Typename | AexprConst TYPECAST Typename
{ {
/* AexprConst can be either A_Const or ParamNo */ /* AexprConst can be either A_Const or ParamNo */
if (nodeTag($1) == T_A_Const) { if (nodeTag($1) == T_A_Const)
((A_Const *)$1)->typename = $3; ((A_Const *)$1)->typename = $3;
}else { else
elog (WARN, "Cannot handle parameter in DEFAULT"); elog (WARN, "Cannot handle parameter in DEFAULT");
}
$$ = (Node *)$1; $$ = (Node *)$1;
} }
| CAST AexprConst AS Typename | CAST AexprConst AS Typename
{ {
/* AexprConst can be either A_Const or ParamNo */ /* AexprConst can be either A_Const or ParamNo */
if (nodeTag($2) == T_A_Const) { if (nodeTag($2) == T_A_Const)
((A_Const *)$2)->typename = $4; ((A_Const *)$2)->typename = $4;
}else { else
elog (WARN, "Cannot handle parameter in DEFAULT"); elog (WARN, "Cannot handle parameter in DEFAULT");
}
$$ = (Node *)$2; $$ = (Node *)$2;
} }
| '(' default_expr ')' | '(' default_expr ')'
...@@ -661,7 +659,8 @@ ConstraintElem: ...@@ -661,7 +659,8 @@ ConstraintElem:
| ConstraintDef { $$ = $1; } | ConstraintDef { $$ = $1; }
; ;
ConstraintDef: CHECK a_expr { ConstraintDef: CHECK a_expr
{
ConstraintDef *constr = palloc (sizeof(ConstraintDef)); ConstraintDef *constr = palloc (sizeof(ConstraintDef));
int chklen = CurScanPosition() - CheckStartPosition; int chklen = CurScanPosition() - CheckStartPosition;
char *check; char *check;
...@@ -956,12 +955,14 @@ privileges: ALL PRIVILEGES ...@@ -956,12 +955,14 @@ privileges: ALL PRIVILEGES
{ {
$$ = aclmakepriv("rwaR",0); $$ = aclmakepriv("rwaR",0);
} }
| operation_commalist { | operation_commalist
{
$$ = $1; $$ = $1;
} }
; ;
operation_commalist: operation { operation_commalist: operation
{
$$ = aclmakepriv("",$1); $$ = aclmakepriv("",$1);
} }
| operation_commalist ',' operation | operation_commalist ',' operation
...@@ -971,30 +972,38 @@ operation_commalist: operation { ...@@ -971,30 +972,38 @@ operation_commalist: operation {
} }
; ;
operation: SELECT { operation: SELECT
{
$$ = ACL_MODE_RD_CHR; $$ = ACL_MODE_RD_CHR;
} }
| INSERT { | INSERT
{
$$ = ACL_MODE_AP_CHR; $$ = ACL_MODE_AP_CHR;
} }
| UPDATE { | UPDATE
{
$$ = ACL_MODE_WR_CHR; $$ = ACL_MODE_WR_CHR;
} }
| DELETE { | DELETE
{
$$ = ACL_MODE_WR_CHR; $$ = ACL_MODE_WR_CHR;
} }
| RULE { | RULE
{
$$ = ACL_MODE_RU_CHR; $$ = ACL_MODE_RU_CHR;
} }
; ;
grantee: PUBLIC { grantee: PUBLIC
{
$$ = aclmakeuser("A",""); $$ = aclmakeuser("A","");
} }
| GROUP Id { | GROUP Id
{
$$ = aclmakeuser("G",$2); $$ = aclmakeuser("G",$2);
} }
| Id { | Id
{
$$ = aclmakeuser("U",$1); $$ = aclmakeuser("U",$1);
} }
; ;
...@@ -1005,6 +1014,7 @@ opt_with_grant : /* empty */ ...@@ -1005,6 +1014,7 @@ opt_with_grant : /* empty */
yyerror("WITH GRANT OPTION is not supported. Only relation owners can set privileges"); yyerror("WITH GRANT OPTION is not supported. Only relation owners can set privileges");
} }
; ;
/***************************************************************************** /*****************************************************************************
* *
* QUERY: * QUERY:
...@@ -2246,22 +2256,20 @@ typname: txname ...@@ -2246,22 +2256,20 @@ typname: txname
/* Is this the name of a complex type? If so, implement /* Is this the name of a complex type? If so, implement
* it as a set. * it as a set.
*/ */
if (!strcmp(saved_relname, tname)) { if (!strcmp(saved_relname, tname))
/* This attr is the same type as the relation /* This attr is the same type as the relation
* being defined. The classic example: create * being defined. The classic example: create
* emp(name=text,mgr=emp) * emp(name=text,mgr=emp)
*/ */
$$->setof = TRUE; $$->setof = TRUE;
}else if (get_typrelid((Type)type(tname)) else if (get_typrelid((Type)type(tname)) != InvalidOid)
!= InvalidOid) {
/* (Eventually add in here that the set can only /* (Eventually add in here that the set can only
* contain one element.) * contain one element.)
*/ */
$$->setof = TRUE; $$->setof = TRUE;
} else { else
$$->setof = FALSE; $$->setof = FALSE;
} }
}
| SETOF txname | SETOF txname
{ {
char *tname = xlateSqlType($2); char *tname = xlateSqlType($2);
...@@ -2305,7 +2313,8 @@ Typename: typname opt_array_bounds ...@@ -2305,7 +2313,8 @@ Typename: typname opt_array_bounds
* here, and do nothing if so. This seems to fix the problem. * here, and do nothing if so. This seems to fix the problem.
* - thomas 1997-07-13 * - thomas 1997-07-13
*/ */
if (strlen($1) > 0) { if (strlen($1) > 0)
{
/* /*
* The following implements char() and varchar(). * The following implements char() and varchar().
...@@ -2315,25 +2324,22 @@ Typename: typname opt_array_bounds ...@@ -2315,25 +2324,22 @@ Typename: typname opt_array_bounds
* - ay 6/95 * - ay 6/95
*/ */
$$ = makeNode(TypeName); $$ = makeNode(TypeName);
if (!strcasecmp($1, "char")) { if (!strcasecmp($1, "char"))
$$->name = "bpchar"; /* strdup("bpchar"); */ $$->name = "bpchar"; /* strdup("bpchar"); */
} else if (!strcasecmp($1, "varchar")) { else if (!strcasecmp($1, "varchar"))
$$->name = "varchar"; /* strdup("varchar"); */ $$->name = "varchar"; /* strdup("varchar"); */
} else { else
yyerror("parse error"); yyerror("parse error");
} if ($3 < 1)
if ($3 < 1) { elog(WARN, "length for '%s' type must be at least 1",$1);
elog(WARN, "length for '%s' type must be at least 1", else if ($3 > 4096)
$1);
} else if ($3 > 4096) {
/* we can store a char() of length up to the size /* we can store a char() of length up to the size
* of a page (8KB) - page headers and friends but * of a page (8KB) - page headers and friends but
* just to be safe here... - ay 6/95 * just to be safe here... - ay 6/95
* XXX note this hardcoded limit - thomas 1997-07-13 * XXX note this hardcoded limit - thomas 1997-07-13
*/ */
elog(WARN, "length for '%s' type cannot exceed 4096", elog(WARN, "length for '%s' type cannot exceed 4096",$1);
$1);
}
/* we actually implement this sort of like a varlen, so /* we actually implement this sort of like a varlen, so
* the first 4 bytes is the length. (the difference * the first 4 bytes is the length. (the difference
* between this and "text" is that we blank-pad and * between this and "text" is that we blank-pad and
...@@ -2393,21 +2399,19 @@ a_expr: attr opt_indirection ...@@ -2393,21 +2399,19 @@ a_expr: attr opt_indirection
| AexprConst TYPECAST Typename | AexprConst TYPECAST Typename
{ {
/* AexprConst can be either A_Const or ParamNo */ /* AexprConst can be either A_Const or ParamNo */
if (nodeTag($1) == T_A_Const) { if (nodeTag($1) == T_A_Const)
((A_Const *)$1)->typename = $3; ((A_Const *)$1)->typename = $3;
}else { else
((ParamNo *)$1)->typename = $3; ((ParamNo *)$1)->typename = $3;
}
$$ = (Node *)$1; $$ = (Node *)$1;
} }
| CAST AexprConst AS Typename | CAST AexprConst AS Typename
{ {
/* AexprConst can be either A_Const or ParamNo */ /* AexprConst can be either A_Const or ParamNo */
if (nodeTag($2) == T_A_Const) { if (nodeTag($2) == T_A_Const)
((A_Const *)$2)->typename = $4; ((A_Const *)$2)->typename = $4;
}else { else
((ParamNo *)$2)->typename = $4; ((ParamNo *)$2)->typename = $4;
}
$$ = (Node *)$2; $$ = (Node *)$2;
} }
| '(' a_expr_or_null ')' | '(' a_expr_or_null ')'
...@@ -2423,7 +2427,8 @@ a_expr: attr opt_indirection ...@@ -2423,7 +2427,8 @@ a_expr: attr opt_indirection
| a_expr Op | a_expr Op
{ $$ = makeA_Expr(OP, $2, $1, NULL); } { $$ = makeA_Expr(OP, $2, $1, NULL); }
| Id | Id
{ /* could be a column name or a relation_name */ {
/* could be a column name or a relation_name */
Ident *n = makeNode(Ident); Ident *n = makeNode(Ident);
n->name = $1; n->name = $1;
n->indirection = NULL; n->indirection = NULL;
...@@ -2523,12 +2528,14 @@ a_expr: attr opt_indirection ...@@ -2523,12 +2528,14 @@ a_expr: attr opt_indirection
| a_expr IS NOT PNULL | a_expr IS NOT PNULL
{ $$ = makeA_Expr(NOTNULL, NULL, $1, NULL); } { $$ = makeA_Expr(NOTNULL, NULL, $1, NULL); }
| a_expr BETWEEN AexprConst AND AexprConst | a_expr BETWEEN AexprConst AND AexprConst
{ $$ = makeA_Expr(AND, NULL, {
$$ = makeA_Expr(AND, NULL,
makeA_Expr(OP, ">=", $1, $3), makeA_Expr(OP, ">=", $1, $3),
makeA_Expr(OP, "<=", $1, $5)); makeA_Expr(OP, "<=", $1, $5));
} }
| a_expr NOT BETWEEN AexprConst AND AexprConst | a_expr NOT BETWEEN AexprConst AND AexprConst
{ $$ = makeA_Expr(OR, NULL, {
$$ = makeA_Expr(OR, NULL,
makeA_Expr(OP, "<", $1, $4), makeA_Expr(OP, "<", $1, $4),
makeA_Expr(OP, ">", $1, $6)); makeA_Expr(OP, ">", $1, $6));
} }
...@@ -2583,9 +2590,7 @@ printf( "string is %s\n", $1); ...@@ -2583,9 +2590,7 @@ printf( "string is %s\n", $1);
; ;
position_list: a_expr IN expr_list position_list: a_expr IN expr_list
{ { $$ = lappend($3, $1); }
$$ = lappend($3, $1);
}
| /* EMPTY */ | /* EMPTY */
{ $$ = NIL; } { $$ = NIL; }
; ;
...@@ -2790,11 +2795,10 @@ relation_name: SpecialRuleRelation ...@@ -2790,11 +2795,10 @@ relation_name: SpecialRuleRelation
if (strcmp(LogRelationName, $1) == 0 if (strcmp(LogRelationName, $1) == 0
|| strcmp(VariableRelationName, $1) == 0 || strcmp(VariableRelationName, $1) == 0
|| strcmp(TimeRelationName, $1) == 0 || strcmp(TimeRelationName, $1) == 0
|| strcmp(MagicRelationName, $1) == 0) { || strcmp(MagicRelationName, $1) == 0)
elog(WARN, "%s cannot be accessed by users", $1); elog(WARN, "%s cannot be accessed by users", $1);
} else { else
$$ = $1; $$ = $1;
}
strNcpy(saved_relname, $1, NAMEDATALEN-1); strNcpy(saved_relname, $1, NAMEDATALEN-1);
} }
; ;
...@@ -2913,4 +2917,3 @@ void parser_init(Oid *typev, int nargs) ...@@ -2913,4 +2917,3 @@ void parser_init(Oid *typev, int nargs)
param_type_init(typev, nargs); param_type_init(typev, nargs);
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.18 1997/09/05 09:05:48 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.19 1997/09/08 03:20:04 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -155,18 +155,14 @@ other . ...@@ -155,18 +155,14 @@ other .
} }
<xq>{xqdouble} | <xq>{xqdouble} |
<xq>{xqinside} { <xq>{xqinside} {
if ((llen+yyleng) > (MAX_PARSE_BUFFER - 1)) { if ((llen+yyleng) > (MAX_PARSE_BUFFER - 1))
elog(WARN,"quoted string parse buffer of %d chars exceeded",MAX_PARSE_BUFFER); elog(WARN,"quoted string parse buffer of %d chars exceeded",MAX_PARSE_BUFFER);
/* not reached */
}
memcpy(literal+llen, yytext, yyleng+1); memcpy(literal+llen, yytext, yyleng+1);
llen += yyleng; llen += yyleng;
} }
<xq>{xqliteral} { <xq>{xqliteral} {
if ((llen+yyleng-1) > (MAX_PARSE_BUFFER - 1)) { if ((llen+yyleng-1) > (MAX_PARSE_BUFFER - 1))
elog(WARN,"quoted string parse buffer of %d chars exceeded",MAX_PARSE_BUFFER); elog(WARN,"quoted string parse buffer of %d chars exceeded",MAX_PARSE_BUFFER);
/* not reached */
}
memcpy(literal+llen, yytext+1, yyleng); memcpy(literal+llen, yytext+1, yyleng);
llen += yyleng-1; llen += yyleng-1;
} }
...@@ -191,7 +187,8 @@ other . ...@@ -191,7 +187,8 @@ other .
yylval.str = pstrdup((char*)yytext); yylval.str = pstrdup((char*)yytext);
return (Op); return (Op);
} }
{param} { yylval.ival = atoi((char*)&yytext[1]); {param} {
yylval.ival = atoi((char*)&yytext[1]);
return (PARAM); return (PARAM);
} }
{integer} { {integer} {
...@@ -200,6 +197,7 @@ other . ...@@ -200,6 +197,7 @@ other .
} }
{real} { {real} {
char* endptr; char* endptr;
errno = 0; errno = 0;
yylval.dval = strtod(((char *)yytext),&endptr); yylval.dval = strtod(((char *)yytext),&endptr);
if (*endptr != '\0' || errno == ERANGE) if (*endptr != '\0' || errno == ERANGE)
...@@ -217,18 +215,20 @@ other . ...@@ -217,18 +215,20 @@ other .
keyword = ScanKeywordLookup((char*)yytext); keyword = ScanKeywordLookup((char*)yytext);
if (keyword != NULL) { if (keyword != NULL) {
if ( keyword->value == DEFAULT ) { if ( keyword->value == DEFAULT )
{
DefaultStartPosition = CurScanPosition () + yyleng + 1; DefaultStartPosition = CurScanPosition () + yyleng + 1;
printf( "default offset is %d\n", DefaultStartPosition); printf( "default offset is %d\n", DefaultStartPosition);
}
} else if ( keyword->value == CHECK ) { else if ( keyword->value == CHECK )
{
CheckStartPosition = CurScanPosition () + yyleng + 1; CheckStartPosition = CurScanPosition () + yyleng + 1;
printf( "check offset is %d\n", CheckStartPosition); printf( "check offset is %d\n", CheckStartPosition);
}
};
return (keyword->value); return (keyword->value);
} else { }
else
{
yylval.str = pstrdup((char*)yytext); yylval.str = pstrdup((char*)yytext);
return (IDENT); return (IDENT);
} }
...@@ -274,25 +274,25 @@ init_io() ...@@ -274,25 +274,25 @@ init_io()
int int
input() input()
{ {
if (parseCh == NULL) { if (parseCh == NULL)
{
parseCh = parseString; parseCh = parseString;
return(*parseCh++); return(*parseCh++);
} else if (*parseCh == '\0') { }
else if (*parseCh == '\0')
return(0); return(0);
} else { else
return(*parseCh++); return(*parseCh++);
}
} }
/* undo lex input from a string instead of from stdin */ /* undo lex input from a string instead of from stdin */
void void
unput(char c) unput(char c)
{ {
if (parseCh == NULL) { if (parseCh == NULL)
elog(FATAL, "Unput() failed.\n"); elog(FATAL, "Unput() failed.\n");
} else if (c != 0) { else if (c != 0)
*--parseCh = c; *--parseCh = c;
}
} }
int int
...@@ -309,7 +309,8 @@ myinput(char* buf, int max) ...@@ -309,7 +309,8 @@ myinput(char* buf, int max)
{ {
int len, copylen; int len, copylen;
if (parseCh == NULL) { if (parseCh == NULL)
{
len = strlen(parseString); len = strlen(parseString);
if (len >= max) if (len >= max)
copylen = max - 1; copylen = max - 1;
...@@ -320,16 +321,15 @@ myinput(char* buf, int max) ...@@ -320,16 +321,15 @@ myinput(char* buf, int max)
buf[copylen] = '\0'; buf[copylen] = '\0';
parseCh = parseString; parseCh = parseString;
return copylen; return copylen;
} else {
return 0; /* end of string */
} }
else
return 0; /* end of string */
} }
int int
CurScanPosition(void) CurScanPosition(void)
{ {
printf( "current position is %d\n", yy_c_buf_p - yy_current_buffer->yy_ch_buf - yyleng); printf( "current position is %d\n", yy_c_buf_p - yy_current_buffer->yy_ch_buf - yyleng);
return (yy_c_buf_p - yy_current_buffer->yy_ch_buf - yyleng); return (yy_c_buf_p - yy_current_buffer->yy_ch_buf - yyleng);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment