1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-17 17:02:08 +03:00

Remove all time travel stuff. Small parser cleanup.

This commit is contained in:
Bruce Momjian
1997-11-20 23:24:03 +00:00
parent e075271c17
commit e9e1ff226f
66 changed files with 574 additions and 899 deletions

View File

@ -6,45 +6,20 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.27 1997/11/17 16:59:08 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.28 1997/11/20 23:22:24 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include <string.h>
#include <stdio.h>
#include <pwd.h>
#include <sys/param.h> /* for MAXPATHLEN */
#include "postgres.h"
#include "parser/catalog_utils.h"
#include "parser/gramparse.h"
#include "parser/parse_query.h"
#include "nodes/pg_list.h"
#include "nodes/execnodes.h"
#include "nodes/makefuncs.h"
#include "nodes/primnodes.h"
#include "nodes/plannodes.h"
#include "nodes/relation.h"
#include "utils/builtins.h"
#include "utils/exc.h"
#include "utils/excid.h"
#include "utils/lsyscache.h"
#include "utils/palloc.h"
#include "utils/syscache.h"
#include "catalog/pg_aggregate.h"
#include "catalog/pg_type.h"
#include "access/heapam.h"
#include "optimizer/clauses.h"
void init_io(); /* from scan.l */
void parser_init(Oid *typev, int nargs); /* from gram.y */
int yyparse(); /* from gram.c */
char *parseString; /* the char* which holds the string to be
* parsed */
char *parseCh; /* a pointer used during parsing to walk
* down ParseString */
List *parsetree = NIL;
#ifdef SETS_FIXED
@ -70,9 +45,7 @@ parser(char *str, Oid *typev, int nargs)
init_io();
/* Set things up to read from the string, if there is one */
parseString = (char *) palloc(strlen(str) + 1);
memmove(parseString, str, strlen(str) + 1);
parseString = pstrdup(str);
parser_init(typev, nargs);
yyresult = yyparse();
@ -83,10 +56,8 @@ parser(char *str, Oid *typev, int nargs)
clearerr(stdin);
if (yyresult)
{ /* error */
if (yyresult) /* error */
return ((QueryTreeList *) NULL);
}
queryList = parse_analyze(parsetree);
@ -205,339 +176,3 @@ define_sets(Node *clause)
#endif
/* not used
#define PSIZE(PTR) (*((int32 *)(PTR) - 1))
*/
Node *
parser_typecast(Value *expr, TypeName *typename, int typlen)
{
/* check for passing non-ints */
Const *adt;
Datum lcp;
Type tp;
char type_string[NAMEDATALEN];
int32 len;
char *cp = NULL;
char *const_string = NULL;
bool string_palloced = false;
switch (nodeTag(expr))
{
case T_String:
const_string = DatumGetPointer(expr->val.str);
break;
case T_Integer:
const_string = (char *) palloc(256);
string_palloced = true;
sprintf(const_string, "%ld", expr->val.ival);
break;
default:
elog(WARN,
"parser_typecast: cannot cast this expression to type \"%s\"",
typename->name);
}
if (typename->arrayBounds != NIL)
{
sprintf(type_string, "_%s", typename->name);
tp = (Type) type(type_string);
}
else
{
tp = (Type) type(typename->name);
}
len = tlen(tp);
#if 0 /* fix me */
switch (CInteger(lfirst(expr)))
{
case INT4OID: /* int4 */
const_string = (char *) palloc(256);
string_palloced = true;
sprintf(const_string, "%d", ((Const *) lnext(expr))->constvalue);
break;
case NAMEOID: /* char16 */
const_string = (char *) palloc(256);
string_palloced = true;
sprintf(const_string, "%s", ((Const *) lnext(expr))->constvalue);
break;
case CHAROID: /* char */
const_string = (char *) palloc(256);
string_palloced = true;
sprintf(const_string, "%c", ((Const) lnext(expr))->constvalue);
break;
case FLOAT8OID: /* float8 */
const_string = (char *) palloc(256);
string_palloced = true;
sprintf(const_string, "%f", ((Const) lnext(expr))->constvalue);
break;
case CASHOID: /* money */
const_string = (char *) palloc(256);
string_palloced = true;
sprintf(const_string, "%d",
(int) ((Const *) expr)->constvalue);
break;
case TEXTOID: /* text */
const_string = DatumGetPointer(((Const) lnext(expr))->constvalue);
const_string = (char *) textout((struct varlena *) const_string);
break;
case UNKNOWNOID: /* unknown */
const_string = DatumGetPointer(((Const) lnext(expr))->constvalue);
const_string = (char *) textout((struct varlena *) const_string);
break;
default:
elog(WARN, "unknown type %d", CInteger(lfirst(expr)));
}
#endif
cp = instr2(tp, const_string, typlen);
if (!tbyvalue(tp))
{
/*
if (len >= 0 && len != PSIZE(cp)) {
char *pp;
pp = (char *) palloc(len);
memmove(pp, cp, len);
cp = pp;
}
*/
lcp = PointerGetDatum(cp);
}
else
{
switch (len)
{
case 1:
lcp = Int8GetDatum(cp);
break;
case 2:
lcp = Int16GetDatum(cp);
break;
case 4:
lcp = Int32GetDatum(cp);
break;
default:
lcp = PointerGetDatum(cp);
break;
}
}
adt = makeConst(typeid(tp),
len,
(Datum) lcp,
false,
tbyvalue(tp),
false, /* not a set */
true /* is cast */ );
if (string_palloced)
pfree(const_string);
return (Node *) adt;
}
Node *
parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen)
{
/* check for passing non-ints */
Const *adt;
Datum lcp;
int32 len = tlen(tp);
char *cp = NULL;
char *const_string = NULL;
bool string_palloced = false;
Assert(IsA(expr, Const));
switch (exprType)
{
case 0: /* NULL */
break;
case INT4OID: /* int4 */
const_string = (char *) palloc(256);
string_palloced = true;
sprintf(const_string, "%d",
(int) ((Const *) expr)->constvalue);
break;
case NAMEOID: /* char16 */
const_string = (char *) palloc(256);
string_palloced = true;
sprintf(const_string, "%s",
(char *) ((Const *) expr)->constvalue);
break;
case CHAROID: /* char */
const_string = (char *) palloc(256);
string_palloced = true;
sprintf(const_string, "%c",
(char) ((Const *) expr)->constvalue);
break;
case FLOAT4OID: /* float4 */
{
float32 floatVal =
DatumGetFloat32(((Const *) expr)->constvalue);
const_string = (char *) palloc(256);
string_palloced = true;
sprintf(const_string, "%f", *floatVal);
break;
}
case FLOAT8OID: /* float8 */
{
float64 floatVal =
DatumGetFloat64(((Const *) expr)->constvalue);
const_string = (char *) palloc(256);
string_palloced = true;
sprintf(const_string, "%f", *floatVal);
break;
}
case CASHOID: /* money */
const_string = (char *) palloc(256);
string_palloced = true;
sprintf(const_string, "%ld",
(long) ((Const *) expr)->constvalue);
break;
case TEXTOID: /* text */
const_string =
DatumGetPointer(((Const *) expr)->constvalue);
const_string = (char *) textout((struct varlena *) const_string);
break;
case UNKNOWNOID: /* unknown */
const_string =
DatumGetPointer(((Const *) expr)->constvalue);
const_string = (char *) textout((struct varlena *) const_string);
break;
default:
elog(WARN, "unknown type %u ", exprType);
}
if (!exprType)
{
adt = makeConst(typeid(tp),
(Size) 0,
(Datum) NULL,
true, /* isnull */
false, /* was omitted */
false, /* not a set */
true /* is cast */ );
return ((Node *) adt);
}
cp = instr2(tp, const_string, typlen);
if (!tbyvalue(tp))
{
/*
if (len >= 0 && len != PSIZE(cp)) {
char *pp;
pp = (char *) palloc(len);
memmove(pp, cp, len);
cp = pp;
}
*/
lcp = PointerGetDatum(cp);
}
else
{
switch (len)
{
case 1:
lcp = Int8GetDatum(cp);
break;
case 2:
lcp = Int16GetDatum(cp);
break;
case 4:
lcp = Int32GetDatum(cp);
break;
default:
lcp = PointerGetDatum(cp);
break;
}
}
adt = makeConst(typeid(tp),
(Size) len,
(Datum) lcp,
false,
false, /* was omitted */
false, /* not a set */
true /* is cast */ );
/*
* printf("adt %s : %u %d %d\n",CString(expr),typeid(tp) , len,cp);
*/
if (string_palloced)
pfree(const_string);
return ((Node *) adt);
}
Aggreg *
ParseAgg(char *aggname, Oid basetype, Node *target)
{
Oid fintype;
Oid vartype;
Oid xfn1;
Form_pg_aggregate aggform;
Aggreg *aggreg;
HeapTuple theAggTuple;
theAggTuple = SearchSysCacheTuple(AGGNAME, PointerGetDatum(aggname),
ObjectIdGetDatum(basetype),
0, 0);
if (!HeapTupleIsValid(theAggTuple))
{
elog(WARN, "aggregate %s does not exist", aggname);
}
aggform = (Form_pg_aggregate) GETSTRUCT(theAggTuple);
fintype = aggform->aggfinaltype;
xfn1 = aggform->aggtransfn1;
if (nodeTag(target) != T_Var && nodeTag(target) != T_Expr)
elog(WARN, "parser: aggregate can only be applied on an attribute or expression");
/* only aggregates with transfn1 need a base type */
if (OidIsValid(xfn1))
{
basetype = aggform->aggbasetype;
if (nodeTag(target) == T_Var)
vartype = ((Var *) target)->vartype;
else
vartype = ((Expr *) target)->typeOid;
if (basetype != vartype)
{
Type tp1,
tp2;
tp1 = get_id_type(basetype);
tp2 = get_id_type(vartype);
elog(NOTICE, "Aggregate type mismatch:");
elog(WARN, "%s works on %s, not %s", aggname,
tname(tp1), tname(tp2));
}
}
aggreg = makeNode(Aggreg);
aggreg->aggname = pstrdup(aggname);
aggreg->basetype = aggform->aggbasetype;
aggreg->aggtype = fintype;
aggreg->target = target;
return aggreg;
}