diff options
Diffstat (limited to 'src/include/parser')
-rw-r--r-- | src/include/parser/analyze.h | 19 | ||||
-rw-r--r-- | src/include/parser/catalog_utils.h | 54 | ||||
-rw-r--r-- | src/include/parser/parse_agg.h | 38 | ||||
-rw-r--r-- | src/include/parser/parse_clause.h | 39 | ||||
-rw-r--r-- | src/include/parser/parse_expr.h | 34 | ||||
-rw-r--r-- | src/include/parser/parse_func.h | 97 | ||||
-rw-r--r-- | src/include/parser/parse_node.h | 67 | ||||
-rw-r--r-- | src/include/parser/parse_oper.h | 50 | ||||
-rw-r--r-- | src/include/parser/parse_query.h | 70 | ||||
-rw-r--r-- | src/include/parser/parse_relation.h | 56 | ||||
-rw-r--r-- | src/include/parser/parse_state.h | 34 | ||||
-rw-r--r-- | src/include/parser/parse_target.h | 39 | ||||
-rw-r--r-- | src/include/parser/parse_type.h | 37 | ||||
-rw-r--r-- | src/include/parser/parser.h | 21 |
14 files changed, 497 insertions, 158 deletions
diff --git a/src/include/parser/analyze.h b/src/include/parser/analyze.h new file mode 100644 index 00000000000..a85e2074bbe --- /dev/null +++ b/src/include/parser/analyze.h @@ -0,0 +1,19 @@ +/*------------------------------------------------------------------------- + * + * analyze.h + * + * + * Copyright (c) 1994, Regents of the University of California + * + * $Id: analyze.h,v 1.1 1997/11/25 22:06:47 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef ANALYZE_H +#define ANALYZE_H + +#include <parser/parse_node.h> + +QueryTreeList *parse_analyze(List *pl); + +#endif /* ANALYZE_H */ diff --git a/src/include/parser/catalog_utils.h b/src/include/parser/catalog_utils.h deleted file mode 100644 index 707ca3a1c6e..00000000000 --- a/src/include/parser/catalog_utils.h +++ /dev/null @@ -1,54 +0,0 @@ -/*------------------------------------------------------------------------- - * - * catalog_utils.h-- - * - * - * - * Copyright (c) 1994, Regents of the University of California - * - * $Id: catalog_utils.h,v 1.13 1997/09/08 21:53:35 momjian Exp $ - * - *------------------------------------------------------------------------- - */ -#ifndef CATALOG_UTILS_H -#define CATALOG_UTILS_H - -#include <catalog/pg_type.h> -#include <access/htup.h> - -typedef HeapTuple Type; -typedef HeapTuple Operator; - -extern Type get_id_type(Oid id); -extern char *get_id_typname(Oid id); -extern Type type(char *); -extern Oid att_typeid(Relation rd, int attid); -extern int att_attnelems(Relation rd, int attid); -extern Oid typeid(Type tp); -extern int16 tlen(Type t); -extern bool tbyval(Type t); -extern char *tname(Type t); -extern int tbyvalue(Type t); -extern Oid oprid(Operator op); -extern Operator oper(char *op, Oid arg1, Oid arg2, bool noWarnings); -extern Operator right_oper(char *op, Oid arg); -extern Operator left_oper(char *op, Oid arg); -extern int varattno(Relation rd, char *a); -extern bool varisset(Relation rd, char *name); -extern int nf_varattno(Relation rd, char *a); -extern char *getAttrName(Relation rd, int attrno); -extern char *instr2(Type tp, char *string, int typlen); -extern Oid GetArrayElementType(Oid typearray); -extern Oid funcid_get_rettype(Oid funcid); -extern bool -func_get_detail(char *funcname, int nargs, Oid *oid_array, - Oid *funcid, Oid *rettype, bool *retset, Oid **true_typeids); -extern Oid typeid_get_retinfunc(Oid type_id); -extern Oid typeid_get_retoutfunc(Oid type_id); -extern Oid typeid_get_relid(Oid type_id); -extern Oid get_typrelid(Type typ); -extern Oid get_typelem(Oid type_id); -extern void func_error(char *caller, char *funcname, int nargs, Oid *argtypes); -extern void agg_error(char *caller, char *aggname, Oid basetypeID); - -#endif /* CATALOG_UTILS_H */ diff --git a/src/include/parser/parse_agg.h b/src/include/parser/parse_agg.h new file mode 100644 index 00000000000..21ef36248fd --- /dev/null +++ b/src/include/parser/parse_agg.h @@ -0,0 +1,38 @@ +/*------------------------------------------------------------------------- + * + * parse_agg.h + * + * + * + * Copyright (c) 1994, Regents of the University of California + * + * $Id: parse_agg.h,v 1.1 1997/11/25 22:06:53 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef PARSE_AGG_H +#define PARSE_AGG_H + +#include <nodes/nodes.h> +#include <nodes/parsenodes.h> +#include <nodes/primnodes.h> +#include <parser/parse_node.h> + +void AddAggToParseState(ParseState *pstate, Aggreg *aggreg); + +void finalizeAggregates(ParseState *pstate, Query *qry); + +bool contain_agg_clause(Node *clause); + +bool exprIsAggOrGroupCol(Node *expr, List *groupClause); + +bool tleIsAggOrGroupCol(TargetEntry *tle, List *groupClause); + +void parseCheckAggregates(ParseState *pstate, Query *qry); + +Aggreg *ParseAgg(char *aggname, Oid basetype, Node *target); + +void agg_error(char *caller, char *aggname, Oid basetypeID); + +#endif /* PARSE_AGG_H */ + diff --git a/src/include/parser/parse_clause.h b/src/include/parser/parse_clause.h new file mode 100644 index 00000000000..2c0a5278f60 --- /dev/null +++ b/src/include/parser/parse_clause.h @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + * + * parse_clause.h + * + * + * + * Copyright (c) 1994, Regents of the University of California + * + * $Id: parse_clause.h,v 1.1 1997/11/25 22:06:54 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef PARSE_CLAUSE_H +#define PARSE_CLAUSE_H + +#include <nodes/pg_list.h> +#include <nodes/nodes.h> +#include <nodes/parsenodes.h> +#include <nodes/primnodes.h> +#include <parser/parse_node.h> + +void parseFromClause(ParseState *pstate, List *frmList); + +void makeRangeTable(ParseState *pstate, char *relname, List *frmList); + +Node *transformWhereClause(ParseState *pstate, Node *a_expr); + +TargetEntry *find_targetlist_entry(ParseState *pstate, + SortGroupBy *sortgroupby, List *tlist); + +List *transformGroupClause(ParseState *pstate, List *grouplist, + List *targetlist); + +List *transformSortClause(ParseState *pstate, + List *orderlist, List *targetlist, + char *uniqueFlag); + +#endif /* PARSE_CLAUSE_H */ + diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h new file mode 100644 index 00000000000..e7c4a04b011 --- /dev/null +++ b/src/include/parser/parse_expr.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------- + * + * parse_exer.h + * + * + * + * Copyright (c) 1994, Regents of the University of California + * + * $Id: parse_expr.h,v 1.1 1997/11/25 22:06:55 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef PARSE_EXPR_H +#define PARSE_EXPR_H + +#include <nodes/nodes.h> +#include <nodes/parsenodes.h> +#include <nodes/primnodes.h> +#include <parser/parse_node.h> + +Node *transformExpr(ParseState *pstate, Node *expr, int precedence); + +Node *transformIdent(ParseState *pstate, Node *expr, int precedence); + +Oid exprType(Node *expr); + +Node *handleNestedDots(ParseState *pstate, Attr *attr, int *curr_resno); + +Node *parser_typecast(Value *expr, TypeName *typename, int typlen); + +Node *parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen); + +#endif /* PARSE_EXPR_H */ + diff --git a/src/include/parser/parse_func.h b/src/include/parser/parse_func.h new file mode 100644 index 00000000000..de8fc66d848 --- /dev/null +++ b/src/include/parser/parse_func.h @@ -0,0 +1,97 @@ +/*------------------------------------------------------------------------- + * + * catalog_utils.h-- + * + * + * + * Copyright (c) 1994, Regents of the University of California + * + * $Id: parse_func.h,v 1.1 1997/11/25 22:06:56 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef PARSER_FUNC_H +#define PARSER_FUNC_H + +#include <nodes/nodes.h> +#include <nodes/pg_list.h> +#include <nodes/parsenodes.h> +#include <nodes/primnodes.h> +#include <parser/parse_func.h> +#include <parser/parse_node.h> + +/* + * This structure is used to explore the inheritance hierarchy above + * nodes in the type tree in order to disambiguate among polymorphic + * functions. + */ +typedef struct _InhPaths +{ + int nsupers; /* number of superclasses */ + Oid self; /* this class */ + Oid *supervec; /* vector of superclasses */ +} InhPaths; + +/* + * This structure holds a list of possible functions or operators that + * agree with the known name and argument types of the function/operator. + */ +typedef struct _CandidateList +{ + Oid *args; + struct _CandidateList *next; +} *CandidateList; + +Node *ParseFunc(ParseState *pstate, char *funcname, List *fargs, + int *curr_resno); + +Oid funcid_get_rettype(Oid funcid); + +CandidateList func_get_candidates(char *funcname, int nargs); + +bool can_coerce(int nargs, Oid *input_typeids, Oid *func_typeids); + +int match_argtypes(int nargs, + Oid *input_typeids, + CandidateList function_typeids, + CandidateList *candidates); + +Oid * func_select_candidate(int nargs, + Oid *input_typeids, + CandidateList candidates); + +bool func_get_detail(char *funcname, + int nargs, + Oid *oid_array, + Oid *funcid, /* return value */ + Oid *rettype, /* return value */ + bool *retset, /* return value */ + Oid **true_typeids); + +Oid ** argtype_inherit(int nargs, Oid *oid_array); + +int findsupers(Oid relid, Oid **supervec); + +Oid **genxprod(InhPaths *arginh, int nargs); + +void make_arguments(int nargs, + List *fargs, + Oid *input_typeids, + Oid *function_typeids); + +List *setup_tlist(char *attname, Oid relid); + +List *setup_base_tlist(Oid typeid); + +Node *ParseComplexProjection(ParseState *pstate, + char *funcname, + Node *first_arg, + bool *attisset); + +void func_error(char *caller, char *funcname, int nargs, Oid *argtypes); + + + + +#endif /* PARSE_FUNC_H */ + diff --git a/src/include/parser/parse_node.h b/src/include/parser/parse_node.h new file mode 100644 index 00000000000..bac05cb1506 --- /dev/null +++ b/src/include/parser/parse_node.h @@ -0,0 +1,67 @@ +/*------------------------------------------------------------------------- + * + * parse_node.h + * + * + * Copyright (c) 1994, Regents of the University of California + * + * $Id: parse_node.h,v 1.1 1997/11/25 22:06:57 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef PARSE_NODE_H +#define PARSE_NODE_H + +#include <nodes/nodes.h> +#include <nodes/pg_list.h> +#include <nodes/primnodes.h> +#include <nodes/parsenodes.h> +#include <parser/parse_type.h> +#include <utils/rel.h> + +typedef struct QueryTreeList +{ + int len; /* number of queries */ + Query **qtrees; +} QueryTreeList; + +/* state information used during parse analysis */ +typedef struct ParseState +{ + int p_last_resno; + List *p_rtable; + int p_numAgg; + List *p_aggs; + bool p_is_insert; + List *p_insert_columns; + bool p_is_update; + bool p_is_rule; + bool p_in_where_clause; + Relation p_target_relation; + RangeTblEntry *p_target_rangetblentry; +} ParseState; + +ParseState *make_parsestate(void); + +Node *make_operand(char *opname, + Node *tree, + Oid orig_typeId, + Oid true_typeId); + +void disallow_setop(char *op, Type optype, Node *operand); + +Expr *make_op(char *opname, Node *ltree, Node *rtree); + +Var *make_var(ParseState *pstate, char *refname, char *attrname, Oid *type_id); + +ArrayRef *make_array_ref(Node *expr, + List *indirection); + +ArrayRef *make_array_set(Expr *target_expr, + List *upperIndexpr, + List *lowerIndexpr, + Expr *expr); + +Const *make_const(Value *value); + +#endif /* PARSE_NODE_H */ diff --git a/src/include/parser/parse_oper.h b/src/include/parser/parse_oper.h new file mode 100644 index 00000000000..c013af628c3 --- /dev/null +++ b/src/include/parser/parse_oper.h @@ -0,0 +1,50 @@ +/*------------------------------------------------------------------------- + * + * catalog_utils.h-- + * + * + * + * Copyright (c) 1994, Regents of the University of California + * + * $Id: parse_oper.h,v 1.1 1997/11/25 22:06:59 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef PARSE_OPER_H +#define PARSE_OPER_H + +#include <parser/parse_func.h> +#include <parser/parse_node.h> + +typedef HeapTuple Operator; + +Oid any_ordering_op(int restype); + +Oid oprid(Operator op); + +int binary_oper_get_candidates(char *opname, + Oid leftTypeId, + Oid rightTypeId, + CandidateList *candidates); + +bool equivalentOpersAfterPromotion(CandidateList candidates); + +CandidateList binary_oper_select_candidate(Oid arg1, + Oid arg2, + CandidateList candidates); + +Operator oper(char *op, Oid arg1, Oid arg2, bool noWarnings); + +int +unary_oper_get_candidates(char *op, + Oid typeId, + CandidateList *candidates, + char rightleft); + +Operator right_oper(char *op, Oid arg); + +Operator left_oper(char *op, Oid arg); + +void op_error(char *op, Oid arg1, Oid arg2); + +#endif /* PARSE_OPER_H */ diff --git a/src/include/parser/parse_query.h b/src/include/parser/parse_query.h deleted file mode 100644 index 0a7d534b85b..00000000000 --- a/src/include/parser/parse_query.h +++ /dev/null @@ -1,70 +0,0 @@ - /*------------------------------------------------------------------------- - * - * parse_query.h-- - * prototypes for parse_query.c. - * - * - * Copyright (c) 1994, Regents of the University of California - * - * $Id: parse_query.h,v 1.14 1997/11/20 23:23:53 momjian Exp $ - * - *------------------------------------------------------------------------- - */ -#ifndef PARSE_QUERY_H -#define PARSE_QUERY_H - -#include <parser/catalog_utils.h> -#include <parser/parse_state.h> -#include <nodes/parsenodes.h> - -typedef struct QueryTreeList -{ - int len; /* number of queries */ - Query **qtrees; -} QueryTreeList; - -extern RangeTblEntry *refnameRangeTableEntry(List *rtable, char *refname); -extern RangeTblEntry *colnameRangeTableEntry(ParseState *pstate, char *colname); -extern int refnameRangeTablePosn(List *rtable, char *refname); -extern RangeTblEntry * -addRangeTableEntry(ParseState *pstate, - char *relname, char *refname, - bool inh, bool inFromCl); -extern List * -expandAll(ParseState *pstate, char *relname, char *refname, - int *this_resno); -extern Expr *make_op(char *opname, Node *ltree, Node *rtree); - -extern Oid find_atttype(Oid relid, char *attrname); -extern Var * -make_var(ParseState *pstate, - char *relname, char *attrname, Oid *type_id); -extern ArrayRef *make_array_ref(Node *array, List *indirection); -extern ArrayRef * -make_array_set(Expr *target_expr, List *upperIndexpr, - List *lowerIndexpr, Expr *expr); -extern Const *make_const(Value *value); - -extern void param_type_init(Oid *typev, int nargs); -extern Oid param_type(int t); - -extern QueryTreeList *parser(char *str, Oid *typev, int nargs); - -extern void handleTargetColname(ParseState *pstate, char **resname, - char *refname, char *colname); - -/* - * analyze.c - */ - -Oid exprType(Node *expr); -QueryTreeList *parse_analyze(List *querytree_list); - -/* define in parse_query.c, used in gram.y */ -extern Oid *param_type_info; -extern int pfunc_num_args; - -/* useful macros */ -#define ISCOMPLEX(type) (typeid_get_relid(type) ? true : false) - -#endif /* PARSE_QUERY_H */ diff --git a/src/include/parser/parse_relation.h b/src/include/parser/parse_relation.h new file mode 100644 index 00000000000..ed470822ff5 --- /dev/null +++ b/src/include/parser/parse_relation.h @@ -0,0 +1,56 @@ + /*------------------------------------------------------------------------- + * + * parse_query.h-- + * prototypes for parse_query.c. + * + * + * Copyright (c) 1994, Regents of the University of California + * + * $Id: parse_relation.h,v 1.1 1997/11/25 22:07:02 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef PARSE_QUERY_H +#define PARSE_RANGE_H + +#include <nodes/nodes.h> +#include <nodes/parsenodes.h> +#include <nodes/pg_list.h> +#include <nodes/primnodes.h> +#include <parser/parse_node.h> +#include <utils/rel.h> + +RangeTblEntry *refnameRangeTableEntry(List *rtable, char *refname); + +int refnameRangeTablePosn(List *rtable, char *refname); + +RangeTblEntry *colnameRangeTableEntry(ParseState *pstate, char *colname); + +RangeTblEntry *addRangeTableEntry(ParseState *pstate, + char *relname, + char *refname, + bool inh, + bool inFromCl); + +List *expandAll(ParseState *pstate, char *relname, char *refname, + int *this_resno); + +int attnameAttNum(Relation rd, char *a); + +bool attnameIsSet(Relation rd, char *name); + +char *attnumAttName(Relation rd, int attrno); + +int attnumAttNelems(Relation rd, int attid); + +Oid attnameTypeId(Oid relid, char *attrname); + +Oid attnumTypeId(Relation rd, int attid); + +void handleTargetColname(ParseState *pstate, char **resname, + char *refname, char *colname); + +void checkTargetTypes(ParseState *pstate, char *target_colname, + char *refname, char *colname); + +#endif /* PARSE_RANGE_H */ diff --git a/src/include/parser/parse_state.h b/src/include/parser/parse_state.h deleted file mode 100644 index abda19b18c5..00000000000 --- a/src/include/parser/parse_state.h +++ /dev/null @@ -1,34 +0,0 @@ -/*------------------------------------------------------------------------- - * - * parse_state.h-- - * - * Copyright (c) 1994, Regents of the University of California - * - * $Id: parse_state.h,v 1.8 1997/09/08 21:53:40 momjian Exp $ - * - *------------------------------------------------------------------------- - */ - -#ifndef PARSE_STATE_H -#define PARSE_STATE_H - -#include <nodes/parsenodes.h> -#include <utils/rel.h> - -/* state information used during parse analysis */ -typedef struct ParseState -{ - int p_last_resno; - List *p_rtable; - int p_numAgg; - List *p_aggs; - bool p_is_insert; - List *p_insert_columns; - bool p_is_update; - bool p_is_rule; - Relation p_target_relation; - RangeTblEntry *p_target_rangetblentry; -} ParseState; - - -#endif /* PARSE_QUERY_H */ diff --git a/src/include/parser/parse_target.h b/src/include/parser/parse_target.h new file mode 100644 index 00000000000..c7faa6b3db9 --- /dev/null +++ b/src/include/parser/parse_target.h @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + * + * parse_target.h + * + * + * + * Copyright (c) 1994, Regents of the University of California + * + * $Id: parse_target.h,v 1.1 1997/11/25 22:07:06 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef PARSE_TARGET_H +#define PARSE_TARGET_H + +#include <nodes/pg_list.h> +#include <nodes/nodes.h> +#include <nodes/parsenodes.h> +#include <nodes/primnodes.h> +#include <parser/parse_node.h> + +#define EXPR_COLUMN_FIRST 1 +#define EXPR_RELATION_FIRST 2 + +List *transformTargetList(ParseState *pstate, List *targetlist); + +TargetEntry *make_targetlist_expr(ParseState *pstate, + char *colname, + Node *expr, + List *arrayRef); + +List *expandAllTables(ParseState *pstate); + +char *figureColname(Node *expr, Node *resval); + +List *makeTargetNames(ParseState *pstate, List *cols); + +#endif /* PARSE_TARGET_H */ + diff --git a/src/include/parser/parse_type.h b/src/include/parser/parse_type.h new file mode 100644 index 00000000000..63c38ab98dc --- /dev/null +++ b/src/include/parser/parse_type.h @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + * + * parse_type.h + * + * + * + * Copyright (c) 1994, Regents of the University of California + * + * $Id: parse_type.h,v 1.1 1997/11/25 22:07:07 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef PARSE_TYPE_H +#define PARSE_TYPE_H + +#include "access/htup.h" + +typedef HeapTuple Type; + +bool typeidIsValid(Oid id); +Type typeidType(Oid id); +Type typenameType(char *s); +char *typeidTypeName(Oid id); +Oid typeTypeId(Type tp); +int16 typeLen(Type t); +bool typeByVal(Type t); +char *typeTypeName(Type t); +char typeTypeFlag(Type t); +char *stringTypeString(Type tp, char *string, int typlen); +Oid typeidRetoutfunc(Oid type_id); +Oid typeidTypeRelid(Oid type_id); +Oid typeTypeRelid(Type typ); +Oid typeidTypElem(Oid type_id); +Oid GetArrayElementType(Oid typearray); +Oid typeidRetinfunc(Oid type_id); + +#endif /* PARSE_TYPE_H */ diff --git a/src/include/parser/parser.h b/src/include/parser/parser.h new file mode 100644 index 00000000000..4362ebb4803 --- /dev/null +++ b/src/include/parser/parser.h @@ -0,0 +1,21 @@ +/*------------------------------------------------------------------------- + * + * parser.h + * + * + * + * Copyright (c) 1994, Regents of the University of California + * + * $Id: parser.h,v 1.1 1997/11/25 22:07:08 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef PARSER_H +#define PARSER_H + +#include <parser/parse_node.h> + +QueryTreeList *parser(char *str, Oid *typev, int nargs); + +#endif /* PARSER_H */ + |