From 442e12dc0fc44959ef31e229db39ea9955a85818 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Fri, 19 Feb 2016 17:41:53 +0300 Subject: [PATCH 01/41] ported to 9.6devel --- crossmatch.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crossmatch.c b/crossmatch.c index 3baabe5..85858bd 100644 --- a/crossmatch.c +++ b/crossmatch.c @@ -34,6 +34,9 @@ #if PG_VERSION_NUM >= 90300 #include "access/htup_details.h" #endif +#if PG_VERSION_NUM >= 90600 +#include "catalog/pg_am.h" +#endif #include "catalog/namespace.h" #include "funcapi.h" #include "nodes/pg_list.h" @@ -106,7 +109,11 @@ PG_FUNCTION_INFO_V1(crossmatch); static Relation checkOpenedRelation(Relation r, Oid PgAmOid) { +#if PG_VERSION_NUM >= 90600 + if (r->rd_amroutine == NULL) +#else if (r->rd_am == NULL) +#endif elog(ERROR, "Relation %s.%s is not an index", get_namespace_name(RelationGetNamespace(r)), RelationGetRelationName(r)); From 3f1dc0370f825c8794826bf3c8265c6cfb0522b0 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Thu, 25 Feb 2016 16:16:29 +0300 Subject: [PATCH 02/41] init --- Makefile | 6 +- init.c | 222 +++++++ sparse.c | 1626 ++++++++++++++++++++++++-------------------------- sparse.h | 94 +-- sscan.c | 1736 ++++++++++++++++++++++++++---------------------------- 5 files changed, 1904 insertions(+), 1780 deletions(-) create mode 100644 init.c diff --git a/Makefile b/Makefile index d278ad8..b2b7985 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ MODULE_big = pg_sphere OBJS = sscan.o sparse.o sbuffer.o vector3d.o point.o \ euler.o circle.o line.o ellipse.o polygon.o \ path.o box.o output.o gq_cache.o gist.o key.o \ - crossmatch.o gnomo.o + crossmatch.o gnomo.o init.o EXTENSION = pg_sphere DATA_built = pg_sphere--1.0.sql @@ -10,9 +10,9 @@ DOCS = README.pg_sphere COPYRIGHT.pg_sphere REGRESS = init tables points euler circle line ellipse poly path box index \ contains_ops contains_ops_compat bounding_box_gist gnomo -EXTRA_CLEAN = pg_sphere--1.0.sql $(PGS_SQL) +EXTRA_CLEAN = pg_sphere--1.0.sql $(PGS_SQL) -CRUSH_TESTS = init_extended circle_extended +CRUSH_TESTS = init_extended circle_extended # order of sql files is important PGS_SQL = pgs_types.sql pgs_point.sql pgs_euler.sql pgs_circle.sql \ diff --git a/init.c b/init.c new file mode 100644 index 0000000..76cd972 --- /dev/null +++ b/init.c @@ -0,0 +1,222 @@ +#include "postgres.h" +#include "optimizer/paths.h" +#include "optimizer/restrictinfo.h" +#include "utils/builtins.h" +#include "utils/elog.h" +#include "utils/lsyscache.h" +#include "nodes/print.h" +#include "catalog/pg_proc.h" +#include "catalog/pg_operator.h" +#include "commands/explain.h" +#include "funcapi.h" + +extern void _PG_init(void); + +static set_join_pathlist_hook_type set_join_pathlist_next; + +typedef struct +{ + CustomPath cpath; + + JoinType jointype; + + Path *outer_path; + Path *inner_path; + + List *joinrestrictinfo; +} CrossmatchJoinPath; + +static CustomPathMethods crossmatch_path_methods; +static CustomScanMethods crossmatch_plan_methods; +static CustomExecMethods crossmatch_exec_methods; + +void join_pathlist_hook (PlannerInfo *root, + RelOptInfo *joinrel, + RelOptInfo *outerrel, + RelOptInfo *innerrel, + JoinType jointype, + JoinPathExtraData *extra) +{ + ListCell *restr; + text *dist_func_name = cstring_to_text("dist(spoint,spoint)"); + Oid dist_func; + + dist_func = DatumGetObjectId(DirectFunctionCall1(to_regprocedure, + PointerGetDatum(dist_func_name))); + + if (dist_func == InvalidOid) + elog(ERROR, "function dist not found!"); + + if (set_join_pathlist_next) + set_join_pathlist_next(root, + joinrel, + outerrel, + innerrel, + jointype, + extra); + + foreach(restr, extra->restrictlist) + { + RestrictInfo *restrInfo = (RestrictInfo *) lfirst(restr); + + if (IsA(restrInfo->clause, OpExpr)) + { + OpExpr *opExpr = (OpExpr *) restrInfo->clause; + int nargs = list_length(opExpr->args); + Node *arg1; + Node *arg2; + + if (nargs != 2) + continue; + + arg1 = linitial(opExpr->args); + arg2 = lsecond(opExpr->args); + + if (opExpr->opno == Float8LessOperator && + IsA(arg1, FuncExpr) && + ((FuncExpr *) arg1)->funcid == dist_func && + IsA(arg2, Const)) + { + elog(LOG, "found <"); + } + else if (opExpr->opno == get_commutator(Float8LessOperator) && + IsA(arg1, Const) && + IsA(arg2, FuncExpr) && + ((FuncExpr *) arg2)->funcid == dist_func) + { + elog(LOG, "found >"); + } + } + } + + pprint(root->parse->rtable); +} + +static CrossmatchJoinPath * +create_crossmatch_path(PlannerInfo *root, + RelOptInfo *joinrel, + Path *outer_path, + Path *inner_path, + ParamPathInfo *param_info, + List *restrict_clauses, + Relids required_outer) +{ + CrossmatchJoinPath *result; + + result = palloc0(sizeof(CrossmatchJoinPath)); + NodeSetTag(result, T_CustomPath); + + result->cpath.path.pathtype = T_CustomScan; + result->cpath.path.parent = joinrel; + result->cpath.path.param_info = param_info; + result->cpath.path.pathkeys = NIL; + result->cpath.path.rows = joinrel->rows; + result->cpath.flags = 0; + result->cpath.methods = &crossmatch_path_methods; + result->outer_path = outer_path; + result->inner_path = inner_path; + result->joinrestrictinfo = restrict_clauses; + + /* DEBUG costs */ + result->cpath.path.startup_cost = 1; + result->cpath.path.total_cost = 1; + + return result; +} + +static Plan * +create_crossmatch_plan(PlannerInfo *root, + RelOptInfo *rel, + CustomPath *best_path, + List *tlist, + List *clauses, + List *custom_plans) +{ + CrossmatchJoinPath *gpath = (CrossmatchJoinPath *) best_path; + List *joinrestrictclauses = gpath->joinrestrictinfo; + List *joinclauses; + List *otherclauses; + CustomScan *cscan; + + if (IS_OUTER_JOIN(gpath->jointype)) + { + extract_actual_join_clauses(joinrestrictclauses, + &joinclauses, &otherclauses); + } + else + { + joinclauses = extract_actual_clauses(joinrestrictclauses, + false); + otherclauses = NIL; + } + + cscan = makeNode(CustomScan); + cscan->scan.plan.targetlist = tlist; + cscan->scan.plan.qual = NIL; + + cscan->flags = best_path->flags; + cscan->methods = &crossmatch_plan_methods; + cscan->custom_plans = list_copy_tail(custom_plans, 1); + + +} + +static Node * +crossmatch_create_scan_state(CustomScan *node) +{ + return NULL; +} + +static void +crossmatch_begin(CustomScanState *node, EState *estate, int eflags) +{ + +} + +static TupleTableSlot * +crossmatch_exec(CustomScanState *node) +{ + return NULL; +} + +static void +crossmatch_end(CustomScanState *node) +{ + +} + +static void +crossmatch_rescan(CustomScanState *node) +{ + +} + +static void +crossmatch_explain(CustomScanState *node, List *ancestors, ExplainState *es) +{ + +} + +void +_PG_init(void) +{ + elog(LOG, "loading pg_sphere"); + + set_join_pathlist_next = set_join_pathlist_hook; + set_join_pathlist_hook = join_pathlist_hook; + + crossmatch_path_methods.CustomName = "CrossmatchJoin"; + crossmatch_path_methods.PlanCustomPath = &create_crossmatch_plan; + + crossmatch_plan_methods.CustomName = "CrossmatchJoin"; + crossmatch_plan_methods.CreateCustomScanState = &crossmatch_create_scan_state; + + crossmatch_exec_methods.CustomName = "CrossmatchJoin"; + crossmatch_exec_methods.BeginCustomScan = &crossmatch_begin; + crossmatch_exec_methods.ExecCustomScan = &crossmatch_exec; + crossmatch_exec_methods.EndCustomScan = &crossmatch_end; + crossmatch_exec_methods.ReScanCustomScan = &crossmatch_rescan; + crossmatch_exec_methods.MarkPosCustomScan = NULL; + crossmatch_exec_methods.RestrPosCustomScan = NULL; + crossmatch_exec_methods.ExplainCustomScan = &crossmatch_explain; +} \ No newline at end of file diff --git a/sparse.c b/sparse.c index 97c652d..e857d88 100644 --- a/sparse.c +++ b/sparse.c @@ -1,14 +1,13 @@ -/* A Bison parser, made by GNU Bison 2.3. */ +/* A Bison parser, made by GNU Bison 3.0.4. */ -/* Skeleton implementation for Bison's Yacc-like parsers in C +/* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -16,9 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -47,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.3" +#define YYBISON_VERSION "3.0.4" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -55,64 +52,25 @@ /* Pure parsers. */ #define YYPURE 0 -/* Using locations. */ -#define YYLSP_NEEDED 0 +/* Push parsers. */ +#define YYPUSH 0 -/* Substitute the variable and function names. */ -#define yyparse sphere_yyparse -#define yylex sphere_yylex -#define yyerror sphere_yyerror -#define yylval sphere_yylval -#define yychar sphere_yychar -#define yydebug sphere_yydebug -#define yynerrs sphere_yynerrs - - -/* Tokens. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - HOUR = 258, - DEG = 259, - MIN = 260, - SEC = 261, - COMMA = 262, - OPENCIRC = 263, - CLOSECIRC = 264, - OPENPOINT = 265, - CLOSEPOINT = 266, - OPENARR = 267, - CLOSEARR = 268, - SIGN = 269, - INT = 270, - FLOAT = 271, - EULERAXIS = 272 - }; -#endif -/* Tokens. */ -#define HOUR 258 -#define DEG 259 -#define MIN 260 -#define SEC 261 -#define COMMA 262 -#define OPENCIRC 263 -#define CLOSECIRC 264 -#define OPENPOINT 265 -#define CLOSEPOINT 266 -#define OPENARR 267 -#define CLOSEARR 268 -#define SIGN 269 -#define INT 270 -#define FLOAT 271 -#define EULERAXIS 272 +/* Pull parsers. */ +#define YYPULL 1 +/* Substitute the variable and function names. */ +#define yyparse sphere_yyparse +#define yylex sphere_yylex +#define yyerror sphere_yyerror +#define yydebug sphere_yydebug +#define yynerrs sphere_yynerrs +#define yylval sphere_yylval +#define yychar sphere_yychar /* Copy the first part of user declarations. */ -#line 1 "sparse.y" +#line 1 "sparse.y" /* yacc.c:339 */ #include #include @@ -146,11 +104,15 @@ static double human2dec ( double d , double m, double s ){ +#line 108 "sparse.c" /* yacc.c:339 */ -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif +# ifndef YY_NULLPTR +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif +# endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE @@ -160,34 +122,86 @@ static double human2dec ( double d , double m, double s ){ # define YYERROR_VERBOSE 0 #endif -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE 0 +/* In a future release of Bison, this section will be replaced + by #include "sparse.h". */ +#ifndef YY_SPHERE_YY_SPARSE_H_INCLUDED +# define YY_SPHERE_YY_SPARSE_H_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int sphere_yydebug; +#endif + +/* Token type. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + HOUR = 258, + DEG = 259, + MIN = 260, + SEC = 261, + COMMA = 262, + OPENCIRC = 263, + CLOSECIRC = 264, + OPENPOINT = 265, + CLOSEPOINT = 266, + OPENARR = 267, + CLOSEARR = 268, + SIGN = 269, + INT = 270, + FLOAT = 271, + EULERAXIS = 272 + }; #endif +/* Tokens. */ +#define HOUR 258 +#define DEG 259 +#define MIN 260 +#define SEC 261 +#define COMMA 262 +#define OPENCIRC 263 +#define CLOSECIRC 264 +#define OPENPOINT 265 +#define CLOSEPOINT 266 +#define OPENARR 267 +#define CLOSEARR 268 +#define SIGN 269 +#define INT 270 +#define FLOAT 271 +#define EULERAXIS 272 +/* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE -#line 39 "sparse.y" -{ + +union YYSTYPE +{ +#line 39 "sparse.y" /* yacc.c:355 */ + int i; double d; char c[3]; -} -/* Line 193 of yacc.c. */ -#line 178 "sparse.c" - YYSTYPE; -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ -# define YYSTYPE_IS_DECLARED 1 + +#line 188 "sparse.c" /* yacc.c:355 */ +}; + +typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 #endif +extern YYSTYPE sphere_yylval; -/* Copy the second part of user declarations. */ +int sphere_yyparse (void); + +#endif /* !YY_SPHERE_YY_SPARSE_H_INCLUDED */ +/* Copy the second part of user declarations. */ -/* Line 216 of yacc.c. */ -#line 191 "sparse.c" +#line 205 "sparse.c" /* yacc.c:358 */ #ifdef short # undef short @@ -201,11 +215,8 @@ typedef unsigned char yytype_uint8; #ifdef YYTYPE_INT8 typedef YYTYPE_INT8 yytype_int8; -#elif (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -typedef signed char yytype_int8; #else -typedef short int yytype_int8; +typedef signed char yytype_int8; #endif #ifdef YYTYPE_UINT16 @@ -225,8 +236,7 @@ typedef short int yytype_int16; # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t -# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# elif ! defined YYSIZE_T # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else @@ -240,38 +250,67 @@ typedef short int yytype_int16; # if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ -# define YY_(msgid) dgettext ("bison-runtime", msgid) +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) # endif # endif # ifndef YY_ -# define YY_(msgid) msgid +# define YY_(Msgid) Msgid +# endif +#endif + +#ifndef YY_ATTRIBUTE +# if (defined __GNUC__ \ + && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ + || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C +# define YY_ATTRIBUTE(Spec) __attribute__(Spec) +# else +# define YY_ATTRIBUTE(Spec) /* empty */ +# endif +#endif + +#ifndef YY_ATTRIBUTE_PURE +# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +#endif + +#ifndef YY_ATTRIBUTE_UNUSED +# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +#endif + +#if !defined _Noreturn \ + && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) +# if defined _MSC_VER && 1200 <= _MSC_VER +# define _Noreturn __declspec (noreturn) +# else +# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(e) ((void) (e)) +# define YYUSE(E) ((void) (E)) #else -# define YYUSE(e) /* empty */ +# define YYUSE(E) /* empty */ #endif -/* Identity function, used to suppress warnings about constant conditions. */ -#ifndef lint -# define YYID(n) (n) +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") #else -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static int -YYID (int i) -#else -static int -YYID (i) - int i; +# define YY_INITIAL_VALUE(Value) Value #endif -{ - return i; -} +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END #endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + #if ! defined yyoverflow || YYERROR_VERBOSE @@ -290,11 +329,11 @@ YYID (i) # define alloca _alloca # else # define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # endif @@ -302,8 +341,8 @@ YYID (i) # endif # ifdef YYSTACK_ALLOC - /* Pacify GCC's `empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) + /* Pacify GCC's 'empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) # ifndef YYSTACK_ALLOC_MAXIMUM /* The OS might guarantee only one guard page at the bottom of the stack, and a page size can be as small as 4096 bytes. So we cannot safely @@ -317,25 +356,23 @@ YYID (i) # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif -# if (defined __cplusplus && ! defined _STDLIB_H \ +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) + && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ -# ifndef _STDLIB_H -# define _STDLIB_H 1 +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc -# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# if ! defined malloc && ! defined EXIT_SUCCESS void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free -# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) +# if ! defined free && ! defined EXIT_SUCCESS void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif @@ -345,14 +382,14 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ #if (! defined yyoverflow \ && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { - yytype_int16 yyss; - YYSTYPE yyvs; - }; + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; +}; /* The size of the maximum gap between one aligned stack and the next. */ # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) @@ -363,42 +400,46 @@ union yyalloc ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (YYID (0)) -# endif -# endif +# define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ -# define YYSTACK_RELOCATE(Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack, Stack, yysize); \ - Stack = &yyptr->Stack; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (YYID (0)) +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (0) #endif +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from SRC to DST. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (0) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + /* YYFINAL -- State number of the termination state. */ #define YYFINAL 31 /* YYLAST -- Last index in YYTABLE. */ @@ -410,17 +451,19 @@ union yyalloc #define YYNNTS 16 /* YYNRULES -- Number of rules. */ #define YYNRULES 46 -/* YYNRULES -- Number of states. */ +/* YYNSTATES -- Number of states. */ #define YYNSTATES 109 -/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned + by yylex, with out-of-bounds checking. */ #define YYUNDEFTOK 2 #define YYMAXUTOK 272 -#define YYTRANSLATE(YYX) \ +#define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) -/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, without out-of-bounds checking. */ static const yytype_uint8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -454,42 +497,7 @@ static const yytype_uint8 yytranslate[] = }; #if YYDEBUG -/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in - YYRHS. */ -static const yytype_uint8 yyprhs[] = -{ - 0, 0, 3, 4, 6, 8, 10, 12, 14, 16, - 18, 20, 22, 24, 26, 29, 32, 36, 41, 46, - 52, 59, 61, 64, 67, 71, 76, 81, 87, 94, - 98, 104, 111, 113, 116, 118, 121, 127, 133, 139, - 147, 153, 156, 160, 165, 177, 183 -}; - -/* YYRHS -- A `-1'-separated list of the rules' RHS. */ -static const yytype_int8 yyrhs[] = -{ - 19, 0, -1, -1, 20, -1, 26, -1, 27, -1, - 29, -1, 28, -1, 31, -1, 32, -1, 33, -1, - 16, -1, 15, -1, 21, -1, 16, 4, -1, 15, - 4, -1, 15, 4, 21, -1, 15, 4, 16, 5, - -1, 15, 4, 15, 5, -1, 15, 4, 15, 5, - 21, -1, 15, 4, 15, 5, 21, 6, -1, 21, - -1, 16, 4, -1, 15, 4, -1, 15, 4, 21, - -1, 15, 4, 16, 5, -1, 15, 4, 15, 5, - -1, 15, 4, 15, 5, 21, -1, 15, 4, 15, - 5, 21, 6, -1, 15, 3, 21, -1, 15, 3, - 15, 5, 21, -1, 15, 3, 15, 5, 21, 6, - -1, 23, -1, 14, 23, -1, 22, -1, 14, 22, - -1, 10, 24, 7, 25, 11, -1, 8, 26, 7, - 22, 9, -1, 24, 7, 24, 7, 24, -1, 24, - 7, 24, 7, 24, 7, 17, -1, 10, 28, 11, - 7, 23, -1, 26, 7, -1, 30, 26, 7, -1, - 12, 30, 26, 13, -1, 8, 12, 22, 7, 22, - 13, 7, 26, 7, 25, 9, -1, 10, 26, 7, - 26, 11, -1, 26, 7, 26, -1 -}; - -/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { 0, 62, 62, 63, 67, 69, 71, 73, 75, 77, @@ -500,7 +508,7 @@ static const yytype_uint8 yyrline[] = }; #endif -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +#if YYDEBUG || YYERROR_VERBOSE || 0 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = @@ -510,13 +518,13 @@ static const char *const yytname[] = "CLOSEARR", "SIGN", "INT", "FLOAT", "EULERAXIS", "$accept", "commands", "command", "number", "angle_lat_us", "angle_long_us", "angle_long", "angle_lat", "spherepoint", "spherecircle", "eulertrans", "sphereline", - "spherepointlist", "spherepath", "sphereellipse", "spherebox", 0 + "spherepointlist", "spherepath", "sphereellipse", "spherebox", YY_NULLPTR }; #endif # ifdef YYPRINT -/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to - token YYLEX-NUM. */ +/* YYTOKNUM[NUM] -- (External) token number corresponding to the + (internal) symbol number NUM (which must be that of a token). */ static const yytype_uint16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, @@ -524,54 +532,18 @@ static const yytype_uint16 yytoknum[] = }; # endif -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = -{ - 0, 18, 19, 19, 20, 20, 20, 20, 20, 20, - 20, 21, 21, 22, 22, 22, 22, 22, 22, 22, - 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, - 23, 23, 24, 24, 25, 25, 26, 27, 28, 28, - 29, 30, 30, 31, 32, 33, 33 -}; +#define YYPACT_NINF -18 -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = -{ - 0, 2, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 2, 2, 3, 4, 4, 5, - 6, 1, 2, 2, 3, 4, 4, 5, 6, 3, - 5, 6, 1, 2, 1, 2, 5, 5, 5, 7, - 5, 2, 3, 4, 11, 5, 3 -}; +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-18))) -/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state - STATE-NUM when YYTABLE doesn't specify something else to do. Zero - means the default is an error. */ -static const yytype_uint8 yydefact[] = -{ - 2, 0, 0, 0, 0, 12, 11, 0, 3, 21, - 32, 0, 4, 5, 7, 6, 8, 9, 10, 0, - 0, 0, 0, 0, 0, 0, 0, 33, 0, 23, - 22, 1, 0, 0, 0, 12, 11, 13, 0, 0, - 0, 0, 0, 41, 0, 12, 11, 29, 12, 11, - 24, 0, 46, 0, 15, 14, 0, 0, 0, 12, - 11, 13, 34, 0, 0, 0, 42, 43, 0, 26, - 25, 0, 0, 12, 11, 16, 0, 37, 35, 15, - 14, 36, 45, 40, 12, 30, 27, 38, 18, 17, - 0, 12, 11, 16, 31, 28, 0, 19, 0, 18, - 17, 39, 20, 0, 19, 0, 20, 0, 44 -}; +#define YYTABLE_NINF -29 -/* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int8 yydefgoto[] = -{ - -1, 7, 8, 9, 62, 10, 51, 63, 12, 13, - 14, 15, 26, 16, 17, 18 -}; +#define yytable_value_is_error(Yytable_value) \ + 0 -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -#define YYPACT_NINF -18 + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ static const yytype_int8 yypact[] = { 58, 9, 33, -4, -2, 27, 11, 26, -18, -18, @@ -587,18 +559,41 @@ static const yytype_int8 yypact[] = 118, -18, -18, 119, 87, 69, 120, 111, -18 }; -/* YYPGOTO[NTERM-NUM]. */ + /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 2, 0, 0, 0, 0, 12, 11, 0, 3, 21, + 32, 0, 4, 5, 7, 6, 8, 9, 10, 0, + 0, 0, 0, 0, 0, 0, 0, 33, 0, 23, + 22, 1, 0, 0, 0, 12, 11, 13, 0, 0, + 0, 0, 0, 41, 0, 12, 11, 29, 12, 11, + 24, 0, 46, 0, 15, 14, 0, 0, 0, 12, + 11, 13, 34, 0, 0, 0, 42, 43, 0, 26, + 25, 0, 0, 12, 11, 16, 0, 37, 35, 15, + 14, 36, 45, 40, 12, 30, 27, 38, 18, 17, + 0, 12, 11, 16, 31, 28, 0, 19, 0, 18, + 17, 39, 20, 0, 19, 0, 20, 0, 44 +}; + + /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { -18, -18, -18, -17, -12, 0, 5, 16, -1, -18, 126, -18, -18, -18, -18, -18 }; -/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. - If YYTABLE_NINF, syntax error. */ -#define YYTABLE_NINF -29 + /* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int8 yydefgoto[] = +{ + -1, 7, 8, 9, 62, 10, 51, 63, 12, 13, + 14, 15, 26, 16, 17, 18 +}; + + /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ static const yytype_int8 yytable[] = { 21, 23, 25, 37, 27, 11, 19, 22, 38, -23, @@ -633,8 +628,8 @@ static const yytype_int8 yycheck[] = 9, 105, 7, 6, 17, 7, 7, 7, 2 }; -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ + /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ static const yytype_uint8 yystos[] = { 0, 8, 10, 12, 14, 15, 16, 19, 20, 21, @@ -650,95 +645,61 @@ static const yytype_uint8 yystos[] = 5, 17, 6, 26, 21, 7, 6, 25, 9 }; -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 18, 19, 19, 20, 20, 20, 20, 20, 20, + 20, 21, 21, 22, 22, 22, 22, 22, 22, 22, + 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 24, 24, 25, 25, 26, 27, 28, 28, + 29, 30, 30, 31, 32, 33, 33 +}; + + /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 2, 2, 3, 4, 4, 5, + 6, 1, 2, 2, 3, 4, 4, 5, 6, 3, + 5, 6, 1, 2, 1, 2, 5, 5, 5, 7, + 5, 2, 3, 4, 11, 5, 3 +}; -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 -/* Like YYERROR except do call yyerror. This remains here temporarily - to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. */ +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab -#define YYFAIL goto yyerrlab #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - yytoken = YYTRANSLATE (yychar); \ - YYPOPSTACK (1); \ - goto yybackup; \ - } \ - else \ - { \ +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ yyerror (YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (YYID (0)) - - -#define YYTERROR 1 -#define YYERRCODE 256 - - -/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. - If N is 0, then set CURRENT to the empty location which ends - the previous symbol: RHS[0] (always defined). */ - -#define YYRHSLOC(Rhs, K) ((Rhs)[K]) -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (YYID (N)) \ - { \ - (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ - (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ - (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ - (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ - } \ - else \ - { \ - (Current).first_line = (Current).last_line = \ - YYRHSLOC (Rhs, 0).last_line; \ - (Current).first_column = (Current).last_column = \ - YYRHSLOC (Rhs, 0).last_column; \ - } \ - while (YYID (0)) -#endif - - -/* YY_LOCATION_PRINT -- Print the location on the stream. - This macro was not mandated originally: define only if we know - we won't break user code: when these are the locations we know. */ - -#ifndef YY_LOCATION_PRINT -# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) -# else -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -# endif -#endif + YYERROR; \ + } \ +while (0) +/* Error token number */ +#define YYTERROR 1 +#define YYERRCODE 256 -/* YYLEX -- calling `yylex' with the right arguments. */ -#ifdef YYLEX_PARAM -# define YYLEX yylex (YYLEX_PARAM) -#else -# define YYLEX yylex () -#endif /* Enable debugging if requested. */ #if YYDEBUG @@ -748,54 +709,46 @@ while (YYID (0)) # define YYFPRINTF fprintf # endif -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (YYID (0)) +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (YYID (0)) +/* This macro is provided for backward compatibility. */ +#ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#endif -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + + +/*----------------------------------------. +| Print this symbol's value on YYOUTPUT. | +`----------------------------------------*/ -/*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -#else -static void -yy_symbol_value_print (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE const * const yyvaluep; -#endif { + FILE *yyo = yyoutput; + YYUSE (yyo); if (!yyvaluep) return; # ifdef YYPRINT if (yytype < YYNTOKENS) YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# else - YYUSE (yyoutput); # endif - switch (yytype) - { - default: - break; - } + YYUSE (yytype); } @@ -803,22 +756,11 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep) | Print this symbol on YYOUTPUT. | `--------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) -#else -static void -yy_symbol_print (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE const * const yyvaluep; -#endif { - if (yytype < YYNTOKENS) - YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); - else - YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + YYFPRINTF (yyoutput, "%s %s (", + yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); yy_symbol_value_print (yyoutput, yytype, yyvaluep); YYFPRINTF (yyoutput, ")"); @@ -829,66 +771,54 @@ yy_symbol_print (yyoutput, yytype, yyvaluep) | TOP (included). | `------------------------------------------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -static void -yy_stack_print (yytype_int16 *bottom, yytype_int16 *top) -#else static void -yy_stack_print (bottom, top) - yytype_int16 *bottom; - yytype_int16 *top; -#endif +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) { YYFPRINTF (stderr, "Stack now"); - for (; bottom <= top; ++bottom) - YYFPRINTF (stderr, " %d", *bottom); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } YYFPRINTF (stderr, "\n"); } -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (YYID (0)) +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void -yy_reduce_print (YYSTYPE *yyvsp, int yyrule) -#else -static void -yy_reduce_print (yyvsp, yyrule) - YYSTYPE *yyvsp; - int yyrule; -#endif +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule) { + unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - unsigned long int yylno = yyrline[yyrule]; YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); + yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { - fprintf (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], - &(yyvsp[(yyi + 1) - (yynrhs)]) - ); - fprintf (stderr, "\n"); + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, + yystos[yyssp[yyi + 1 - yynrhs]], + &(yyvsp[(yyi + 1) - (yynrhs)]) + ); + YYFPRINTF (stderr, "\n"); } } -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyvsp, Rule); \ -} while (YYID (0)) +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyssp, yyvsp, Rule); \ +} while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ @@ -902,7 +832,7 @@ int yydebug; /* YYINITDEPTH -- initial size of the parser's stacks. */ -#ifndef YYINITDEPTH +#ifndef YYINITDEPTH # define YYINITDEPTH 200 #endif @@ -917,7 +847,6 @@ int yydebug; # define YYMAXDEPTH 10000 #endif - #if YYERROR_VERBOSE @@ -926,15 +855,8 @@ int yydebug; # define yystrlen strlen # else /* Return the length of YYSTR. */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static YYSIZE_T yystrlen (const char *yystr) -#else -static YYSIZE_T -yystrlen (yystr) - const char *yystr; -#endif { YYSIZE_T yylen; for (yylen = 0; yystr[yylen]; yylen++) @@ -950,16 +872,8 @@ yystrlen (yystr) # else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static char * yystpcpy (char *yydest, const char *yysrc) -#else -static char * -yystpcpy (yydest, yysrc) - char *yydest; - const char *yysrc; -#endif { char *yyd = yydest; const char *yys = yysrc; @@ -989,27 +903,27 @@ yytnamerr (char *yyres, const char *yystr) char const *yyp = yystr; for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } do_not_strip_quotes: ; } @@ -1020,211 +934,209 @@ yytnamerr (char *yyres, const char *yystr) } # endif -/* Copy into YYRESULT an error message about the unexpected token - YYCHAR while in state YYSTATE. Return the number of bytes copied, - including the terminating null byte. If YYRESULT is null, do not - copy anything; just return the number of bytes that would be - copied. As a special case, return 0 if an ordinary "syntax error" - message will do. Return YYSIZE_MAXIMUM if overflow occurs during - size calculation. */ -static YYSIZE_T -yysyntax_error (char *yyresult, int yystate, int yychar) +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) { - int yyn = yypact[yystate]; + YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULLPTR; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; + + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) + { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } + } + } - if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) - return 0; - else + switch (yycount) { - int yytype = YYTRANSLATE (yychar); - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); - YYSIZE_T yysize = yysize0; - YYSIZE_T yysize1; - int yysize_overflow = 0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - int yyx; - -# if 0 - /* This is so xgettext sees the translatable formats that are - constructed on the fly. */ - YY_("syntax error, unexpected %s"); - YY_("syntax error, unexpected %s, expecting %s"); - YY_("syntax error, unexpected %s, expecting %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s"); - YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); -# endif - char *yyfmt; - char const *yyf; - static char const yyunexpected[] = "syntax error, unexpected %s"; - static char const yyexpecting[] = ", expecting %s"; - static char const yyor[] = " or %s"; - char yyformat[sizeof yyunexpected - + sizeof yyexpecting - 1 - + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) - * (sizeof yyor - 1))]; - char const *yyprefix = yyexpecting; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yycount = 1; - - yyarg[0] = yytname[yytype]; - yyfmt = yystpcpy (yyformat, yyunexpected); - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - yyformat[sizeof yyunexpected - 1] = '\0'; - break; - } - yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - yyfmt = yystpcpy (yyfmt, yyprefix); - yyprefix = yyor; - } - - yyf = YY_(yyformat); - yysize1 = yysize + yystrlen (yyf); - yysize_overflow |= (yysize1 < yysize); - yysize = yysize1; - - if (yysize_overflow) - return YYSIZE_MAXIMUM; - - if (yyresult) - { - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - char *yyp = yyresult; - int yyi = 0; - while ((*yyp = *yyf) != '\0') - { - if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyf += 2; - } - else - { - yyp++; - yyf++; - } - } - } - return yysize; +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ } + + { + YYSIZE_T yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; } #endif /* YYERROR_VERBOSE */ - /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ -/*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) static void yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) -#else -static void -yydestruct (yymsg, yytype, yyvaluep) - const char *yymsg; - int yytype; - YYSTYPE *yyvaluep; -#endif { YYUSE (yyvaluep); - if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - switch (yytype) - { - - default: - break; - } + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YYUSE (yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_END } - -/* Prevent warnings from -Wmissing-prototypes. */ - -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int yyparse (void *YYPARSE_PARAM); -#else -int yyparse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int yyparse (void); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ -/* The look-ahead symbol. */ +/* The lookahead symbol. */ int yychar; -/* The semantic value of the look-ahead symbol. */ +/* The semantic value of the lookahead symbol. */ YYSTYPE yylval; - /* Number of syntax errors so far. */ int yynerrs; - /*----------. | yyparse. | `----------*/ -#ifdef YYPARSE_PARAM -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) -int -yyparse (void *YYPARSE_PARAM) -#else -int -yyparse (YYPARSE_PARAM) - void *YYPARSE_PARAM; -#endif -#else /* ! YYPARSE_PARAM */ -#if (defined __STDC__ || defined __C99__FUNC__ \ - || defined __cplusplus || defined _MSC_VER) int yyparse (void) -#else -int -yyparse () - -#endif -#endif { - - int yystate; + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + 'yyss': related to states. + 'yyvs': related to semantic values. + + Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + YYSIZE_T yystacksize; + int yyn; int yyresult; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; - /* Look-ahead token as an internal (translated) token number. */ + /* Lookahead token as an internal (translated) token number. */ int yytoken = 0; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + #if YYERROR_VERBOSE /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; @@ -1232,54 +1144,22 @@ yyparse () YYSIZE_T yymsg_alloc = sizeof yymsgbuf; #endif - /* Three stacks and their tools: - `yyss': related to states, - `yyvs': related to semantic values, - `yyls': related to locations. - - Refer to the stacks thru separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ - - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss = yyssa; - yytype_int16 *yyssp; - - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs = yyvsa; - YYSTYPE *yyvsp; - - - #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) - YYSIZE_T yystacksize = YYINITDEPTH; - - /* The variables used to return semantic value and location from the - action routines. */ - YYSTYPE yyval; - - /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ int yylen = 0; + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; + yystacksize = YYINITDEPTH; + YYDPRINTF ((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - - yyssp = yyss; - yyvsp = yyvs; - + yychar = YYEMPTY; /* Cause a token to be read. */ goto yysetstate; /*------------------------------------------------------------. @@ -1300,25 +1180,23 @@ yyparse () #ifdef yyoverflow { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE @@ -1326,23 +1204,22 @@ yyparse () # else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; + goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; + yystacksize = YYMAXDEPTH; { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss); - YYSTACK_RELOCATE (yyvs); - + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); # undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); } # endif #endif /* no yyoverflow */ @@ -1350,16 +1227,18 @@ yyparse () yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); + (unsigned long int) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) - YYABORT; + YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + if (yystate == YYFINAL) + YYACCEPT; + goto yybackup; /*-----------. @@ -1368,20 +1247,20 @@ yyparse () yybackup: /* Do appropriate processing given the current state. Read a - look-ahead token if we need one and don't already have one. */ + lookahead token if we need one and don't already have one. */ - /* First try to decide what to do without reference to look-ahead token. */ + /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yyn == YYPACT_NINF) + if (yypact_value_is_default (yyn)) goto yydefault; - /* Not known => get a look-ahead token if don't already have one. */ + /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; + yychar = yylex (); } if (yychar <= YYEOF) @@ -1403,29 +1282,27 @@ yyparse () yyn = yytable[yyn]; if (yyn <= 0) { - if (yyn == 0 || yyn == YYTABLE_NINF) - goto yyerrlab; + if (yytable_value_is_error (yyn)) + goto yyerrlab; yyn = -yyn; goto yyreduce; } - if (yyn == YYFINAL) - YYACCEPT; - /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; - /* Shift the look-ahead token. */ + /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - /* Discard the shifted token unless it is eof. */ - if (yychar != YYEOF) - yychar = YYEMPTY; + /* Discard the shifted token. */ + yychar = YYEMPTY; yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END goto yynewstate; @@ -1448,7 +1325,7 @@ yyparse () yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: - `$$ = $1'. + '$$ = $1'. Otherwise, the following line sets YYVAL to garbage. This behavior is undocumented and Bison @@ -1462,221 +1339,272 @@ yyparse () switch (yyn) { case 4: -#line 67 "sparse.y" +#line 67 "sparse.y" /* yacc.c:1646 */ { set_spheretype ( STYPE_POINT ); } +#line 1345 "sparse.c" /* yacc.c:1646 */ break; case 5: -#line 69 "sparse.y" +#line 69 "sparse.y" /* yacc.c:1646 */ { set_spheretype ( STYPE_CIRCLE ); } +#line 1351 "sparse.c" /* yacc.c:1646 */ break; case 6: -#line 71 "sparse.y" +#line 71 "sparse.y" /* yacc.c:1646 */ { set_spheretype ( STYPE_LINE ); } +#line 1357 "sparse.c" /* yacc.c:1646 */ break; case 7: -#line 73 "sparse.y" +#line 73 "sparse.y" /* yacc.c:1646 */ { set_spheretype ( STYPE_EULER ); } +#line 1363 "sparse.c" /* yacc.c:1646 */ break; case 8: -#line 75 "sparse.y" +#line 75 "sparse.y" /* yacc.c:1646 */ { set_spheretype ( STYPE_PATH ); } +#line 1369 "sparse.c" /* yacc.c:1646 */ break; case 9: -#line 77 "sparse.y" +#line 77 "sparse.y" /* yacc.c:1646 */ { set_spheretype ( STYPE_ELLIPSE ); } +#line 1375 "sparse.c" /* yacc.c:1646 */ break; case 10: -#line 79 "sparse.y" +#line 79 "sparse.y" /* yacc.c:1646 */ { set_spheretype ( STYPE_BOX ); } +#line 1381 "sparse.c" /* yacc.c:1646 */ break; case 11: -#line 85 "sparse.y" - { (yyval.d) = (yyvsp[(1) - (1)].d); } +#line 85 "sparse.y" /* yacc.c:1646 */ + { (yyval.d) = (yyvsp[0].d); } +#line 1387 "sparse.c" /* yacc.c:1646 */ break; case 12: -#line 87 "sparse.y" - { (yyval.d) = (yyvsp[(1) - (1)].i); } +#line 87 "sparse.y" /* yacc.c:1646 */ + { (yyval.d) = (yyvsp[0].i); } +#line 1393 "sparse.c" /* yacc.c:1646 */ break; case 13: -#line 93 "sparse.y" - { (yyval.i) = set_angle( 0, (yyvsp[(1) - (1)].d) ) ; } +#line 93 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 0, (yyvsp[0].d) ) ; } +#line 1399 "sparse.c" /* yacc.c:1646 */ break; case 14: -#line 94 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (2)].d),0 ,0) ) ; } +#line 94 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-1].d),0 ,0) ) ; } +#line 1405 "sparse.c" /* yacc.c:1646 */ break; case 15: -#line 95 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (2)].i),0 ,0) ) ; } +#line 95 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-1].i),0 ,0) ) ; } +#line 1411 "sparse.c" /* yacc.c:1646 */ break; case 16: -#line 96 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (3)].i),(yyvsp[(3) - (3)].d),0) ) ; } +#line 96 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-2].i),(yyvsp[0].d),0) ) ; } +#line 1417 "sparse.c" /* yacc.c:1646 */ break; case 17: -#line 97 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (4)].i),(yyvsp[(3) - (4)].d),0) ) ; } +#line 97 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-3].i),(yyvsp[-1].d),0) ) ; } +#line 1423 "sparse.c" /* yacc.c:1646 */ break; case 18: -#line 98 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (4)].i),(yyvsp[(3) - (4)].i),0) ) ; } +#line 98 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-3].i),(yyvsp[-1].i),0) ) ; } +#line 1429 "sparse.c" /* yacc.c:1646 */ break; case 19: -#line 99 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (5)].i),(yyvsp[(3) - (5)].i),(yyvsp[(5) - (5)].d)) ) ; } +#line 99 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-4].i),(yyvsp[-2].i),(yyvsp[0].d)) ) ; } +#line 1435 "sparse.c" /* yacc.c:1646 */ break; case 20: -#line 100 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (6)].i),(yyvsp[(3) - (6)].i),(yyvsp[(5) - (6)].d)) ) ; } +#line 100 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-5].i),(yyvsp[-3].i),(yyvsp[-1].d)) ) ; } +#line 1441 "sparse.c" /* yacc.c:1646 */ break; case 21: -#line 106 "sparse.y" - { (yyval.i) = set_angle( 0, (yyvsp[(1) - (1)].d) ) ; } +#line 106 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 0, (yyvsp[0].d) ) ; } +#line 1447 "sparse.c" /* yacc.c:1646 */ break; case 22: -#line 107 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (2)].d),0 ,0) ) ; } +#line 107 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-1].d),0 ,0) ) ; } +#line 1453 "sparse.c" /* yacc.c:1646 */ break; case 23: -#line 108 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (2)].i),0 ,0) ) ; } +#line 108 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-1].i),0 ,0) ) ; } +#line 1459 "sparse.c" /* yacc.c:1646 */ break; case 24: -#line 109 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (3)].i),(yyvsp[(3) - (3)].d),0) ) ; } +#line 109 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-2].i),(yyvsp[0].d),0) ) ; } +#line 1465 "sparse.c" /* yacc.c:1646 */ break; case 25: -#line 110 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (4)].i),(yyvsp[(3) - (4)].d),0) ) ; } +#line 110 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-3].i),(yyvsp[-1].d),0) ) ; } +#line 1471 "sparse.c" /* yacc.c:1646 */ break; case 26: -#line 111 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (4)].i),(yyvsp[(3) - (4)].i),0) ) ; } +#line 111 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-3].i),(yyvsp[-1].i),0) ) ; } +#line 1477 "sparse.c" /* yacc.c:1646 */ break; case 27: -#line 112 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (5)].i),(yyvsp[(3) - (5)].i),(yyvsp[(5) - (5)].d)) ) ; } +#line 112 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-4].i),(yyvsp[-2].i),(yyvsp[0].d)) ) ; } +#line 1483 "sparse.c" /* yacc.c:1646 */ break; case 28: -#line 113 "sparse.y" - { (yyval.i) = set_angle( 1, human2dec((yyvsp[(1) - (6)].i),(yyvsp[(3) - (6)].i),(yyvsp[(5) - (6)].d)) ) ; } +#line 113 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1, human2dec((yyvsp[-5].i),(yyvsp[-3].i),(yyvsp[-1].d)) ) ; } +#line 1489 "sparse.c" /* yacc.c:1646 */ break; case 29: -#line 114 "sparse.y" - { (yyval.i) = set_angle( 1,15*human2dec((yyvsp[(1) - (3)].i),(yyvsp[(3) - (3)].d),0)) ; } +#line 114 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1,15*human2dec((yyvsp[-2].i),(yyvsp[0].d),0)) ; } +#line 1495 "sparse.c" /* yacc.c:1646 */ break; case 30: -#line 115 "sparse.y" - { (yyval.i) = set_angle( 1,15*human2dec((yyvsp[(1) - (5)].i),(yyvsp[(3) - (5)].i),(yyvsp[(5) - (5)].d))); } +#line 115 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1,15*human2dec((yyvsp[-4].i),(yyvsp[-2].i),(yyvsp[0].d))); } +#line 1501 "sparse.c" /* yacc.c:1646 */ break; case 31: -#line 116 "sparse.y" - { (yyval.i) = set_angle( 1,15*human2dec((yyvsp[(1) - (6)].i),(yyvsp[(3) - (6)].i),(yyvsp[(5) - (6)].d))); } +#line 116 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle( 1,15*human2dec((yyvsp[-5].i),(yyvsp[-3].i),(yyvsp[-1].d))); } +#line 1507 "sparse.c" /* yacc.c:1646 */ break; case 32: -#line 122 "sparse.y" - { (yyval.i) = set_angle_sign( (yyvsp[(1) - (1)].i), 1 ) ; } +#line 122 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle_sign( (yyvsp[0].i), 1 ) ; } +#line 1513 "sparse.c" /* yacc.c:1646 */ break; case 33: -#line 124 "sparse.y" - { (yyval.i) = set_angle_sign( (yyvsp[(2) - (2)].i), (yyvsp[(1) - (2)].i) ) ; } +#line 124 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle_sign( (yyvsp[0].i), (yyvsp[-1].i) ) ; } +#line 1519 "sparse.c" /* yacc.c:1646 */ break; case 34: -#line 130 "sparse.y" - { (yyval.i) = set_angle_sign( (yyvsp[(1) - (1)].i), 1 ) ; } +#line 130 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle_sign( (yyvsp[0].i), 1 ) ; } +#line 1525 "sparse.c" /* yacc.c:1646 */ break; case 35: -#line 132 "sparse.y" - { (yyval.i) = set_angle_sign( (yyvsp[(2) - (2)].i), (yyvsp[(1) - (2)].i) ) ; } +#line 132 "sparse.y" /* yacc.c:1646 */ + { (yyval.i) = set_angle_sign( (yyvsp[0].i), (yyvsp[-1].i) ) ; } +#line 1531 "sparse.c" /* yacc.c:1646 */ break; case 36: -#line 140 "sparse.y" +#line 140 "sparse.y" /* yacc.c:1646 */ { - (yyval.i) = set_point( (yyvsp[(2) - (5)].i) , (yyvsp[(4) - (5)].i) ); + (yyval.i) = set_point( (yyvsp[-3].i) , (yyvsp[-1].i) ); } +#line 1539 "sparse.c" /* yacc.c:1646 */ break; case 37: -#line 150 "sparse.y" +#line 150 "sparse.y" /* yacc.c:1646 */ { - set_circle( (yyvsp[(2) - (5)].i), (yyvsp[(4) - (5)].i) ); + set_circle( (yyvsp[-3].i), (yyvsp[-1].i) ); } +#line 1547 "sparse.c" /* yacc.c:1646 */ break; case 38: -#line 160 "sparse.y" - { set_euler ( (yyvsp[(1) - (5)].i) , (yyvsp[(3) - (5)].i) , (yyvsp[(5) - (5)].i) , "ZXZ" ) ; } +#line 160 "sparse.y" /* yacc.c:1646 */ + { set_euler ( (yyvsp[-4].i) , (yyvsp[-2].i) , (yyvsp[0].i) , "ZXZ" ) ; } +#line 1553 "sparse.c" /* yacc.c:1646 */ break; case 39: -#line 163 "sparse.y" - { set_euler ( (yyvsp[(1) - (7)].i) , (yyvsp[(3) - (7)].i) , (yyvsp[(5) - (7)].i) , (yyvsp[(7) - (7)].c) ) ; } +#line 163 "sparse.y" /* yacc.c:1646 */ + { set_euler ( (yyvsp[-6].i) , (yyvsp[-4].i) , (yyvsp[-2].i) , (yyvsp[0].c) ) ; } +#line 1559 "sparse.c" /* yacc.c:1646 */ break; case 40: -#line 170 "sparse.y" +#line 170 "sparse.y" /* yacc.c:1646 */ { - set_line ( (yyvsp[(5) - (5)].i) ) ; + set_line ( (yyvsp[0].i) ) ; } +#line 1567 "sparse.c" /* yacc.c:1646 */ break; case 43: -#line 183 "sparse.y" +#line 183 "sparse.y" /* yacc.c:1646 */ { } +#line 1573 "sparse.c" /* yacc.c:1646 */ break; case 44: -#line 190 "sparse.y" - { set_ellipse ( (yyvsp[(3) - (11)].i) , (yyvsp[(5) - (11)].i) , (yyvsp[(8) - (11)].i) , (yyvsp[(10) - (11)].i) ) ; } +#line 190 "sparse.y" /* yacc.c:1646 */ + { set_ellipse ( (yyvsp[-8].i) , (yyvsp[-6].i) , (yyvsp[-3].i) , (yyvsp[-1].i) ) ; } +#line 1579 "sparse.c" /* yacc.c:1646 */ break; case 45: -#line 197 "sparse.y" +#line 197 "sparse.y" /* yacc.c:1646 */ { } +#line 1585 "sparse.c" /* yacc.c:1646 */ break; case 46: -#line 200 "sparse.y" +#line 200 "sparse.y" /* yacc.c:1646 */ { } +#line 1591 "sparse.c" /* yacc.c:1646 */ break; -/* Line 1267 of yacc.c. */ -#line 1678 "sparse.c" +#line 1595 "sparse.c" /* yacc.c:1646 */ default: break; } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); @@ -1685,8 +1613,7 @@ yyparse () *++yyvsp = yyval; - - /* Now `shift' the result of the reduction. Determine what state + /* Now 'shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ @@ -1701,10 +1628,14 @@ yyparse () goto yynewstate; -/*------------------------------------. -| yyerrlab -- here on detecting error | -`------------------------------------*/ +/*--------------------------------------. +| yyerrlab -- here on detecting error. | +`--------------------------------------*/ yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { @@ -1712,37 +1643,36 @@ yyparse () #if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); #else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) { - YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); - if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) - { - YYSIZE_T yyalloc = 2 * yysize; - if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) - yyalloc = YYSTACK_ALLOC_MAXIMUM; - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yyalloc); - if (yymsg) - yymsg_alloc = yyalloc; - else - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - } - } - - if (0 < yysize && yysize <= yymsg_alloc) - { - (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (yymsg); - } - else - { - yyerror (YY_("syntax error")); - if (yysize != 0) - goto yyexhaustedlab; - } + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } +# undef YYSYNTAX_ERROR #endif } @@ -1750,24 +1680,24 @@ yyparse () if (yyerrstatus == 3) { - /* If just tried and failed to reuse look-ahead token after an - error, discard it. */ + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } else - { - yydestruct ("Error: discarding", - yytoken, &yylval); - yychar = YYEMPTY; - } + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } } - /* Else will try to reuse look-ahead token after shifting the error + /* Else will try to reuse lookahead token after shifting the error token. */ goto yyerrlab1; @@ -1783,7 +1713,7 @@ yyparse () if (/*CONSTCOND*/ 0) goto yyerrorlab; - /* Do not reclaim the symbols of the rule which action triggered + /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ YYPOPSTACK (yylen); yylen = 0; @@ -1796,38 +1726,37 @@ yyparse () | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ + yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) { yyn = yypact[yystate]; - if (yyn != YYPACT_NINF) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } + if (!yypact_value_is_default (yyn)) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } /* Pop the current state because it cannot handle the error token. */ if (yyssp == yyss) - YYABORT; + YYABORT; yydestruct ("Error: popping", - yystos[yystate], yyvsp); + yystos[yystate], yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } - if (yyn == YYFINAL) - YYACCEPT; - + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END /* Shift the error token. */ @@ -1851,7 +1780,7 @@ yyparse () yyresult = 1; goto yyreturn; -#ifndef yyoverflow +#if !defined yyoverflow || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ @@ -1862,17 +1791,22 @@ yyparse () #endif yyreturn: - if (yychar != YYEOF && yychar != YYEMPTY) - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval); - /* Do not reclaim the symbols of the rule which action triggered + if (yychar != YYEMPTY) + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + } + /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); YY_STACK_PRINT (yyss, yyssp); while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp); + yystos[*yyssp], yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow @@ -1883,9 +1817,5 @@ yyparse () if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); #endif - /* Make sure YYID is used. */ - return YYID (yyresult); + return yyresult; } - - - diff --git a/sparse.h b/sparse.h index 71e7512..0d76571 100644 --- a/sparse.h +++ b/sparse.h @@ -1,14 +1,13 @@ -/* A Bison parser, made by GNU Bison 2.3. */ +/* A Bison parser, made by GNU Bison 3.0.4. */ -/* Skeleton interface for Bison's Yacc-like parsers in C +/* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -16,9 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -33,28 +30,37 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ -/* Tokens. */ +#ifndef YY_SPHERE_YY_SPARSE_H_INCLUDED +# define YY_SPHERE_YY_SPARSE_H_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int sphere_yydebug; +#endif + +/* Token type. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - HOUR = 258, - DEG = 259, - MIN = 260, - SEC = 261, - COMMA = 262, - OPENCIRC = 263, - CLOSECIRC = 264, - OPENPOINT = 265, - CLOSEPOINT = 266, - OPENARR = 267, - CLOSEARR = 268, - SIGN = 269, - INT = 270, - FLOAT = 271, - EULERAXIS = 272 - }; + enum yytokentype + { + HOUR = 258, + DEG = 259, + MIN = 260, + SEC = 261, + COMMA = 262, + OPENCIRC = 263, + CLOSECIRC = 264, + OPENPOINT = 265, + CLOSEPOINT = 266, + OPENARR = 267, + CLOSEARR = 268, + SIGN = 269, + INT = 270, + FLOAT = 271, + EULERAXIS = 272 + }; #endif /* Tokens. */ #define HOUR 258 @@ -73,24 +79,28 @@ #define FLOAT 271 #define EULERAXIS 272 - - - +/* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef union YYSTYPE -#line 39 "sparse.y" -{ + +union YYSTYPE +{ +#line 39 "sparse.y" /* yacc.c:1909 */ + int i; double d; char c[3]; -} -/* Line 1529 of yacc.c. */ -#line 89 "sparse.h" - YYSTYPE; -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ -# define YYSTYPE_IS_DECLARED 1 + +#line 94 "sparse.h" /* yacc.c:1909 */ +}; + +typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 #endif + extern YYSTYPE sphere_yylval; +int sphere_yyparse (void); + +#endif /* !YY_SPHERE_YY_SPARSE_H_INCLUDED */ diff --git a/sscan.c b/sscan.c index 6d94fd3..ee67d89 100644 --- a/sscan.c +++ b/sscan.c @@ -27,13 +27,13 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 37 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 0 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif -/* First, we deal with platform-specific or compiler-specific issues. */ +/* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ #include @@ -53,7 +53,7 @@ #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. + * if you want the limit (max/min) macros for int types. */ #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS 1 @@ -70,57 +70,57 @@ typedef uint32_t flex_uint32_t; typedef signed char flex_int8_t; typedef short int flex_int16_t; typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; +typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; /* Limits of integral types. */ #ifndef INT8_MIN -#define INT8_MIN (-128) +#define INT8_MIN (-128) #endif #ifndef INT16_MIN -#define INT16_MIN (-32767-1) +#define INT16_MIN (-32767-1) #endif #ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) +#define INT32_MIN (-2147483647-1) #endif #ifndef INT8_MAX -#define INT8_MAX (127) +#define INT8_MAX (127) #endif #ifndef INT16_MAX -#define INT16_MAX (32767) +#define INT16_MAX (32767) #endif #ifndef INT32_MAX -#define INT32_MAX (2147483647) +#define INT32_MAX (2147483647) #endif #ifndef UINT8_MAX -#define UINT8_MAX (255U) +#define UINT8_MAX (255U) #endif #ifndef UINT16_MAX -#define UINT16_MAX (65535U) +#define UINT16_MAX (65535U) #endif #ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) +#define UINT32_MAX (4294967295U) #endif -#endif /* ! C99 */ +#endif /* ! C99 */ -#endif /* ! FLEXINT_H */ +#endif /* ! FLEXINT_H */ #ifdef __cplusplus /* The "const" storage-class-modifier is valid. */ #define YY_USE_CONST -#else /* ! __cplusplus */ +#else /* ! __cplusplus */ /* C99 requires __STDC__ to be defined as 1. */ #if defined (__STDC__) #define YY_USE_CONST -#endif /* defined (__STDC__) */ -#endif /* ! __cplusplus */ +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ #ifdef YY_USE_CONST #define yyconst const @@ -155,18 +155,26 @@ typedef unsigned int flex_uint32_t; #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE sphererestart(spherein ) +#define YY_NEW_FILE sphererestart(spherein ) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ #ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else #define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ #endif /* The state buf must be large enough to hold one state per character in the main buffer. */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) #ifndef YY_TYPEDEF_YY_BUFFER_STATE #define YY_TYPEDEF_YY_BUFFER_STATE @@ -180,22 +188,22 @@ typedef size_t yy_size_t; extern yy_size_t sphereleng; -extern FILE *spherein, - *sphereout; +extern FILE *spherein, *sphereout; #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 -#define YY_LESS_LINENO(n) - + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) + /* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ do \ { \ /* Undo effects of setting up spheretext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ *yy_cp = (yy_hold_char); \ YY_RESTORE_YY_MORE_OFFSET \ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ @@ -208,73 +216,72 @@ extern FILE *spherein, #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state -{ - FILE *yy_input_file; + { + FILE *yy_input_file; - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ - /* - * Size of input buffer in bytes, not including room for EOB characters. + /* Size of input buffer in bytes, not including room for EOB + * characters. */ - yy_size_t yy_buf_size; + yy_size_t yy_buf_size; - /* - * Number of characters read into yy_ch_buf, not including EOB characters. + /* Number of characters read into yy_ch_buf, not including EOB + * characters. */ - yy_size_t yy_n_chars; + yy_size_t yy_n_chars; - /* - * Whether we "own" the buffer - i.e., we know we created it, and can - * realloc() it to grow it, and should free() it to delete it. + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. */ - int yy_is_our_buffer; + int yy_is_our_buffer; - /* - * Whether this is an "interactive" input source; if so, and if we're - * using stdio for input, then we want to use getc() instead of fread(), - * to make sure we stop fetching input after each newline. + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. */ - int yy_is_interactive; + int yy_is_interactive; - /* - * Whether we're considered to be at the beginning of a line. If so, '^' - * rules will be active on the next match, otherwise not. + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ + int yy_at_bol; - /* - * Whether to try to fill the input buffer when we reach the end of it. + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. */ - int yy_fill_buffer; + int yy_fill_buffer; - int yy_buffer_status; + int yy_buffer_status; #define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 - - /* - * When an EOF's been seen but there's still some text to process then we - * mark the buffer as YY_EOF_PENDING, to indicate that we shouldn't try - * reading from the input source any more. We might still have a bunch of - * tokens to match, though, because of possible backing-up. + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. * - * When we actually see the EOF, we change the status to "new" (via - * sphererestart()), so that the user can continue scanning by just - * pointing spherein at a new input file. + * When we actually see the EOF, we change the status to "new" + * (via sphererestart()), so that the user can continue scanning by + * just pointing spherein at a new input file. */ #define YY_BUFFER_EOF_PENDING 2 -}; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ /* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE *yy_buffer_stack = 0; /**< Stack as an array. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general @@ -283,8 +290,8 @@ static YY_BUFFER_STATE *yy_buffer_stack = 0; /**< Stack as an array. */ * Returns the top of the stack, or NULL. */ #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. @@ -293,49 +300,49 @@ static YY_BUFFER_STATE *yy_buffer_stack = 0; /**< Stack as an array. */ /* yy_hold_char holds the character lost when spheretext is formed. */ static char yy_hold_char; -static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ -yy_size_t sphereleng; +static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ +yy_size_t sphereleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ /* Flag which is used to allow spherewrap()'s to do buffer switches * instead of setting up a fresh spherein. A bit of a hack ... */ -static int yy_did_buffer_switch_on_eof; +static int yy_did_buffer_switch_on_eof; -void sphererestart(FILE *input_file); -void sphere_switch_to_buffer(YY_BUFFER_STATE new_buffer); -YY_BUFFER_STATE sphere_create_buffer(FILE *file, int size); -void sphere_delete_buffer(YY_BUFFER_STATE b); -void sphere_flush_buffer(YY_BUFFER_STATE b); -void spherepush_buffer_state(YY_BUFFER_STATE new_buffer); -void spherepop_buffer_state(void); +void sphererestart (FILE *input_file ); +void sphere_switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE sphere_create_buffer (FILE *file,int size ); +void sphere_delete_buffer (YY_BUFFER_STATE b ); +void sphere_flush_buffer (YY_BUFFER_STATE b ); +void spherepush_buffer_state (YY_BUFFER_STATE new_buffer ); +void spherepop_buffer_state (void ); -static void sphereensure_buffer_stack(void); -static void sphere_load_buffer_state(void); -static void sphere_init_buffer(YY_BUFFER_STATE b, FILE *file); +static void sphereensure_buffer_stack (void ); +static void sphere_load_buffer_state (void ); +static void sphere_init_buffer (YY_BUFFER_STATE b,FILE *file ); #define YY_FLUSH_BUFFER sphere_flush_buffer(YY_CURRENT_BUFFER ) -YY_BUFFER_STATE sphere_scan_buffer(char *base, yy_size_t size); -YY_BUFFER_STATE sphere_scan_string(yyconst char *yy_str); -YY_BUFFER_STATE sphere_scan_bytes(yyconst char *bytes, yy_size_t len); +YY_BUFFER_STATE sphere_scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE sphere_scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE sphere_scan_bytes (yyconst char *bytes,yy_size_t len ); -void *spherealloc(yy_size_t); -void *sphererealloc(void *, yy_size_t); -void spherefree(void *); +void *spherealloc (yy_size_t ); +void *sphererealloc (void *,yy_size_t ); +void spherefree (void * ); #define yy_new_buffer sphere_create_buffer #define yy_set_interactive(is_interactive) \ { \ if ( ! YY_CURRENT_BUFFER ){ \ - sphereensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - sphere_create_buffer(spherein,YY_BUF_SIZE ); \ + sphereensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + sphere_create_buffer(spherein,YY_BUF_SIZE ); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ } @@ -343,9 +350,9 @@ void spherefree(void *); #define yy_set_bol(at_bol) \ { \ if ( ! YY_CURRENT_BUFFER ){\ - sphereensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - sphere_create_buffer(spherein,YY_BUF_SIZE ); \ + sphereensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + sphere_create_buffer(spherein,YY_BUF_SIZE ); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ } @@ -354,26 +361,32 @@ void spherefree(void *); /* Begin user sect3 */ -#define spherewrap() 1 +#define spherewrap() (/*CONSTCOND*/1) #define YY_SKIP_YYWRAP typedef unsigned char YY_CHAR; -FILE *spherein = (FILE *) 0, *sphereout = (FILE *) 0; +FILE *spherein = (FILE *) 0, *sphereout = (FILE *) 0; typedef int yy_state_type; -extern int spherelineno; +extern int spherelineno; -int spherelineno = 1; +int spherelineno = 1; extern char *spheretext; +#ifdef yytext_ptr +#undef yytext_ptr +#endif #define yytext_ptr spheretext -static yy_state_type yy_get_previous_state(void); -static yy_state_type yy_try_NUL_trans(yy_state_type current_state); -static int yy_get_next_buffer(void); -static void yy_fatal_error(yyconst char msg[]); +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +#if defined(__GNUC__) && __GNUC__ >= 3 +__attribute__((__noreturn__)) +#endif +static void yy_fatal_error (yyconst char msg[] ); /* Done after the current pattern has been matched and before the * corresponding action - sets up spheretext. @@ -390,100 +403,100 @@ static void yy_fatal_error(yyconst char msg[]); /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info -{ + { flex_int32_t yy_verify; flex_int32_t yy_nxt; -}; + }; static yyconst flex_int16_t yy_accept[34] = -{0, - 0, 0, 21, 19, 18, 18, 9, 7, 14, 15, - 1, 11, 19, 2, 12, 13, 19, 6, 5, 8, - 10, 16, 17, 18, 3, 0, 2, 0, 0, 0, - 4, 3, 0 -}; - -static yyconst flex_int32_t yy_ec[256] = -{0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 1, 4, 1, 1, 1, 1, 5, 6, - 7, 1, 8, 9, 8, 10, 1, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 1, 1, 12, - 1, 13, 1, 1, 1, 1, 1, 1, 14, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 15, 15, 15, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, - - 14, 1, 1, 17, 1, 1, 1, 1, 18, 1, - 1, 1, 1, 1, 19, 1, 1, 1, 1, 15, - 15, 15, 20, 1, 21, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 -}; - -static yyconst flex_int32_t yy_meta[22] = -{0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1 -}; - -static yyconst flex_int16_t yy_base[34] = -{0, - 0, 0, 43, 44, 20, 22, 44, 44, 44, 44, - 44, 44, 31, 16, 44, 44, 26, 44, 44, 44, - 44, 44, 44, 26, 20, 29, 22, 31, 23, 26, - 44, 24, 44 -}; + { 0, + 0, 0, 21, 19, 18, 18, 9, 7, 14, 15, + 1, 11, 19, 2, 12, 13, 19, 6, 5, 8, + 10, 16, 17, 18, 3, 0, 2, 0, 0, 0, + 4, 3, 0 + } ; + +static yyconst YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 4, 1, 1, 1, 1, 5, 6, + 7, 1, 8, 9, 8, 10, 1, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 1, 1, 12, + 1, 13, 1, 1, 1, 1, 1, 1, 14, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 15, 15, 15, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, + + 14, 1, 1, 17, 1, 1, 1, 1, 18, 1, + 1, 1, 1, 1, 19, 1, 1, 1, 1, 15, + 15, 15, 20, 1, 21, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst YY_CHAR yy_meta[22] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1 + } ; + +static yyconst flex_uint16_t yy_base[34] = + { 0, + 0, 0, 43, 44, 20, 22, 44, 44, 44, 44, + 44, 44, 31, 16, 44, 44, 26, 44, 44, 44, + 44, 44, 44, 26, 20, 29, 22, 31, 23, 26, + 44, 24, 44 + } ; static yyconst flex_int16_t yy_def[34] = -{0, - 33, 1, 33, 33, 33, 33, 33, 33, 33, 33, - 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, - 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, - 33, 33, 0 -}; - -static yyconst flex_int16_t yy_nxt[66] = -{0, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 4, 17, 18, 19, 20, 21, 22, - 23, 24, 24, 24, 24, 26, 27, 24, 24, 28, - 25, 26, 27, 28, 32, 28, 32, 31, 30, 25, - 29, 25, 33, 3, 33, 33, 33, 33, 33, 33, - 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, - 33, 33, 33, 33, 33 -}; + { 0, + 33, 1, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 0 + } ; + +static yyconst flex_uint16_t yy_nxt[66] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 4, 17, 18, 19, 20, 21, 22, + 23, 24, 24, 24, 24, 26, 27, 24, 24, 28, + 25, 26, 27, 28, 32, 28, 32, 31, 30, 25, + 29, 25, 33, 3, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; static yyconst flex_int16_t yy_chk[66] = -{0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 5, 5, 6, 6, 14, 14, 24, 24, 14, - 25, 27, 27, 25, 32, 27, 30, 29, 28, 26, - 17, 13, 3, 33, 33, 33, 33, 33, 33, 33, - 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, - 33, 33, 33, 33, 33 -}; + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 5, 5, 6, 6, 14, 14, 24, 24, 14, + 25, 27, 27, 25, 32, 27, 30, 29, 28, 26, + 17, 13, 3, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, + 33, 33, 33, 33, 33 + } ; static yy_state_type yy_last_accepting_state; static char *yy_last_accepting_cpos; -extern int sphere_flex_debug; -int sphere_flex_debug = 0; +extern int sphere_flex_debug; +int sphere_flex_debug = 0; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. @@ -492,7 +505,7 @@ int sphere_flex_debug = 0; #define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET -char *spheretext; +char *spheretext; #line 1 "sscan.l" #line 2 "sscan.l" #include @@ -508,18 +521,16 @@ YY_DECL; #define YY_NO_INPUT #define YY_INPUT(buf,result,max_size) \ { \ - result = get_buffer( buf, max_size ); \ - result = ( result > 0 )?( result ):(YY_NULL); \ + result = get_buffer( buf, max_size ); \ + result = ( result > 0 )?( result ):(YY_NULL); \ } -void -sphere_flush_scanner_buffer(void) -{ - YY_FLUSH_BUFFER; -} +void sphere_flush_scanner_buffer(void) { + YY_FLUSH_BUFFER; +} -#line 519 "sscan.c" +#line 534 "sscan.c" #define INITIAL 0 @@ -535,36 +546,36 @@ sphere_flush_scanner_buffer(void) #define YY_EXTRA_TYPE void * #endif -static int yy_init_globals(void); +static int yy_init_globals (void ); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int spherelex_destroy(void); +int spherelex_destroy (void ); -int sphereget_debug(void); +int sphereget_debug (void ); -void sphereset_debug(int debug_flag); +void sphereset_debug (int debug_flag ); -YY_EXTRA_TYPE sphereget_extra(void); +YY_EXTRA_TYPE sphereget_extra (void ); -void sphereset_extra(YY_EXTRA_TYPE user_defined); +void sphereset_extra (YY_EXTRA_TYPE user_defined ); -FILE *sphereget_in(void); +FILE *sphereget_in (void ); -void sphereset_in(FILE *in_str); +void sphereset_in (FILE * _in_str ); -FILE *sphereget_out(void); +FILE *sphereget_out (void ); -void sphereset_out(FILE *out_str); +void sphereset_out (FILE * _out_str ); -yy_size_t sphereget_leng(void); +yy_size_t sphereget_leng (void ); -char *sphereget_text(void); +char *sphereget_text (void ); -int sphereget_lineno(void); +int sphereget_lineno (void ); -void sphereset_lineno(int line_number); +void sphereset_lineno (int _line_number ); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -572,33 +583,42 @@ void sphereset_lineno(int line_number); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int spherewrap(void); +extern "C" int spherewrap (void ); #else -extern int spherewrap(void); +extern int spherewrap (void ); #endif #endif +#ifndef YY_NO_UNPUT + +#endif + #ifndef yytext_ptr -static void yy_flex_strncpy(char *, yyconst char *, int); +static void yy_flex_strncpy (char *,yyconst char *,int ); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen(yyconst char *); +static int yy_flex_strlen (yyconst char * ); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput(void); +static int yyinput (void ); #else -static int input(void); +static int input (void ); #endif #endif /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else #define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ #endif /* Copy whatever the last rule matched to the standard output. */ @@ -619,7 +639,7 @@ static int input(void); int c = '*'; \ size_t n; \ for ( n = 0; n < max_size && \ - (c = getc( spherein )) != EOF && c != '\n'; ++n ) \ + (c = getc( spherein )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ if ( c == '\n' ) \ buf[n++] = (char) c; \ @@ -671,10 +691,10 @@ static int input(void); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int spherelex(void); +extern int spherelex (void); #define YY_DECL int spherelex (void) -#endif /* !YY_DECL */ +#endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after spheretext and sphereleng * have been set up. @@ -685,7 +705,7 @@ extern int spherelex(void); /* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK break; +#define YY_BREAK /*LINTED*/break; #endif #define YY_RULE_SETUP \ @@ -695,76 +715,73 @@ extern int spherelex(void); */ YY_DECL { - register yy_state_type yy_current_state; - register char *yy_cp, - *yy_bp; - register int yy_act; - -#line 36 "sscan.l" - -#line 701 "sscan.c" - - if (!(yy_init)) - { + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + + if ( !(yy_init) ) + { (yy_init) = 1; #ifdef YY_USER_INIT YY_USER_INIT; #endif - if (!(yy_start)) - (yy_start) = 1; /* first start state */ + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ - if (!spherein) + if ( ! spherein ) spherein = stdin; - if (!sphereout) + if ( ! sphereout ) sphereout = stdout; - if (!YY_CURRENT_BUFFER) - { - sphereensure_buffer_stack(); + if ( ! YY_CURRENT_BUFFER ) { + sphereensure_buffer_stack (); YY_CURRENT_BUFFER_LVALUE = - sphere_create_buffer(spherein, YY_BUF_SIZE); + sphere_create_buffer(spherein,YY_BUF_SIZE ); } - sphere_load_buffer_state(); - } + sphere_load_buffer_state( ); + } - while (1) /* loops until end-of-file is reached */ { +#line 36 "sscan.l" + +#line 752 "sscan.c" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ + { yy_cp = (yy_c_buf_p); /* Support of spheretext. */ *yy_cp = (yy_hold_char); - /* - * yy_bp points to the position in yy_ch_buf of the start of the - * current run. + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. */ yy_bp = yy_cp; yy_current_state = (yy_start); yy_match: do - { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; - - if (yy_accept[yy_current_state]) { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) + { (yy_last_accepting_state) = yy_current_state; (yy_last_accepting_cpos) = yy_cp; - } - while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) - { + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { yy_current_state = (int) yy_def[yy_current_state]; - if (yy_current_state >= 34) + if ( yy_current_state >= 34 ) yy_c = yy_meta[(unsigned int) yy_c]; - } + } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; - } - while (yy_current_state != 33); + } + while ( yy_current_state != 33 ); yy_cp = (yy_last_accepting_cpos); yy_current_state = (yy_last_accepting_state); @@ -773,261 +790,252 @@ YY_DECL YY_DO_BEFORE_ACTION; -do_action: /* This label is used only to access EOF - * actions. */ +do_action: /* This label is used only to access EOF actions. */ - switch (yy_act) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; - case 1: - YY_RULE_SETUP +case 1: +YY_RULE_SETUP #line 37 "sscan.l" - sphere_yylval.i = (strcmp("-", spheretext)) ? (1) : (-1); - return SIGN; - YY_BREAK - case 2: - YY_RULE_SETUP +sphere_yylval.i = ( strcmp("-",spheretext) )?(1):(-1); return SIGN ; + YY_BREAK +case 2: +YY_RULE_SETUP #line 38 "sscan.l" - sphere_yylval.i = atoi(spheretext); - return INT; - YY_BREAK - case 3: - YY_RULE_SETUP +sphere_yylval.i = atoi(spheretext); return INT ; + YY_BREAK +case 3: +YY_RULE_SETUP #line 39 "sscan.l" - sphere_yylval.d = atof(spheretext); - return FLOAT; - YY_BREAK - case 4: - YY_RULE_SETUP +sphere_yylval.d = atof(spheretext); return FLOAT ; + YY_BREAK +case 4: +YY_RULE_SETUP #line 40 "sscan.l" - memcpy((void *) &sphere_yylval.c[0], (void *) spheretext, 3); - return EULERAXIS; - YY_BREAK - case 5: - YY_RULE_SETUP +memcpy( (void * ) &sphere_yylval.c[0], (void * ) spheretext, 3 ) ; return EULERAXIS ; + YY_BREAK +case 5: +YY_RULE_SETUP #line 41 "sscan.l" - return HOUR; - YY_BREAK - case 6: - YY_RULE_SETUP +return HOUR ; + YY_BREAK +case 6: +YY_RULE_SETUP #line 42 "sscan.l" - return DEG; - YY_BREAK - case 7: - YY_RULE_SETUP +return DEG ; + YY_BREAK +case 7: +YY_RULE_SETUP #line 43 "sscan.l" - return MIN; - YY_BREAK - case 8: - YY_RULE_SETUP +return MIN ; + YY_BREAK +case 8: +YY_RULE_SETUP #line 44 "sscan.l" - return MIN; - YY_BREAK - case 9: - YY_RULE_SETUP +return MIN ; + YY_BREAK +case 9: +YY_RULE_SETUP #line 45 "sscan.l" - return SEC; - YY_BREAK - case 10: - YY_RULE_SETUP +return SEC ; + YY_BREAK +case 10: +YY_RULE_SETUP #line 46 "sscan.l" - return SEC; - YY_BREAK - case 11: - YY_RULE_SETUP +return SEC ; + YY_BREAK +case 11: +YY_RULE_SETUP #line 47 "sscan.l" - return COMMA; - YY_BREAK - case 12: - YY_RULE_SETUP +return COMMA ; + YY_BREAK +case 12: +YY_RULE_SETUP #line 48 "sscan.l" - return OPENCIRC; - YY_BREAK - case 13: - YY_RULE_SETUP +return OPENCIRC ; + YY_BREAK +case 13: +YY_RULE_SETUP #line 49 "sscan.l" - return CLOSECIRC; - YY_BREAK - case 14: - YY_RULE_SETUP +return CLOSECIRC ; + YY_BREAK +case 14: +YY_RULE_SETUP #line 50 "sscan.l" - return OPENPOINT; - YY_BREAK - case 15: - YY_RULE_SETUP +return OPENPOINT ; + YY_BREAK +case 15: +YY_RULE_SETUP #line 51 "sscan.l" - return CLOSEPOINT; - YY_BREAK - case 16: - YY_RULE_SETUP +return CLOSEPOINT ; + YY_BREAK +case 16: +YY_RULE_SETUP #line 52 "sscan.l" - return OPENARR; - YY_BREAK - case 17: - YY_RULE_SETUP +return OPENARR ; + YY_BREAK +case 17: +YY_RULE_SETUP #line 53 "sscan.l" - return CLOSEARR; - YY_BREAK - case 18: +return CLOSEARR ; + YY_BREAK +case 18: /* rule 18 can match eol */ - YY_RULE_SETUP +YY_RULE_SETUP #line 54 "sscan.l" -/* discard spaces */ - YY_BREAK - case 19: - YY_RULE_SETUP +// discard spaces + YY_BREAK +case 19: +YY_RULE_SETUP #line 55 "sscan.l" -/* alert parser of the garbage */ - YY_BREAK - case 20: - YY_RULE_SETUP +// alert parser of the garbage + YY_BREAK +case 20: +YY_RULE_SETUP #line 56 "sscan.l" - ECHO; - YY_BREAK -#line 881 "sscan.c" - case YY_STATE_EOF(INITIAL): - yyterminate(); +ECHO; + YY_BREAK +#line 906 "sscan.c" +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed spherein at a new source and called + * spherelex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = spherein; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; - case YY_END_OF_BUFFER: + if ( yy_next_state ) { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + } + } - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; - if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW) + if ( spherewrap( ) ) { - /* - * We're scanning a new file or input source. It's - * possible that this happened because the user just - * pointed spherein at a new source and called - * spherelex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = spherein; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* - * Note that here we test for yy_c_buf_p "<=" to the - * position of the first EOB in the buffer, since - * yy_c_buf_p will already have been incremented past the - * NUL character (since all states make transitions on EOB - * to the end-of-buffer state). Contrast this with the - * test in input(). + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * spheretext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. */ - if ((yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state(); - - /* - * Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it for us - * because it doesn't know how to deal with the - * possibility of jamming (and we don't want to build - * jamming into it because then it will run more - * slowly). - */ - - yy_next_state = yy_try_NUL_trans(yy_current_state); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if (yy_next_state) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - } + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; } - else - switch (yy_get_next_buffer()) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if (spherewrap()) - { - /* - * Note: because we've taken care in - * yy_get_next_buffer() to have set up - * spheretext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return - * the YY_NULL, it'll still work - - * another YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if (!(yy_did_buffer_switch_on_eof)) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state(); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state(); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; } - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found"); - } /* end of action switch */ - } /* end of scanning one token */ -} /* end of spherelex */ + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ +} /* end of spherelex */ /* yy_get_next_buffer - try to read in a new buffer * @@ -1036,135 +1044,127 @@ YY_DECL * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ -static int -yy_get_next_buffer(void) +static int yy_get_next_buffer (void) { - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); - register int number_to_move, - i; - int ret_val; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + yy_size_t number_to_move, i; + int ret_val; - if ((yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1]) + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed"); + "fatal flex scanner internal error--end of buffer missed" ); - if (YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0) - { /* Don't try to fill the buffer, so this is an - * EOF. */ - if ((yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1) - { - /* - * We matched a single character, the EOB, so treat this as a - * final EOF. + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. */ return EOB_ACT_END_OF_FILE; - } + } else - { - /* - * We matched some text prior to the EOB, first process it. + { + /* We matched some text prior to the EOB, first + * process it. */ return EOB_ACT_LAST_MATCH; + } } - } /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + number_to_move = (yy_size_t) ((yy_c_buf_p) - (yytext_ptr)) - 1; - for (i = 0; i < number_to_move; ++i) + for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); - if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING) - - /* - * don't do the read, it's not guaranteed to return an EOF, just force - * an EOF + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF */ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; else - { - yy_size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + { + yy_size_t num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - while (num_to_read <= 0) - { /* Not enough room in the buffer - grow it. */ + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ /* just a shorter name for the current buffer */ YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); - if (b->yy_is_our_buffer) - { - yy_size_t new_size = b->yy_buf_size * 2; + if ( b->yy_is_our_buffer ) + { + yy_size_t new_size = b->yy_buf_size * 2; - if (new_size <= 0) + if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; else b->yy_buf_size *= 2; b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - sphererealloc((void *) b->yy_ch_buf, b->yy_buf_size + 2); - } + /* Include room in for 2 EOB chars. */ + sphererealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } else /* Can't grow it, we don't own it. */ b->yy_ch_buf = 0; - if (!b->yy_ch_buf) + if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow"); + "fatal error - scanner input buffer overflow" ); (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; + number_to_move - 1; - } + } - if (num_to_read > YY_READ_BUF_SIZE) + if ( num_to_read > YY_READ_BUF_SIZE ) num_to_read = YY_READ_BUF_SIZE; /* Read in more data. */ - YY_INPUT((&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read); + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } + } - if ((yy_n_chars) == 0) - { - if (number_to_move == YY_MORE_ADJ) + if ( (yy_n_chars) == 0 ) { + if ( number_to_move == YY_MORE_ADJ ) + { ret_val = EOB_ACT_END_OF_FILE; - sphererestart(spherein); - } + sphererestart(spherein ); + } else - { + { ret_val = EOB_ACT_LAST_MATCH; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_EOF_PENDING; + } } - } else ret_val = EOB_ACT_CONTINUE_SCAN; - if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) - { + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) sphererealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, new_size); - if (!YY_CURRENT_BUFFER_LVALUE->yy_ch_buf) - YY_FATAL_ERROR("out of dynamic memory in yy_get_next_buffer()"); + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) sphererealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); } (yy_n_chars) += number_to_move; @@ -1178,31 +1178,29 @@ yy_get_next_buffer(void) /* yy_get_previous_state - get the state just before the EOB char was reached */ -static yy_state_type -yy_get_previous_state(void) + static yy_state_type yy_get_previous_state (void) { - register yy_state_type yy_current_state; - register char *yy_cp; - + yy_state_type yy_current_state; + char *yy_cp; + yy_current_state = (yy_start); - for (yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp) - { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - - if (yy_accept[yy_current_state]) + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { (yy_last_accepting_state) = yy_current_state; (yy_last_accepting_cpos) = yy_cp; - } - while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) - { + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { yy_current_state = (int) yy_def[yy_current_state]; - if (yy_current_state >= 34) + if ( yy_current_state >= 34 ) yy_c = yy_meta[(unsigned int) yy_c]; - } + } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } + } return yy_current_state; } @@ -1212,166 +1210,163 @@ yy_get_previous_state(void) * synopsis * next_state = yy_try_NUL_trans( current_state ); */ -static yy_state_type -yy_try_NUL_trans(yy_state_type yy_current_state) + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) { - register int yy_is_jam; - register char *yy_cp = (yy_c_buf_p); - - register YY_CHAR yy_c = 1; + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); - if (yy_accept[yy_current_state]) - { + YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { (yy_last_accepting_state) = yy_current_state; (yy_last_accepting_cpos) = yy_cp; - } - while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) - { + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { yy_current_state = (int) yy_def[yy_current_state]; - if (yy_current_state >= 34) + if ( yy_current_state >= 34 ) yy_c = yy_meta[(unsigned int) yy_c]; - } + } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_is_jam = (yy_current_state == 33); - return yy_is_jam ? 0 : yy_current_state; + return yy_is_jam ? 0 : yy_current_state; } +#ifndef YY_NO_UNPUT + +#endif + #ifndef YY_NO_INPUT #ifdef __cplusplus -static int -yyinput(void) + static int yyinput (void) #else -static int -input(void) + static int input (void) #endif { - int c; - + int c; + *(yy_c_buf_p) = (yy_hold_char); - if (*(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR) - { - /* - * yy_c_buf_p now points to the character we want to return. If this - * occurs *before* the EOB characters, then it's a valid NUL; if not, - * then we've hit the end of the buffer. + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. */ - if ((yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]) + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) /* This was really a NUL. */ *(yy_c_buf_p) = '\0'; else - { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); - + { /* need more input */ + yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); ++(yy_c_buf_p); - switch (yy_get_next_buffer()) - { + switch ( yy_get_next_buffer( ) ) + { case EOB_ACT_LAST_MATCH: - - /* - * This happens because yy_g_n_b() sees that we've - * accumulated a token and flags that we need to try - * matching the token before proceeding. But for input(), - * there's no matching to consider. So convert the - * EOB_ACT_LAST_MATCH to EOB_ACT_END_OF_FILE. + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. */ /* Reset buffer status. */ - sphererestart(spherein); + sphererestart(spherein ); - /* FALLTHROUGH */ + /*FALLTHROUGH*/ case EOB_ACT_END_OF_FILE: { - if (spherewrap()) - return EOF; + if ( spherewrap( ) ) + return EOF; - if (!(yy_did_buffer_switch_on_eof)) - YY_NEW_FILE; + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; #ifdef __cplusplus - return yyinput(); + return yyinput(); #else - return input(); + return input(); #endif } case EOB_ACT_CONTINUE_SCAN: (yy_c_buf_p) = (yytext_ptr) + offset; break; + } } } - } - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve spheretext */ + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve spheretext */ (yy_hold_char) = *++(yy_c_buf_p); return c; } -#endif /* ifndef YY_NO_INPUT */ +#endif /* ifndef YY_NO_INPUT */ /** Immediately switch to a different input stream. * @param input_file A readable stream. - * + * * @note This function does not reset the start condition to @c INITIAL . */ -void -sphererestart(FILE *input_file) + void sphererestart (FILE * input_file ) { - if (!YY_CURRENT_BUFFER) - { - sphereensure_buffer_stack(); + + if ( ! YY_CURRENT_BUFFER ){ + sphereensure_buffer_stack (); YY_CURRENT_BUFFER_LVALUE = - sphere_create_buffer(spherein, YY_BUF_SIZE); + sphere_create_buffer(spherein,YY_BUF_SIZE ); } - sphere_init_buffer(YY_CURRENT_BUFFER, input_file); - sphere_load_buffer_state(); + sphere_init_buffer(YY_CURRENT_BUFFER,input_file ); + sphere_load_buffer_state( ); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. - * + * */ -void -sphere_switch_to_buffer(YY_BUFFER_STATE new_buffer) + void sphere_switch_to_buffer (YY_BUFFER_STATE new_buffer ) { - /* - * TODO. We should be able to replace this entire function body with - * spherepop_buffer_state(); spherepush_buffer_state(new_buffer); - */ - sphereensure_buffer_stack(); - if (YY_CURRENT_BUFFER == new_buffer) + + /* TODO. We should be able to replace this entire function body + * with + * spherepop_buffer_state(); + * spherepush_buffer_state(new_buffer); + */ + sphereensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) return; - if (YY_CURRENT_BUFFER) - { + if ( YY_CURRENT_BUFFER ) + { /* Flush out information for old buffer. */ *(yy_c_buf_p) = (yy_hold_char); YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } + } YY_CURRENT_BUFFER_LVALUE = new_buffer; - sphere_load_buffer_state(); + sphere_load_buffer_state( ); - /* - * We don't actually know whether we did this switch during EOF - * (spherewrap()) processing, but the only time this flag is looked at is - * after spherewrap() is called, so it's safe to go ahead and always set - * it. + /* We don't actually know whether we did this switch during + * EOF (spherewrap()) processing, but the only time this flag + * is looked at is after spherewrap() is called, so it's safe + * to go ahead and always set it. */ (yy_did_buffer_switch_on_eof) = 1; } -static void -sphere_load_buffer_state(void) +static void sphere_load_buffer_state (void) { - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; spherein = YY_CURRENT_BUFFER_LVALUE->yy_input_file; (yy_hold_char) = *(yy_c_buf_p); @@ -1380,101 +1375,94 @@ sphere_load_buffer_state(void) /** Allocate and initialize an input buffer state. * @param file A readable stream. * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * + * * @return the allocated buffer state. */ -YY_BUFFER_STATE -sphere_create_buffer(FILE *file, int size) + YY_BUFFER_STATE sphere_create_buffer (FILE * file, int size ) { YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) spherealloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in sphere_create_buffer()" ); - b = (YY_BUFFER_STATE) spherealloc(sizeof(struct yy_buffer_state)); - if (!b) - YY_FATAL_ERROR("out of dynamic memory in sphere_create_buffer()"); - - b->yy_buf_size = size; + b->yy_buf_size = (yy_size_t)size; - /* - * yy_ch_buf has to be 2 characters longer than the size given because we - * need to put in 2 end-of-buffer characters. + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. */ - b->yy_ch_buf = (char *) spherealloc(b->yy_buf_size + 2); - if (!b->yy_ch_buf) - YY_FATAL_ERROR("out of dynamic memory in sphere_create_buffer()"); + b->yy_ch_buf = (char *) spherealloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in sphere_create_buffer()" ); b->yy_is_our_buffer = 1; - sphere_init_buffer(b, file); + sphere_init_buffer(b,file ); return b; } /** Destroy the buffer. * @param b a buffer created with sphere_create_buffer() - * + * */ -void -sphere_delete_buffer(YY_BUFFER_STATE b) + void sphere_delete_buffer (YY_BUFFER_STATE b ) { - if (!b) + + if ( ! b ) return; - if (b == YY_CURRENT_BUFFER) /* Not sure if we should pop here. */ + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - if (b->yy_is_our_buffer) - spherefree((void *) b->yy_ch_buf); + if ( b->yy_is_our_buffer ) + spherefree((void *) b->yy_ch_buf ); - spherefree((void *) b); + spherefree((void *) b ); } /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a sphererestart() or at EOF. */ -static void -sphere_init_buffer(YY_BUFFER_STATE b, FILE *file) + static void sphere_init_buffer (YY_BUFFER_STATE b, FILE * file ) { - int oerrno = errno; - - sphere_flush_buffer(b); + int oerrno = errno; + + sphere_flush_buffer(b ); b->yy_input_file = file; b->yy_fill_buffer = 1; - /* - * If b is the current buffer, then sphere_init_buffer was _probably_ - * called from sphererestart() or through yy_get_next_buffer. In that - * case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER) - { - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = 0; - + /* If b is the current buffer, then sphere_init_buffer was _probably_ + * called from sphererestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = 0; + errno = oerrno; } /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * + * */ -void -sphere_flush_buffer(YY_BUFFER_STATE b) + void sphere_flush_buffer (YY_BUFFER_STATE b ) { - if (!b) + if ( ! b ) return; b->yy_n_chars = 0; - /* - * We always need two end-of-buffer characters. The first causes a - * transition to the end-of-buffer state. The second causes a jam in that - * state. + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. */ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; @@ -1484,32 +1472,31 @@ sphere_flush_buffer(YY_BUFFER_STATE b) b->yy_at_bol = 1; b->yy_buffer_status = YY_BUFFER_NEW; - if (b == YY_CURRENT_BUFFER) - sphere_load_buffer_state(); + if ( b == YY_CURRENT_BUFFER ) + sphere_load_buffer_state( ); } /** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * */ -void -spherepush_buffer_state(YY_BUFFER_STATE new_buffer) +void spherepush_buffer_state (YY_BUFFER_STATE new_buffer ) { - if (new_buffer == NULL) + if (new_buffer == NULL) return; sphereensure_buffer_stack(); /* This block is copied from sphere_switch_to_buffer. */ - if (YY_CURRENT_BUFFER) - { + if ( YY_CURRENT_BUFFER ) + { /* Flush out information for old buffer. */ *(yy_c_buf_p) = (yy_hold_char); YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } + } /* Only push if top exists. Otherwise, replace top. */ if (YY_CURRENT_BUFFER) @@ -1517,77 +1504,72 @@ spherepush_buffer_state(YY_BUFFER_STATE new_buffer) YY_CURRENT_BUFFER_LVALUE = new_buffer; /* copied from sphere_switch_to_buffer. */ - sphere_load_buffer_state(); + sphere_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; } /** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * + * The next element becomes the new top. + * */ -void -spherepop_buffer_state(void) +void spherepop_buffer_state (void) { - if (!YY_CURRENT_BUFFER) + if (!YY_CURRENT_BUFFER) return; - sphere_delete_buffer(YY_CURRENT_BUFFER); + sphere_delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; if ((yy_buffer_stack_top) > 0) --(yy_buffer_stack_top); - if (YY_CURRENT_BUFFER) - { - sphere_load_buffer_state(); + if (YY_CURRENT_BUFFER) { + sphere_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; } } /* Allocates the stack if it does not exist. - * Guarantees space for at least one push. + * Guarantees space for at least one push. */ -static void -sphereensure_buffer_stack(void) +static void sphereensure_buffer_stack (void) { - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) - { - /* - * First allocation is just for 2 elements, since we don't know if - * this scanner will even need a stack. We use 2 instead of 1 to avoid - * an immediate realloc on the next call. - */ - num_to_alloc = 1; - (yy_buffer_stack) = (struct yy_buffer_state **) spherealloc - (num_to_alloc * sizeof(struct yy_buffer_state *) - ); - if (!(yy_buffer_stack)) - YY_FATAL_ERROR("out of dynamic memory in sphereensure_buffer_stack()"); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state *)); - + yy_size_t num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; // After all that talk, this was set to 1 anyways... + (yy_buffer_stack) = (struct yy_buffer_state**)spherealloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in sphereensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; (yy_buffer_stack_top) = 0; return; } - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1) - { + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */ ; + yy_size_t grow_size = 8 /* arbitrary grow size */; num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state **) sphererealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state *) - ); - if (!(yy_buffer_stack)) - YY_FATAL_ERROR("out of dynamic memory in sphereensure_buffer_stack()"); - - /* zero only the new slots. */ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state *)); + (yy_buffer_stack) = (struct yy_buffer_state**)sphererealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in sphereensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; } } @@ -1595,23 +1577,22 @@ sphereensure_buffer_stack(void) /** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. + * + * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE -sphere_scan_buffer(char *base, yy_size_t size) +YY_BUFFER_STATE sphere_scan_buffer (char * base, yy_size_t size ) { YY_BUFFER_STATE b; - - if (size < 2 || - base[size - 2] != YY_END_OF_BUFFER_CHAR || - base[size - 1] != YY_END_OF_BUFFER_CHAR) + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ return 0; - b = (YY_BUFFER_STATE) spherealloc(sizeof(struct yy_buffer_state)); - if (!b) - YY_FATAL_ERROR("out of dynamic memory in sphere_scan_buffer()"); + b = (YY_BUFFER_STATE) spherealloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in sphere_scan_buffer()" ); b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; @@ -1623,7 +1604,7 @@ sphere_scan_buffer(char *base, yy_size_t size) b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; - sphere_switch_to_buffer(b); + sphere_switch_to_buffer(b ); return b; } @@ -1631,50 +1612,48 @@ sphere_scan_buffer(char *base, yy_size_t size) /** Setup the input buffer state to scan a string. The next call to spherelex() will * scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan - * + * * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use - * sphere_scan_bytes() instead. + * sphere_scan_bytes() instead. */ -YY_BUFFER_STATE -sphere_scan_string(yyconst char *yystr) +YY_BUFFER_STATE sphere_scan_string (yyconst char * yystr ) { - return sphere_scan_bytes(yystr, strlen(yystr)); + + return sphere_scan_bytes(yystr,strlen(yystr) ); } /** Setup the input buffer state to scan the given bytes. The next call to spherelex() will * scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * + * * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE -sphere_scan_bytes(yyconst char *yybytes, yy_size_t _yybytes_len) +YY_BUFFER_STATE sphere_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) { YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - + char *buf; + yy_size_t n; + yy_size_t i; + /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; - buf = (char *) spherealloc(n); - if (!buf) - YY_FATAL_ERROR("out of dynamic memory in sphere_scan_bytes()"); + buf = (char *) spherealloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in sphere_scan_bytes()" ); - for (i = 0; i < _yybytes_len; ++i) + for ( i = 0; i < _yybytes_len; ++i ) buf[i] = yybytes[i]; - buf[_yybytes_len] = buf[_yybytes_len + 1] = YY_END_OF_BUFFER_CHAR; + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - b = sphere_scan_buffer(buf, n); - if (!b) - YY_FATAL_ERROR("bad buffer in sphere_scan_bytes()"); + b = sphere_scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in sphere_scan_bytes()" ); - /* - * It's okay to grow etc. this buffer, and we should throw it away when - * we're done. + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. */ b->yy_is_our_buffer = 1; @@ -1685,11 +1664,10 @@ sphere_scan_bytes(yyconst char *yybytes, yy_size_t _yybytes_len) #define YY_EXIT_FAILURE 2 #endif -static void -yy_fatal_error(yyconst char *msg) +static void yy_fatal_error (yyconst char* msg ) { - (void) fprintf(stderr, "%s\n", msg); - exit(YY_EXIT_FAILURE); + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); } /* Redefine yyless() so it works in section 3 code. */ @@ -1699,8 +1677,8 @@ yy_fatal_error(yyconst char *msg) do \ { \ /* Undo effects of setting up spheretext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ spheretext[sphereleng] = (yy_hold_char); \ (yy_c_buf_p) = spheretext + yyless_macro_arg; \ (yy_hold_char) = *(yy_c_buf_p); \ @@ -1712,145 +1690,131 @@ yy_fatal_error(yyconst char *msg) /* Accessor methods (get/set functions) to struct members. */ /** Get the current line number. - * + * */ -int -sphereget_lineno(void) +int sphereget_lineno (void) { - return spherelineno; + + return spherelineno; } /** Get the input stream. - * + * */ -FILE * -sphereget_in(void) +FILE *sphereget_in (void) { - return spherein; + return spherein; } /** Get the output stream. - * + * */ -FILE * -sphereget_out(void) +FILE *sphereget_out (void) { - return sphereout; + return sphereout; } /** Get the length of the current token. - * + * */ -yy_size_t -sphereget_leng(void) +yy_size_t sphereget_leng (void) { - return sphereleng; + return sphereleng; } /** Get the current token. - * + * */ -char * -sphereget_text(void) +char *sphereget_text (void) { - return spheretext; + return spheretext; } /** Set the current line number. - * @param line_number - * + * @param _line_number line number + * */ -void -sphereset_lineno(int line_number) +void sphereset_lineno (int _line_number ) { - spherelineno = line_number; + + spherelineno = _line_number; } /** Set the input stream. This does not discard the current * input buffer. - * @param in_str A readable stream. - * + * @param _in_str A readable stream. + * * @see sphere_switch_to_buffer */ -void -sphereset_in(FILE *in_str) +void sphereset_in (FILE * _in_str ) { - spherein = in_str; + spherein = _in_str ; } -void -sphereset_out(FILE *out_str) +void sphereset_out (FILE * _out_str ) { - sphereout = out_str; + sphereout = _out_str ; } -int -sphereget_debug(void) +int sphereget_debug (void) { - return sphere_flex_debug; + return sphere_flex_debug; } -void -sphereset_debug(int bdebug) +void sphereset_debug (int _bdebug ) { - sphere_flex_debug = bdebug; + sphere_flex_debug = _bdebug ; } -static int -yy_init_globals(void) +static int yy_init_globals (void) { - /* - * Initialization is the same as for the non-reentrant scanner. This - * function is called from spherelex_destroy(), so don't allocate here. - */ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from spherelex_destroy(), so don't allocate here. + */ - (yy_buffer_stack) = 0; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; - (yy_init) = 0; - (yy_start) = 0; + (yy_buffer_stack) = 0; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = (char *) 0; + (yy_init) = 0; + (yy_start) = 0; /* Defined in main.c */ #ifdef YY_STDINIT - spherein = stdin; - sphereout = stdout; + spherein = stdin; + sphereout = stdout; #else - spherein = (FILE *) 0; - sphereout = (FILE *) 0; + spherein = (FILE *) 0; + sphereout = (FILE *) 0; #endif - /* - * For future reference: Set errno on error, since we are called by - * spherelex_init() - */ - return 0; + /* For future reference: Set errno on error, since we are called by + * spherelex_init() + */ + return 0; } /* spherelex_destroy is for both reentrant and non-reentrant scanners. */ -int -spherelex_destroy(void) +int spherelex_destroy (void) { - /* Pop the buffer stack, destroying each element. */ - while (YY_CURRENT_BUFFER) - { - sphere_delete_buffer(YY_CURRENT_BUFFER); + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + sphere_delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; spherepop_buffer_state(); } /* Destroy the stack itself. */ - spherefree((yy_buffer_stack)); + spherefree((yy_buffer_stack) ); (yy_buffer_stack) = NULL; - /* - * Reset the globals. This is important in a non-reentrant scanner so the - * next time spherelex() is called, initialization will occur. - */ - yy_init_globals(); + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * spherelex() is called, initialization will occur. */ + yy_init_globals( ); - return 0; + return 0; } /* @@ -1858,54 +1822,52 @@ spherelex_destroy(void) */ #ifndef yytext_ptr -static void -yy_flex_strncpy(char *s1, yyconst char *s2, int n) +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) { - register int i; - - for (i = 0; i < n; ++i) + + int i; + for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN -static int -yy_flex_strlen(yyconst char *s) +static int yy_flex_strlen (yyconst char * s ) { - register int n; - - for (n = 0; s[n]; ++n) + int n; + for ( n = 0; s[n]; ++n ) ; return n; } #endif -void * -spherealloc(yy_size_t size) +void *spherealloc (yy_size_t size ) { - return (void *) malloc(size); + return (void *) malloc( size ); } -void * -sphererealloc(void *ptr, yy_size_t size) +void *sphererealloc (void * ptr, yy_size_t size ) { - /* - * The cast to (char *) in the following accommodates both implementations - * that use char* generic pointers, and those that use void* generic - * pointers. It works with the latter because both ANSI C and C++ allow - * castless assignment from any pointer type to void*, and deal with - * argument conversions as though doing an assignment. + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. */ - return (void *) realloc((char *) ptr, size); + return (void *) realloc( (char *) ptr, size ); } -void -spherefree(void *ptr) +void spherefree (void * ptr ) { - free((char *) ptr); /* see sphererealloc() for (char *) cast */ + free( (char *) ptr ); /* see sphererealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" #line 56 "sscan.l" + + + From 971d2c5d61f17774a6d8d137ca3ad87e2883048f Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Fri, 26 Feb 2016 16:29:45 +0300 Subject: [PATCH 03/41] dummy node works --- init.c | 225 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 174 insertions(+), 51 deletions(-) diff --git a/init.c b/init.c index 76cd972..793d959 100644 --- a/init.c +++ b/init.c @@ -1,5 +1,6 @@ #include "postgres.h" #include "optimizer/paths.h" +#include "optimizer/pathnode.h" #include "optimizer/restrictinfo.h" #include "utils/builtins.h" #include "utils/elog.h" @@ -10,6 +11,9 @@ #include "commands/explain.h" #include "funcapi.h" +#include "access/htup_details.h" +#include "point.h" + extern void _PG_init(void); static set_join_pathlist_hook_type set_join_pathlist_next; @@ -26,20 +30,93 @@ typedef struct List *joinrestrictinfo; } CrossmatchJoinPath; +typedef struct +{ + CustomScanState css; + + HeapTupleData scan_tuple; /* buffer to fetch tuple */ + List *dev_tlist; /* tlist to be returned from the device */ + List *dev_quals; /* quals to be run on the device */ +} CrossmatchScanState; + static CustomPathMethods crossmatch_path_methods; static CustomScanMethods crossmatch_plan_methods; static CustomExecMethods crossmatch_exec_methods; -void join_pathlist_hook (PlannerInfo *root, - RelOptInfo *joinrel, - RelOptInfo *outerrel, - RelOptInfo *innerrel, - JoinType jointype, - JoinPathExtraData *extra) + +static Path * +crossmatch_find_cheapest_path(PlannerInfo *root, + RelOptInfo *joinrel, + RelOptInfo *inputrel) +{ + Path *input_path = inputrel->cheapest_total_path; + Relids other_relids; + ListCell *lc; + + other_relids = bms_difference(joinrel->relids, inputrel->relids); + if (bms_overlap(PATH_REQ_OUTER(input_path), other_relids)) + { + input_path = NULL; + foreach (lc, inputrel->pathlist) + { + Path *curr_path = lfirst(lc); + + if (bms_overlap(PATH_REQ_OUTER(curr_path), other_relids)) + continue; + if (input_path == NULL || + input_path->total_cost > curr_path->total_cost) + input_path = curr_path; + } + } + bms_free(other_relids); + + return input_path; +} + +static void +create_crossmatch_path(PlannerInfo *root, + RelOptInfo *joinrel, + Path *outer_path, + Path *inner_path, + ParamPathInfo *param_info, + List *restrict_clauses, + Relids required_outer) +{ + CrossmatchJoinPath *result; + + result = palloc0(sizeof(CrossmatchJoinPath)); + NodeSetTag(result, T_CustomPath); + + result->cpath.path.pathtype = T_CustomScan; + result->cpath.path.parent = joinrel; + result->cpath.path.param_info = param_info; + result->cpath.path.pathkeys = NIL; + result->cpath.path.rows = joinrel->rows; + result->cpath.flags = 0; + result->cpath.methods = &crossmatch_path_methods; + result->outer_path = outer_path; + result->inner_path = inner_path; + result->joinrestrictinfo = restrict_clauses; + + /* TODO: real costs */ + result->cpath.path.startup_cost = 1; + result->cpath.path.total_cost = 1; + + add_path(joinrel, &result->cpath.path); +} + +static void +join_pathlist_hook(PlannerInfo *root, + RelOptInfo *joinrel, + RelOptInfo *outerrel, + RelOptInfo *innerrel, + JoinType jointype, + JoinPathExtraData *extra) { ListCell *restr; text *dist_func_name = cstring_to_text("dist(spoint,spoint)"); Oid dist_func; + List *restrict_clauses = extra->restrictlist; dist_func = DatumGetObjectId(DirectFunctionCall1(to_regprocedure, PointerGetDatum(dist_func_name))); @@ -59,6 +136,15 @@ void join_pathlist_hook (PlannerInfo *root, { RestrictInfo *restrInfo = (RestrictInfo *) lfirst(restr); + if (outerrel->reloptkind == RELOPT_BASEREL && + innerrel->reloptkind == RELOPT_BASEREL && + bms_is_member(outerrel->relid, restrInfo->clause_relids) && + bms_is_member(innerrel->relid, restrInfo->clause_relids)) + { + /* This is our case */ + } + else continue; + if (IsA(restrInfo->clause, OpExpr)) { OpExpr *opExpr = (OpExpr *) restrInfo->clause; @@ -77,14 +163,46 @@ void join_pathlist_hook (PlannerInfo *root, ((FuncExpr *) arg1)->funcid == dist_func && IsA(arg2, Const)) { - elog(LOG, "found <"); + Path *outer_path = crossmatch_find_cheapest_path(root, joinrel, outerrel); + Path *inner_path = crossmatch_find_cheapest_path(root, joinrel, innerrel); + + Relids required_outer = calc_nestloop_required_outer(outer_path, inner_path); + + ParamPathInfo *param_info = get_joinrel_parampathinfo(root, + joinrel, + outer_path, + inner_path, + extra->sjinfo, + required_outer, + &restrict_clauses); + + /* DEBUG */ + create_crossmatch_path(root, joinrel, outer_path, inner_path, + param_info, restrict_clauses, required_outer); + + break; } else if (opExpr->opno == get_commutator(Float8LessOperator) && IsA(arg1, Const) && IsA(arg2, FuncExpr) && ((FuncExpr *) arg2)->funcid == dist_func) { - elog(LOG, "found >"); + Path *outer_path = crossmatch_find_cheapest_path(root, joinrel, outerrel); + Path *inner_path = crossmatch_find_cheapest_path(root, joinrel, innerrel); + + Relids required_outer = calc_nestloop_required_outer(outer_path, inner_path); + + ParamPathInfo *param_info = get_joinrel_parampathinfo(root, + joinrel, + outer_path, + inner_path, + extra->sjinfo, + required_outer, + &restrict_clauses); + + /* DEBUG */ + create_crossmatch_path(root, joinrel, outer_path, inner_path, + param_info, restrict_clauses, required_outer); } } } @@ -92,38 +210,6 @@ void join_pathlist_hook (PlannerInfo *root, pprint(root->parse->rtable); } -static CrossmatchJoinPath * -create_crossmatch_path(PlannerInfo *root, - RelOptInfo *joinrel, - Path *outer_path, - Path *inner_path, - ParamPathInfo *param_info, - List *restrict_clauses, - Relids required_outer) -{ - CrossmatchJoinPath *result; - - result = palloc0(sizeof(CrossmatchJoinPath)); - NodeSetTag(result, T_CustomPath); - - result->cpath.path.pathtype = T_CustomScan; - result->cpath.path.parent = joinrel; - result->cpath.path.param_info = param_info; - result->cpath.path.pathkeys = NIL; - result->cpath.path.rows = joinrel->rows; - result->cpath.flags = 0; - result->cpath.methods = &crossmatch_path_methods; - result->outer_path = outer_path; - result->inner_path = inner_path; - result->joinrestrictinfo = restrict_clauses; - - /* DEBUG costs */ - result->cpath.path.startup_cost = 1; - result->cpath.path.total_cost = 1; - - return result; -} - static Plan * create_crossmatch_plan(PlannerInfo *root, RelOptInfo *rel, @@ -153,30 +239,67 @@ create_crossmatch_plan(PlannerInfo *root, cscan = makeNode(CustomScan); cscan->scan.plan.targetlist = tlist; cscan->scan.plan.qual = NIL; + cscan->scan.scanrelid = 0; + + cscan->custom_scan_tlist = tlist; + + elog(LOG, "tlist:"); + pprint(tlist); cscan->flags = best_path->flags; cscan->methods = &crossmatch_plan_methods; cscan->custom_plans = list_copy_tail(custom_plans, 1); - + return &cscan->scan.plan; } static Node * crossmatch_create_scan_state(CustomScan *node) { - return NULL; + CrossmatchScanState *scan_state = palloc0(sizeof(CrossmatchScanState)); + + NodeSetTag(scan_state, T_CustomScanState); + scan_state->css.flags = node->flags; + if (node->methods == &crossmatch_plan_methods) + scan_state->css.methods = &crossmatch_exec_methods; + else + elog(ERROR, "Bug? unexpected CustomPlanMethods"); + + return (Node *) scan_state; } +static int i = 0; + static void crossmatch_begin(CustomScanState *node, EState *estate, int eflags) { - + i = 0; } static TupleTableSlot * crossmatch_exec(CustomScanState *node) { - return NULL; + TupleTableSlot *slot = node->ss.ss_ScanTupleSlot; + TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; + HeapTuple htup; + + /* TODO: fill with real data from joined tables */ + Datum values[2] = { DirectFunctionCall1(spherepoint_in, CStringGetDatum("(0d, 0d)")), + DirectFunctionCall1(spherepoint_in, CStringGetDatum("(0d, 0d)")) }; + bool nulls[2] = {0, 0}; + + htup = heap_form_tuple(tupdesc, values, nulls); + + elog(LOG, "natts: %d", tupdesc->natts); + + i++; + + if (i > 10) + ExecClearTuple(slot); + else + ExecStoreTuple(htup, slot, InvalidBuffer, false); + + return slot; } static void @@ -206,17 +329,17 @@ _PG_init(void) set_join_pathlist_hook = join_pathlist_hook; crossmatch_path_methods.CustomName = "CrossmatchJoin"; - crossmatch_path_methods.PlanCustomPath = &create_crossmatch_plan; + crossmatch_path_methods.PlanCustomPath = create_crossmatch_plan; crossmatch_plan_methods.CustomName = "CrossmatchJoin"; - crossmatch_plan_methods.CreateCustomScanState = &crossmatch_create_scan_state; + crossmatch_plan_methods.CreateCustomScanState = crossmatch_create_scan_state; crossmatch_exec_methods.CustomName = "CrossmatchJoin"; - crossmatch_exec_methods.BeginCustomScan = &crossmatch_begin; - crossmatch_exec_methods.ExecCustomScan = &crossmatch_exec; - crossmatch_exec_methods.EndCustomScan = &crossmatch_end; - crossmatch_exec_methods.ReScanCustomScan = &crossmatch_rescan; + crossmatch_exec_methods.BeginCustomScan = crossmatch_begin; + crossmatch_exec_methods.ExecCustomScan = crossmatch_exec; + crossmatch_exec_methods.EndCustomScan = crossmatch_end; + crossmatch_exec_methods.ReScanCustomScan = crossmatch_rescan; crossmatch_exec_methods.MarkPosCustomScan = NULL; crossmatch_exec_methods.RestrPosCustomScan = NULL; - crossmatch_exec_methods.ExplainCustomScan = &crossmatch_explain; + crossmatch_exec_methods.ExplainCustomScan = crossmatch_explain; } \ No newline at end of file From 105c14936954d5c33bbc36c7a957e3d4d5a7f199 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Fri, 26 Feb 2016 17:39:19 +0300 Subject: [PATCH 04/41] check restrInfo->required_relids in order to discard irrelevant joins --- init.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/init.c b/init.c index 793d959..34e6597 100644 --- a/init.c +++ b/init.c @@ -117,6 +117,15 @@ join_pathlist_hook(PlannerInfo *root, text *dist_func_name = cstring_to_text("dist(spoint,spoint)"); Oid dist_func; List *restrict_clauses = extra->restrictlist; + Relids required_relids = NULL; + + if (outerrel->reloptkind == RELOPT_BASEREL && + innerrel->reloptkind == RELOPT_BASEREL) + { + required_relids = bms_add_member(required_relids, outerrel->relid); + required_relids = bms_add_member(required_relids, innerrel->relid); + } + else return; /* one of relations can't have index */ dist_func = DatumGetObjectId(DirectFunctionCall1(to_regprocedure, PointerGetDatum(dist_func_name))); @@ -136,14 +145,9 @@ join_pathlist_hook(PlannerInfo *root, { RestrictInfo *restrInfo = (RestrictInfo *) lfirst(restr); - if (outerrel->reloptkind == RELOPT_BASEREL && - innerrel->reloptkind == RELOPT_BASEREL && - bms_is_member(outerrel->relid, restrInfo->clause_relids) && - bms_is_member(innerrel->relid, restrInfo->clause_relids)) - { - /* This is our case */ - } - else continue; + /* Skip irrelevant JOIN case */ + if (!bms_equal(required_relids, restrInfo->required_relids)) + continue; if (IsA(restrInfo->clause, OpExpr)) { @@ -176,7 +180,6 @@ join_pathlist_hook(PlannerInfo *root, required_outer, &restrict_clauses); - /* DEBUG */ create_crossmatch_path(root, joinrel, outer_path, inner_path, param_info, restrict_clauses, required_outer); @@ -187,6 +190,7 @@ join_pathlist_hook(PlannerInfo *root, IsA(arg2, FuncExpr) && ((FuncExpr *) arg2)->funcid == dist_func) { + /* TODO: merge duplicate code */ Path *outer_path = crossmatch_find_cheapest_path(root, joinrel, outerrel); Path *inner_path = crossmatch_find_cheapest_path(root, joinrel, innerrel); @@ -200,14 +204,11 @@ join_pathlist_hook(PlannerInfo *root, required_outer, &restrict_clauses); - /* DEBUG */ create_crossmatch_path(root, joinrel, outer_path, inner_path, param_info, restrict_clauses, required_outer); } } } - - pprint(root->parse->rtable); } static Plan * @@ -241,7 +242,7 @@ create_crossmatch_plan(PlannerInfo *root, cscan->scan.plan.qual = NIL; cscan->scan.scanrelid = 0; - cscan->custom_scan_tlist = tlist; + cscan->custom_scan_tlist = tlist; /* TODO: recheck target list */ elog(LOG, "tlist:"); pprint(tlist); @@ -268,6 +269,7 @@ crossmatch_create_scan_state(CustomScan *node) return (Node *) scan_state; } +/* HACK: remove this */ static int i = 0; static void From 87b72e14709b87b646d1ee0616ac760c2807ddb5 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Mon, 29 Feb 2016 19:28:11 +0300 Subject: [PATCH 05/41] dummy projection --- init.c | 56 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/init.c b/init.c index 34e6597..555dff2 100644 --- a/init.c +++ b/init.c @@ -12,7 +12,10 @@ #include "funcapi.h" #include "access/htup_details.h" +#include "access/heapam.h" + #include "point.h" +#include "crossmatch.h" extern void _PG_init(void); @@ -37,6 +40,9 @@ typedef struct HeapTupleData scan_tuple; /* buffer to fetch tuple */ List *dev_tlist; /* tlist to be returned from the device */ List *dev_quals; /* quals to be run on the device */ + + Relation left; + Relation right; } CrossmatchScanState; static CustomPathMethods crossmatch_path_methods; @@ -91,6 +97,7 @@ create_crossmatch_path(PlannerInfo *root, result->cpath.path.parent = joinrel; result->cpath.path.param_info = param_info; result->cpath.path.pathkeys = NIL; + result->cpath.path.pathtarget = &joinrel->reltarget; result->cpath.path.rows = joinrel->rows; result->cpath.flags = 0; result->cpath.methods = &crossmatch_path_methods; @@ -221,7 +228,7 @@ create_crossmatch_plan(PlannerInfo *root, { CrossmatchJoinPath *gpath = (CrossmatchJoinPath *) best_path; List *joinrestrictclauses = gpath->joinrestrictinfo; - List *joinclauses; + List *joinclauses; /* NOTE: do we really need it? */ List *otherclauses; CustomScan *cscan; @@ -249,7 +256,6 @@ create_crossmatch_plan(PlannerInfo *root, cscan->flags = best_path->flags; cscan->methods = &crossmatch_plan_methods; - cscan->custom_plans = list_copy_tail(custom_plans, 1); return &cscan->scan.plan; } @@ -261,45 +267,57 @@ crossmatch_create_scan_state(CustomScan *node) NodeSetTag(scan_state, T_CustomScanState); scan_state->css.flags = node->flags; - if (node->methods == &crossmatch_plan_methods) - scan_state->css.methods = &crossmatch_exec_methods; - else - elog(ERROR, "Bug? unexpected CustomPlanMethods"); + scan_state->css.methods = &crossmatch_exec_methods; + + scan_state->css.ss.ps.ps_TupFromTlist = false; return (Node *) scan_state; } -/* HACK: remove this */ -static int i = 0; - static void crossmatch_begin(CustomScanState *node, EState *estate, int eflags) { - i = 0; + } static TupleTableSlot * crossmatch_exec(CustomScanState *node) { - TupleTableSlot *slot = node->ss.ss_ScanTupleSlot; - TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; + TupleTableSlot *slot = node->ss.ps.ps_ResultTupleSlot; + TupleDesc tupdesc = node->ss.ps.ps_ResultTupleSlot->tts_tupleDescriptor; + ExprContext *econtext = node->ss.ps.ps_ProjInfo->pi_exprContext; HeapTuple htup; + HeapTupleData fetched_tup; + + ResetExprContext(econtext); + /* TODO: fill with real data from joined tables */ - Datum values[2] = { DirectFunctionCall1(spherepoint_in, CStringGetDatum("(0d, 0d)")), + Datum values[4] = { DirectFunctionCall1(spherepoint_in, CStringGetDatum("(0d, 0d)")), DirectFunctionCall1(spherepoint_in, CStringGetDatum("(0d, 0d)")) }; - bool nulls[2] = {0, 0}; + bool nulls[4] = {0,1,1,1}; + + elog(LOG, "slot.natts: %d", tupdesc->natts); htup = heap_form_tuple(tupdesc, values, nulls); - elog(LOG, "natts: %d", tupdesc->natts); + if (node->ss.ps.ps_ProjInfo->pi_itemIsDone != ExprEndResult) + { + TupleTableSlot *result; + ExprDoneCond isDone; + + econtext->ecxt_scantuple = ExecStoreTuple(htup, slot, InvalidBuffer, false); - i++; + result = ExecProject(node->ss.ps.ps_ProjInfo, &isDone); - if (i > 10) - ExecClearTuple(slot); + if (isDone != ExprEndResult) + { + node->ss.ps.ps_TupFromTlist = (isDone == ExprMultipleResult); + return result; + } + } else - ExecStoreTuple(htup, slot, InvalidBuffer, false); + ExecClearTuple(slot); return slot; } From 9c2fcd057a6816d8234f9a1a0876649ec5b6cffd Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 1 Mar 2016 18:01:34 +0300 Subject: [PATCH 06/41] still broken, although projection works --- init.c | 80 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/init.c b/init.c index 555dff2..70babf3 100644 --- a/init.c +++ b/init.c @@ -5,7 +5,9 @@ #include "utils/builtins.h" #include "utils/elog.h" #include "utils/lsyscache.h" + #include "nodes/print.h" + #include "catalog/pg_proc.h" #include "catalog/pg_operator.h" #include "commands/explain.h" @@ -37,12 +39,15 @@ typedef struct { CustomScanState css; - HeapTupleData scan_tuple; /* buffer to fetch tuple */ - List *dev_tlist; /* tlist to be returned from the device */ - List *dev_quals; /* quals to be run on the device */ + List *scan_tlist; + + Relation outer_rel; + ItemPointer outer_ptr; + HeapTuple outer_tup; - Relation left; - Relation right; + Relation inner_rel; + ItemPointer inner_ptr; + HeapTuple inner_tup; } CrossmatchScanState; static CustomPathMethods crossmatch_path_methods; @@ -232,6 +237,12 @@ create_crossmatch_plan(PlannerInfo *root, List *otherclauses; CustomScan *cscan; + Index lrel = gpath->outer_path->parent->relid; + Index rrel = gpath->inner_path->parent->relid; + + /* relids should not be 0 */ + Assert(lrel != 0 && rrel != 0); + if (IS_OUTER_JOIN(gpath->jointype)) { extract_actual_join_clauses(joinrestrictclauses, @@ -246,17 +257,16 @@ create_crossmatch_plan(PlannerInfo *root, cscan = makeNode(CustomScan); cscan->scan.plan.targetlist = tlist; + cscan->custom_scan_tlist = tlist; /* output of this node */ cscan->scan.plan.qual = NIL; cscan->scan.scanrelid = 0; - cscan->custom_scan_tlist = tlist; /* TODO: recheck target list */ - - elog(LOG, "tlist:"); - pprint(tlist); - cscan->flags = best_path->flags; cscan->methods = &crossmatch_plan_methods; + cscan->custom_private = list_make2_oid(root->simple_rte_array[lrel]->relid, + root->simple_rte_array[rrel]->relid); + return &cscan->scan.plan; } @@ -271,6 +281,12 @@ crossmatch_create_scan_state(CustomScan *node) scan_state->css.ss.ps.ps_TupFromTlist = false; + scan_state->scan_tlist = node->custom_scan_tlist; + scan_state->outer_rel = heap_open(linitial_oid(node->custom_private), + AccessShareLock); + scan_state->inner_rel = heap_open(lsecond_oid(node->custom_private), + AccessShareLock); + return (Node *) scan_state; } @@ -283,49 +299,53 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags) static TupleTableSlot * crossmatch_exec(CustomScanState *node) { - TupleTableSlot *slot = node->ss.ps.ps_ResultTupleSlot; - TupleDesc tupdesc = node->ss.ps.ps_ResultTupleSlot->tts_tupleDescriptor; - ExprContext *econtext = node->ss.ps.ps_ProjInfo->pi_exprContext; + TupleTableSlot *slot = node->ss.ss_ScanTupleSlot; + TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; HeapTuple htup; - - HeapTupleData fetched_tup; - - ResetExprContext(econtext); + TupleTableSlot *result; /* TODO: fill with real data from joined tables */ - Datum values[4] = { DirectFunctionCall1(spherepoint_in, CStringGetDatum("(0d, 0d)")), + Datum values[2] = { DirectFunctionCall1(spherepoint_in, CStringGetDatum("(0d, 0d)")), DirectFunctionCall1(spherepoint_in, CStringGetDatum("(0d, 0d)")) }; - bool nulls[4] = {0,1,1,1}; + bool nulls[2] = {0,0}; elog(LOG, "slot.natts: %d", tupdesc->natts); htup = heap_form_tuple(tupdesc, values, nulls); - if (node->ss.ps.ps_ProjInfo->pi_itemIsDone != ExprEndResult) + if (node->ss.ps.ps_ProjInfo) { - TupleTableSlot *result; - ExprDoneCond isDone; + if (*(node->ss.ps.ps_ProjInfo->pi_itemIsDone) != ExprEndResult) + { + ExprDoneCond isDone; - econtext->ecxt_scantuple = ExecStoreTuple(htup, slot, InvalidBuffer, false); + node->ss.ps.ps_ProjInfo->pi_exprContext->ecxt_scantuple = ExecStoreTuple(htup, slot, InvalidBuffer, false); - result = ExecProject(node->ss.ps.ps_ProjInfo, &isDone); + result = ExecProject(node->ss.ps.ps_ProjInfo, &isDone); - if (isDone != ExprEndResult) - { - node->ss.ps.ps_TupFromTlist = (isDone == ExprMultipleResult); - return result; + if (isDone != ExprEndResult) + { + node->ss.ps.ps_TupFromTlist = (isDone == ExprMultipleResult); + } } + else + result = ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); } else - ExecClearTuple(slot); + { + result = ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); + } - return slot; + return result; } static void crossmatch_end(CustomScanState *node) { + CrossmatchScanState *scan_state = (CrossmatchScanState *) node; + heap_close(scan_state->outer_rel, AccessShareLock); + heap_close(scan_state->inner_rel, AccessShareLock); } static void From 723076ca7716e25bb243ada13f3b75e3a8462ee1 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 2 Mar 2016 03:19:48 +0300 Subject: [PATCH 07/41] refactoring, +pick_suitable_index() --- init.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 106 insertions(+), 19 deletions(-) diff --git a/init.c b/init.c index 70babf3..6bdd34e 100644 --- a/init.c +++ b/init.c @@ -5,9 +5,12 @@ #include "utils/builtins.h" #include "utils/elog.h" #include "utils/lsyscache.h" +#include "utils/rel.h" +#include "utils/fmgroids.h" #include "nodes/print.h" +#include "catalog/pg_am.h" #include "catalog/pg_proc.h" #include "catalog/pg_operator.h" #include "commands/explain.h" @@ -30,7 +33,12 @@ typedef struct JoinType jointype; Path *outer_path; + Oid outer_idx; + Oid outer_rel; + Path *inner_path; + Oid inner_idx; + Oid inner_rel; List *joinrestrictinfo; } CrossmatchJoinPath; @@ -41,11 +49,13 @@ typedef struct List *scan_tlist; - Relation outer_rel; + Oid outer_idx; + Oid outer_rel; ItemPointer outer_ptr; HeapTuple outer_tup; - Relation inner_rel; + Oid inner_idx; + Oid inner_rel; ItemPointer inner_ptr; HeapTuple inner_tup; } CrossmatchScanState; @@ -55,6 +65,71 @@ static CustomScanMethods crossmatch_plan_methods; static CustomExecMethods crossmatch_exec_methods; +/* + * TODO: check for the predicates & decide + * whether some partial indices may suffice + */ +static Oid +pick_suitable_index(Oid relation, AttrNumber column) +{ + Oid found_index = InvalidOid; + int64 found_index_size = 0; + HeapTuple htup; + SysScanDesc scan; + Relation pg_index; + ScanKeyData key[3]; + + ScanKeyInit(&key[0], + Anum_pg_index_indrelid, + BTEqualStrategyNumber, + F_OIDEQ, + ObjectIdGetDatum(relation)); + + pg_index = heap_open(IndexRelationId, AccessShareLock); + scan = systable_beginscan(pg_index, InvalidOid, false, NULL, 1, key); + + while (HeapTupleIsValid(htup = systable_getnext(scan))) + { + Form_pg_index pg_ind = (Form_pg_index) GETSTRUCT(htup); + Relation index; + Oid index_am; + + index = index_open(pg_ind->indexrelid, AccessShareLock); + index_am = index->rd_rel->relam; + index_close(index, AccessShareLock); + + /* check if this is a valid GIST index with no predicates */ + if (index_am == GIST_AM_OID && pg_ind->indisvalid && + heap_attisnull(htup, Anum_pg_index_indpred)) + { + int i; + + for (i = 0; i < pg_ind->indkey.dim1; i++) + { + int64 cur_index_size = 0; + + if (pg_ind->indkey.values[i] == column) + { + cur_index_size = DatumGetInt64( + DirectFunctionCall2(pg_relation_size, + ObjectIdGetDatum(relation), + PointerGetDatum(cstring_to_text("main")))); + + if (found_index == InvalidOid || cur_index_size < found_index_size) + found_index = pg_ind->indexrelid; + + break; /* no need to go further */ + } + } + } + } + + systable_endscan(scan); + heap_close(pg_index, AccessShareLock); + + return found_index; +} + static Path * crossmatch_find_cheapest_path(PlannerInfo *root, RelOptInfo *joinrel, @@ -95,6 +170,18 @@ create_crossmatch_path(PlannerInfo *root, { CrossmatchJoinPath *result; + Oid outer_rel = root->simple_rte_array[outer_path->parent->relid]->relid; + Oid inner_rel = root->simple_rte_array[inner_path->parent->relid]->relid; + Oid outer_idx; + Oid inner_idx; + + /* TODO: use actual column numbers */ + if ((outer_idx = pick_suitable_index(outer_rel, 1)) == InvalidOid || + (inner_idx = pick_suitable_index(inner_rel, 1)) == InvalidOid) + { + return; + } + result = palloc0(sizeof(CrossmatchJoinPath)); NodeSetTag(result, T_CustomPath); @@ -107,11 +194,15 @@ create_crossmatch_path(PlannerInfo *root, result->cpath.flags = 0; result->cpath.methods = &crossmatch_path_methods; result->outer_path = outer_path; + result->outer_idx = outer_idx; + result->outer_rel = outer_rel; result->inner_path = inner_path; + result->inner_idx = inner_idx; + result->inner_rel = inner_rel; result->joinrestrictinfo = restrict_clauses; /* TODO: real costs */ - result->cpath.path.startup_cost = 1; + result->cpath.path.startup_cost = 0; result->cpath.path.total_cost = 1; add_path(joinrel, &result->cpath.path); @@ -237,12 +328,6 @@ create_crossmatch_plan(PlannerInfo *root, List *otherclauses; CustomScan *cscan; - Index lrel = gpath->outer_path->parent->relid; - Index rrel = gpath->inner_path->parent->relid; - - /* relids should not be 0 */ - Assert(lrel != 0 && rrel != 0); - if (IS_OUTER_JOIN(gpath->jointype)) { extract_actual_join_clauses(joinrestrictclauses, @@ -264,8 +349,10 @@ create_crossmatch_plan(PlannerInfo *root, cscan->flags = best_path->flags; cscan->methods = &crossmatch_plan_methods; - cscan->custom_private = list_make2_oid(root->simple_rte_array[lrel]->relid, - root->simple_rte_array[rrel]->relid); + cscan->custom_private = list_make4_oid(gpath->outer_idx, + gpath->outer_rel, + gpath->inner_idx, + gpath->inner_rel); return &cscan->scan.plan; } @@ -279,13 +366,15 @@ crossmatch_create_scan_state(CustomScan *node) scan_state->css.flags = node->flags; scan_state->css.methods = &crossmatch_exec_methods; + /* TODO: check if this assignment is redundant */ scan_state->css.ss.ps.ps_TupFromTlist = false; scan_state->scan_tlist = node->custom_scan_tlist; - scan_state->outer_rel = heap_open(linitial_oid(node->custom_private), - AccessShareLock); - scan_state->inner_rel = heap_open(lsecond_oid(node->custom_private), - AccessShareLock); + + scan_state->outer_idx = linitial_oid(node->custom_private); + scan_state->outer_rel = lsecond_oid(node->custom_private); + scan_state->inner_idx = lthird_oid(node->custom_private); + scan_state->outer_rel = lfourth_oid(node->custom_private); return (Node *) scan_state; } @@ -306,7 +395,7 @@ crossmatch_exec(CustomScanState *node) /* TODO: fill with real data from joined tables */ Datum values[2] = { DirectFunctionCall1(spherepoint_in, CStringGetDatum("(0d, 0d)")), - DirectFunctionCall1(spherepoint_in, CStringGetDatum("(0d, 0d)")) }; + DirectFunctionCall1(spherepoint_in, CStringGetDatum("(1d, 1d)")) }; bool nulls[2] = {0,0}; elog(LOG, "slot.natts: %d", tupdesc->natts); @@ -319,6 +408,7 @@ crossmatch_exec(CustomScanState *node) { ExprDoneCond isDone; + /* TODO: find a better way to fill 'ecxt_scantuple' */ node->ss.ps.ps_ProjInfo->pi_exprContext->ecxt_scantuple = ExecStoreTuple(htup, slot, InvalidBuffer, false); result = ExecProject(node->ss.ps.ps_ProjInfo, &isDone); @@ -342,10 +432,7 @@ crossmatch_exec(CustomScanState *node) static void crossmatch_end(CustomScanState *node) { - CrossmatchScanState *scan_state = (CrossmatchScanState *) node; - heap_close(scan_state->outer_rel, AccessShareLock); - heap_close(scan_state->inner_rel, AccessShareLock); } static void From ea935758fb135f769903342c3b6c27d515ac5fd2 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 2 Mar 2016 06:15:10 +0300 Subject: [PATCH 08/41] experimental changes to crossmatch() function, projection is broken --- crossmatch.c | 176 +++++---------------------------------------------- crossmatch.h | 24 ++++++- init.c | 67 ++++++++++++++++---- 3 files changed, 96 insertions(+), 171 deletions(-) diff --git a/crossmatch.c b/crossmatch.c index 85858bd..ca86957 100644 --- a/crossmatch.c +++ b/crossmatch.c @@ -67,21 +67,6 @@ typedef struct iptr2; } ResultPair; -/* - * Context of crossmatch: represents data which are persistent across SRF calls. - */ -typedef struct -{ - MemoryContext context; - Relation indexes[2]; - List *pendingPairs; - List *resultsPairs; - float8 pointThreshold; - int box3dThreshold; - SBOX *box; - int32 boxkey[6]; -} CrossmatchContext; - /* * Point information for line sweep algorithm. */ @@ -101,28 +86,6 @@ typedef struct GistNSN parentlsn; } Box3DInfo; -PG_FUNCTION_INFO_V1(crossmatch); - -/* - * Check if relation is index and has specified am oid. Trigger error if not - */ -static Relation -checkOpenedRelation(Relation r, Oid PgAmOid) -{ -#if PG_VERSION_NUM >= 90600 - if (r->rd_amroutine == NULL) -#else - if (r->rd_am == NULL) -#endif - elog(ERROR, "Relation %s.%s is not an index", - get_namespace_name(RelationGetNamespace(r)), - RelationGetRelationName(r)); - if (r->rd_rel->relam != PgAmOid) - elog(ERROR, "Index %s.%s has wrong type", - get_namespace_name(RelationGetNamespace(r)), - RelationGetRelationName(r)); - return r; -} /* * Add pending pages pair to context. @@ -132,10 +95,6 @@ addPendingPair(CrossmatchContext *ctx, BlockNumber blk1, BlockNumber blk2, GistNSN parentlsn1, GistNSN parentlsn2) { PendingPair *blockNumberPair; - MemoryContext oldcontext; - - /* Switch to persistent memory context */ - oldcontext = MemoryContextSwitchTo(ctx->context); /* Add pending pair */ blockNumberPair = (PendingPair *) palloc(sizeof(PendingPair)); @@ -144,9 +103,6 @@ addPendingPair(CrossmatchContext *ctx, BlockNumber blk1, BlockNumber blk2, blockNumberPair->parentlsn1 = parentlsn1; blockNumberPair->parentlsn2 = parentlsn2; ctx->pendingPairs = lcons(blockNumberPair, ctx->pendingPairs); - - /* Return old memory context */ - MemoryContextSwitchTo(oldcontext); } /* @@ -156,10 +112,6 @@ static void addResultPair(CrossmatchContext *ctx, ItemPointer iptr1, ItemPointer iptr2) { ResultPair *itemPointerPair; - MemoryContext oldcontext; - - /* Switch to persistent memory context */ - oldcontext = MemoryContextSwitchTo(ctx->context); /* Add result pair */ itemPointerPair = (ResultPair *) @@ -167,24 +119,6 @@ addResultPair(CrossmatchContext *ctx, ItemPointer iptr1, ItemPointer iptr2) itemPointerPair->iptr1 = *iptr1; itemPointerPair->iptr2 = *iptr2; ctx->resultsPairs = lappend(ctx->resultsPairs, itemPointerPair); - - /* Return old memory context */ - MemoryContextSwitchTo(oldcontext); -} - -/* - * Open index relation with AccessShareLock. - */ -static Relation -indexOpen(RangeVar *relvar) -{ -#if PG_VERSION_NUM < 90200 - Oid relOid = RangeVarGetRelid(relvar, false); -#else - Oid relOid = RangeVarGetRelid(relvar, NoLock, false); -#endif - return checkOpenedRelation( - index_open(relOid, AccessShareLock), GIST_AM_OID); } /* @@ -199,41 +133,21 @@ indexClose(Relation r) /* * Do necessary initialization for first SRF call. */ -static void -setupFirstcall(FuncCallContext *funcctx, text *names[2], - float8 threshold, SBOX *box) +void +setupFirstcall(CrossmatchContext *ctx, Oid idx1, Oid idx2, + float8 threshold) { - MemoryContext oldcontext; - CrossmatchContext *ctx; - TupleDesc tupdesc; GistNSN parentnsn = InvalidNSN; - int i; - /* Switch to persistent memory context */ - oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + ctx->box = NULL; + + Assert(idx1 != idx2); + + ctx->indexes[0] = index_open(idx1, AccessShareLock); + ctx->indexes[1] = index_open(idx2, AccessShareLock); - /* Allocate crossmarch context and fill it with scan parameters */ - ctx = (CrossmatchContext *) palloc0(sizeof(CrossmatchContext)); - ctx->context = funcctx->multi_call_memory_ctx; - ctx->box = box; - if (box) - spherebox_gen_key(ctx->boxkey, box); ctx->pointThreshold = 2.0 * sin(0.5 * threshold); ctx->box3dThreshold = MAXCVALUE * ctx->pointThreshold; - funcctx->user_fctx = (void *) ctx; - - /* Open both indexes */ - for (i = 0; i < 2; i++) - { - char *relname = text_to_cstring(names[i]); - List *relname_list; - RangeVar *relvar; - - relname_list = stringToQualifiedNameList(relname); - relvar = makeRangeVarFromNameList(relname_list); - ctx->indexes[i] = indexOpen(relvar); - pfree(relname); - } /* * Add first pending pair of pages: we start scan both indexes from their @@ -241,27 +155,10 @@ setupFirstcall(FuncCallContext *funcctx, text *names[2], */ addPendingPair(ctx, GIST_ROOT_BLKNO, GIST_ROOT_BLKNO, parentnsn, parentnsn); - - /* Describe structure of resulting tuples */ - tupdesc = CreateTemplateTupleDesc(2, false); - TupleDescInitEntry(tupdesc, 1, "ctid1", TIDOID, -1, 0); - TupleDescInitEntry(tupdesc, 2, "ctid2", TIDOID, -1, 0); - funcctx->slot = TupleDescGetSlot(tupdesc); - funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc); - - /* Return old memory context */ - MemoryContextSwitchTo(oldcontext); } -/* - * Close SRF call: free occupied resources. - */ -static void -closeCall(FuncCallContext *funcctx) +void endCall(CrossmatchContext *ctx) { - CrossmatchContext *ctx = (CrossmatchContext *) (funcctx->user_fctx); - - /* Close indexes */ indexClose(ctx->indexes[0]); indexClose(ctx->indexes[1]); } @@ -969,39 +866,9 @@ processPendingPair(CrossmatchContext *ctx, BlockNumber blk1, BlockNumber blk2, /* * Crossmatch SRF */ -Datum -crossmatch(PG_FUNCTION_ARGS) +void +crossmatch(CrossmatchContext *ctx, ItemPointer values) { - FuncCallContext *funcctx; - CrossmatchContext *ctx; - - /* - * Initialize crossmatch context if first call of SRF. - */ - if (SRF_IS_FIRSTCALL()) - { - SBOX *box; - text *names[2]; - float8 threshold = PG_GETARG_FLOAT8(2); - - names[0] = PG_GETARG_TEXT_P(0); - names[1] = PG_GETARG_TEXT_P(1); - funcctx = SRF_FIRSTCALL_INIT(); - - /* Assume no restriction on first dataset if less than 3 args */ - if (PG_NARGS() < 4) - box = NULL; - else - box = (SBOX *) PG_GETARG_POINTER(3); - - setupFirstcall(funcctx, names, threshold, box); - PG_FREE_IF_COPY(names[0], 0); - PG_FREE_IF_COPY(names[1], 0); - } - - funcctx = SRF_PERCALL_SETUP(); - ctx = (CrossmatchContext *) funcctx->user_fctx; - /* Scan pending pairs until we have some result pairs */ while (ctx->resultsPairs == NIL && ctx->pendingPairs != NIL) { @@ -1018,27 +885,18 @@ crossmatch(PG_FUNCTION_ARGS) /* Return next result pair if any. Otherwise close SRF. */ if (ctx->resultsPairs != NIL) { - Datum datums[2], - result; - bool nulls[2]; ResultPair *itemPointerPair = (ResultPair *) palloc(sizeof(ResultPair)); - HeapTuple htuple; *itemPointerPair = *((ResultPair *) linitial(ctx->resultsPairs)); pfree(linitial(ctx->resultsPairs)); ctx->resultsPairs = list_delete_first(ctx->resultsPairs); - datums[0] = PointerGetDatum(&itemPointerPair->iptr1); - datums[1] = PointerGetDatum(&itemPointerPair->iptr2); - nulls[0] = false; - nulls[1] = false; - - htuple = heap_formtuple(funcctx->attinmeta->tupdesc, datums, nulls); - result = TupleGetDatum(funcctx->slot, htuple); - SRF_RETURN_NEXT(funcctx, result); + + values[0] = itemPointerPair->iptr1; + values[1] = itemPointerPair->iptr2; } else { - closeCall(funcctx); - SRF_RETURN_DONE(funcctx); + ItemPointerSetInvalid(&values[0]); + ItemPointerSetInvalid(&values[1]); } } diff --git a/crossmatch.h b/crossmatch.h index 5d46c5a..5ba4f6f 100644 --- a/crossmatch.h +++ b/crossmatch.h @@ -2,6 +2,7 @@ #define __PGS_CROSSMATCH_H_ #include "types.h" +#include "funcapi.h" #if PG_VERSION_NUM >= 90300 #define GIST_SCAN_FOLLOW_RIGHT(parentlsn,page) \ @@ -19,7 +20,28 @@ #define InvalidNSN {0, 0} #endif +/* + * Context of crossmatch: represents data which are persistent across SRF calls. + */ +typedef struct +{ + Relation indexes[2]; + List *pendingPairs; + List *resultsPairs; + float8 pointThreshold; + int box3dThreshold; + SBOX *box; + int32 boxkey[6]; -Datum crossmatch(PG_FUNCTION_ARGS); + TupleTableSlot *slot; + AttInMetadata *attinmeta; +} CrossmatchContext; + +void setupFirstcall(CrossmatchContext *ctx, Oid idx1, Oid idx2, + float8 threshold); + +void endCall(CrossmatchContext *ctx); + +void crossmatch(CrossmatchContext *ctx, ItemPointer values); #endif /* __PGS_CROSSMATCH_H_ */ diff --git a/init.c b/init.c index 6bdd34e..32a9db2 100644 --- a/init.c +++ b/init.c @@ -2,11 +2,13 @@ #include "optimizer/paths.h" #include "optimizer/pathnode.h" #include "optimizer/restrictinfo.h" +#include "utils/tqual.h" #include "utils/builtins.h" #include "utils/elog.h" #include "utils/lsyscache.h" #include "utils/rel.h" #include "utils/fmgroids.h" +#include "storage/bufmgr.h" #include "nodes/print.h" @@ -47,17 +49,23 @@ typedef struct { CustomScanState css; + HeapTuple stored_tuple; + List *scan_tlist; Oid outer_idx; Oid outer_rel; ItemPointer outer_ptr; HeapTuple outer_tup; + Relation outer; Oid inner_idx; Oid inner_rel; ItemPointer inner_ptr; HeapTuple inner_tup; + Relation inner; + + CrossmatchContext *ctx; } CrossmatchScanState; static CustomPathMethods crossmatch_path_methods; @@ -374,7 +382,7 @@ crossmatch_create_scan_state(CustomScan *node) scan_state->outer_idx = linitial_oid(node->custom_private); scan_state->outer_rel = lsecond_oid(node->custom_private); scan_state->inner_idx = lthird_oid(node->custom_private); - scan_state->outer_rel = lfourth_oid(node->custom_private); + scan_state->inner_rel = lfourth_oid(node->custom_private); return (Node *) scan_state; } @@ -382,25 +390,59 @@ crossmatch_create_scan_state(CustomScan *node) static void crossmatch_begin(CustomScanState *node, EState *estate, int eflags) { + CrossmatchScanState *scan_state = (CrossmatchScanState *) node; + CrossmatchContext *ctx = (CrossmatchContext *) palloc0(sizeof(CrossmatchContext)); + scan_state->ctx = ctx; + setupFirstcall(ctx, scan_state->outer_idx, scan_state->inner_idx, 1); + + scan_state->outer = heap_open(scan_state->outer_rel, AccessShareLock); + scan_state->inner = heap_open(scan_state->inner_rel, AccessShareLock); } static TupleTableSlot * crossmatch_exec(CustomScanState *node) { + CrossmatchScanState *scan_state = (CrossmatchScanState *) node; TupleTableSlot *slot = node->ss.ss_ScanTupleSlot; TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; - HeapTuple htup; + HeapTuple htup = scan_state->stored_tuple; + TupleTableSlot *result; - /* TODO: fill with real data from joined tables */ - Datum values[2] = { DirectFunctionCall1(spherepoint_in, CStringGetDatum("(0d, 0d)")), - DirectFunctionCall1(spherepoint_in, CStringGetDatum("(1d, 1d)")) }; - bool nulls[2] = {0,0}; + if (!node->ss.ps.ps_TupFromTlist) + { + Datum values[2]; + bool nulls[2] = { 0 }; + + ItemPointerData p_tids[2] = { 0 }; + HeapTupleData htup1; + HeapTupleData htup2; + Buffer buf1; + Buffer buf2; + + crossmatch(scan_state->ctx, p_tids); + + if (!ItemPointerIsValid(&p_tids[0]) || !ItemPointerIsValid(&p_tids[1])) + { + result = ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); + return result; + } + + htup1.t_self = p_tids[0]; + heap_fetch(scan_state->outer, SnapshotSelf, &htup1, &buf1, false, NULL); + values[0] = heap_getattr(&htup1, 1, scan_state->outer->rd_att, &nulls[0]); - elog(LOG, "slot.natts: %d", tupdesc->natts); + htup2.t_self = p_tids[1]; + heap_fetch(scan_state->inner, SnapshotSelf, &htup2, &buf2, false, NULL); + values[1] = heap_getattr(&htup2, 1, scan_state->inner->rd_att, &nulls[1]); - htup = heap_form_tuple(tupdesc, values, nulls); + ReleaseBuffer(buf1); + ReleaseBuffer(buf2); + + htup = heap_form_tuple(tupdesc, values, nulls); + scan_state->stored_tuple = htup; + } if (node->ss.ps.ps_ProjInfo) { @@ -418,12 +460,10 @@ crossmatch_exec(CustomScanState *node) node->ss.ps.ps_TupFromTlist = (isDone == ExprMultipleResult); } } - else - result = ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); } else { - result = ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); + result = ExecStoreTuple(htup, node->ss.ps.ps_ResultTupleSlot, InvalidBuffer, false); } return result; @@ -432,7 +472,12 @@ crossmatch_exec(CustomScanState *node) static void crossmatch_end(CustomScanState *node) { + CrossmatchScanState *scan_state = (CrossmatchScanState *) node; + + heap_close(scan_state->outer, AccessShareLock); + heap_close(scan_state->inner, AccessShareLock); + endCall(scan_state->ctx); } static void From 6ab0ff8847c9ab8d9f1669b3eea252d4f270fbc8 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 2 Mar 2016 14:24:00 +0300 Subject: [PATCH 09/41] enable threshold --- init.c | 55 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/init.c b/init.c index 32a9db2..fd5986e 100644 --- a/init.c +++ b/init.c @@ -16,6 +16,7 @@ #include "catalog/pg_proc.h" #include "catalog/pg_operator.h" #include "commands/explain.h" +#include "commands/defrem.h" #include "funcapi.h" #include "access/htup_details.h" @@ -43,6 +44,8 @@ typedef struct Oid inner_rel; List *joinrestrictinfo; + + float8 threshold; } CrossmatchJoinPath; typedef struct @@ -65,6 +68,8 @@ typedef struct HeapTuple inner_tup; Relation inner; + float8 threshold; + CrossmatchContext *ctx; } CrossmatchScanState; @@ -73,6 +78,23 @@ static CustomScanMethods crossmatch_plan_methods; static CustomExecMethods crossmatch_exec_methods; +static float8 +get_const_val(Const *node) +{ + FmgrInfo finfo; + Oid cast; + + Assert(IsA(node, Const)); + + if (node->consttype == FLOAT8OID) + return DatumGetFloat8(node->constvalue); + + cast = get_cast_oid(node->consttype, FLOAT8OID, false); + fmgr_info(cast, &finfo); + + return DatumGetFloat8(FunctionCall1(&finfo, node->constvalue)); +} + /* * TODO: check for the predicates & decide * whether some partial indices may suffice @@ -174,7 +196,8 @@ create_crossmatch_path(PlannerInfo *root, Path *inner_path, ParamPathInfo *param_info, List *restrict_clauses, - Relids required_outer) + Relids required_outer, + float8 threshold) { CrossmatchJoinPath *result; @@ -207,6 +230,7 @@ create_crossmatch_path(PlannerInfo *root, result->inner_path = inner_path; result->inner_idx = inner_idx; result->inner_rel = inner_rel; + result->threshold = threshold; result->joinrestrictinfo = restrict_clauses; /* TODO: real costs */ @@ -292,7 +316,8 @@ join_pathlist_hook(PlannerInfo *root, &restrict_clauses); create_crossmatch_path(root, joinrel, outer_path, inner_path, - param_info, restrict_clauses, required_outer); + param_info, restrict_clauses, required_outer, + get_const_val((Const *) arg2)); break; } @@ -316,7 +341,8 @@ join_pathlist_hook(PlannerInfo *root, &restrict_clauses); create_crossmatch_path(root, joinrel, outer_path, inner_path, - param_info, restrict_clauses, required_outer); + param_info, restrict_clauses, required_outer, + get_const_val((Const *) arg1)); } } } @@ -335,6 +361,7 @@ create_crossmatch_plan(PlannerInfo *root, List *joinclauses; /* NOTE: do we really need it? */ List *otherclauses; CustomScan *cscan; + float8 *threshold = palloc(sizeof(float8)); if (IS_OUTER_JOIN(gpath->jointype)) { @@ -357,10 +384,12 @@ create_crossmatch_plan(PlannerInfo *root, cscan->flags = best_path->flags; cscan->methods = &crossmatch_plan_methods; - cscan->custom_private = list_make4_oid(gpath->outer_idx, - gpath->outer_rel, - gpath->inner_idx, - gpath->inner_rel); + cscan->custom_private = list_make2(list_make4_oid(gpath->outer_idx, + gpath->outer_rel, + gpath->inner_idx, + gpath->inner_rel), + list_make1(threshold)); + *threshold = gpath->threshold; return &cscan->scan.plan; } @@ -379,10 +408,11 @@ crossmatch_create_scan_state(CustomScan *node) scan_state->scan_tlist = node->custom_scan_tlist; - scan_state->outer_idx = linitial_oid(node->custom_private); - scan_state->outer_rel = lsecond_oid(node->custom_private); - scan_state->inner_idx = lthird_oid(node->custom_private); - scan_state->inner_rel = lfourth_oid(node->custom_private); + scan_state->outer_idx = linitial_oid(linitial(node->custom_private)); + scan_state->outer_rel = lsecond_oid(linitial(node->custom_private)); + scan_state->inner_idx = lthird_oid(linitial(node->custom_private)); + scan_state->inner_rel = lfourth_oid(linitial(node->custom_private)); + scan_state->threshold = *(float8 *) linitial(lsecond(node->custom_private)); return (Node *) scan_state; } @@ -394,7 +424,8 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags) CrossmatchContext *ctx = (CrossmatchContext *) palloc0(sizeof(CrossmatchContext)); scan_state->ctx = ctx; - setupFirstcall(ctx, scan_state->outer_idx, scan_state->inner_idx, 1); + setupFirstcall(ctx, scan_state->outer_idx, + scan_state->inner_idx, scan_state->threshold); scan_state->outer = heap_open(scan_state->outer_rel, AccessShareLock); scan_state->inner = heap_open(scan_state->inner_rel, AccessShareLock); From ac23cbaf7a84d58d585e03aaef64f14db08755ee Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 2 Mar 2016 17:06:13 +0300 Subject: [PATCH 10/41] limit threshold using PI --- crossmatch.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crossmatch.c b/crossmatch.c index ca86957..95de4f6 100644 --- a/crossmatch.c +++ b/crossmatch.c @@ -47,6 +47,10 @@ #define heap_formtuple heap_form_tuple #endif +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + /* * Pair of pages for pending scan. */ @@ -146,7 +150,7 @@ setupFirstcall(CrossmatchContext *ctx, Oid idx1, Oid idx2, ctx->indexes[0] = index_open(idx1, AccessShareLock); ctx->indexes[1] = index_open(idx2, AccessShareLock); - ctx->pointThreshold = 2.0 * sin(0.5 * threshold); + ctx->pointThreshold = 2.0 * sin(0.5 * (threshold > M_PI ? M_PI : threshold)); ctx->box3dThreshold = MAXCVALUE * ctx->pointThreshold; /* From 65145e61cf3a65f4a5b9597c36c91ebf12a1b482 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 2 Mar 2016 17:09:05 +0300 Subject: [PATCH 11/41] remove public SQL definition of crossmatch() function --- Makefile | 2 +- crossmatch.c | 10 ---------- pgs_crossmatch.sql.in | 18 ------------------ 3 files changed, 1 insertion(+), 29 deletions(-) delete mode 100644 pgs_crossmatch.sql.in diff --git a/Makefile b/Makefile index b2b7985..e310e89 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ CRUSH_TESTS = init_extended circle_extended PGS_SQL = pgs_types.sql pgs_point.sql pgs_euler.sql pgs_circle.sql \ pgs_line.sql pgs_ellipse.sql pgs_polygon.sql pgs_path.sql \ pgs_box.sql pgs_contains_ops.sql pgs_contains_ops_compat.sql \ - pgs_gist.sql pgs_crossmatch.sql gnomo.sql \ + pgs_gist.sql gnomo.sql \ ifdef USE_PGXS ifndef PG_CONFIG diff --git a/crossmatch.c b/crossmatch.c index 95de4f6..1dca37a 100644 --- a/crossmatch.c +++ b/crossmatch.c @@ -12,16 +12,6 @@ * tuples in page is significant simple variation of line sweep algorithm is * used to compare index tuples inside pages. * - * There are two versions of crossmatch function: - * - crossmatch(text, text, float8) - * - crossmatch(text, text, float8, sbox) - * First two argument is names of GiST indexes of spoint2 opclass. - * Third argument is threshold for crossmatch. - * Forth optional argument is filter for tuples of first index. If this - * argument gived then in first index only spoints inside given sbox will be - * considered. Useful for parallel processing. - * The result is set of tid pairs which points to matching heap tuples. - * * Author: Alexander Korotkov *---------------------------------------------------------------------------- */ diff --git a/pgs_crossmatch.sql.in b/pgs_crossmatch.sql.in deleted file mode 100644 index baf9f9f..0000000 --- a/pgs_crossmatch.sql.in +++ /dev/null @@ -1,18 +0,0 @@ --- **************************** --- --- crossmatch --- --- **************************** - -CREATE FUNCTION crossmatch(text, text, float8) - RETURNS SETOF record - AS 'MODULE_PATHNAME', 'crossmatch' - LANGUAGE 'c' - STABLE STRICT; - -CREATE FUNCTION crossmatch(text, text, float8, sbox) - RETURNS SETOF record - AS 'MODULE_PATHNAME', 'crossmatch' - LANGUAGE 'c' - STABLE STRICT; - \ No newline at end of file From 19da69a0e421c8dd9b92be75fd78c1899c2a282b Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 2 Mar 2016 20:05:03 +0300 Subject: [PATCH 12/41] check whether index column opclass is spoint2 --- init.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/init.c b/init.c index fd5986e..262d326 100644 --- a/init.c +++ b/init.c @@ -107,8 +107,13 @@ pick_suitable_index(Oid relation, AttrNumber column) HeapTuple htup; SysScanDesc scan; Relation pg_index; + List *spoint2_opclass_name; + Oid spoint2_opclass; ScanKeyData key[3]; + spoint2_opclass_name = stringToQualifiedNameList("public.spoint2"); + spoint2_opclass = get_opclass_oid(GIST_AM_OID, spoint2_opclass_name, false); + ScanKeyInit(&key[0], Anum_pg_index_indrelid, BTEqualStrategyNumber, @@ -146,9 +151,18 @@ pick_suitable_index(Oid relation, AttrNumber column) PointerGetDatum(cstring_to_text("main")))); if (found_index == InvalidOid || cur_index_size < found_index_size) - found_index = pg_ind->indexrelid; - - break; /* no need to go further */ + { + bool is_null; + Datum indclass = heap_getattr(htup, Anum_pg_index_indclass, + pg_index->rd_att, &is_null); + oidvector *indclasses = (oidvector *) DatumGetPointer(indclass); + + /* column must use 'spoint2' opclass */ + if (!is_null && indclasses->values[i] == spoint2_opclass) + found_index = pg_ind->indexrelid; + } + + break; /* no need to scan 'indkey' further */ } } } From f56c12c236c16b54837f829f301e18c26977a4ee Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 2 Mar 2016 20:26:56 +0300 Subject: [PATCH 13/41] add index names to explain output --- init.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/init.c b/init.c index 262d326..3e4772d 100644 --- a/init.c +++ b/init.c @@ -434,8 +434,8 @@ crossmatch_create_scan_state(CustomScan *node) static void crossmatch_begin(CustomScanState *node, EState *estate, int eflags) { - CrossmatchScanState *scan_state = (CrossmatchScanState *) node; - CrossmatchContext *ctx = (CrossmatchContext *) palloc0(sizeof(CrossmatchContext)); + CrossmatchScanState *scan_state = (CrossmatchScanState *) node; + CrossmatchContext *ctx = (CrossmatchContext *) palloc0(sizeof(CrossmatchContext)); scan_state->ctx = ctx; setupFirstcall(ctx, scan_state->outer_idx, @@ -448,10 +448,10 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags) static TupleTableSlot * crossmatch_exec(CustomScanState *node) { - CrossmatchScanState *scan_state = (CrossmatchScanState *) node; - TupleTableSlot *slot = node->ss.ss_ScanTupleSlot; - TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; - HeapTuple htup = scan_state->stored_tuple; + CrossmatchScanState *scan_state = (CrossmatchScanState *) node; + TupleTableSlot *slot = node->ss.ss_ScanTupleSlot; + TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; + HeapTuple htup = scan_state->stored_tuple; TupleTableSlot *result; @@ -534,7 +534,20 @@ crossmatch_rescan(CustomScanState *node) static void crossmatch_explain(CustomScanState *node, List *ancestors, ExplainState *es) { + CrossmatchScanState *scan_state = (CrossmatchScanState *) node; + StringInfoData str; + + initStringInfo(&str); + appendStringInfo(&str, "%s", + get_rel_name(scan_state->outer_idx)); + ExplainPropertyText("Outer index", str.data, es); + + resetStringInfo(&str); + + appendStringInfo(&str, "%s", + get_rel_name(scan_state->inner_idx)); + ExplainPropertyText("Inner index", str.data, es); } void @@ -559,4 +572,4 @@ _PG_init(void) crossmatch_exec_methods.MarkPosCustomScan = NULL; crossmatch_exec_methods.RestrPosCustomScan = NULL; crossmatch_exec_methods.ExplainCustomScan = crossmatch_explain; -} \ No newline at end of file +} From 63479679320f565f5f44999de17d8289edfb9ced Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Thu, 3 Mar 2016 03:02:10 +0300 Subject: [PATCH 14/41] fixed projection loop --- init.c | 83 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/init.c b/init.c index 3e4772d..7bb2cce 100644 --- a/init.c +++ b/init.c @@ -8,10 +8,8 @@ #include "utils/lsyscache.h" #include "utils/rel.h" #include "utils/fmgroids.h" +#include "utils/memutils.h" #include "storage/bufmgr.h" - -#include "nodes/print.h" - #include "catalog/pg_am.h" #include "catalog/pg_proc.h" #include "catalog/pg_operator.h" @@ -52,6 +50,8 @@ typedef struct { CustomScanState css; + Datum *values; + bool *nulls; HeapTuple stored_tuple; List *scan_tlist; @@ -437,12 +437,18 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags) CrossmatchScanState *scan_state = (CrossmatchScanState *) node; CrossmatchContext *ctx = (CrossmatchContext *) palloc0(sizeof(CrossmatchContext)); + /* TODO: fix this kludge */ + int nlist = list_length(scan_state->scan_tlist) + 2; + scan_state->ctx = ctx; setupFirstcall(ctx, scan_state->outer_idx, scan_state->inner_idx, scan_state->threshold); scan_state->outer = heap_open(scan_state->outer_rel, AccessShareLock); scan_state->inner = heap_open(scan_state->inner_rel, AccessShareLock); + + scan_state->values = palloc(sizeof(Datum) * nlist); + scan_state->nulls = palloc(sizeof(bool) * nlist); } static TupleTableSlot * @@ -453,47 +459,47 @@ crossmatch_exec(CustomScanState *node) TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; HeapTuple htup = scan_state->stored_tuple; - TupleTableSlot *result; - - if (!node->ss.ps.ps_TupFromTlist) + for(;;) { - Datum values[2]; - bool nulls[2] = { 0 }; + if (!node->ss.ps.ps_TupFromTlist) + { + Datum *values = scan_state->values; + bool *nulls = scan_state->nulls; - ItemPointerData p_tids[2] = { 0 }; - HeapTupleData htup1; - HeapTupleData htup2; - Buffer buf1; - Buffer buf2; + ItemPointerData p_tids[2] = { 0 }; + HeapTupleData htup1; + HeapTupleData htup2; + Buffer buf1; + Buffer buf2; - crossmatch(scan_state->ctx, p_tids); + crossmatch(scan_state->ctx, p_tids); - if (!ItemPointerIsValid(&p_tids[0]) || !ItemPointerIsValid(&p_tids[1])) - { - result = ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); - return result; - } + if (!ItemPointerIsValid(&p_tids[0]) || !ItemPointerIsValid(&p_tids[1])) + { + return ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); + } - htup1.t_self = p_tids[0]; - heap_fetch(scan_state->outer, SnapshotSelf, &htup1, &buf1, false, NULL); - values[0] = heap_getattr(&htup1, 1, scan_state->outer->rd_att, &nulls[0]); + htup1.t_self = p_tids[0]; + heap_fetch(scan_state->outer, SnapshotSelf, &htup1, &buf1, false, NULL); + values[0] = heap_getattr(&htup1, 1, scan_state->outer->rd_att, &nulls[0]); - htup2.t_self = p_tids[1]; - heap_fetch(scan_state->inner, SnapshotSelf, &htup2, &buf2, false, NULL); - values[1] = heap_getattr(&htup2, 1, scan_state->inner->rd_att, &nulls[1]); + htup2.t_self = p_tids[1]; + heap_fetch(scan_state->inner, SnapshotSelf, &htup2, &buf2, false, NULL); + values[1] = heap_getattr(&htup2, 1, scan_state->inner->rd_att, &nulls[1]); - ReleaseBuffer(buf1); - ReleaseBuffer(buf2); + ReleaseBuffer(buf1); + ReleaseBuffer(buf2); - htup = heap_form_tuple(tupdesc, values, nulls); - scan_state->stored_tuple = htup; - } + htup = heap_form_tuple(tupdesc, values, nulls); + scan_state->stored_tuple = htup; + } - if (node->ss.ps.ps_ProjInfo) - { - if (*(node->ss.ps.ps_ProjInfo->pi_itemIsDone) != ExprEndResult) + if (node->ss.ps.ps_ProjInfo) { ExprDoneCond isDone; + TupleTableSlot *result; + + ResetExprContext(node->ss.ps.ps_ProjInfo->pi_exprContext); /* TODO: find a better way to fill 'ecxt_scantuple' */ node->ss.ps.ps_ProjInfo->pi_exprContext->ecxt_scantuple = ExecStoreTuple(htup, slot, InvalidBuffer, false); @@ -503,15 +509,14 @@ crossmatch_exec(CustomScanState *node) if (isDone != ExprEndResult) { node->ss.ps.ps_TupFromTlist = (isDone == ExprMultipleResult); + return result; } + else + node->ss.ps.ps_TupFromTlist = false; } + else + return ExecStoreTuple(htup, node->ss.ps.ps_ResultTupleSlot, InvalidBuffer, false); } - else - { - result = ExecStoreTuple(htup, node->ss.ps.ps_ResultTupleSlot, InvalidBuffer, false); - } - - return result; } static void From 73cc7ccf3d7700004b4ccf96764409b8c867ea63 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Thu, 3 Mar 2016 03:40:18 +0300 Subject: [PATCH 15/41] do not fetch heap tuples if it's not necessary --- init.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/init.c b/init.c index 7bb2cce..876a899 100644 --- a/init.c +++ b/init.c @@ -449,6 +449,15 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags) scan_state->values = palloc(sizeof(Datum) * nlist); scan_state->nulls = palloc(sizeof(bool) * nlist); + + /* Store blank tuple in case scan tlist is empty */ + if (scan_state->scan_tlist == NIL) + { + TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; + scan_state->stored_tuple = heap_form_tuple(tupdesc, NULL, NULL); + } + else + scan_state->stored_tuple = NULL; } static TupleTableSlot * @@ -456,7 +465,6 @@ crossmatch_exec(CustomScanState *node) { CrossmatchScanState *scan_state = (CrossmatchScanState *) node; TupleTableSlot *slot = node->ss.ss_ScanTupleSlot; - TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; HeapTuple htup = scan_state->stored_tuple; for(;;) @@ -479,19 +487,29 @@ crossmatch_exec(CustomScanState *node) return ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); } - htup1.t_self = p_tids[0]; - heap_fetch(scan_state->outer, SnapshotSelf, &htup1, &buf1, false, NULL); - values[0] = heap_getattr(&htup1, 1, scan_state->outer->rd_att, &nulls[0]); + /* We don't have to fetch tuples if scan tlist is empty */ + if (scan_state->scan_tlist != NIL) + { + TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; + + htup1.t_self = p_tids[0]; + heap_fetch(scan_state->outer, SnapshotSelf, + &htup1, &buf1, false, NULL); + values[0] = heap_getattr(&htup1, 1, scan_state->outer->rd_att, + &nulls[0]); - htup2.t_self = p_tids[1]; - heap_fetch(scan_state->inner, SnapshotSelf, &htup2, &buf2, false, NULL); - values[1] = heap_getattr(&htup2, 1, scan_state->inner->rd_att, &nulls[1]); + htup2.t_self = p_tids[1]; + heap_fetch(scan_state->inner, SnapshotSelf, + &htup2, &buf2, false, NULL); + values[1] = heap_getattr(&htup2, 1, scan_state->inner->rd_att, + &nulls[1]); - ReleaseBuffer(buf1); - ReleaseBuffer(buf2); + ReleaseBuffer(buf1); + ReleaseBuffer(buf2); - htup = heap_form_tuple(tupdesc, values, nulls); - scan_state->stored_tuple = htup; + htup = heap_form_tuple(tupdesc, values, nulls); + scan_state->stored_tuple = htup; + } } if (node->ss.ps.ps_ProjInfo) @@ -515,7 +533,8 @@ crossmatch_exec(CustomScanState *node) node->ss.ps.ps_TupFromTlist = false; } else - return ExecStoreTuple(htup, node->ss.ps.ps_ResultTupleSlot, InvalidBuffer, false); + return ExecStoreTuple(htup, node->ss.ps.ps_ResultTupleSlot, + InvalidBuffer, false); } } From 934e8d0b35699a93c4c6bbdb30f404f54578fc85 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Fri, 4 Mar 2016 17:36:58 +0300 Subject: [PATCH 16/41] new macro IsVarSpointDist, create_crossmatch_path() uses actual spoint attnums, fixed threshold save\restore --- init.c | 126 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 91 insertions(+), 35 deletions(-) diff --git a/init.c b/init.c index 876a899..421f836 100644 --- a/init.c +++ b/init.c @@ -78,6 +78,29 @@ static CustomScanMethods crossmatch_plan_methods; static CustomExecMethods crossmatch_exec_methods; +#define IsVarSpointDist(arg, dist_func_oid) \ + ( \ + IsA(arg, FuncExpr) && \ + ((FuncExpr *) (arg))->funcid == (dist_func_oid) && \ + IsA(linitial(((FuncExpr *) (arg))->args), Var) && \ + IsA(lsecond(((FuncExpr *) (arg))->args), Var) \ + ) + + +static float8 +cstring_to_float8(char *str) +{ + return DatumGetFloat8(DirectFunctionCall1(float8in, + CStringGetDatum(str))); +} + +static char * +float8_to_cstring(float8 val) +{ + return DatumGetCString(DirectFunctionCall1(float8out, + Float8GetDatum(val))); +} + static float8 get_const_val(Const *node) { @@ -174,6 +197,26 @@ pick_suitable_index(Oid relation, AttrNumber column) return found_index; } +static void +get_spoint_attnums(FuncExpr *fexpr, RelOptInfo *outer, RelOptInfo *inner, + AttrNumber *outer_spoint, AttrNumber *inner_spoint) +{ + ListCell *dist_arg; + + Assert(outer->relid != 0 && inner->relid != 0); + + foreach(dist_arg, fexpr->args) + { + Var *arg = (Var *) lfirst(dist_arg); + + if (arg->varno == outer->relid) + *outer_spoint = arg->varoattno; + + if (arg->varno == inner->relid) + *inner_spoint = arg->varoattno; + } +} + static Path * crossmatch_find_cheapest_path(PlannerInfo *root, RelOptInfo *joinrel, @@ -211,7 +254,9 @@ create_crossmatch_path(PlannerInfo *root, ParamPathInfo *param_info, List *restrict_clauses, Relids required_outer, - float8 threshold) + float8 threshold, + AttrNumber outer_spoint, + AttrNumber inner_spoint) { CrossmatchJoinPath *result; @@ -221,8 +266,8 @@ create_crossmatch_path(PlannerInfo *root, Oid inner_idx; /* TODO: use actual column numbers */ - if ((outer_idx = pick_suitable_index(outer_rel, 1)) == InvalidOid || - (inner_idx = pick_suitable_index(inner_rel, 1)) == InvalidOid) + if ((outer_idx = pick_suitable_index(outer_rel, outer_spoint)) == InvalidOid || + (inner_idx = pick_suitable_index(inner_rel, inner_spoint)) == InvalidOid) { return; } @@ -280,7 +325,7 @@ join_pathlist_hook(PlannerInfo *root, PointerGetDatum(dist_func_name))); if (dist_func == InvalidOid) - elog(ERROR, "function dist not found!"); + return; if (set_join_pathlist_next) set_join_pathlist_next(root, @@ -312,10 +357,11 @@ join_pathlist_hook(PlannerInfo *root, arg2 = lsecond(opExpr->args); if (opExpr->opno == Float8LessOperator && - IsA(arg1, FuncExpr) && - ((FuncExpr *) arg1)->funcid == dist_func && - IsA(arg2, Const)) + IsVarSpointDist(arg1, dist_func) && IsA(arg2, Const)) { + AttrNumber outer_spoint, + inner_spoint; + Path *outer_path = crossmatch_find_cheapest_path(root, joinrel, outerrel); Path *inner_path = crossmatch_find_cheapest_path(root, joinrel, innerrel); @@ -329,17 +375,22 @@ join_pathlist_hook(PlannerInfo *root, required_outer, &restrict_clauses); + get_spoint_attnums((FuncExpr *) arg1, outerrel, innerrel, + &outer_spoint, &inner_spoint); + create_crossmatch_path(root, joinrel, outer_path, inner_path, param_info, restrict_clauses, required_outer, - get_const_val((Const *) arg2)); + get_const_val((Const *) arg2), + outer_spoint, inner_spoint); break; } else if (opExpr->opno == get_commutator(Float8LessOperator) && - IsA(arg1, Const) && - IsA(arg2, FuncExpr) && - ((FuncExpr *) arg2)->funcid == dist_func) + IsA(arg1, Const) && IsVarSpointDist(arg2, dist_func)) { + AttrNumber outer_spoint, + inner_spoint; + /* TODO: merge duplicate code */ Path *outer_path = crossmatch_find_cheapest_path(root, joinrel, outerrel); Path *inner_path = crossmatch_find_cheapest_path(root, joinrel, innerrel); @@ -354,9 +405,13 @@ join_pathlist_hook(PlannerInfo *root, required_outer, &restrict_clauses); + get_spoint_attnums((FuncExpr *) arg2, outerrel, innerrel, + &outer_spoint, &inner_spoint); + create_crossmatch_path(root, joinrel, outer_path, inner_path, param_info, restrict_clauses, required_outer, - get_const_val((Const *) arg1)); + get_const_val((Const *) arg1), + outer_spoint, inner_spoint); } } } @@ -372,38 +427,27 @@ create_crossmatch_plan(PlannerInfo *root, { CrossmatchJoinPath *gpath = (CrossmatchJoinPath *) best_path; List *joinrestrictclauses = gpath->joinrestrictinfo; - List *joinclauses; /* NOTE: do we really need it? */ - List *otherclauses; + List *joinclauses; CustomScan *cscan; - float8 *threshold = palloc(sizeof(float8)); - if (IS_OUTER_JOIN(gpath->jointype)) - { - extract_actual_join_clauses(joinrestrictclauses, - &joinclauses, &otherclauses); - } - else - { - joinclauses = extract_actual_clauses(joinrestrictclauses, - false); - otherclauses = NIL; - } + Assert(!IS_OUTER_JOIN(gpath->jointype)); + joinclauses = extract_actual_clauses(joinrestrictclauses, false); cscan = makeNode(CustomScan); cscan->scan.plan.targetlist = tlist; - cscan->custom_scan_tlist = tlist; /* output of this node */ cscan->scan.plan.qual = NIL; cscan->scan.scanrelid = 0; + cscan->custom_scan_tlist = tlist; /* output of this node */ cscan->flags = best_path->flags; cscan->methods = &crossmatch_plan_methods; - cscan->custom_private = list_make2(list_make4_oid(gpath->outer_idx, + cscan->custom_private = list_make1(list_make4_oid(gpath->outer_idx, gpath->outer_rel, gpath->inner_idx, - gpath->inner_rel), - list_make1(threshold)); - *threshold = gpath->threshold; + gpath->inner_rel)); + cscan->custom_private = lappend(cscan->custom_private, + makeString(float8_to_cstring(gpath->threshold))); return &cscan->scan.plan; } @@ -411,7 +455,7 @@ create_crossmatch_plan(PlannerInfo *root, static Node * crossmatch_create_scan_state(CustomScan *node) { - CrossmatchScanState *scan_state = palloc0(sizeof(CrossmatchScanState)); + CrossmatchScanState *scan_state = palloc0(sizeof(CrossmatchScanState)); NodeSetTag(scan_state, T_CustomScanState); scan_state->css.flags = node->flags; @@ -426,7 +470,7 @@ crossmatch_create_scan_state(CustomScan *node) scan_state->outer_rel = lsecond_oid(linitial(node->custom_private)); scan_state->inner_idx = lthird_oid(linitial(node->custom_private)); scan_state->inner_rel = lfourth_oid(linitial(node->custom_private)); - scan_state->threshold = *(float8 *) linitial(lsecond(node->custom_private)); + scan_state->threshold = cstring_to_float8(strVal(lsecond(node->custom_private))); return (Node *) scan_state; } @@ -533,8 +577,14 @@ crossmatch_exec(CustomScanState *node) node->ss.ps.ps_TupFromTlist = false; } else - return ExecStoreTuple(htup, node->ss.ps.ps_ResultTupleSlot, - InvalidBuffer, false); + { + TupleTableSlot *result; + + result = ExecStoreTuple(htup, node->ss.ps.ps_ResultTupleSlot, + InvalidBuffer, false); + + return result; + } } } @@ -572,6 +622,12 @@ crossmatch_explain(CustomScanState *node, List *ancestors, ExplainState *es) appendStringInfo(&str, "%s", get_rel_name(scan_state->inner_idx)); ExplainPropertyText("Inner index", str.data, es); + + resetStringInfo(&str); + + appendStringInfo(&str, "%s", + float8_to_cstring(scan_state->threshold)); + ExplainPropertyText("Threshold", str.data, es); } void From 725fefec48d84ada2e16bc1fc05b4b92a23c3dc1 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Fri, 4 Mar 2016 19:07:51 +0300 Subject: [PATCH 17/41] improve projection (dispatch columns via tlist) --- init.c | 91 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 25 deletions(-) diff --git a/init.c b/init.c index 421f836..0902d21 100644 --- a/init.c +++ b/init.c @@ -56,16 +56,14 @@ typedef struct List *scan_tlist; + Index outer_relid; Oid outer_idx; Oid outer_rel; - ItemPointer outer_ptr; - HeapTuple outer_tup; Relation outer; + Index inner_relid; Oid inner_idx; Oid inner_rel; - ItemPointer inner_ptr; - HeapTuple inner_tup; Relation inner; float8 threshold; @@ -446,9 +444,17 @@ create_crossmatch_plan(PlannerInfo *root, gpath->outer_rel, gpath->inner_idx, gpath->inner_rel)); + + /* store threshold as cstring */ cscan->custom_private = lappend(cscan->custom_private, makeString(float8_to_cstring(gpath->threshold))); + cscan->custom_private = lappend(cscan->custom_private, + makeInteger(gpath->outer_path->parent->relid)); + + cscan->custom_private = lappend(cscan->custom_private, + makeInteger(gpath->inner_path->parent->relid)); + return &cscan->scan.plan; } @@ -470,8 +476,12 @@ crossmatch_create_scan_state(CustomScan *node) scan_state->outer_rel = lsecond_oid(linitial(node->custom_private)); scan_state->inner_idx = lthird_oid(linitial(node->custom_private)); scan_state->inner_rel = lfourth_oid(linitial(node->custom_private)); + scan_state->threshold = cstring_to_float8(strVal(lsecond(node->custom_private))); + scan_state->outer_relid = intVal(lthird(node->custom_private)); + scan_state->inner_relid = intVal(lfourth(node->custom_private)); + return (Node *) scan_state; } @@ -480,9 +490,7 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags) { CrossmatchScanState *scan_state = (CrossmatchScanState *) node; CrossmatchContext *ctx = (CrossmatchContext *) palloc0(sizeof(CrossmatchContext)); - - /* TODO: fix this kludge */ - int nlist = list_length(scan_state->scan_tlist) + 2; + int nlist = list_length(scan_state->scan_tlist); scan_state->ctx = ctx; setupFirstcall(ctx, scan_state->outer_idx, @@ -519,8 +527,8 @@ crossmatch_exec(CustomScanState *node) bool *nulls = scan_state->nulls; ItemPointerData p_tids[2] = { 0 }; - HeapTupleData htup1; - HeapTupleData htup2; + HeapTupleData htup_outer; + HeapTupleData htup_inner; Buffer buf1; Buffer buf2; @@ -534,22 +542,55 @@ crossmatch_exec(CustomScanState *node) /* We don't have to fetch tuples if scan tlist is empty */ if (scan_state->scan_tlist != NIL) { - TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; - - htup1.t_self = p_tids[0]; - heap_fetch(scan_state->outer, SnapshotSelf, - &htup1, &buf1, false, NULL); - values[0] = heap_getattr(&htup1, 1, scan_state->outer->rd_att, - &nulls[0]); - - htup2.t_self = p_tids[1]; - heap_fetch(scan_state->inner, SnapshotSelf, - &htup2, &buf2, false, NULL); - values[1] = heap_getattr(&htup2, 1, scan_state->inner->rd_att, - &nulls[1]); - - ReleaseBuffer(buf1); - ReleaseBuffer(buf2); + TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; + int col_index = 0; + bool htup_outer_ready = false; + bool htup_inner_ready = false; + ListCell *l; + + htup_outer.t_self = p_tids[0]; + htup_inner.t_self = p_tids[1]; + + foreach(l, scan_state->scan_tlist) + { + TargetEntry *target = (TargetEntry *) lfirst(l); + Var *var = (Var *) target->expr; + + if (var->varno == scan_state->outer_relid) + { + if (!htup_outer_ready) + { + htup_outer_ready = true; + heap_fetch(scan_state->outer, SnapshotSelf, + &htup_outer, &buf1, false, NULL); + } + + values[col_index] = heap_getattr(&htup_outer, var->varattno, + scan_state->outer->rd_att, + &nulls[col_index]); + } + + if (var->varno == scan_state->inner_relid) + { + if (!htup_inner_ready) + { + htup_inner_ready = true; + heap_fetch(scan_state->inner, SnapshotSelf, + &htup_inner, &buf2, false, NULL); + } + + values[col_index] = heap_getattr(&htup_inner, var->varattno, + scan_state->outer->rd_att, + &nulls[col_index]); + } + + col_index++; + } + + if (htup_outer_ready) + ReleaseBuffer(buf1); + if (htup_inner_ready) + ReleaseBuffer(buf2); htup = heap_form_tuple(tupdesc, values, nulls); scan_state->stored_tuple = htup; From 6508567ea5b6606fb438d59d98421de6b2f00d03 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Thu, 10 Mar 2016 17:07:13 +0300 Subject: [PATCH 18/41] refactoring (+try_crossmatch_path() function), check join quals --- init.c | 128 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 66 insertions(+), 62 deletions(-) diff --git a/init.c b/init.c index 0902d21..50c920b 100644 --- a/init.c +++ b/init.c @@ -263,7 +263,6 @@ create_crossmatch_path(PlannerInfo *root, Oid outer_idx; Oid inner_idx; - /* TODO: use actual column numbers */ if ((outer_idx = pick_suitable_index(outer_rel, outer_spoint)) == InvalidOid || (inner_idx = pick_suitable_index(inner_rel, inner_spoint)) == InvalidOid) { @@ -297,6 +296,49 @@ create_crossmatch_path(PlannerInfo *root, add_path(joinrel, &result->cpath.path); } +static void +try_crossmatch_path(RestrictInfo *restrInfo, + FuncExpr *distFuncExpr, + Const *thresholdConst, + PlannerInfo *root, + RelOptInfo *joinrel, + RelOptInfo *outerrel, + RelOptInfo *innerrel, + JoinPathExtraData *extra) +{ + AttrNumber outer_spoint, + inner_spoint; + List *restrict_clauses; + Path *outer_path, + *inner_path; + Relids required_outer; + ParamPathInfo *param_info; + + /* Remove current RestrictInfo from restrict clauses */ + restrict_clauses = list_delete_ptr(list_copy(extra->restrictlist), restrInfo); + + outer_path = crossmatch_find_cheapest_path(root, joinrel, outerrel); + inner_path = crossmatch_find_cheapest_path(root, joinrel, innerrel); + + required_outer = calc_nestloop_required_outer(outer_path, inner_path); + + param_info = get_joinrel_parampathinfo(root, + joinrel, + outer_path, + inner_path, + extra->sjinfo, + required_outer, + &restrict_clauses); + + get_spoint_attnums(distFuncExpr, outerrel, innerrel, + &outer_spoint, &inner_spoint); + + create_crossmatch_path(root, joinrel, outer_path, inner_path, + param_info, restrict_clauses, required_outer, + get_const_val(thresholdConst), + outer_spoint, inner_spoint); +} + static void join_pathlist_hook(PlannerInfo *root, RelOptInfo *joinrel, @@ -308,7 +350,6 @@ join_pathlist_hook(PlannerInfo *root, ListCell *restr; text *dist_func_name = cstring_to_text("dist(spoint,spoint)"); Oid dist_func; - List *restrict_clauses = extra->restrictlist; Relids required_relids = NULL; if (outerrel->reloptkind == RELOPT_BASEREL && @@ -357,59 +398,16 @@ join_pathlist_hook(PlannerInfo *root, if (opExpr->opno == Float8LessOperator && IsVarSpointDist(arg1, dist_func) && IsA(arg2, Const)) { - AttrNumber outer_spoint, - inner_spoint; - - Path *outer_path = crossmatch_find_cheapest_path(root, joinrel, outerrel); - Path *inner_path = crossmatch_find_cheapest_path(root, joinrel, innerrel); - - Relids required_outer = calc_nestloop_required_outer(outer_path, inner_path); - - ParamPathInfo *param_info = get_joinrel_parampathinfo(root, - joinrel, - outer_path, - inner_path, - extra->sjinfo, - required_outer, - &restrict_clauses); - - get_spoint_attnums((FuncExpr *) arg1, outerrel, innerrel, - &outer_spoint, &inner_spoint); - - create_crossmatch_path(root, joinrel, outer_path, inner_path, - param_info, restrict_clauses, required_outer, - get_const_val((Const *) arg2), - outer_spoint, inner_spoint); - + try_crossmatch_path(restrInfo, (FuncExpr *) arg1, (Const *) arg2, + root, joinrel, outerrel, innerrel, extra); break; } else if (opExpr->opno == get_commutator(Float8LessOperator) && IsA(arg1, Const) && IsVarSpointDist(arg2, dist_func)) { - AttrNumber outer_spoint, - inner_spoint; - - /* TODO: merge duplicate code */ - Path *outer_path = crossmatch_find_cheapest_path(root, joinrel, outerrel); - Path *inner_path = crossmatch_find_cheapest_path(root, joinrel, innerrel); - - Relids required_outer = calc_nestloop_required_outer(outer_path, inner_path); - - ParamPathInfo *param_info = get_joinrel_parampathinfo(root, - joinrel, - outer_path, - inner_path, - extra->sjinfo, - required_outer, - &restrict_clauses); - - get_spoint_attnums((FuncExpr *) arg2, outerrel, innerrel, - &outer_spoint, &inner_spoint); - - create_crossmatch_path(root, joinrel, outer_path, inner_path, - param_info, restrict_clauses, required_outer, - get_const_val((Const *) arg1), - outer_spoint, inner_spoint); + try_crossmatch_path(restrInfo, (FuncExpr *) arg2, (Const *) arg1, + root, joinrel, outerrel, innerrel, extra); + break; } } } @@ -433,7 +431,7 @@ create_crossmatch_plan(PlannerInfo *root, cscan = makeNode(CustomScan); cscan->scan.plan.targetlist = tlist; - cscan->scan.plan.qual = NIL; + cscan->scan.plan.qual = joinclauses; cscan->scan.scanrelid = 0; cscan->custom_scan_tlist = tlist; /* output of this node */ @@ -516,7 +514,7 @@ static TupleTableSlot * crossmatch_exec(CustomScanState *node) { CrossmatchScanState *scan_state = (CrossmatchScanState *) node; - TupleTableSlot *slot = node->ss.ss_ScanTupleSlot; + TupleTableSlot *scanSlot = node->ss.ss_ScanTupleSlot; HeapTuple htup = scan_state->stored_tuple; for(;;) @@ -594,37 +592,43 @@ crossmatch_exec(CustomScanState *node) htup = heap_form_tuple(tupdesc, values, nulls); scan_state->stored_tuple = htup; + + /* Fill scanSlot with a new tuple */ + ExecStoreTuple(htup, scanSlot, InvalidBuffer, false); } } if (node->ss.ps.ps_ProjInfo) { ExprDoneCond isDone; - TupleTableSlot *result; + TupleTableSlot *resultSlot; ResetExprContext(node->ss.ps.ps_ProjInfo->pi_exprContext); - /* TODO: find a better way to fill 'ecxt_scantuple' */ - node->ss.ps.ps_ProjInfo->pi_exprContext->ecxt_scantuple = ExecStoreTuple(htup, slot, InvalidBuffer, false); + /* Check join conditions */ + node->ss.ps.ps_ExprContext->ecxt_scantuple = scanSlot; + if (!ExecQual(node->ss.ps.qual, node->ss.ps.ps_ExprContext, false)) + continue; - result = ExecProject(node->ss.ps.ps_ProjInfo, &isDone); + node->ss.ps.ps_ProjInfo->pi_exprContext->ecxt_scantuple = scanSlot; + resultSlot = ExecProject(node->ss.ps.ps_ProjInfo, &isDone); if (isDone != ExprEndResult) { node->ss.ps.ps_TupFromTlist = (isDone == ExprMultipleResult); - return result; + return resultSlot; } else node->ss.ps.ps_TupFromTlist = false; } else { - TupleTableSlot *result; - - result = ExecStoreTuple(htup, node->ss.ps.ps_ResultTupleSlot, - InvalidBuffer, false); + ExecStoreTuple(htup, scanSlot, InvalidBuffer, false); - return result; + /* Check join conditions */ + node->ss.ps.ps_ExprContext->ecxt_scantuple = scanSlot; + if (ExecQual(node->ss.ps.qual, node->ss.ps.ps_ExprContext, false)) + return scanSlot; } } } From 0a3500cb598929fada767e242e4ffbd8c3699427 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Thu, 10 Mar 2016 17:11:58 +0300 Subject: [PATCH 19/41] remove redundant ExecStoreTuple(...) --- init.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/init.c b/init.c index 50c920b..b1466e9 100644 --- a/init.c +++ b/init.c @@ -623,8 +623,6 @@ crossmatch_exec(CustomScanState *node) } else { - ExecStoreTuple(htup, scanSlot, InvalidBuffer, false); - /* Check join conditions */ node->ss.ps.ps_ExprContext->ecxt_scantuple = scanSlot; if (ExecQual(node->ss.ps.qual, node->ss.ps.ps_ExprContext, false)) From 74438aab8d54e17a54689cf511e169f958783afa Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Fri, 11 Mar 2016 14:41:01 +0300 Subject: [PATCH 20/41] light refactoring, index size fetching fixed --- init.c | 62 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/init.c b/init.c index b1466e9..37007c0 100644 --- a/init.c +++ b/init.c @@ -85,6 +85,25 @@ static CustomExecMethods crossmatch_exec_methods; ) +static inline int64 +get_index_size(Oid idx) +{ + Datum size = DirectFunctionCall2(pg_relation_size, + ObjectIdGetDatum(idx), + PointerGetDatum(cstring_to_text("main"))); + return DatumGetInt64(size); +} + +static inline Oid +get_dist_func() +{ + text *dist_func_name = + cstring_to_text("public.dist(public.spoint, public.spoint)"); + + return DatumGetObjectId(DirectFunctionCall1(to_regprocedure, + PointerGetDatum(dist_func_name))); +} + static float8 cstring_to_float8(char *str) { @@ -166,10 +185,7 @@ pick_suitable_index(Oid relation, AttrNumber column) if (pg_ind->indkey.values[i] == column) { - cur_index_size = DatumGetInt64( - DirectFunctionCall2(pg_relation_size, - ObjectIdGetDatum(relation), - PointerGetDatum(cstring_to_text("main")))); + cur_index_size = get_index_size(pg_ind->indexrelid); if (found_index == InvalidOid || cur_index_size < found_index_size) { @@ -263,6 +279,9 @@ create_crossmatch_path(PlannerInfo *root, Oid outer_idx; Oid inner_idx; + if (outer_rel == inner_rel) + return; + if ((outer_idx = pick_suitable_index(outer_rel, outer_spoint)) == InvalidOid || (inner_idx = pick_suitable_index(inner_rel, inner_spoint)) == InvalidOid) { @@ -348,10 +367,17 @@ join_pathlist_hook(PlannerInfo *root, JoinPathExtraData *extra) { ListCell *restr; - text *dist_func_name = cstring_to_text("dist(spoint,spoint)"); Oid dist_func; Relids required_relids = NULL; + if (set_join_pathlist_next) + set_join_pathlist_next(root, joinrel, outerrel, + innerrel, jointype, extra); + + /* Get oid of the dist(spoint, spoint) function */ + if ((dist_func = get_dist_func()) == InvalidOid) + return; + if (outerrel->reloptkind == RELOPT_BASEREL && innerrel->reloptkind == RELOPT_BASEREL) { @@ -360,20 +386,6 @@ join_pathlist_hook(PlannerInfo *root, } else return; /* one of relations can't have index */ - dist_func = DatumGetObjectId(DirectFunctionCall1(to_regprocedure, - PointerGetDatum(dist_func_name))); - - if (dist_func == InvalidOid) - return; - - if (set_join_pathlist_next) - set_join_pathlist_next(root, - joinrel, - outerrel, - innerrel, - jointype, - extra); - foreach(restr, extra->restrictlist) { RestrictInfo *restrInfo = (RestrictInfo *) lfirst(restr); @@ -433,7 +445,8 @@ create_crossmatch_plan(PlannerInfo *root, cscan->scan.plan.targetlist = tlist; cscan->scan.plan.qual = joinclauses; cscan->scan.scanrelid = 0; - cscan->custom_scan_tlist = tlist; /* output of this node */ + cscan->custom_scan_tlist = tlist; /* tlist of the 'virtual' join rel + we'll have to build and scan */ cscan->flags = best_path->flags; cscan->methods = &crossmatch_plan_methods; @@ -465,9 +478,7 @@ crossmatch_create_scan_state(CustomScan *node) scan_state->css.flags = node->flags; scan_state->css.methods = &crossmatch_exec_methods; - /* TODO: check if this assignment is redundant */ - scan_state->css.ss.ps.ps_TupFromTlist = false; - + /* Save scan tlist for join relation */ scan_state->scan_tlist = node->custom_scan_tlist; scan_state->outer_idx = linitial_oid(linitial(node->custom_private)); @@ -519,6 +530,7 @@ crossmatch_exec(CustomScanState *node) for(;;) { + /* Fetch next tid pair */ if (!node->ss.ps.ps_TupFromTlist) { Datum *values = scan_state->values; @@ -541,9 +553,9 @@ crossmatch_exec(CustomScanState *node) if (scan_state->scan_tlist != NIL) { TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; - int col_index = 0; bool htup_outer_ready = false; bool htup_inner_ready = false; + int col_index = 0; ListCell *l; htup_outer.t_self = p_tids[0]; @@ -645,7 +657,7 @@ crossmatch_end(CustomScanState *node) static void crossmatch_rescan(CustomScanState *node) { - + /* NOTE: nothing to do here? */ } static void From 9d1abae538c3ce1bab3578fbbdda5902df980d28 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Mon, 14 Mar 2016 12:39:10 +0300 Subject: [PATCH 21/41] concat restrict_info with 'baserestrictinfo' of outerrel & innerrel --- init.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/init.c b/init.c index 37007c0..a224ac5 100644 --- a/init.c +++ b/init.c @@ -335,6 +335,10 @@ try_crossmatch_path(RestrictInfo *restrInfo, /* Remove current RestrictInfo from restrict clauses */ restrict_clauses = list_delete_ptr(list_copy(extra->restrictlist), restrInfo); + restrict_clauses = list_concat_unique(restrict_clauses, + outerrel->baserestrictinfo); + restrict_clauses = list_concat_unique(restrict_clauses, + innerrel->baserestrictinfo); outer_path = crossmatch_find_cheapest_path(root, joinrel, outerrel); inner_path = crossmatch_find_cheapest_path(root, joinrel, innerrel); From 69b58d9e89fc4ec7659480c8a34f3f6e6586211d Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Mon, 14 Mar 2016 14:54:30 +0300 Subject: [PATCH 22/41] count rows removed by filter --- init.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/init.c b/init.c index a224ac5..ceb326c 100644 --- a/init.c +++ b/init.c @@ -621,18 +621,19 @@ crossmatch_exec(CustomScanState *node) ResetExprContext(node->ss.ps.ps_ProjInfo->pi_exprContext); - /* Check join conditions */ - node->ss.ps.ps_ExprContext->ecxt_scantuple = scanSlot; - if (!ExecQual(node->ss.ps.qual, node->ss.ps.ps_ExprContext, false)) - continue; - node->ss.ps.ps_ProjInfo->pi_exprContext->ecxt_scantuple = scanSlot; resultSlot = ExecProject(node->ss.ps.ps_ProjInfo, &isDone); if (isDone != ExprEndResult) { node->ss.ps.ps_TupFromTlist = (isDone == ExprMultipleResult); - return resultSlot; + + /* Check join conditions */ + node->ss.ps.ps_ExprContext->ecxt_scantuple = scanSlot; + if (ExecQual(node->ss.ps.qual, node->ss.ps.ps_ExprContext, false)) + return resultSlot; + else + InstrCountFiltered1(node, 1); } else node->ss.ps.ps_TupFromTlist = false; @@ -643,6 +644,8 @@ crossmatch_exec(CustomScanState *node) node->ss.ps.ps_ExprContext->ecxt_scantuple = scanSlot; if (ExecQual(node->ss.ps.qual, node->ss.ps.ps_ExprContext, false)) return scanSlot; + else + InstrCountFiltered1(node, 1); } } } From 01f39d4564e60ae39b6e6252c4721cc2cae744d2 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Mon, 14 Mar 2016 17:19:43 +0300 Subject: [PATCH 23/41] init outer_spoint & inner_spoint --- init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.c b/init.c index ceb326c..5281197 100644 --- a/init.c +++ b/init.c @@ -325,8 +325,8 @@ try_crossmatch_path(RestrictInfo *restrInfo, RelOptInfo *innerrel, JoinPathExtraData *extra) { - AttrNumber outer_spoint, - inner_spoint; + AttrNumber outer_spoint = InvalidAttrNumber, + inner_spoint = InvalidAttrNumber; List *restrict_clauses; Path *outer_path, *inner_path; From d16eda931c0d618face2ee3cb7cf590df94e95fc Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 15 Mar 2016 14:47:37 +0300 Subject: [PATCH 24/41] fixed plan's custom_scan_tlist according to PostgreSQL 3fc6e2d7f5 --- init.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/init.c b/init.c index 5281197..46ac4fb 100644 --- a/init.c +++ b/init.c @@ -2,6 +2,7 @@ #include "optimizer/paths.h" #include "optimizer/pathnode.h" #include "optimizer/restrictinfo.h" +#include "optimizer/tlist.h" #include "utils/tqual.h" #include "utils/builtins.h" #include "utils/elog.h" @@ -449,7 +450,7 @@ create_crossmatch_plan(PlannerInfo *root, cscan->scan.plan.targetlist = tlist; cscan->scan.plan.qual = joinclauses; cscan->scan.scanrelid = 0; - cscan->custom_scan_tlist = tlist; /* tlist of the 'virtual' join rel + cscan->custom_scan_tlist = make_tlist_from_pathtarget(&rel->reltarget); /* tlist of the 'virtual' join rel we'll have to build and scan */ cscan->flags = best_path->flags; @@ -512,8 +513,8 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags) scan_state->outer = heap_open(scan_state->outer_rel, AccessShareLock); scan_state->inner = heap_open(scan_state->inner_rel, AccessShareLock); - scan_state->values = palloc(sizeof(Datum) * nlist); - scan_state->nulls = palloc(sizeof(bool) * nlist); + scan_state->values = palloc0(sizeof(Datum) * nlist); + scan_state->nulls = palloc0(sizeof(bool) * nlist); /* Store blank tuple in case scan tlist is empty */ if (scan_state->scan_tlist == NIL) @@ -575,6 +576,7 @@ crossmatch_exec(CustomScanState *node) if (!htup_outer_ready) { htup_outer_ready = true; + /* TODO: check result */ heap_fetch(scan_state->outer, SnapshotSelf, &htup_outer, &buf1, false, NULL); } @@ -665,6 +667,7 @@ static void crossmatch_rescan(CustomScanState *node) { /* NOTE: nothing to do here? */ + node->ss.ps.ps_TupFromTlist = false; } static void From de99e0c6fb96b398e014e20b84503a6fecf6f244 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 15 Mar 2016 18:07:23 +0300 Subject: [PATCH 25/41] refactoring, fetch_next_pair() function --- crossmatch.c | 3 +- crossmatch.h | 3 +- init.c | 165 +++++++++++++++++++++++++++------------------------ 3 files changed, 91 insertions(+), 80 deletions(-) diff --git a/crossmatch.c b/crossmatch.c index 1dca37a..9ff46a4 100644 --- a/crossmatch.c +++ b/crossmatch.c @@ -128,8 +128,7 @@ indexClose(Relation r) * Do necessary initialization for first SRF call. */ void -setupFirstcall(CrossmatchContext *ctx, Oid idx1, Oid idx2, - float8 threshold) +setupFirstcall(CrossmatchContext *ctx, Oid idx1, Oid idx2, float8 threshold) { GistNSN parentnsn = InvalidNSN; diff --git a/crossmatch.h b/crossmatch.h index 5ba4f6f..82158e4 100644 --- a/crossmatch.h +++ b/crossmatch.h @@ -37,8 +37,7 @@ typedef struct AttInMetadata *attinmeta; } CrossmatchContext; -void setupFirstcall(CrossmatchContext *ctx, Oid idx1, Oid idx2, - float8 threshold); +void setupFirstcall(CrossmatchContext *ctx, Oid idx1, Oid idx2, float8 threshold); void endCall(CrossmatchContext *ctx); diff --git a/init.c b/init.c index 46ac4fb..ba4d62e 100644 --- a/init.c +++ b/init.c @@ -53,7 +53,6 @@ typedef struct Datum *values; bool *nulls; - HeapTuple stored_tuple; List *scan_tlist; @@ -450,8 +449,9 @@ create_crossmatch_plan(PlannerInfo *root, cscan->scan.plan.targetlist = tlist; cscan->scan.plan.qual = joinclauses; cscan->scan.scanrelid = 0; - cscan->custom_scan_tlist = make_tlist_from_pathtarget(&rel->reltarget); /* tlist of the 'virtual' join rel - we'll have to build and scan */ + + /* tlist of the 'virtual' join rel we'll have to build and scan */ + cscan->custom_scan_tlist = make_tlist_from_pathtarget(&rel->reltarget); cscan->flags = best_path->flags; cscan->methods = &crossmatch_plan_methods; @@ -520,100 +520,113 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags) if (scan_state->scan_tlist == NIL) { TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; - scan_state->stored_tuple = heap_form_tuple(tupdesc, NULL, NULL); + + ExecStoreTuple(heap_form_tuple(tupdesc, NULL, NULL), + node->ss.ss_ScanTupleSlot, + InvalidBuffer, + false); } - else - scan_state->stored_tuple = NULL; } -static TupleTableSlot * -crossmatch_exec(CustomScanState *node) +static bool +fetch_next_pair(CrossmatchScanState *scan_state) { - CrossmatchScanState *scan_state = (CrossmatchScanState *) node; - TupleTableSlot *scanSlot = node->ss.ss_ScanTupleSlot; - HeapTuple htup = scan_state->stored_tuple; + ScanState *ss = &scan_state->css.ss; + TupleTableSlot *slot = ss->ss_ScanTupleSlot; + TupleDesc tupdesc = ss->ss_ScanTupleSlot->tts_tupleDescriptor; - for(;;) + HeapTuple htup; + Datum *values = scan_state->values; + bool *nulls = scan_state->nulls; + + ItemPointerData p_tids[2] = { 0 }; + HeapTupleData htup_outer; + HeapTupleData htup_inner; + Buffer buf1; + Buffer buf2; + + crossmatch(scan_state->ctx, p_tids); + + if (!ItemPointerIsValid(&p_tids[0]) || !ItemPointerIsValid(&p_tids[1])) { - /* Fetch next tid pair */ - if (!node->ss.ps.ps_TupFromTlist) - { - Datum *values = scan_state->values; - bool *nulls = scan_state->nulls; + return false; + } - ItemPointerData p_tids[2] = { 0 }; - HeapTupleData htup_outer; - HeapTupleData htup_inner; - Buffer buf1; - Buffer buf2; + /* We don't have to fetch tuples if scan tlist is empty */ + if (scan_state->scan_tlist != NIL) + { + bool htup_outer_ready = false; + bool htup_inner_ready = false; + int col_index = 0; + ListCell *l; - crossmatch(scan_state->ctx, p_tids); + htup_outer.t_self = p_tids[0]; + htup_inner.t_self = p_tids[1]; + + foreach(l, scan_state->scan_tlist) + { + TargetEntry *target = (TargetEntry *) lfirst(l); + Var *var = (Var *) target->expr; - if (!ItemPointerIsValid(&p_tids[0]) || !ItemPointerIsValid(&p_tids[1])) + if (var->varno == scan_state->outer_relid) { - return ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); + if (!htup_outer_ready) + { + htup_outer_ready = true; + /* TODO: check result */ + heap_fetch(scan_state->outer, SnapshotSelf, + &htup_outer, &buf1, false, NULL); + } + + values[col_index] = heap_getattr(&htup_outer, var->varattno, + scan_state->outer->rd_att, + &nulls[col_index]); } - /* We don't have to fetch tuples if scan tlist is empty */ - if (scan_state->scan_tlist != NIL) + if (var->varno == scan_state->inner_relid) { - TupleDesc tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor; - bool htup_outer_ready = false; - bool htup_inner_ready = false; - int col_index = 0; - ListCell *l; + if (!htup_inner_ready) + { + htup_inner_ready = true; + heap_fetch(scan_state->inner, SnapshotSelf, + &htup_inner, &buf2, false, NULL); + } - htup_outer.t_self = p_tids[0]; - htup_inner.t_self = p_tids[1]; + values[col_index] = heap_getattr(&htup_inner, var->varattno, + scan_state->outer->rd_att, + &nulls[col_index]); + } - foreach(l, scan_state->scan_tlist) - { - TargetEntry *target = (TargetEntry *) lfirst(l); - Var *var = (Var *) target->expr; + col_index++; + } - if (var->varno == scan_state->outer_relid) - { - if (!htup_outer_ready) - { - htup_outer_ready = true; - /* TODO: check result */ - heap_fetch(scan_state->outer, SnapshotSelf, - &htup_outer, &buf1, false, NULL); - } - - values[col_index] = heap_getattr(&htup_outer, var->varattno, - scan_state->outer->rd_att, - &nulls[col_index]); - } + if (htup_outer_ready) + ReleaseBuffer(buf1); + if (htup_inner_ready) + ReleaseBuffer(buf2); - if (var->varno == scan_state->inner_relid) - { - if (!htup_inner_ready) - { - htup_inner_ready = true; - heap_fetch(scan_state->inner, SnapshotSelf, - &htup_inner, &buf2, false, NULL); - } - - values[col_index] = heap_getattr(&htup_inner, var->varattno, - scan_state->outer->rd_att, - &nulls[col_index]); - } + htup = heap_form_tuple(tupdesc, values, nulls); - col_index++; - } + /* Fill scanSlot with a new tuple */ + ExecStoreTuple(htup, slot, InvalidBuffer, false); + } - if (htup_outer_ready) - ReleaseBuffer(buf1); - if (htup_inner_ready) - ReleaseBuffer(buf2); + return true; +} - htup = heap_form_tuple(tupdesc, values, nulls); - scan_state->stored_tuple = htup; +static TupleTableSlot * +crossmatch_exec(CustomScanState *node) +{ + CrossmatchScanState *scan_state = (CrossmatchScanState *) node; + TupleTableSlot *scanSlot = node->ss.ss_ScanTupleSlot; - /* Fill scanSlot with a new tuple */ - ExecStoreTuple(htup, scanSlot, InvalidBuffer, false); - } + for(;;) + { + if (!node->ss.ps.ps_TupFromTlist) + { + /* Fetch next tid pair if we're done with the SRF function */ + if (!fetch_next_pair(scan_state)) + return NULL; } if (node->ss.ps.ps_ProjInfo) From 56187becbd15c57ec5f593b1b3a8be2f8b29a835 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 15 Mar 2016 18:56:42 +0300 Subject: [PATCH 26/41] minor refactoring for fetch_next_pair() --- init.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/init.c b/init.c index ba4d62e..d2a8815 100644 --- a/init.c +++ b/init.c @@ -28,6 +28,13 @@ extern void _PG_init(void); static set_join_pathlist_hook_type set_join_pathlist_next; +typedef enum +{ + FetchTidPairFinished = 0, + FetchTidPairInvalid, + FetchTidPairReady +} FetchTidPairState; + typedef struct { CustomPath cpath; @@ -528,7 +535,7 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags) } } -static bool +static FetchTidPairState fetch_next_pair(CrossmatchScanState *scan_state) { ScanState *ss = &scan_state->css.ss; @@ -549,7 +556,7 @@ fetch_next_pair(CrossmatchScanState *scan_state) if (!ItemPointerIsValid(&p_tids[0]) || !ItemPointerIsValid(&p_tids[1])) { - return false; + return FetchTidPairFinished; } /* We don't have to fetch tuples if scan tlist is empty */ @@ -573,9 +580,11 @@ fetch_next_pair(CrossmatchScanState *scan_state) if (!htup_outer_ready) { htup_outer_ready = true; - /* TODO: check result */ - heap_fetch(scan_state->outer, SnapshotSelf, - &htup_outer, &buf1, false, NULL); + if(!heap_fetch(scan_state->outer, SnapshotSelf, + &htup_outer, &buf1, false, NULL)) + { + return FetchTidPairInvalid; + } } values[col_index] = heap_getattr(&htup_outer, var->varattno, @@ -588,8 +597,11 @@ fetch_next_pair(CrossmatchScanState *scan_state) if (!htup_inner_ready) { htup_inner_ready = true; - heap_fetch(scan_state->inner, SnapshotSelf, - &htup_inner, &buf2, false, NULL); + if(!heap_fetch(scan_state->inner, SnapshotSelf, + &htup_inner, &buf2, false, NULL)) + { + return FetchTidPairInvalid; + } } values[col_index] = heap_getattr(&htup_inner, var->varattno, @@ -611,7 +623,7 @@ fetch_next_pair(CrossmatchScanState *scan_state) ExecStoreTuple(htup, slot, InvalidBuffer, false); } - return true; + return FetchTidPairReady; } static TupleTableSlot * @@ -620,12 +632,19 @@ crossmatch_exec(CustomScanState *node) CrossmatchScanState *scan_state = (CrossmatchScanState *) node; TupleTableSlot *scanSlot = node->ss.ss_ScanTupleSlot; - for(;;) + for (;;) { if (!node->ss.ps.ps_TupFromTlist) { - /* Fetch next tid pair if we're done with the SRF function */ - if (!fetch_next_pair(scan_state)) + FetchTidPairState fetch_state; + + do + { + fetch_state = fetch_next_pair(scan_state); + } + while (fetch_state == FetchTidPairInvalid); + + if (fetch_state == FetchTidPairFinished) return NULL; } From 03713a399fbc86a30b46c67bae3d049decfad12d Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 15 Mar 2016 18:58:24 +0300 Subject: [PATCH 27/41] formatting --- init.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/init.c b/init.c index d2a8815..f1ba2a9 100644 --- a/init.c +++ b/init.c @@ -572,8 +572,8 @@ fetch_next_pair(CrossmatchScanState *scan_state) foreach(l, scan_state->scan_tlist) { - TargetEntry *target = (TargetEntry *) lfirst(l); - Var *var = (Var *) target->expr; + TargetEntry *target = (TargetEntry *) lfirst(l); + Var *var = (Var *) target->expr; if (var->varno == scan_state->outer_relid) { @@ -588,8 +588,8 @@ fetch_next_pair(CrossmatchScanState *scan_state) } values[col_index] = heap_getattr(&htup_outer, var->varattno, - scan_state->outer->rd_att, - &nulls[col_index]); + scan_state->outer->rd_att, + &nulls[col_index]); } if (var->varno == scan_state->inner_relid) @@ -605,8 +605,8 @@ fetch_next_pair(CrossmatchScanState *scan_state) } values[col_index] = heap_getattr(&htup_inner, var->varattno, - scan_state->outer->rd_att, - &nulls[col_index]); + scan_state->outer->rd_att, + &nulls[col_index]); } col_index++; From 16e45b5f03b89d748bab4d36ce69e4cd48dd77d9 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 15 Mar 2016 22:01:43 +0300 Subject: [PATCH 28/41] check tuple visibility --- init.c | 53 +++++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/init.c b/init.c index f1ba2a9..cc4bd76 100644 --- a/init.c +++ b/init.c @@ -91,6 +91,11 @@ static CustomExecMethods crossmatch_exec_methods; IsA(lsecond(((FuncExpr *) (arg))->args), Var) \ ) +#define HeapFetchVisibleTuple(rel, htup, buf) \ + ( \ + heap_fetch((rel), SnapshotSelf, (htup), &(buf), false, NULL) && \ + HeapTupleSatisfiesVisibility((htup), SnapshotSelf, (buf)) \ + ) static inline int64 get_index_size(Oid idx) @@ -549,8 +554,8 @@ fetch_next_pair(CrossmatchScanState *scan_state) ItemPointerData p_tids[2] = { 0 }; HeapTupleData htup_outer; HeapTupleData htup_inner; - Buffer buf1; - Buffer buf2; + Buffer buf1 = InvalidBuffer; + Buffer buf2 = InvalidBuffer; crossmatch(scan_state->ctx, p_tids); @@ -559,17 +564,21 @@ fetch_next_pair(CrossmatchScanState *scan_state) return FetchTidPairFinished; } + htup_outer.t_self = p_tids[0]; + htup_inner.t_self = p_tids[1]; + + if (!HeapFetchVisibleTuple(scan_state->outer, &htup_outer, buf1) || + !HeapFetchVisibleTuple(scan_state->inner, &htup_inner, buf2)) + { + return FetchTidPairInvalid; + } + /* We don't have to fetch tuples if scan tlist is empty */ if (scan_state->scan_tlist != NIL) { - bool htup_outer_ready = false; - bool htup_inner_ready = false; int col_index = 0; ListCell *l; - htup_outer.t_self = p_tids[0]; - htup_inner.t_self = p_tids[1]; - foreach(l, scan_state->scan_tlist) { TargetEntry *target = (TargetEntry *) lfirst(l); @@ -577,16 +586,6 @@ fetch_next_pair(CrossmatchScanState *scan_state) if (var->varno == scan_state->outer_relid) { - if (!htup_outer_ready) - { - htup_outer_ready = true; - if(!heap_fetch(scan_state->outer, SnapshotSelf, - &htup_outer, &buf1, false, NULL)) - { - return FetchTidPairInvalid; - } - } - values[col_index] = heap_getattr(&htup_outer, var->varattno, scan_state->outer->rd_att, &nulls[col_index]); @@ -594,16 +593,6 @@ fetch_next_pair(CrossmatchScanState *scan_state) if (var->varno == scan_state->inner_relid) { - if (!htup_inner_ready) - { - htup_inner_ready = true; - if(!heap_fetch(scan_state->inner, SnapshotSelf, - &htup_inner, &buf2, false, NULL)) - { - return FetchTidPairInvalid; - } - } - values[col_index] = heap_getattr(&htup_inner, var->varattno, scan_state->outer->rd_att, &nulls[col_index]); @@ -612,17 +601,17 @@ fetch_next_pair(CrossmatchScanState *scan_state) col_index++; } - if (htup_outer_ready) - ReleaseBuffer(buf1); - if (htup_inner_ready) - ReleaseBuffer(buf2); - htup = heap_form_tuple(tupdesc, values, nulls); /* Fill scanSlot with a new tuple */ ExecStoreTuple(htup, slot, InvalidBuffer, false); } + if (buf1 != InvalidBuffer) + ReleaseBuffer(buf1); + if (buf2 != InvalidBuffer) + ReleaseBuffer(buf2); + return FetchTidPairReady; } From 1e3bf66d968a48fb22f7fed8886e369631863700 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 15 Mar 2016 22:15:12 +0300 Subject: [PATCH 29/41] fix found_index_size in pick_suitable_index() --- init.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/init.c b/init.c index cc4bd76..463c73f 100644 --- a/init.c +++ b/init.c @@ -208,7 +208,10 @@ pick_suitable_index(Oid relation, AttrNumber column) /* column must use 'spoint2' opclass */ if (!is_null && indclasses->values[i] == spoint2_opclass) + { found_index = pg_ind->indexrelid; + found_index_size = cur_index_size; + } } break; /* no need to scan 'indkey' further */ From 54246dd7a3645a5265c35dcd0dd350b02d20de19 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Wed, 16 Mar 2016 14:58:45 +0300 Subject: [PATCH 30/41] fix get_const_val() --- init.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/init.c b/init.c index 463c73f..cb641a8 100644 --- a/init.c +++ b/init.c @@ -7,6 +7,7 @@ #include "utils/builtins.h" #include "utils/elog.h" #include "utils/lsyscache.h" +#include "utils/syscache.h" #include "utils/rel.h" #include "utils/fmgroids.h" #include "utils/memutils.h" @@ -14,6 +15,7 @@ #include "catalog/pg_am.h" #include "catalog/pg_proc.h" #include "catalog/pg_operator.h" +#include "catalog/pg_cast.h" #include "commands/explain.h" #include "commands/defrem.h" #include "funcapi.h" @@ -133,16 +135,34 @@ float8_to_cstring(float8 val) static float8 get_const_val(Const *node) { - FmgrInfo finfo; - Oid cast; + FmgrInfo finfo; + Oid cast_func; + HeapTuple cast_tup; + Form_pg_cast cast; Assert(IsA(node, Const)); if (node->consttype == FLOAT8OID) return DatumGetFloat8(node->constvalue); - cast = get_cast_oid(node->consttype, FLOAT8OID, false); - fmgr_info(cast, &finfo); + /* It looks like this is not necessary at all, but anyway */ + cast_tup = SearchSysCache2(CASTSOURCETARGET, + ObjectIdGetDatum(node->consttype), + ObjectIdGetDatum(FLOAT8OID)); + + if (!HeapTupleIsValid(cast_tup)) + ereport(ERROR, + (errcode(ERRCODE_DUPLICATE_OBJECT), + errmsg("no cast from type %s to type %s", + format_type_be(node->consttype), + format_type_be(FLOAT8OID)))); + + cast = (Form_pg_cast) GETSTRUCT(cast_tup); + cast_func = cast->castfunc; + + ReleaseSysCache(cast_tup); + + fmgr_info(cast_func, &finfo); return DatumGetFloat8(FunctionCall1(&finfo, node->constvalue)); } From 5ba59b948854d3e3f3bdc0af49aa7f85a767058d Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Thu, 17 Mar 2016 13:15:16 +0300 Subject: [PATCH 31/41] 9.6devel-related fixes --- init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.c b/init.c index cb641a8..0160d30 100644 --- a/init.c +++ b/init.c @@ -330,7 +330,7 @@ create_crossmatch_path(PlannerInfo *root, result->cpath.path.parent = joinrel; result->cpath.path.param_info = param_info; result->cpath.path.pathkeys = NIL; - result->cpath.path.pathtarget = &joinrel->reltarget; + result->cpath.path.pathtarget = joinrel->reltarget; result->cpath.path.rows = joinrel->rows; result->cpath.flags = 0; result->cpath.methods = &crossmatch_path_methods; @@ -486,7 +486,7 @@ create_crossmatch_plan(PlannerInfo *root, cscan->scan.scanrelid = 0; /* tlist of the 'virtual' join rel we'll have to build and scan */ - cscan->custom_scan_tlist = make_tlist_from_pathtarget(&rel->reltarget); + cscan->custom_scan_tlist = make_tlist_from_pathtarget(rel->reltarget); cscan->flags = best_path->flags; cscan->methods = &crossmatch_plan_methods; From 7bc359106aa819cd26ff5b291d9c9324a3dd3c1b Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Thu, 17 Mar 2016 13:41:53 +0300 Subject: [PATCH 32/41] check first index column --- init.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/init.c b/init.c index 0160d30..5e4cfd4 100644 --- a/init.c +++ b/init.c @@ -205,36 +205,28 @@ pick_suitable_index(Oid relation, AttrNumber column) index_am = index->rd_rel->relam; index_close(index, AccessShareLock); - /* check if this is a valid GIST index with no predicates */ + /* + * check if this is a valid GIST index with no predicates and + * its first column is the required spoint with opclass 'spoint2'. + */ if (index_am == GIST_AM_OID && pg_ind->indisvalid && - heap_attisnull(htup, Anum_pg_index_indpred)) + heap_attisnull(htup, Anum_pg_index_indpred) && + pg_ind->indkey.dim1 >= 1 && pg_ind->indkey.values[0] == column) { - int i; + int64 cur_index_size = get_index_size(pg_ind->indexrelid); - for (i = 0; i < pg_ind->indkey.dim1; i++) + if (found_index == InvalidOid || cur_index_size < found_index_size) { - int64 cur_index_size = 0; + bool is_null; + Datum indclass = heap_getattr(htup, Anum_pg_index_indclass, + pg_index->rd_att, &is_null); + oidvector *indclasses = (oidvector *) DatumGetPointer(indclass); - if (pg_ind->indkey.values[i] == column) + /* column must use 'spoint2' opclass */ + if (!is_null && indclasses->values[0] == spoint2_opclass) { - cur_index_size = get_index_size(pg_ind->indexrelid); - - if (found_index == InvalidOid || cur_index_size < found_index_size) - { - bool is_null; - Datum indclass = heap_getattr(htup, Anum_pg_index_indclass, - pg_index->rd_att, &is_null); - oidvector *indclasses = (oidvector *) DatumGetPointer(indclass); - - /* column must use 'spoint2' opclass */ - if (!is_null && indclasses->values[i] == spoint2_opclass) - { - found_index = pg_ind->indexrelid; - found_index_size = cur_index_size; - } - } - - break; /* no need to scan 'indkey' further */ + found_index = pg_ind->indexrelid; + found_index_size = cur_index_size; } } } From 3395a25687e46508a863eb1192d2279458afc236 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Mon, 21 Mar 2016 18:47:57 +0300 Subject: [PATCH 33/41] fix custom_scan_tlist generation, improve pick_suitable_index() --- init.c | 94 +++++++++++++++++++++++++--------------------------------- 1 file changed, 40 insertions(+), 54 deletions(-) diff --git a/init.c b/init.c index 5e4cfd4..ac3c636 100644 --- a/init.c +++ b/init.c @@ -3,6 +3,7 @@ #include "optimizer/pathnode.h" #include "optimizer/restrictinfo.h" #include "optimizer/tlist.h" +#include "optimizer/var.h" #include "utils/tqual.h" #include "utils/builtins.h" #include "utils/elog.h" @@ -172,69 +173,43 @@ get_const_val(Const *node) * whether some partial indices may suffice */ static Oid -pick_suitable_index(Oid relation, AttrNumber column) +pick_suitable_index(RelOptInfo *relation, AttrNumber column) { Oid found_index = InvalidOid; int64 found_index_size = 0; - HeapTuple htup; - SysScanDesc scan; - Relation pg_index; - List *spoint2_opclass_name; - Oid spoint2_opclass; - ScanKeyData key[3]; - - spoint2_opclass_name = stringToQualifiedNameList("public.spoint2"); - spoint2_opclass = get_opclass_oid(GIST_AM_OID, spoint2_opclass_name, false); - - ScanKeyInit(&key[0], - Anum_pg_index_indrelid, - BTEqualStrategyNumber, - F_OIDEQ, - ObjectIdGetDatum(relation)); - - pg_index = heap_open(IndexRelationId, AccessShareLock); - scan = systable_beginscan(pg_index, InvalidOid, false, NULL, 1, key); - - while (HeapTupleIsValid(htup = systable_getnext(scan))) - { - Form_pg_index pg_ind = (Form_pg_index) GETSTRUCT(htup); - Relation index; - Oid index_am; + List *spoint2_opfamily_name; + Oid spoint2_opfamily; + ListCell *lc; + + spoint2_opfamily_name = stringToQualifiedNameList("public.spoint2"); + spoint2_opfamily = get_opfamily_oid(GIST_AM_OID, spoint2_opfamily_name, false); - index = index_open(pg_ind->indexrelid, AccessShareLock); - index_am = index->rd_rel->relam; - index_close(index, AccessShareLock); + foreach(lc, relation->indexlist) + { + IndexOptInfo *index = (IndexOptInfo *) lfirst(lc); /* - * check if this is a valid GIST index with no predicates and - * its first column is the required spoint with opclass 'spoint2'. + * check if this is a valid GIST index and its first + * column is the required spoint with opclass 'spoint2'. */ - if (index_am == GIST_AM_OID && pg_ind->indisvalid && - heap_attisnull(htup, Anum_pg_index_indpred) && - pg_ind->indkey.dim1 >= 1 && pg_ind->indkey.values[0] == column) + if (index->relam == GIST_AM_OID && + (index->indpred == NIL || index->predOK) && + index->ncolumns >= 1 && index->indexkeys[0] == column) { - int64 cur_index_size = get_index_size(pg_ind->indexrelid); + int64 cur_index_size = index->pages; if (found_index == InvalidOid || cur_index_size < found_index_size) { - bool is_null; - Datum indclass = heap_getattr(htup, Anum_pg_index_indclass, - pg_index->rd_att, &is_null); - oidvector *indclasses = (oidvector *) DatumGetPointer(indclass); - /* column must use 'spoint2' opclass */ - if (!is_null && indclasses->values[0] == spoint2_opclass) + if (index->opfamily[0] == spoint2_opfamily) { - found_index = pg_ind->indexrelid; + found_index = index->indexoid; found_index_size = cur_index_size; } } } } - systable_endscan(scan); - heap_close(pg_index, AccessShareLock); - return found_index; } @@ -301,16 +276,22 @@ create_crossmatch_path(PlannerInfo *root, { CrossmatchJoinPath *result; - Oid outer_rel = root->simple_rte_array[outer_path->parent->relid]->relid; - Oid inner_rel = root->simple_rte_array[inner_path->parent->relid]->relid; - Oid outer_idx; - Oid inner_idx; + RelOptInfo *outerrel = outer_path->parent; + RelOptInfo *innerrel = inner_path->parent; + Oid outerrelid = root->simple_rte_array[outerrel->relid]->relid; + Oid innerrelid = root->simple_rte_array[innerrel->relid]->relid; + Oid outer_idx; + Oid inner_idx; + + Assert(outerrelid != InvalidOid); + Assert(innerrelid != InvalidOid); - if (outer_rel == inner_rel) + /* Relations should be different */ + if (outerrel->relid == innerrel->relid) return; - if ((outer_idx = pick_suitable_index(outer_rel, outer_spoint)) == InvalidOid || - (inner_idx = pick_suitable_index(inner_rel, inner_spoint)) == InvalidOid) + if ((outer_idx = pick_suitable_index(outerrel, outer_spoint)) == InvalidOid || + (inner_idx = pick_suitable_index(innerrel, inner_spoint)) == InvalidOid) { return; } @@ -328,10 +309,10 @@ create_crossmatch_path(PlannerInfo *root, result->cpath.methods = &crossmatch_path_methods; result->outer_path = outer_path; result->outer_idx = outer_idx; - result->outer_rel = outer_rel; + result->outer_rel = outerrelid; result->inner_path = inner_path; result->inner_idx = inner_idx; - result->inner_rel = inner_rel; + result->inner_rel = innerrelid; result->threshold = threshold; result->joinrestrictinfo = restrict_clauses; @@ -468,6 +449,7 @@ create_crossmatch_plan(PlannerInfo *root, List *joinrestrictclauses = gpath->joinrestrictinfo; List *joinclauses; CustomScan *cscan; + PathTarget *target; Assert(!IS_OUTER_JOIN(gpath->jointype)); joinclauses = extract_actual_clauses(joinrestrictclauses, false); @@ -477,8 +459,12 @@ create_crossmatch_plan(PlannerInfo *root, cscan->scan.plan.qual = joinclauses; cscan->scan.scanrelid = 0; + /* Add Vars needed for our extended 'joinclauses' */ + target = copy_pathtarget(rel->reltarget); + add_new_columns_to_pathtarget(target, pull_var_clause((Node *) joinclauses, 0)); + /* tlist of the 'virtual' join rel we'll have to build and scan */ - cscan->custom_scan_tlist = make_tlist_from_pathtarget(rel->reltarget); + cscan->custom_scan_tlist = make_tlist_from_pathtarget(target); cscan->flags = best_path->flags; cscan->methods = &crossmatch_plan_methods; From 81a491ecbf484a99fc93ed6fa1fae07af7db79a8 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 22 Mar 2016 14:50:30 +0300 Subject: [PATCH 34/41] restore compatibility with PostgreSQL 9.5 --- init.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/init.c b/init.c index ac3c636..286b471 100644 --- a/init.c +++ b/init.c @@ -112,11 +112,31 @@ get_index_size(Oid idx) static inline Oid get_dist_func() { + MemoryContext oldcxt = CurrentMemoryContext; + Datum result; + +#if PG_VERSION_NUM >= 90600 text *dist_func_name = cstring_to_text("public.dist(public.spoint, public.spoint)"); +#else + char *dist_func_name = "public.dist(public.spoint, public.spoint)"; +#endif + + PG_TRY(); + { + result = DirectFunctionCall1(to_regprocedure, + PointerGetDatum(dist_func_name)); + } + PG_CATCH(); + { + MemoryContextSwitchTo(oldcxt); + FlushErrorState(); + + elog(ERROR, "can't find function \"dist(spoint, spoint)\""); + } + PG_END_TRY(); - return DatumGetObjectId(DirectFunctionCall1(to_regprocedure, - PointerGetDatum(dist_func_name))); + return DatumGetObjectId(result); } static float8 @@ -303,7 +323,9 @@ create_crossmatch_path(PlannerInfo *root, result->cpath.path.parent = joinrel; result->cpath.path.param_info = param_info; result->cpath.path.pathkeys = NIL; +#if PG_VERSION_NUM >= 90600 result->cpath.path.pathtarget = joinrel->reltarget; +#endif result->cpath.path.rows = joinrel->rows; result->cpath.flags = 0; result->cpath.methods = &crossmatch_path_methods; @@ -449,7 +471,12 @@ create_crossmatch_plan(PlannerInfo *root, List *joinrestrictclauses = gpath->joinrestrictinfo; List *joinclauses; CustomScan *cscan; + +#if PG_VERSION_NUM >= 90600 PathTarget *target; +#else + List *target; +#endif Assert(!IS_OUTER_JOIN(gpath->jointype)); joinclauses = extract_actual_clauses(joinrestrictclauses, false); @@ -459,12 +486,20 @@ create_crossmatch_plan(PlannerInfo *root, cscan->scan.plan.qual = joinclauses; cscan->scan.scanrelid = 0; +#if PG_VERSION_NUM >= 90600 /* Add Vars needed for our extended 'joinclauses' */ target = copy_pathtarget(rel->reltarget); add_new_columns_to_pathtarget(target, pull_var_clause((Node *) joinclauses, 0)); /* tlist of the 'virtual' join rel we'll have to build and scan */ cscan->custom_scan_tlist = make_tlist_from_pathtarget(target); +#else + target = list_copy(tlist); + target = add_to_flat_tlist(target, pull_var_clause((Node *) joinclauses, + PVC_REJECT_AGGREGATES, + PVC_REJECT_PLACEHOLDERS)); + cscan->custom_scan_tlist = target; +#endif cscan->flags = best_path->flags; cscan->methods = &crossmatch_plan_methods; From b3dcc77bab58c53c3cb4938cc7da227b59b14312 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 22 Mar 2016 14:53:10 +0300 Subject: [PATCH 35/41] remove fixed TODO --- init.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/init.c b/init.c index 286b471..1c8e758 100644 --- a/init.c +++ b/init.c @@ -188,10 +188,6 @@ get_const_val(Const *node) return DatumGetFloat8(FunctionCall1(&finfo, node->constvalue)); } -/* - * TODO: check for the predicates & decide - * whether some partial indices may suffice - */ static Oid pick_suitable_index(RelOptInfo *relation, AttrNumber column) { From 67a4d04cd389ebda79bb9d6513bd0553db1ee1aa Mon Sep 17 00:00:00 2001 From: Markus Nullmeier Date: Tue, 11 Apr 2017 20:29:48 +0200 Subject: [PATCH 36/41] adapt to API change in PostgreSQL 9.6 --- init.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/init.c b/init.c index 1c8e758..cf51504 100644 --- a/init.c +++ b/init.c @@ -24,6 +24,10 @@ #include "access/htup_details.h" #include "access/heapam.h" +#if PG_VERSION_NUM >= 90600 +#include "nodes/extensible.h" +#endif + #include "point.h" #include "crossmatch.h" From e91555b028d18a2968503d088e4104d5ef033eb8 Mon Sep 17 00:00:00 2001 From: Markus Nullmeier Date: Tue, 11 Apr 2017 22:32:55 +0200 Subject: [PATCH 37/41] add missing PG_FUNCTION_INFO_V1 found by building with PG 10 --- box.c | 1 + 1 file changed, 1 insertion(+) diff --git a/box.c b/box.c index 464bba7..98bc1a7 100644 --- a/box.c +++ b/box.c @@ -37,6 +37,7 @@ PG_FUNCTION_INFO_V1(spherebox_overlap_line_com_neg); PG_FUNCTION_INFO_V1(spherebox_cont_path); PG_FUNCTION_INFO_V1(spherebox_cont_path_neg); PG_FUNCTION_INFO_V1(spherebox_cont_eq_path_com); +PG_FUNCTION_INFO_V1(spherebox_cont_path_com); PG_FUNCTION_INFO_V1(spherebox_cont_path_com_neg); PG_FUNCTION_INFO_V1(spherebox_overlap_path); PG_FUNCTION_INFO_V1(spherebox_overlap_path_neg); From 3a900cceeccff23665bfeeebbc549ef046bc8d24 Mon Sep 17 00:00:00 2001 From: Markus Nullmeier Date: Wed, 12 Apr 2017 00:15:45 +0200 Subject: [PATCH 38/41] add simple crossmatch test --- Makefile | 3 +- data/test_spherepointx.data | 24 +++++++ expected/crossmatch.out | 127 ++++++++++++++++++++++++++++++++++++ expected/index.out | 5 ++ expected/tables.out | 2 + sql/crossmatch.sql | 60 +++++++++++++++++ sql/index.sql | 6 ++ sql/tables.sql | 3 + 8 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 data/test_spherepointx.data create mode 100644 expected/crossmatch.out create mode 100644 sql/crossmatch.sql diff --git a/Makefile b/Makefile index e310e89..5c5e00c 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,8 @@ EXTENSION = pg_sphere DATA_built = pg_sphere--1.0.sql DOCS = README.pg_sphere COPYRIGHT.pg_sphere REGRESS = init tables points euler circle line ellipse poly path box index \ - contains_ops contains_ops_compat bounding_box_gist gnomo + contains_ops contains_ops_compat bounding_box_gist gnomo \ + crossmatch EXTRA_CLEAN = pg_sphere--1.0.sql $(PGS_SQL) diff --git a/data/test_spherepointx.data b/data/test_spherepointx.data new file mode 100644 index 0000000..d44f41f --- /dev/null +++ b/data/test_spherepointx.data @@ -0,0 +1,24 @@ +(1.33,0.61) +(-0.43,-0.17) +(2.35,0.65) +(-0.93,-0.29) +(-0.99,0.92) +(1.87,0.11) +(1.43,0.82) +(2.19,0.94) +(0.13,0.34) +(0.92,-0.19) +(0.42,0.56) +(-1.7,-0.77) +(1.88,-0.45) +(0.51,0.10) +(0.54,0.26) +(-2.94,1.04) +(1.44,0.52) +(0.38,0.03) +(1.95,1.33) +(3.11,0.63) +(-1.84,-0.18) +(-3.36,-0.55) +(-2.42,0.06) +\. diff --git a/expected/crossmatch.out b/expected/crossmatch.out new file mode 100644 index 0000000..573020d --- /dev/null +++ b/expected/crossmatch.out @@ -0,0 +1,127 @@ +SET enable_indexscan = OFF; +SET enable_seqscan = ON; +EXPLAIN (COSTS OFF) +SELECT count(*) +FROM spheretmp1 t1 JOIN spheretmpx tx ON dist(t1.p, tx.p) < 0.03; + QUERY PLAN +-------------------------------------------------------------------- + Aggregate + -> Nested Loop + Join Filter: (dist(t1.p, tx.p) < '0.03'::double precision) + -> Seq Scan on spheretmpx tx + -> Materialize + -> Seq Scan on spheretmp1 t1 +(6 rows) + +SELECT count(*) +FROM spheretmp1 t1 JOIN spheretmpx tx ON dist(t1.p, tx.p) < 0.03; + count +------- + 44 +(1 row) + +SELECT DISTINCT concat_ws(', ', t1.p, tx.p) AS xm +FROM spheretmp1 t1 JOIN spheretmpx tx ON dist(t1.p, tx.p) < 0.03 ORDER BY xm; + xm +-------------------------------------------------------- + (0.13 , 0.34), (0.13 , 0.34) + (0.38 , 0.04), (0.38 , 0.03) + (0.55 , 0.27), (0.54 , 0.26) + (1.32 , 0.61), (1.33 , 0.61) + (1.85 , -0.46), (1.88 , -0.45) + (1.89 , 0.1), (1.87 , 0.11) + (1.94 , 1.33), (1.95 , 1.33) + (2.19 , 0.94), (2.19 , 0.94) + (3.34318530717959 , 1.05), (3.34318530717959 , 1.04) + (3.87318530717959 , 0.05), (3.86318530717959 , 0.06) + (5.88318530717959 , -0.17), (5.85318530717959 , -0.17) +(11 rows) + +SET enable_seqscan = OFF; +SET enable_indexscan = ON; +CREATE INDEX idx_spoint1_1 ON spheretmp1 USING gist (p spoint); +CREATE INDEX idx_spoint1_x ON spheretmpx USING gist (p spoint); +ANALYZE spheretmp1; +ANALYZE spheretmpx; +EXPLAIN (COSTS OFF) +SELECT count(*) +FROM spheretmp1 t1 JOIN spheretmpx tx ON t1.p <@ scircle(tx.p, 0.03); + QUERY PLAN +-------------------------------------------------------------------------- + Aggregate + -> Nested Loop + -> Seq Scan on spheretmpx tx + -> Index Scan using idx_spoint1_1 on spheretmp1 t1 + Index Cond: (p <@ scircle(tx.p, '0.03'::double precision)) +(5 rows) + +SELECT count(*) +FROM spheretmp1 t1 JOIN spheretmpx tx ON t1.p <@ scircle(tx.p, 0.03); + count +------- + 44 +(1 row) + +SELECT DISTINCT concat_ws(', ', t1.p, tx.p) AS xm +FROM spheretmp1 t1 JOIN spheretmpx tx ON t1.p <@ scircle(tx.p, 0.03) ORDER BY xm; + xm +-------------------------------------------------------- + (0.13 , 0.34), (0.13 , 0.34) + (0.38 , 0.04), (0.38 , 0.03) + (0.55 , 0.27), (0.54 , 0.26) + (1.32 , 0.61), (1.33 , 0.61) + (1.85 , -0.46), (1.88 , -0.45) + (1.89 , 0.1), (1.87 , 0.11) + (1.94 , 1.33), (1.95 , 1.33) + (2.19 , 0.94), (2.19 , 0.94) + (3.34318530717959 , 1.05), (3.34318530717959 , 1.04) + (3.87318530717959 , 0.05), (3.86318530717959 , 0.06) + (5.88318530717959 , -0.17), (5.85318530717959 , -0.17) +(11 rows) + +DROP INDEX idx_spoint1_1; +DROP INDEX idx_spoint1_x; +CREATE INDEX idx_spoint2_1 ON spheretmp1 USING gist (p spoint2); +CREATE INDEX idx_spoint2_x ON spheretmpx USING gist (p spoint2); +ANALYZE spheretmp1; +ANALYZE spheretmpx; +EXPLAIN (COSTS OFF) +SELECT count(*) +FROM spheretmp1 t1 JOIN spheretmpx tx ON dist(t1.p, tx.p) < 0.03; + QUERY PLAN +------------------------------------ + Aggregate + -> Custom Scan (CrossmatchJoin) + Outer index: idx_spoint2_1 + Inner index: idx_spoint2_x + Threshold: 0.03 +(5 rows) + +SELECT count(*) +FROM spheretmp1 t1 JOIN spheretmpx tx ON dist(t1.p, tx.p) < 0.03; + count +------- + 44 +(1 row) + +SELECT DISTINCT concat_ws(', ', t1.p, tx.p) AS xm +FROM spheretmp1 t1 JOIN spheretmpx tx ON dist(t1.p, tx.p) < 0.03 ORDER BY xm; + xm +-------------------------------------------------------- + (0.13 , 0.34), (0.13 , 0.34) + (0.38 , 0.04), (0.38 , 0.03) + (0.55 , 0.27), (0.54 , 0.26) + (1.32 , 0.61), (1.33 , 0.61) + (1.85 , -0.46), (1.88 , -0.45) + (1.89 , 0.1), (1.87 , 0.11) + (1.94 , 1.33), (1.95 , 1.33) + (2.19 , 0.94), (2.19 , 0.94) + (3.34318530717959 , 1.05), (3.34318530717959 , 1.04) + (3.87318530717959 , 0.05), (3.86318530717959 , 0.06) + (5.88318530717959 , -0.17), (5.85318530717959 , -0.17) +(11 rows) + +SET enable_seqscan = ON; +SET enable_indexscan = ON; +DROP INDEX idx_spoint2_1; +DROP INDEX idx_spoint2_x; diff --git a/expected/index.out b/expected/index.out index 24355c3..54111a4 100644 --- a/expected/index.out +++ b/expected/index.out @@ -108,3 +108,8 @@ SELECT count(*) FROM spheretmp4 WHERE l && scircle '<(1,1),0.3>' ; 40 (1 row) +DROP INDEX aaaidx; +DROP INDEX bbbidx; +DROP INDEX cccidx; +DROP INDEX dddidx; +SET enable_seqscan = ON; diff --git a/expected/tables.out b/expected/tables.out index eb6f1a3..ad32bd8 100644 --- a/expected/tables.out +++ b/expected/tables.out @@ -5,6 +5,8 @@ CREATE TABLE spheretmp1 (p spoint); \copy spheretmp1 from 'data/test_spherepoint.data' \copy spheretmp1 from 'data/test_spherepoint.data' \copy spheretmp1 from 'data/test_spherepoint.data' +CREATE TABLE spheretmpx (p spoint); +\copy spheretmpx from 'data/test_spherepointx.data' CREATE TABLE spheretmp2 (c scircle); \copy spheretmp2 from 'data/test_spherecircle.data' \copy spheretmp2 from 'data/test_spherecircle.data' diff --git a/sql/crossmatch.sql b/sql/crossmatch.sql new file mode 100644 index 0000000..835974f --- /dev/null +++ b/sql/crossmatch.sql @@ -0,0 +1,60 @@ +SET enable_indexscan = OFF; +SET enable_seqscan = ON; + +EXPLAIN (COSTS OFF) +SELECT count(*) +FROM spheretmp1 t1 JOIN spheretmpx tx ON dist(t1.p, tx.p) < 0.03; + +SELECT count(*) +FROM spheretmp1 t1 JOIN spheretmpx tx ON dist(t1.p, tx.p) < 0.03; + +SELECT DISTINCT concat_ws(', ', t1.p, tx.p) AS xm +FROM spheretmp1 t1 JOIN spheretmpx tx ON dist(t1.p, tx.p) < 0.03 ORDER BY xm; + + + +SET enable_seqscan = OFF; +SET enable_indexscan = ON; + +CREATE INDEX idx_spoint1_1 ON spheretmp1 USING gist (p spoint); +CREATE INDEX idx_spoint1_x ON spheretmpx USING gist (p spoint); + +ANALYZE spheretmp1; +ANALYZE spheretmpx; + +EXPLAIN (COSTS OFF) +SELECT count(*) +FROM spheretmp1 t1 JOIN spheretmpx tx ON t1.p <@ scircle(tx.p, 0.03); + +SELECT count(*) +FROM spheretmp1 t1 JOIN spheretmpx tx ON t1.p <@ scircle(tx.p, 0.03); + +SELECT DISTINCT concat_ws(', ', t1.p, tx.p) AS xm +FROM spheretmp1 t1 JOIN spheretmpx tx ON t1.p <@ scircle(tx.p, 0.03) ORDER BY xm; + +DROP INDEX idx_spoint1_1; +DROP INDEX idx_spoint1_x; + + + +CREATE INDEX idx_spoint2_1 ON spheretmp1 USING gist (p spoint2); +CREATE INDEX idx_spoint2_x ON spheretmpx USING gist (p spoint2); + +ANALYZE spheretmp1; +ANALYZE spheretmpx; + +EXPLAIN (COSTS OFF) +SELECT count(*) +FROM spheretmp1 t1 JOIN spheretmpx tx ON dist(t1.p, tx.p) < 0.03; + +SELECT count(*) +FROM spheretmp1 t1 JOIN spheretmpx tx ON dist(t1.p, tx.p) < 0.03; + +SELECT DISTINCT concat_ws(', ', t1.p, tx.p) AS xm +FROM spheretmp1 t1 JOIN spheretmpx tx ON dist(t1.p, tx.p) < 0.03 ORDER BY xm; + +SET enable_seqscan = ON; +SET enable_indexscan = ON; + +DROP INDEX idx_spoint2_1; +DROP INDEX idx_spoint2_x; diff --git a/sql/index.sql b/sql/index.sql index c4612c2..13ad9de 100644 --- a/sql/index.sql +++ b/sql/index.sql @@ -51,3 +51,9 @@ SELECT count(*) FROM spheretmp4 WHERE l @ scircle '<(1,1),0.3>' ; SELECT count(*) FROM spheretmp4 WHERE l && scircle '<(1,1),0.3>' ; +DROP INDEX aaaidx; +DROP INDEX bbbidx; +DROP INDEX cccidx; +DROP INDEX dddidx; + +SET enable_seqscan = ON; diff --git a/sql/tables.sql b/sql/tables.sql index d928a28..262ab3a 100644 --- a/sql/tables.sql +++ b/sql/tables.sql @@ -9,6 +9,9 @@ CREATE TABLE spheretmp1 (p spoint); \copy spheretmp1 from 'data/test_spherepoint.data' \copy spheretmp1 from 'data/test_spherepoint.data' +CREATE TABLE spheretmpx (p spoint); +\copy spheretmpx from 'data/test_spherepointx.data' + CREATE TABLE spheretmp2 (c scircle); \copy spheretmp2 from 'data/test_spherecircle.data' From cd8da521c96e0739f180754fc1db9159550feea8 Mon Sep 17 00:00:00 2001 From: Markus Nullmeier Date: Wed, 12 Apr 2017 01:34:28 +0200 Subject: [PATCH 39/41] adapt custom crossmatch executor node to PostgreSQL 10 Due to changes in the executor of the upcoming PostgreSQL 10, the API changes for set returning expressions in commits 69f4b9c85f168ae006929eec44fc44d569e846b9, ea15e18677fc2eff3135023e27f69ed8821554ed, and b8d7f053c5c2bf2a7e8734fe3327f6a8bc711755 of the PostgreSQL git repository required some adaption in init.c. For details, see the respective commits and especially their commit messages, and also the discussion starting at https://postgr.es/m/20160822214023.aaxz5l4igypowyri@alap3.anarazel.de --- init.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/init.c b/init.c index cf51504..5dbf7a2 100644 --- a/init.c +++ b/init.c @@ -28,6 +28,10 @@ #include "nodes/extensible.h" #endif +#if PG_VERSION_NUM >= 100000 +#include "utils/regproc.h" +#endif + #include "point.h" #include "crossmatch.h" @@ -651,6 +655,14 @@ fetch_next_pair(CrossmatchScanState *scan_state) return FetchTidPairReady; } +#if PG_VERSION_NUM < 100000 +#define COMPAT_PROJECT_ARG , &isDone +#define COMPAT_QUAL_ARG , false +#else +#define COMPAT_PROJECT_ARG +#define COMPAT_QUAL_ARG +#endif + static TupleTableSlot * crossmatch_exec(CustomScanState *node) { @@ -659,7 +671,11 @@ crossmatch_exec(CustomScanState *node) for (;;) { +#if PG_VERSION_NUM < 100000 + ExprDoneCond isDone; + if (!node->ss.ps.ps_TupFromTlist) +#endif { FetchTidPairState fetch_state; @@ -675,33 +691,38 @@ crossmatch_exec(CustomScanState *node) if (node->ss.ps.ps_ProjInfo) { - ExprDoneCond isDone; TupleTableSlot *resultSlot; ResetExprContext(node->ss.ps.ps_ProjInfo->pi_exprContext); node->ss.ps.ps_ProjInfo->pi_exprContext->ecxt_scantuple = scanSlot; - resultSlot = ExecProject(node->ss.ps.ps_ProjInfo, &isDone); - + resultSlot = ExecProject(node->ss.ps.ps_ProjInfo + COMPAT_PROJECT_ARG); +#if PG_VERSION_NUM < 100000 if (isDone != ExprEndResult) { node->ss.ps.ps_TupFromTlist = (isDone == ExprMultipleResult); +#endif /* Check join conditions */ node->ss.ps.ps_ExprContext->ecxt_scantuple = scanSlot; - if (ExecQual(node->ss.ps.qual, node->ss.ps.ps_ExprContext, false)) + if (ExecQual(node->ss.ps.qual, node->ss.ps.ps_ExprContext + COMPAT_QUAL_ARG)) return resultSlot; else InstrCountFiltered1(node, 1); +#if PG_VERSION_NUM < 100000 } else node->ss.ps.ps_TupFromTlist = false; +#endif } else { /* Check join conditions */ node->ss.ps.ps_ExprContext->ecxt_scantuple = scanSlot; - if (ExecQual(node->ss.ps.qual, node->ss.ps.ps_ExprContext, false)) + if (ExecQual(node->ss.ps.qual, node->ss.ps.ps_ExprContext + COMPAT_QUAL_ARG)) return scanSlot; else InstrCountFiltered1(node, 1); @@ -723,8 +744,10 @@ crossmatch_end(CustomScanState *node) static void crossmatch_rescan(CustomScanState *node) { +#if PG_VERSION_NUM < 100000 /* NOTE: nothing to do here? */ node->ss.ps.ps_TupFromTlist = false; +#endif } static void From ff0453fccd5951b027d073d9bdc62403b463faf4 Mon Sep 17 00:00:00 2001 From: Andrey Borodin Date: Tue, 25 Apr 2017 17:40:25 +0500 Subject: [PATCH 40/41] remove small allocation from crossmatch() --- crossmatch.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crossmatch.c b/crossmatch.c index 9ff46a4..3cd6f82 100644 --- a/crossmatch.c +++ b/crossmatch.c @@ -878,14 +878,12 @@ crossmatch(CrossmatchContext *ctx, ItemPointer values) /* Return next result pair if any. Otherwise close SRF. */ if (ctx->resultsPairs != NIL) { - ResultPair *itemPointerPair = (ResultPair *) palloc(sizeof(ResultPair)); - - *itemPointerPair = *((ResultPair *) linitial(ctx->resultsPairs)); + ResultPair itemPointerPair = *((ResultPair *) linitial(ctx->resultsPairs)); pfree(linitial(ctx->resultsPairs)); ctx->resultsPairs = list_delete_first(ctx->resultsPairs); - values[0] = itemPointerPair->iptr1; - values[1] = itemPointerPair->iptr2; + values[0] = itemPointerPair.iptr1; + values[1] = itemPointerPair.iptr2; } else { From 5a146eea240c9e2641e7eb1ea5e01bc202e47fd5 Mon Sep 17 00:00:00 2001 From: Andrey Borodin Date: Wed, 26 Apr 2017 13:32:14 +0500 Subject: [PATCH 41/41] set temporary tup flag in tuple table slot --- init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.c b/init.c index 5dbf7a2..6aea9cb 100644 --- a/init.c +++ b/init.c @@ -644,7 +644,7 @@ fetch_next_pair(CrossmatchScanState *scan_state) htup = heap_form_tuple(tupdesc, values, nulls); /* Fill scanSlot with a new tuple */ - ExecStoreTuple(htup, slot, InvalidBuffer, false); + ExecStoreTuple(htup, slot, InvalidBuffer, true); } if (buf1 != InvalidBuffer)