1/** \file 2 * This C source file was generated by $ANTLR version 3.2 debian-5 3 * 4 * - From the grammar source file : RSP2SQL.g 5 * - On : 2011-09-11 15:48:52 6 * - for the tree parser : RSP2SQLTreeParser * 7 * Editing it, at least manually, is not wise. 8 * 9 * C language generator and runtime by Jim Idle, jimi|hereisanat|idle|dotgoeshere|ws. 10 * 11 * 12*/ 13// [The "BSD licence"] 14// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC 15// http://www.temporal-wave.com 16// http://www.linkedin.com/in/jimidle 17// 18// All rights reserved. 19// 20// Redistribution and use in source and binary forms, with or without 21// modification, are permitted provided that the following conditions 22// are met: 23// 1. Redistributions of source code must retain the above copyright 24// notice, this list of conditions and the following disclaimer. 25// 2. Redistributions in binary form must reproduce the above copyright 26// notice, this list of conditions and the following disclaimer in the 27// documentation and/or other materials provided with the distribution. 28// 3. The name of the author may not be used to endorse or promote products 29// derived from this software without specific prior written permission. 30// 31// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 32// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 33// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 34// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 35// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 36// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 37// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 38// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 40// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 42 43/* ============================================================================= 44 * This is what the grammar programmer asked us to put at the top of every file. 45 */ 46 47 /* Needs #define _GNU_SOURCE for strptime() */ 48 49 #include <stdio.h> 50 #include <string.h> 51 #include <time.h> 52 #include <stdint.h> 53 54 #include "logger.h" 55 #include "db.h" 56 #include "misc.h" 57 #include "rsp_query.h" 58 59/* End of Header action. 60 * ============================================================================= 61 */ 62/* ----------------------------------------- 63 * Include the ANTLR3 generated header file. 64 */ 65#include "RSP2SQL.h" 66/* ----------------------------------------- */ 67 68 69 70 71 72/* MACROS that hide the C interface implementations from the 73 * generated code, which makes it a little more understandable to the human eye. 74 * I am very much against using C pre-processor macros for function calls and bits 75 * of code as you cannot see what is happening when single stepping in debuggers 76 * and so on. The exception (in my book at least) is for generated code, where you are 77 * not maintaining it, but may wish to read and understand it. If you single step it, you know that input() 78 * hides some indirect calls, but is always referring to the input stream. This is 79 * probably more readable than ctx->input->istream->input(snarfle0->blarg) and allows me to rejig 80 * the runtime interfaces without changing the generated code too often, without 81 * confusing the reader of the generated output, who may not wish to know the gory 82 * details of the interface inheritance. 83 */ 84 85#define CTX ctx 86 87/* Aids in accessing scopes for grammar programmers 88 */ 89#undef SCOPE_TYPE 90#undef SCOPE_STACK 91#undef SCOPE_TOP 92#define SCOPE_TYPE(scope) pRSP2SQL_##scope##_SCOPE 93#define SCOPE_STACK(scope) pRSP2SQL_##scope##Stack 94#define SCOPE_TOP(scope) ctx->pRSP2SQL_##scope##Top 95#define SCOPE_SIZE(scope) ctx->pRSP2SQL_##scope##Stack_limit 96#define SCOPE_INSTANCE(scope, i) (ctx->SCOPE_STACK(scope)->get(ctx->SCOPE_STACK(scope),i)) 97 98/* Macros for accessing things in the parser 99 */ 100 101#undef PARSER 102#undef RECOGNIZER 103#undef HAVEPARSEDRULE 104#undef INPUT 105#undef STRSTREAM 106#undef HASEXCEPTION 107#undef EXCEPTION 108#undef MATCHT 109#undef MATCHANYT 110#undef FOLLOWSTACK 111#undef FOLLOWPUSH 112#undef FOLLOWPOP 113#undef PRECOVER 114#undef PREPORTERROR 115#undef LA 116#undef LT 117#undef CONSTRUCTEX 118#undef CONSUME 119#undef MARK 120#undef REWIND 121#undef REWINDLAST 122#undef PERRORRECOVERY 123#undef HASFAILED 124#undef FAILEDFLAG 125#undef RECOVERFROMMISMATCHEDSET 126#undef RECOVERFROMMISMATCHEDELEMENT 127#undef BACKTRACKING 128#undef ADAPTOR 129#undef RULEMEMO 130#undef SEEK 131#undef INDEX 132#undef DBG 133 134#define PARSER ctx->pTreeParser 135#define RECOGNIZER PARSER->rec 136#define PSRSTATE RECOGNIZER->state 137#define HAVEPARSEDRULE(r) RECOGNIZER->alreadyParsedRule(RECOGNIZER, r) 138#define INPUT PARSER->ctnstream 139#define ISTREAM INPUT->tnstream->istream 140#define STRSTREAM INPUT->tnstream 141#define HASEXCEPTION() (PSRSTATE->error == ANTLR3_TRUE) 142#define EXCEPTION PSRSTATE->exception 143#define MATCHT(t, fs) RECOGNIZER->match(RECOGNIZER, t, fs) 144#define MATCHANYT() RECOGNIZER->matchAny(RECOGNIZER) 145#define FOLLOWSTACK PSRSTATE->following 146#define FOLLOWPUSH(x) FOLLOWSTACK->push(FOLLOWSTACK, ((void *)(&(x))), NULL) 147#define FOLLOWPOP() FOLLOWSTACK->pop(FOLLOWSTACK) 148#define PRECOVER() RECOGNIZER->recover(RECOGNIZER) 149#define PREPORTERROR() RECOGNIZER->reportError(RECOGNIZER) 150#define LA(n) ISTREAM->_LA(ISTREAM, n) 151#define LT(n) INPUT->tnstream->_LT(INPUT->tnstream, n) 152#define CONSTRUCTEX() RECOGNIZER->exConstruct(RECOGNIZER) 153#define CONSUME() ISTREAM->consume(ISTREAM) 154#define MARK() ISTREAM->mark(ISTREAM) 155#define REWIND(m) ISTREAM->rewind(ISTREAM, m) 156#define REWINDLAST() ISTREAM->rewindLast(ISTREAM) 157#define PERRORRECOVERY PSRSTATE->errorRecovery 158#define FAILEDFLAG PSRSTATE->failed 159#define HASFAILED() (FAILEDFLAG == ANTLR3_TRUE) 160#define BACKTRACKING PSRSTATE->backtracking 161#define RECOVERFROMMISMATCHEDSET(s) RECOGNIZER->recoverFromMismatchedSet(RECOGNIZER, s) 162#define RECOVERFROMMISMATCHEDELEMENT(e) RECOGNIZER->recoverFromMismatchedElement(RECOGNIZER, s) 163#define ADAPTOR INPUT->adaptor 164#define RULEMEMO PSRSTATE->ruleMemo 165#define SEEK(n) ISTREAM->seek(ISTREAM, n) 166#define INDEX() ISTREAM->index(ISTREAM) 167#define DBG RECOGNIZER->debugger 168 169 170#define TOKTEXT(tok, txt) tok, (pANTLR3_UINT8)txt 171 172/* The 4 tokens defined below may well clash with your own #defines or token types. If so 173 * then for the present you must use different names for your defines as these are hard coded 174 * in the code generator. It would be better not to use such names internally, and maybe 175 * we can change this in a forthcoming release. I deliberately do not #undef these 176 * here as this will at least give you a redefined error somewhere if they clash. 177 */ 178#define UP ANTLR3_TOKEN_UP 179#define DOWN ANTLR3_TOKEN_DOWN 180#define EOR ANTLR3_TOKEN_EOR 181#define INVALID ANTLR3_TOKEN_INVALID 182 183 184/* ============================================================================= 185 * Functions to create and destroy scopes. First come the rule scopes, followed 186 * by the global declared scopes. 187 */ 188 189 190 191/* ============================================================================= */ 192 193/* ============================================================================= 194 * Start of recognizer 195 */ 196 197 198 199/** \brief Table of all token names in symbolic order, mainly used for 200 * error reporting. 201 */ 202pANTLR3_UINT8 RSP2SQLTokenNames[30+4] 203 = { 204 (pANTLR3_UINT8) "<invalid>", /* String to print to indicate an invalid token */ 205 (pANTLR3_UINT8) "<EOR>", 206 (pANTLR3_UINT8) "<DOWN>", 207 (pANTLR3_UINT8) "<UP>", 208 (pANTLR3_UINT8) "NEWLINE", 209 (pANTLR3_UINT8) "OR", 210 (pANTLR3_UINT8) "AND", 211 (pANTLR3_UINT8) "LPAR", 212 (pANTLR3_UINT8) "RPAR", 213 (pANTLR3_UINT8) "FIELD", 214 (pANTLR3_UINT8) "STR", 215 (pANTLR3_UINT8) "NOT", 216 (pANTLR3_UINT8) "EQUAL", 217 (pANTLR3_UINT8) "INCLUDES", 218 (pANTLR3_UINT8) "STARTSW", 219 (pANTLR3_UINT8) "ENDSW", 220 (pANTLR3_UINT8) "INT", 221 (pANTLR3_UINT8) "LESS", 222 (pANTLR3_UINT8) "GREATER", 223 (pANTLR3_UINT8) "LTE", 224 (pANTLR3_UINT8) "GTE", 225 (pANTLR3_UINT8) "BEFORE", 226 (pANTLR3_UINT8) "AFTER", 227 (pANTLR3_UINT8) "DATE", 228 (pANTLR3_UINT8) "TODAY", 229 (pANTLR3_UINT8) "DAY", 230 (pANTLR3_UINT8) "WEEK", 231 (pANTLR3_UINT8) "MONTH", 232 (pANTLR3_UINT8) "YEAR", 233 (pANTLR3_UINT8) "QUOTE", 234 (pANTLR3_UINT8) "WS", 235 (pANTLR3_UINT8) "DIGIT19", 236 (pANTLR3_UINT8) "DIGIT09", 237 (pANTLR3_UINT8) "ESCAPED" 238 }; 239 240 241 242// Forward declare the locally static matching functions we have generated. 243// 244static pANTLR3_STRING query (pRSP2SQL ctx); 245static RSP2SQL_expr_return expr (pRSP2SQL ctx); 246static RSP2SQL_strcrit_return strcrit (pRSP2SQL ctx); 247static pANTLR3_COMMON_TOKEN strop (pRSP2SQL ctx); 248static RSP2SQL_intcrit_return intcrit (pRSP2SQL ctx); 249static pANTLR3_COMMON_TOKEN intop (pRSP2SQL ctx); 250static RSP2SQL_datecrit_return datecrit (pRSP2SQL ctx); 251static pANTLR3_COMMON_TOKEN dateop (pRSP2SQL ctx); 252static RSP2SQL_datespec_return datespec (pRSP2SQL ctx); 253static RSP2SQL_dateref_return dateref (pRSP2SQL ctx); 254static RSP2SQL_dateintval_return dateintval (pRSP2SQL ctx); 255static void RSP2SQLFree(pRSP2SQL ctx); 256/* For use in tree output where we are accumulating rule labels via label += ruleRef 257 * we need a function that knows how to free a return scope when the list is destroyed. 258 * We cannot just use ANTLR3_FREE because in debug tracking mode, this is a macro. 259 */ 260static void ANTLR3_CDECL freeScope(void * scope) 261{ 262 ANTLR3_FREE(scope); 263} 264 265/** \brief Name of the grammar file that generated this code 266 */ 267static const char fileName[] = "RSP2SQL.g"; 268 269/** \brief Return the name of the grammar file that generated this code. 270 */ 271static const char * getGrammarFileName() 272{ 273 return fileName; 274} 275/** \brief Create a new RSP2SQL parser and return a context for it. 276 * 277 * \param[in] instream Pointer to an input stream interface. 278 * 279 * \return Pointer to new parser context upon success. 280 */ 281ANTLR3_API pRSP2SQL 282RSP2SQLNew (pANTLR3_COMMON_TREE_NODE_STREAM instream) 283{ 284 // See if we can create a new parser with the standard constructor 285 // 286 return RSP2SQLNewSSD(instream, NULL); 287} 288 289/** \brief Create a new RSP2SQL parser and return a context for it. 290 * 291 * \param[in] instream Pointer to an input stream interface. 292 * 293 * \return Pointer to new parser context upon success. 294 */ 295ANTLR3_API pRSP2SQL 296RSP2SQLNewSSD (pANTLR3_COMMON_TREE_NODE_STREAM instream, pANTLR3_RECOGNIZER_SHARED_STATE state) 297{ 298 pRSP2SQL ctx; /* Context structure we will build and return */ 299 300 ctx = (pRSP2SQL) ANTLR3_CALLOC(1, sizeof(RSP2SQL)); 301 302 if (ctx == NULL) 303 { 304 // Failed to allocate memory for parser context 305 // 306 return NULL; 307 } 308 309 /* ------------------------------------------------------------------- 310 * Memory for basic structure is allocated, now to fill in 311 * the base ANTLR3 structures. We initialize the function pointers 312 * for the standard ANTLR3 parser function set, but upon return 313 * from here, the programmer may set the pointers to provide custom 314 * implementations of each function. 315 * 316 * We don't use the macros defined in RSP2SQL.h here, in order that you can get a sense 317 * of what goes where. 318 */ 319 320 /* Create a base Tree parser/recognizer, using the supplied tree node stream 321 */ 322 ctx->pTreeParser = antlr3TreeParserNewStream(ANTLR3_SIZE_HINT, instream, state); 323 /* Install the implementation of our RSP2SQL interface 324 */ 325 ctx->query = query; 326 ctx->expr = expr; 327 ctx->strcrit = strcrit; 328 ctx->strop = strop; 329 ctx->intcrit = intcrit; 330 ctx->intop = intop; 331 ctx->datecrit = datecrit; 332 ctx->dateop = dateop; 333 ctx->datespec = datespec; 334 ctx->dateref = dateref; 335 ctx->dateintval = dateintval; 336 ctx->free = RSP2SQLFree; 337 ctx->getGrammarFileName = getGrammarFileName; 338 339 /* Install the scope pushing methods. 340 */ 341 342 343 344 345 346 /* Install the token table 347 */ 348 PSRSTATE->tokenNames = RSP2SQLTokenNames; 349 350 351 /* Return the newly built parser to the caller 352 */ 353 return ctx; 354} 355 356/** Free the parser resources 357 */ 358 static void 359 RSP2SQLFree(pRSP2SQL ctx) 360 { 361 /* Free any scope memory 362 */ 363 364 365 // Free this parser 366 // 367 ctx->pTreeParser->free(ctx->pTreeParser); 368 ANTLR3_FREE(ctx); 369 370 /* Everything is released, so we can return 371 */ 372 return; 373 } 374 375/** Return token names used by this tree parser 376 * 377 * The returned pointer is used as an index into the token names table (using the token 378 * number as the index). 379 * 380 * \return Pointer to first char * in the table. 381 */ 382static pANTLR3_UINT8 *getTokenNames() 383{ 384 return RSP2SQLTokenNames; 385} 386 387 388 #define RSP_TYPE_STRING 0 389 #define RSP_TYPE_INT 1 390 #define RSP_TYPE_DATE 2 391 392 struct rsp_query_field_map { 393 char *rsp_field; 394 int field_type; 395 /* RSP fields are named after the DB columns - or vice versa */ 396 }; 397 398 /* gperf static hash, rsp_query.gperf */ 399 #include "rsp_query_hash.c" 400 401 402/* Declare the bitsets 403 */ 404 405/** Bitset defining follow set for error recovery in rule state: FOLLOW_expr_in_query70 */ 406static ANTLR3_BITWORD FOLLOW_expr_in_query70_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 407static ANTLR3_BITSET_LIST FOLLOW_expr_in_query70 = { FOLLOW_expr_in_query70_bits, 1 }; 408/** Bitset defining follow set for error recovery in rule state: FOLLOW_AND_in_expr95 */ 409static ANTLR3_BITWORD FOLLOW_AND_in_expr95_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000004) }; 410static ANTLR3_BITSET_LIST FOLLOW_AND_in_expr95 = { FOLLOW_AND_in_expr95_bits, 1 }; 411/** Bitset defining follow set for error recovery in rule state: FOLLOW_expr_in_expr101 */ 412static ANTLR3_BITWORD FOLLOW_expr_in_expr101_bits[] = { ANTLR3_UINT64_LIT(0x00000000007EF860) }; 413static ANTLR3_BITSET_LIST FOLLOW_expr_in_expr101 = { FOLLOW_expr_in_expr101_bits, 1 }; 414/** Bitset defining follow set for error recovery in rule state: FOLLOW_expr_in_expr107 */ 415static ANTLR3_BITWORD FOLLOW_expr_in_expr107_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000008) }; 416static ANTLR3_BITSET_LIST FOLLOW_expr_in_expr107 = { FOLLOW_expr_in_expr107_bits, 1 }; 417/** Bitset defining follow set for error recovery in rule state: FOLLOW_OR_in_expr118 */ 418static ANTLR3_BITWORD FOLLOW_OR_in_expr118_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000004) }; 419static ANTLR3_BITSET_LIST FOLLOW_OR_in_expr118 = { FOLLOW_OR_in_expr118_bits, 1 }; 420/** Bitset defining follow set for error recovery in rule state: FOLLOW_expr_in_expr124 */ 421static ANTLR3_BITWORD FOLLOW_expr_in_expr124_bits[] = { ANTLR3_UINT64_LIT(0x00000000007EF860) }; 422static ANTLR3_BITSET_LIST FOLLOW_expr_in_expr124 = { FOLLOW_expr_in_expr124_bits, 1 }; 423/** Bitset defining follow set for error recovery in rule state: FOLLOW_expr_in_expr130 */ 424static ANTLR3_BITWORD FOLLOW_expr_in_expr130_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000008) }; 425static ANTLR3_BITSET_LIST FOLLOW_expr_in_expr130 = { FOLLOW_expr_in_expr130_bits, 1 }; 426/** Bitset defining follow set for error recovery in rule state: FOLLOW_strcrit_in_expr144 */ 427static ANTLR3_BITWORD FOLLOW_strcrit_in_expr144_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 428static ANTLR3_BITSET_LIST FOLLOW_strcrit_in_expr144 = { FOLLOW_strcrit_in_expr144_bits, 1 }; 429/** Bitset defining follow set for error recovery in rule state: FOLLOW_NOT_in_expr154 */ 430static ANTLR3_BITWORD FOLLOW_NOT_in_expr154_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000004) }; 431static ANTLR3_BITSET_LIST FOLLOW_NOT_in_expr154 = { FOLLOW_NOT_in_expr154_bits, 1 }; 432/** Bitset defining follow set for error recovery in rule state: FOLLOW_strcrit_in_expr160 */ 433static ANTLR3_BITWORD FOLLOW_strcrit_in_expr160_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000008) }; 434static ANTLR3_BITSET_LIST FOLLOW_strcrit_in_expr160 = { FOLLOW_strcrit_in_expr160_bits, 1 }; 435/** Bitset defining follow set for error recovery in rule state: FOLLOW_intcrit_in_expr174 */ 436static ANTLR3_BITWORD FOLLOW_intcrit_in_expr174_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 437static ANTLR3_BITSET_LIST FOLLOW_intcrit_in_expr174 = { FOLLOW_intcrit_in_expr174_bits, 1 }; 438/** Bitset defining follow set for error recovery in rule state: FOLLOW_NOT_in_expr184 */ 439static ANTLR3_BITWORD FOLLOW_NOT_in_expr184_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000004) }; 440static ANTLR3_BITSET_LIST FOLLOW_NOT_in_expr184 = { FOLLOW_NOT_in_expr184_bits, 1 }; 441/** Bitset defining follow set for error recovery in rule state: FOLLOW_intcrit_in_expr190 */ 442static ANTLR3_BITWORD FOLLOW_intcrit_in_expr190_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000008) }; 443static ANTLR3_BITSET_LIST FOLLOW_intcrit_in_expr190 = { FOLLOW_intcrit_in_expr190_bits, 1 }; 444/** Bitset defining follow set for error recovery in rule state: FOLLOW_datecrit_in_expr204 */ 445static ANTLR3_BITWORD FOLLOW_datecrit_in_expr204_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 446static ANTLR3_BITSET_LIST FOLLOW_datecrit_in_expr204 = { FOLLOW_datecrit_in_expr204_bits, 1 }; 447/** Bitset defining follow set for error recovery in rule state: FOLLOW_strop_in_strcrit233 */ 448static ANTLR3_BITWORD FOLLOW_strop_in_strcrit233_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000004) }; 449static ANTLR3_BITSET_LIST FOLLOW_strop_in_strcrit233 = { FOLLOW_strop_in_strcrit233_bits, 1 }; 450/** Bitset defining follow set for error recovery in rule state: FOLLOW_FIELD_in_strcrit239 */ 451static ANTLR3_BITWORD FOLLOW_FIELD_in_strcrit239_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000400) }; 452static ANTLR3_BITSET_LIST FOLLOW_FIELD_in_strcrit239 = { FOLLOW_FIELD_in_strcrit239_bits, 1 }; 453/** Bitset defining follow set for error recovery in rule state: FOLLOW_STR_in_strcrit245 */ 454static ANTLR3_BITWORD FOLLOW_STR_in_strcrit245_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000008) }; 455static ANTLR3_BITSET_LIST FOLLOW_STR_in_strcrit245 = { FOLLOW_STR_in_strcrit245_bits, 1 }; 456/** Bitset defining follow set for error recovery in rule state: FOLLOW_EQUAL_in_strop274 */ 457static ANTLR3_BITWORD FOLLOW_EQUAL_in_strop274_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 458static ANTLR3_BITSET_LIST FOLLOW_EQUAL_in_strop274 = { FOLLOW_EQUAL_in_strop274_bits, 1 }; 459/** Bitset defining follow set for error recovery in rule state: FOLLOW_INCLUDES_in_strop287 */ 460static ANTLR3_BITWORD FOLLOW_INCLUDES_in_strop287_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 461static ANTLR3_BITSET_LIST FOLLOW_INCLUDES_in_strop287 = { FOLLOW_INCLUDES_in_strop287_bits, 1 }; 462/** Bitset defining follow set for error recovery in rule state: FOLLOW_STARTSW_in_strop300 */ 463static ANTLR3_BITWORD FOLLOW_STARTSW_in_strop300_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 464static ANTLR3_BITSET_LIST FOLLOW_STARTSW_in_strop300 = { FOLLOW_STARTSW_in_strop300_bits, 1 }; 465/** Bitset defining follow set for error recovery in rule state: FOLLOW_ENDSW_in_strop313 */ 466static ANTLR3_BITWORD FOLLOW_ENDSW_in_strop313_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 467static ANTLR3_BITSET_LIST FOLLOW_ENDSW_in_strop313 = { FOLLOW_ENDSW_in_strop313_bits, 1 }; 468/** Bitset defining follow set for error recovery in rule state: FOLLOW_intop_in_intcrit342 */ 469static ANTLR3_BITWORD FOLLOW_intop_in_intcrit342_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000004) }; 470static ANTLR3_BITSET_LIST FOLLOW_intop_in_intcrit342 = { FOLLOW_intop_in_intcrit342_bits, 1 }; 471/** Bitset defining follow set for error recovery in rule state: FOLLOW_FIELD_in_intcrit348 */ 472static ANTLR3_BITWORD FOLLOW_FIELD_in_intcrit348_bits[] = { ANTLR3_UINT64_LIT(0x0000000000010000) }; 473static ANTLR3_BITSET_LIST FOLLOW_FIELD_in_intcrit348 = { FOLLOW_FIELD_in_intcrit348_bits, 1 }; 474/** Bitset defining follow set for error recovery in rule state: FOLLOW_INT_in_intcrit354 */ 475static ANTLR3_BITWORD FOLLOW_INT_in_intcrit354_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000008) }; 476static ANTLR3_BITSET_LIST FOLLOW_INT_in_intcrit354 = { FOLLOW_INT_in_intcrit354_bits, 1 }; 477/** Bitset defining follow set for error recovery in rule state: FOLLOW_EQUAL_in_intop383 */ 478static ANTLR3_BITWORD FOLLOW_EQUAL_in_intop383_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 479static ANTLR3_BITSET_LIST FOLLOW_EQUAL_in_intop383 = { FOLLOW_EQUAL_in_intop383_bits, 1 }; 480/** Bitset defining follow set for error recovery in rule state: FOLLOW_LESS_in_intop396 */ 481static ANTLR3_BITWORD FOLLOW_LESS_in_intop396_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 482static ANTLR3_BITSET_LIST FOLLOW_LESS_in_intop396 = { FOLLOW_LESS_in_intop396_bits, 1 }; 483/** Bitset defining follow set for error recovery in rule state: FOLLOW_GREATER_in_intop409 */ 484static ANTLR3_BITWORD FOLLOW_GREATER_in_intop409_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 485static ANTLR3_BITSET_LIST FOLLOW_GREATER_in_intop409 = { FOLLOW_GREATER_in_intop409_bits, 1 }; 486/** Bitset defining follow set for error recovery in rule state: FOLLOW_LTE_in_intop422 */ 487static ANTLR3_BITWORD FOLLOW_LTE_in_intop422_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 488static ANTLR3_BITSET_LIST FOLLOW_LTE_in_intop422 = { FOLLOW_LTE_in_intop422_bits, 1 }; 489/** Bitset defining follow set for error recovery in rule state: FOLLOW_GTE_in_intop435 */ 490static ANTLR3_BITWORD FOLLOW_GTE_in_intop435_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 491static ANTLR3_BITSET_LIST FOLLOW_GTE_in_intop435 = { FOLLOW_GTE_in_intop435_bits, 1 }; 492/** Bitset defining follow set for error recovery in rule state: FOLLOW_dateop_in_datecrit464 */ 493static ANTLR3_BITWORD FOLLOW_dateop_in_datecrit464_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000004) }; 494static ANTLR3_BITSET_LIST FOLLOW_dateop_in_datecrit464 = { FOLLOW_dateop_in_datecrit464_bits, 1 }; 495/** Bitset defining follow set for error recovery in rule state: FOLLOW_FIELD_in_datecrit470 */ 496static ANTLR3_BITWORD FOLLOW_FIELD_in_datecrit470_bits[] = { ANTLR3_UINT64_LIT(0x0000000001FEF860) }; 497static ANTLR3_BITSET_LIST FOLLOW_FIELD_in_datecrit470 = { FOLLOW_FIELD_in_datecrit470_bits, 1 }; 498/** Bitset defining follow set for error recovery in rule state: FOLLOW_datespec_in_datecrit476 */ 499static ANTLR3_BITWORD FOLLOW_datespec_in_datecrit476_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000008) }; 500static ANTLR3_BITSET_LIST FOLLOW_datespec_in_datecrit476 = { FOLLOW_datespec_in_datecrit476_bits, 1 }; 501/** Bitset defining follow set for error recovery in rule state: FOLLOW_BEFORE_in_dateop505 */ 502static ANTLR3_BITWORD FOLLOW_BEFORE_in_dateop505_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 503static ANTLR3_BITSET_LIST FOLLOW_BEFORE_in_dateop505 = { FOLLOW_BEFORE_in_dateop505_bits, 1 }; 504/** Bitset defining follow set for error recovery in rule state: FOLLOW_AFTER_in_dateop518 */ 505static ANTLR3_BITWORD FOLLOW_AFTER_in_dateop518_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 506static ANTLR3_BITSET_LIST FOLLOW_AFTER_in_dateop518 = { FOLLOW_AFTER_in_dateop518_bits, 1 }; 507/** Bitset defining follow set for error recovery in rule state: FOLLOW_dateref_in_datespec546 */ 508static ANTLR3_BITWORD FOLLOW_dateref_in_datespec546_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 509static ANTLR3_BITSET_LIST FOLLOW_dateref_in_datespec546 = { FOLLOW_dateref_in_datespec546_bits, 1 }; 510/** Bitset defining follow set for error recovery in rule state: FOLLOW_dateop_in_datespec560 */ 511static ANTLR3_BITWORD FOLLOW_dateop_in_datespec560_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000004) }; 512static ANTLR3_BITSET_LIST FOLLOW_dateop_in_datespec560 = { FOLLOW_dateop_in_datespec560_bits, 1 }; 513/** Bitset defining follow set for error recovery in rule state: FOLLOW_dateref_in_datespec566 */ 514static ANTLR3_BITWORD FOLLOW_dateref_in_datespec566_bits[] = { ANTLR3_UINT64_LIT(0x0000000000010000) }; 515static ANTLR3_BITSET_LIST FOLLOW_dateref_in_datespec566 = { FOLLOW_dateref_in_datespec566_bits, 1 }; 516/** Bitset defining follow set for error recovery in rule state: FOLLOW_INT_in_datespec572 */ 517static ANTLR3_BITWORD FOLLOW_INT_in_datespec572_bits[] = { ANTLR3_UINT64_LIT(0x000000001E000000) }; 518static ANTLR3_BITSET_LIST FOLLOW_INT_in_datespec572 = { FOLLOW_INT_in_datespec572_bits, 1 }; 519/** Bitset defining follow set for error recovery in rule state: FOLLOW_dateintval_in_datespec578 */ 520static ANTLR3_BITWORD FOLLOW_dateintval_in_datespec578_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000008) }; 521static ANTLR3_BITSET_LIST FOLLOW_dateintval_in_datespec578 = { FOLLOW_dateintval_in_datespec578_bits, 1 }; 522/** Bitset defining follow set for error recovery in rule state: FOLLOW_DATE_in_dateref607 */ 523static ANTLR3_BITWORD FOLLOW_DATE_in_dateref607_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 524static ANTLR3_BITSET_LIST FOLLOW_DATE_in_dateref607 = { FOLLOW_DATE_in_dateref607_bits, 1 }; 525/** Bitset defining follow set for error recovery in rule state: FOLLOW_TODAY_in_dateref616 */ 526static ANTLR3_BITWORD FOLLOW_TODAY_in_dateref616_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 527static ANTLR3_BITSET_LIST FOLLOW_TODAY_in_dateref616 = { FOLLOW_TODAY_in_dateref616_bits, 1 }; 528/** Bitset defining follow set for error recovery in rule state: FOLLOW_DAY_in_dateintval640 */ 529static ANTLR3_BITWORD FOLLOW_DAY_in_dateintval640_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 530static ANTLR3_BITSET_LIST FOLLOW_DAY_in_dateintval640 = { FOLLOW_DAY_in_dateintval640_bits, 1 }; 531/** Bitset defining follow set for error recovery in rule state: FOLLOW_WEEK_in_dateintval649 */ 532static ANTLR3_BITWORD FOLLOW_WEEK_in_dateintval649_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 533static ANTLR3_BITSET_LIST FOLLOW_WEEK_in_dateintval649 = { FOLLOW_WEEK_in_dateintval649_bits, 1 }; 534/** Bitset defining follow set for error recovery in rule state: FOLLOW_MONTH_in_dateintval658 */ 535static ANTLR3_BITWORD FOLLOW_MONTH_in_dateintval658_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 536static ANTLR3_BITSET_LIST FOLLOW_MONTH_in_dateintval658 = { FOLLOW_MONTH_in_dateintval658_bits, 1 }; 537/** Bitset defining follow set for error recovery in rule state: FOLLOW_YEAR_in_dateintval667 */ 538static ANTLR3_BITWORD FOLLOW_YEAR_in_dateintval667_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; 539static ANTLR3_BITSET_LIST FOLLOW_YEAR_in_dateintval667 = { FOLLOW_YEAR_in_dateintval667_bits, 1 }; 540 541 542 543 544/* ============================================== 545 * Parsing rules 546 */ 547/** 548 * $ANTLR start query 549 * RSP2SQL.g:56:1: query returns [ pANTLR3_STRING result ] : e= expr ; 550 */ 551static pANTLR3_STRING 552query(pRSP2SQL ctx) 553{ 554 pANTLR3_STRING result = NULL; 555 556 RSP2SQL_expr_return e; 557 #undef RETURN_TYPE_e 558 #define RETURN_TYPE_e RSP2SQL_expr_return 559 560 /* Initialize rule variables 561 */ 562 563 564 result= NULL; 565 { 566 // RSP2SQL.g:58:2: (e= expr ) 567 // RSP2SQL.g:58:4: e= expr 568 { 569 FOLLOWPUSH(FOLLOW_expr_in_query70); 570 e=expr(ctx); 571 572 FOLLOWPOP(); 573 if (HASEXCEPTION()) 574 { 575 goto rulequeryEx; 576 } 577 578 { 579 580 if (!e.valid) 581 { 582 result= NULL; 583 } 584 else 585 { 586 result= e.result->factory->newRaw(e.result->factory); 587 result->append8(result, "("); 588 result->appendS(result, e.result); 589 result->append8(result, ")"); 590 } 591 592 } 593 594 } 595 596 } 597 598 599 // This is where rules clean up and exit 600 // 601 goto rulequeryEx; /* Prevent compiler warnings */ 602 rulequeryEx: ; 603 604 if (HASEXCEPTION()) 605 { 606 PREPORTERROR(); 607 PRECOVER(); 608 } 609 610 611 return result; 612} 613/* $ANTLR end query */ 614 615/** 616 * $ANTLR start expr 617 * RSP2SQL.g:74:1: expr returns [ pANTLR3_STRING result, int valid ] : ( ^( AND a= expr b= expr ) | ^( OR a= expr b= expr ) | c= strcrit | ^( NOT c= strcrit ) | i= intcrit | ^( NOT i= intcrit ) | d= datecrit ); 618 */ 619static RSP2SQL_expr_return 620expr(pRSP2SQL ctx) 621{ 622 RSP2SQL_expr_return retval; 623 624 RSP2SQL_expr_return a; 625 #undef RETURN_TYPE_a 626 #define RETURN_TYPE_a RSP2SQL_expr_return 627 628 RSP2SQL_expr_return b; 629 #undef RETURN_TYPE_b 630 #define RETURN_TYPE_b RSP2SQL_expr_return 631 632 RSP2SQL_strcrit_return c; 633 #undef RETURN_TYPE_c 634 #define RETURN_TYPE_c RSP2SQL_strcrit_return 635 636 RSP2SQL_intcrit_return i; 637 #undef RETURN_TYPE_i 638 #define RETURN_TYPE_i RSP2SQL_intcrit_return 639 640 RSP2SQL_datecrit_return d; 641 #undef RETURN_TYPE_d 642 #define RETURN_TYPE_d RSP2SQL_datecrit_return 643 644 /* Initialize rule variables 645 */ 646 647 648 retval.result= NULL; retval.valid= 1; 649 retval.start = LT(1); retval.stop = retval.start; 650 651 { 652 { 653 // RSP2SQL.g:76:2: ( ^( AND a= expr b= expr ) | ^( OR a= expr b= expr ) | c= strcrit | ^( NOT c= strcrit ) | i= intcrit | ^( NOT i= intcrit ) | d= datecrit ) 654 655 ANTLR3_UINT32 alt1; 656 657 alt1=7; 658 659 switch ( LA(1) ) 660 { 661 case AND: 662 { 663 alt1=1; 664 } 665 break; 666 case OR: 667 { 668 alt1=2; 669 } 670 break; 671 case EQUAL: 672 { 673 switch ( LA(2) ) 674 { 675 case DOWN: 676 { 677 switch ( LA(3) ) 678 { 679 case FIELD: 680 { 681 switch ( LA(4) ) 682 { 683 case INT: 684 { 685 alt1=5; 686 } 687 break; 688 case STR: 689 { 690 alt1=3; 691 } 692 break; 693 694 default: 695 CONSTRUCTEX(); 696 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 697 EXCEPTION->message = (void *)""; 698 EXCEPTION->decisionNum = 1; 699 EXCEPTION->state = 10; 700 701 702 goto ruleexprEx; 703 } 704 705 } 706 break; 707 708 default: 709 CONSTRUCTEX(); 710 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 711 EXCEPTION->message = (void *)""; 712 EXCEPTION->decisionNum = 1; 713 EXCEPTION->state = 8; 714 715 716 goto ruleexprEx; 717 } 718 719 } 720 break; 721 722 default: 723 CONSTRUCTEX(); 724 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 725 EXCEPTION->message = (void *)""; 726 EXCEPTION->decisionNum = 1; 727 EXCEPTION->state = 3; 728 729 730 goto ruleexprEx; 731 } 732 733 } 734 break; 735 case INCLUDES: 736 case STARTSW: 737 case ENDSW: 738 { 739 alt1=3; 740 } 741 break; 742 case NOT: 743 { 744 switch ( LA(2) ) 745 { 746 case DOWN: 747 { 748 switch ( LA(3) ) 749 { 750 case EQUAL: 751 { 752 switch ( LA(4) ) 753 { 754 case DOWN: 755 { 756 switch ( LA(5) ) 757 { 758 case FIELD: 759 { 760 switch ( LA(6) ) 761 { 762 case STR: 763 { 764 alt1=4; 765 } 766 break; 767 case INT: 768 { 769 alt1=6; 770 } 771 break; 772 773 default: 774 CONSTRUCTEX(); 775 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 776 EXCEPTION->message = (void *)""; 777 EXCEPTION->decisionNum = 1; 778 EXCEPTION->state = 15; 779 780 781 goto ruleexprEx; 782 } 783 784 } 785 break; 786 787 default: 788 CONSTRUCTEX(); 789 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 790 EXCEPTION->message = (void *)""; 791 EXCEPTION->decisionNum = 1; 792 EXCEPTION->state = 14; 793 794 795 goto ruleexprEx; 796 } 797 798 } 799 break; 800 801 default: 802 CONSTRUCTEX(); 803 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 804 EXCEPTION->message = (void *)""; 805 EXCEPTION->decisionNum = 1; 806 EXCEPTION->state = 11; 807 808 809 goto ruleexprEx; 810 } 811 812 } 813 break; 814 case LESS: 815 case GREATER: 816 case LTE: 817 case GTE: 818 { 819 alt1=6; 820 } 821 break; 822 case INCLUDES: 823 case STARTSW: 824 case ENDSW: 825 { 826 alt1=4; 827 } 828 break; 829 830 default: 831 CONSTRUCTEX(); 832 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 833 EXCEPTION->message = (void *)""; 834 EXCEPTION->decisionNum = 1; 835 EXCEPTION->state = 9; 836 837 838 goto ruleexprEx; 839 } 840 841 } 842 break; 843 844 default: 845 CONSTRUCTEX(); 846 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 847 EXCEPTION->message = (void *)""; 848 EXCEPTION->decisionNum = 1; 849 EXCEPTION->state = 5; 850 851 852 goto ruleexprEx; 853 } 854 855 } 856 break; 857 case LESS: 858 case GREATER: 859 case LTE: 860 case GTE: 861 { 862 alt1=5; 863 } 864 break; 865 case BEFORE: 866 case AFTER: 867 { 868 alt1=7; 869 } 870 break; 871 872 default: 873 CONSTRUCTEX(); 874 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 875 EXCEPTION->message = (void *)""; 876 EXCEPTION->decisionNum = 1; 877 EXCEPTION->state = 0; 878 879 880 goto ruleexprEx; 881 } 882 883 switch (alt1) 884 { 885 case 1: 886 // RSP2SQL.g:76:4: ^( AND a= expr b= expr ) 887 { 888 MATCHT(AND, &FOLLOW_AND_in_expr95); 889 if (HASEXCEPTION()) 890 { 891 goto ruleexprEx; 892 } 893 894 895 MATCHT(ANTLR3_TOKEN_DOWN, NULL); 896 if (HASEXCEPTION()) 897 { 898 goto ruleexprEx; 899 } 900 901 FOLLOWPUSH(FOLLOW_expr_in_expr101); 902 a=expr(ctx); 903 904 FOLLOWPOP(); 905 if (HASEXCEPTION()) 906 { 907 goto ruleexprEx; 908 } 909 910 FOLLOWPUSH(FOLLOW_expr_in_expr107); 911 b=expr(ctx); 912 913 FOLLOWPOP(); 914 if (HASEXCEPTION()) 915 { 916 goto ruleexprEx; 917 } 918 919 920 MATCHT(ANTLR3_TOKEN_UP, NULL); 921 if (HASEXCEPTION()) 922 { 923 goto ruleexprEx; 924 } 925 926 { 927 928 if (!a.valid || !b.valid) 929 { 930 retval.valid= 0; 931 } 932 else 933 { 934 retval.result= a.result->factory->newRaw(a.result->factory); 935 retval.result->append8(retval.result, "("); 936 retval.result->appendS(retval.result, a.result); 937 retval.result->append8(retval.result, " AND "); 938 retval.result->appendS(retval.result, b.result); 939 retval.result->append8(retval.result, ")"); 940 } 941 942 } 943 944 } 945 break; 946 case 2: 947 // RSP2SQL.g:92:4: ^( OR a= expr b= expr ) 948 { 949 MATCHT(OR, &FOLLOW_OR_in_expr118); 950 if (HASEXCEPTION()) 951 { 952 goto ruleexprEx; 953 } 954 955 956 MATCHT(ANTLR3_TOKEN_DOWN, NULL); 957 if (HASEXCEPTION()) 958 { 959 goto ruleexprEx; 960 } 961 962 FOLLOWPUSH(FOLLOW_expr_in_expr124); 963 a=expr(ctx); 964 965 FOLLOWPOP(); 966 if (HASEXCEPTION()) 967 { 968 goto ruleexprEx; 969 } 970 971 FOLLOWPUSH(FOLLOW_expr_in_expr130); 972 b=expr(ctx); 973 974 FOLLOWPOP(); 975 if (HASEXCEPTION()) 976 { 977 goto ruleexprEx; 978 } 979 980 981 MATCHT(ANTLR3_TOKEN_UP, NULL); 982 if (HASEXCEPTION()) 983 { 984 goto ruleexprEx; 985 } 986 987 { 988 989 if (!a.valid || !b.valid) 990 { 991 retval.valid= 0; 992 } 993 else 994 { 995 retval.result= a.result->factory->newRaw(a.result->factory); 996 retval.result->append8(retval.result, "("); 997 retval.result->appendS(retval.result, a.result); 998 retval.result->append8(retval.result, " OR "); 999 retval.result->appendS(retval.result, b.result); 1000 retval.result->append8(retval.result, ")"); 1001 } 1002 1003 } 1004 1005 } 1006 break; 1007 case 3: 1008 // RSP2SQL.g:108:4: c= strcrit 1009 { 1010 FOLLOWPUSH(FOLLOW_strcrit_in_expr144); 1011 c=strcrit(ctx); 1012 1013 FOLLOWPOP(); 1014 if (HASEXCEPTION()) 1015 { 1016 goto ruleexprEx; 1017 } 1018 1019 { 1020 1021 retval.valid= c.valid; 1022 retval.result= c.result; 1023 1024 } 1025 1026 } 1027 break; 1028 case 4: 1029 // RSP2SQL.g:113:4: ^( NOT c= strcrit ) 1030 { 1031 MATCHT(NOT, &FOLLOW_NOT_in_expr154); 1032 if (HASEXCEPTION()) 1033 { 1034 goto ruleexprEx; 1035 } 1036 1037 1038 MATCHT(ANTLR3_TOKEN_DOWN, NULL); 1039 if (HASEXCEPTION()) 1040 { 1041 goto ruleexprEx; 1042 } 1043 1044 FOLLOWPUSH(FOLLOW_strcrit_in_expr160); 1045 c=strcrit(ctx); 1046 1047 FOLLOWPOP(); 1048 if (HASEXCEPTION()) 1049 { 1050 goto ruleexprEx; 1051 } 1052 1053 1054 MATCHT(ANTLR3_TOKEN_UP, NULL); 1055 if (HASEXCEPTION()) 1056 { 1057 goto ruleexprEx; 1058 } 1059 1060 { 1061 1062 if (!c.valid) 1063 { 1064 retval.valid= 0; 1065 } 1066 else 1067 { 1068 retval.result= c.result->factory->newRaw(c.result->factory); 1069 retval.result->append8(retval.result, "(NOT "); 1070 retval.result->appendS(retval.result, c.result); 1071 retval.result->append8(retval.result, ")"); 1072 } 1073 1074 } 1075 1076 } 1077 break; 1078 case 5: 1079 // RSP2SQL.g:127:4: i= intcrit 1080 { 1081 FOLLOWPUSH(FOLLOW_intcrit_in_expr174); 1082 i=intcrit(ctx); 1083 1084 FOLLOWPOP(); 1085 if (HASEXCEPTION()) 1086 { 1087 goto ruleexprEx; 1088 } 1089 1090 { 1091 1092 retval.valid= i.valid; 1093 retval.result= i.result; 1094 1095 } 1096 1097 } 1098 break; 1099 case 6: 1100 // RSP2SQL.g:132:4: ^( NOT i= intcrit ) 1101 { 1102 MATCHT(NOT, &FOLLOW_NOT_in_expr184); 1103 if (HASEXCEPTION()) 1104 { 1105 goto ruleexprEx; 1106 } 1107 1108 1109 MATCHT(ANTLR3_TOKEN_DOWN, NULL); 1110 if (HASEXCEPTION()) 1111 { 1112 goto ruleexprEx; 1113 } 1114 1115 FOLLOWPUSH(FOLLOW_intcrit_in_expr190); 1116 i=intcrit(ctx); 1117 1118 FOLLOWPOP(); 1119 if (HASEXCEPTION()) 1120 { 1121 goto ruleexprEx; 1122 } 1123 1124 1125 MATCHT(ANTLR3_TOKEN_UP, NULL); 1126 if (HASEXCEPTION()) 1127 { 1128 goto ruleexprEx; 1129 } 1130 1131 { 1132 1133 if (!i.valid) 1134 { 1135 retval.valid= 0; 1136 } 1137 else 1138 { 1139 retval.result= i.result->factory->newRaw(i.result->factory); 1140 retval.result->append8(retval.result, "(NOT "); 1141 retval.result->appendS(retval.result, i.result); 1142 retval.result->append8(retval.result, ")"); 1143 } 1144 1145 } 1146 1147 } 1148 break; 1149 case 7: 1150 // RSP2SQL.g:146:4: d= datecrit 1151 { 1152 FOLLOWPUSH(FOLLOW_datecrit_in_expr204); 1153 d=datecrit(ctx); 1154 1155 FOLLOWPOP(); 1156 if (HASEXCEPTION()) 1157 { 1158 goto ruleexprEx; 1159 } 1160 1161 { 1162 1163 retval.valid= d.valid; 1164 retval.result= d.result; 1165 1166 } 1167 1168 } 1169 break; 1170 1171 } 1172 } 1173 } 1174 1175 1176 // This is where rules clean up and exit 1177 // 1178 goto ruleexprEx; /* Prevent compiler warnings */ 1179 ruleexprEx: ; 1180 1181 if (HASEXCEPTION()) 1182 { 1183 PREPORTERROR(); 1184 PRECOVER(); 1185 } 1186 1187 1188 return retval; 1189} 1190/* $ANTLR end expr */ 1191 1192/** 1193 * $ANTLR start strcrit 1194 * RSP2SQL.g:153:1: strcrit returns [ pANTLR3_STRING result, int valid ] : ^(o= strop f= FIELD s= STR ) ; 1195 */ 1196static RSP2SQL_strcrit_return 1197strcrit(pRSP2SQL ctx) 1198{ 1199 RSP2SQL_strcrit_return retval; 1200 1201 pANTLR3_BASE_TREE f; 1202 pANTLR3_BASE_TREE s; 1203 pANTLR3_COMMON_TOKEN o; 1204 #undef RETURN_TYPE_o 1205 #define RETURN_TYPE_o pANTLR3_COMMON_TOKEN 1206 1207 /* Initialize rule variables 1208 */ 1209 1210 1211 retval.result= NULL; retval.valid= 1; 1212 f = NULL; 1213 s = NULL; 1214 o = NULL; 1215 retval.start = LT(1); retval.stop = retval.start; 1216 1217 { 1218 // RSP2SQL.g:155:2: ( ^(o= strop f= FIELD s= STR ) ) 1219 // RSP2SQL.g:155:4: ^(o= strop f= FIELD s= STR ) 1220 { 1221 FOLLOWPUSH(FOLLOW_strop_in_strcrit233); 1222 o=strop(ctx); 1223 1224 FOLLOWPOP(); 1225 if (HASEXCEPTION()) 1226 { 1227 goto rulestrcritEx; 1228 } 1229 1230 1231 MATCHT(ANTLR3_TOKEN_DOWN, NULL); 1232 if (HASEXCEPTION()) 1233 { 1234 goto rulestrcritEx; 1235 } 1236 1237 f = (pANTLR3_BASE_TREE) MATCHT(FIELD, &FOLLOW_FIELD_in_strcrit239); 1238 if (HASEXCEPTION()) 1239 { 1240 goto rulestrcritEx; 1241 } 1242 1243 s = (pANTLR3_BASE_TREE) MATCHT(STR, &FOLLOW_STR_in_strcrit245); 1244 if (HASEXCEPTION()) 1245 { 1246 goto rulestrcritEx; 1247 } 1248 1249 1250 MATCHT(ANTLR3_TOKEN_UP, NULL); 1251 if (HASEXCEPTION()) 1252 { 1253 goto rulestrcritEx; 1254 } 1255 1256 { 1257 1258 char *op; 1259 const struct rsp_query_field_map *rqfp; 1260 pANTLR3_STRING field; 1261 char *escaped; 1262 ANTLR3_UINT32 optok; 1263 1264 escaped = NULL; 1265 1266 op = NULL; 1267 optok = o->getType(o); 1268 switch (optok) 1269 { 1270 case EQUAL: 1271 op = " = "; 1272 break; 1273 1274 case INCLUDES: 1275 case STARTSW: 1276 case ENDSW: 1277 op = " LIKE "; 1278 break; 1279 } 1280 1281 field = f->getText(f); 1282 1283 /* Field lookup */ 1284 rqfp = rsp_query_field_lookup((char *)field->chars, strlen((char *)field->chars)); 1285 if (!rqfp) 1286 { 1287 DPRINTF(E_LOG, L_RSP, "Field '%s' is not a valid field in queries\n", field->chars); 1288 retval.valid= 0; 1289 goto strcrit_valid_0; /* ABORT */ 1290 } 1291 1292 /* Check field type */ 1293 if (rqfp->field_type != RSP_TYPE_STRING) 1294 { 1295 DPRINTF(E_LOG, L_RSP, "Field '%s' is not a string field\n", field->chars); 1296 retval.valid= 0; 1297 goto strcrit_valid_0; /* ABORT */ 1298 } 1299 1300 escaped = db_escape_string((char *)s->getText(s)->chars); 1301 if (!escaped) 1302 { 1303 DPRINTF(E_LOG, L_RSP, "Could not escape value\n"); 1304 retval.valid= 0; 1305 goto strcrit_valid_0; /* ABORT */ 1306 } 1307 1308 retval.result= field->factory->newRaw(field->factory); 1309 retval.result->append8(retval.result, "f."); 1310 retval.result->appendS(retval.result, field); 1311 retval.result->append8(retval.result, op); 1312 retval.result->append8(retval.result, "'"); 1313 if ((optok == INCLUDES) || (optok == STARTSW)) 1314 retval.result->append8(retval.result, "%"); 1315 1316 retval.result->append8(retval.result, escaped); 1317 1318 if ((optok == INCLUDES) || (optok == ENDSW)) 1319 retval.result->append8(retval.result, "%"); 1320 retval.result->append8(retval.result, "'"); 1321 1322 strcrit_valid_0: 1323 ; 1324 1325 if (escaped) 1326 free(escaped); 1327 1328 } 1329 1330 } 1331 1332 } 1333 1334 1335 // This is where rules clean up and exit 1336 // 1337 goto rulestrcritEx; /* Prevent compiler warnings */ 1338 rulestrcritEx: ; 1339 1340 if (HASEXCEPTION()) 1341 { 1342 PREPORTERROR(); 1343 PRECOVER(); 1344 } 1345 1346 1347 return retval; 1348} 1349/* $ANTLR end strcrit */ 1350 1351/** 1352 * $ANTLR start strop 1353 * RSP2SQL.g:229:1: strop returns [ pANTLR3_COMMON_TOKEN op ] : (n= EQUAL | n= INCLUDES | n= STARTSW | n= ENDSW ); 1354 */ 1355static pANTLR3_COMMON_TOKEN 1356strop(pRSP2SQL ctx) 1357{ 1358 pANTLR3_COMMON_TOKEN op = NULL; 1359 1360 pANTLR3_BASE_TREE n; 1361 1362 /* Initialize rule variables 1363 */ 1364 1365 1366 op= NULL; 1367 n = NULL; 1368 1369 { 1370 { 1371 // RSP2SQL.g:231:2: (n= EQUAL | n= INCLUDES | n= STARTSW | n= ENDSW ) 1372 1373 ANTLR3_UINT32 alt2; 1374 1375 alt2=4; 1376 1377 switch ( LA(1) ) 1378 { 1379 case EQUAL: 1380 { 1381 alt2=1; 1382 } 1383 break; 1384 case INCLUDES: 1385 { 1386 alt2=2; 1387 } 1388 break; 1389 case STARTSW: 1390 { 1391 alt2=3; 1392 } 1393 break; 1394 case ENDSW: 1395 { 1396 alt2=4; 1397 } 1398 break; 1399 1400 default: 1401 CONSTRUCTEX(); 1402 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 1403 EXCEPTION->message = (void *)""; 1404 EXCEPTION->decisionNum = 2; 1405 EXCEPTION->state = 0; 1406 1407 1408 goto rulestropEx; 1409 } 1410 1411 switch (alt2) 1412 { 1413 case 1: 1414 // RSP2SQL.g:231:4: n= EQUAL 1415 { 1416 n = (pANTLR3_BASE_TREE) MATCHT(EQUAL, &FOLLOW_EQUAL_in_strop274); 1417 if (HASEXCEPTION()) 1418 { 1419 goto rulestropEx; 1420 } 1421 1422 { 1423 op= n->getToken(n); 1424 } 1425 1426 } 1427 break; 1428 case 2: 1429 // RSP2SQL.g:233:4: n= INCLUDES 1430 { 1431 n = (pANTLR3_BASE_TREE) MATCHT(INCLUDES, &FOLLOW_INCLUDES_in_strop287); 1432 if (HASEXCEPTION()) 1433 { 1434 goto rulestropEx; 1435 } 1436 1437 { 1438 op= n->getToken(n); 1439 } 1440 1441 } 1442 break; 1443 case 3: 1444 // RSP2SQL.g:235:4: n= STARTSW 1445 { 1446 n = (pANTLR3_BASE_TREE) MATCHT(STARTSW, &FOLLOW_STARTSW_in_strop300); 1447 if (HASEXCEPTION()) 1448 { 1449 goto rulestropEx; 1450 } 1451 1452 { 1453 op= n->getToken(n); 1454 } 1455 1456 } 1457 break; 1458 case 4: 1459 // RSP2SQL.g:237:4: n= ENDSW 1460 { 1461 n = (pANTLR3_BASE_TREE) MATCHT(ENDSW, &FOLLOW_ENDSW_in_strop313); 1462 if (HASEXCEPTION()) 1463 { 1464 goto rulestropEx; 1465 } 1466 1467 { 1468 op= n->getToken(n); 1469 } 1470 1471 } 1472 break; 1473 1474 } 1475 } 1476 } 1477 1478 1479 // This is where rules clean up and exit 1480 // 1481 goto rulestropEx; /* Prevent compiler warnings */ 1482 rulestropEx: ; 1483 1484 if (HASEXCEPTION()) 1485 { 1486 PREPORTERROR(); 1487 PRECOVER(); 1488 } 1489 1490 1491 return op; 1492} 1493/* $ANTLR end strop */ 1494 1495/** 1496 * $ANTLR start intcrit 1497 * RSP2SQL.g:241:1: intcrit returns [ pANTLR3_STRING result, int valid ] : ^(o= intop f= FIELD i= INT ) ; 1498 */ 1499static RSP2SQL_intcrit_return 1500intcrit(pRSP2SQL ctx) 1501{ 1502 RSP2SQL_intcrit_return retval; 1503 1504 pANTLR3_BASE_TREE f; 1505 pANTLR3_BASE_TREE i; 1506 pANTLR3_COMMON_TOKEN o; 1507 #undef RETURN_TYPE_o 1508 #define RETURN_TYPE_o pANTLR3_COMMON_TOKEN 1509 1510 /* Initialize rule variables 1511 */ 1512 1513 1514 retval.result= NULL; retval.valid= 1; 1515 f = NULL; 1516 i = NULL; 1517 o = NULL; 1518 retval.start = LT(1); retval.stop = retval.start; 1519 1520 { 1521 // RSP2SQL.g:243:2: ( ^(o= intop f= FIELD i= INT ) ) 1522 // RSP2SQL.g:243:4: ^(o= intop f= FIELD i= INT ) 1523 { 1524 FOLLOWPUSH(FOLLOW_intop_in_intcrit342); 1525 o=intop(ctx); 1526 1527 FOLLOWPOP(); 1528 if (HASEXCEPTION()) 1529 { 1530 goto ruleintcritEx; 1531 } 1532 1533 1534 MATCHT(ANTLR3_TOKEN_DOWN, NULL); 1535 if (HASEXCEPTION()) 1536 { 1537 goto ruleintcritEx; 1538 } 1539 1540 f = (pANTLR3_BASE_TREE) MATCHT(FIELD, &FOLLOW_FIELD_in_intcrit348); 1541 if (HASEXCEPTION()) 1542 { 1543 goto ruleintcritEx; 1544 } 1545 1546 i = (pANTLR3_BASE_TREE) MATCHT(INT, &FOLLOW_INT_in_intcrit354); 1547 if (HASEXCEPTION()) 1548 { 1549 goto ruleintcritEx; 1550 } 1551 1552 1553 MATCHT(ANTLR3_TOKEN_UP, NULL); 1554 if (HASEXCEPTION()) 1555 { 1556 goto ruleintcritEx; 1557 } 1558 1559 { 1560 1561 char *op; 1562 const struct rsp_query_field_map *rqfp; 1563 pANTLR3_STRING field; 1564 1565 op = NULL; 1566 switch (o->getType(o)) 1567 { 1568 case EQUAL: 1569 op = " = "; 1570 break; 1571 1572 case LESS: 1573 op = " < "; 1574 break; 1575 1576 case GREATER: 1577 op = " > "; 1578 break; 1579 1580 case LTE: 1581 op = " <= "; 1582 break; 1583 1584 case GTE: 1585 op = " >= "; 1586 break; 1587 } 1588 1589 field = f->getText(f); 1590 1591 /* Field lookup */ 1592 rqfp = rsp_query_field_lookup((char *)field->chars, strlen((char *)field->chars)); 1593 if (!rqfp) 1594 { 1595 DPRINTF(E_LOG, L_RSP, "Field '%s' is not a valid field in queries\n", field->chars); 1596 retval.valid= 0; 1597 goto intcrit_valid_0; /* ABORT */ 1598 } 1599 1600 /* Check field type */ 1601 if (rqfp->field_type != RSP_TYPE_INT) 1602 { 1603 DPRINTF(E_LOG, L_RSP, "Field '%s' is not an integer field\n", field->chars); 1604 retval.valid= 0; 1605 goto intcrit_valid_0; /* ABORT */ 1606 } 1607 1608 retval.result= field->factory->newRaw(field->factory); 1609 retval.result->append8(retval.result, "f."); 1610 retval.result->appendS(retval.result, field); 1611 retval.result->append8(retval.result, op); 1612 retval.result->appendS(retval.result, i->getText(i)); 1613 1614 intcrit_valid_0: 1615 ; 1616 1617 } 1618 1619 } 1620 1621 } 1622 1623 1624 // This is where rules clean up and exit 1625 // 1626 goto ruleintcritEx; /* Prevent compiler warnings */ 1627 ruleintcritEx: ; 1628 1629 if (HASEXCEPTION()) 1630 { 1631 PREPORTERROR(); 1632 PRECOVER(); 1633 } 1634 1635 1636 return retval; 1637} 1638/* $ANTLR end intcrit */ 1639 1640/** 1641 * $ANTLR start intop 1642 * RSP2SQL.g:303:1: intop returns [ pANTLR3_COMMON_TOKEN op ] : (n= EQUAL | n= LESS | n= GREATER | n= LTE | n= GTE ); 1643 */ 1644static pANTLR3_COMMON_TOKEN 1645intop(pRSP2SQL ctx) 1646{ 1647 pANTLR3_COMMON_TOKEN op = NULL; 1648 1649 pANTLR3_BASE_TREE n; 1650 1651 /* Initialize rule variables 1652 */ 1653 1654 1655 op= NULL; 1656 n = NULL; 1657 1658 { 1659 { 1660 // RSP2SQL.g:305:2: (n= EQUAL | n= LESS | n= GREATER | n= LTE | n= GTE ) 1661 1662 ANTLR3_UINT32 alt3; 1663 1664 alt3=5; 1665 1666 switch ( LA(1) ) 1667 { 1668 case EQUAL: 1669 { 1670 alt3=1; 1671 } 1672 break; 1673 case LESS: 1674 { 1675 alt3=2; 1676 } 1677 break; 1678 case GREATER: 1679 { 1680 alt3=3; 1681 } 1682 break; 1683 case LTE: 1684 { 1685 alt3=4; 1686 } 1687 break; 1688 case GTE: 1689 { 1690 alt3=5; 1691 } 1692 break; 1693 1694 default: 1695 CONSTRUCTEX(); 1696 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 1697 EXCEPTION->message = (void *)""; 1698 EXCEPTION->decisionNum = 3; 1699 EXCEPTION->state = 0; 1700 1701 1702 goto ruleintopEx; 1703 } 1704 1705 switch (alt3) 1706 { 1707 case 1: 1708 // RSP2SQL.g:305:4: n= EQUAL 1709 { 1710 n = (pANTLR3_BASE_TREE) MATCHT(EQUAL, &FOLLOW_EQUAL_in_intop383); 1711 if (HASEXCEPTION()) 1712 { 1713 goto ruleintopEx; 1714 } 1715 1716 { 1717 op= n->getToken(n); 1718 } 1719 1720 } 1721 break; 1722 case 2: 1723 // RSP2SQL.g:307:4: n= LESS 1724 { 1725 n = (pANTLR3_BASE_TREE) MATCHT(LESS, &FOLLOW_LESS_in_intop396); 1726 if (HASEXCEPTION()) 1727 { 1728 goto ruleintopEx; 1729 } 1730 1731 { 1732 op= n->getToken(n); 1733 } 1734 1735 } 1736 break; 1737 case 3: 1738 // RSP2SQL.g:309:4: n= GREATER 1739 { 1740 n = (pANTLR3_BASE_TREE) MATCHT(GREATER, &FOLLOW_GREATER_in_intop409); 1741 if (HASEXCEPTION()) 1742 { 1743 goto ruleintopEx; 1744 } 1745 1746 { 1747 op= n->getToken(n); 1748 } 1749 1750 } 1751 break; 1752 case 4: 1753 // RSP2SQL.g:311:4: n= LTE 1754 { 1755 n = (pANTLR3_BASE_TREE) MATCHT(LTE, &FOLLOW_LTE_in_intop422); 1756 if (HASEXCEPTION()) 1757 { 1758 goto ruleintopEx; 1759 } 1760 1761 { 1762 op= n->getToken(n); 1763 } 1764 1765 } 1766 break; 1767 case 5: 1768 // RSP2SQL.g:313:4: n= GTE 1769 { 1770 n = (pANTLR3_BASE_TREE) MATCHT(GTE, &FOLLOW_GTE_in_intop435); 1771 if (HASEXCEPTION()) 1772 { 1773 goto ruleintopEx; 1774 } 1775 1776 { 1777 op= n->getToken(n); 1778 } 1779 1780 } 1781 break; 1782 1783 } 1784 } 1785 } 1786 1787 1788 // This is where rules clean up and exit 1789 // 1790 goto ruleintopEx; /* Prevent compiler warnings */ 1791 ruleintopEx: ; 1792 1793 if (HASEXCEPTION()) 1794 { 1795 PREPORTERROR(); 1796 PRECOVER(); 1797 } 1798 1799 1800 return op; 1801} 1802/* $ANTLR end intop */ 1803 1804/** 1805 * $ANTLR start datecrit 1806 * RSP2SQL.g:317:1: datecrit returns [ pANTLR3_STRING result, int valid ] : ^(o= dateop f= FIELD d= datespec ) ; 1807 */ 1808static RSP2SQL_datecrit_return 1809datecrit(pRSP2SQL ctx) 1810{ 1811 RSP2SQL_datecrit_return retval; 1812 1813 pANTLR3_BASE_TREE f; 1814 pANTLR3_COMMON_TOKEN o; 1815 #undef RETURN_TYPE_o 1816 #define RETURN_TYPE_o pANTLR3_COMMON_TOKEN 1817 1818 RSP2SQL_datespec_return d; 1819 #undef RETURN_TYPE_d 1820 #define RETURN_TYPE_d RSP2SQL_datespec_return 1821 1822 /* Initialize rule variables 1823 */ 1824 1825 1826 retval.result= NULL; retval.valid= 1; 1827 f = NULL; 1828 o = NULL; 1829 retval.start = LT(1); retval.stop = retval.start; 1830 1831 { 1832 // RSP2SQL.g:319:2: ( ^(o= dateop f= FIELD d= datespec ) ) 1833 // RSP2SQL.g:319:4: ^(o= dateop f= FIELD d= datespec ) 1834 { 1835 FOLLOWPUSH(FOLLOW_dateop_in_datecrit464); 1836 o=dateop(ctx); 1837 1838 FOLLOWPOP(); 1839 if (HASEXCEPTION()) 1840 { 1841 goto ruledatecritEx; 1842 } 1843 1844 1845 MATCHT(ANTLR3_TOKEN_DOWN, NULL); 1846 if (HASEXCEPTION()) 1847 { 1848 goto ruledatecritEx; 1849 } 1850 1851 f = (pANTLR3_BASE_TREE) MATCHT(FIELD, &FOLLOW_FIELD_in_datecrit470); 1852 if (HASEXCEPTION()) 1853 { 1854 goto ruledatecritEx; 1855 } 1856 1857 FOLLOWPUSH(FOLLOW_datespec_in_datecrit476); 1858 d=datespec(ctx); 1859 1860 FOLLOWPOP(); 1861 if (HASEXCEPTION()) 1862 { 1863 goto ruledatecritEx; 1864 } 1865 1866 1867 MATCHT(ANTLR3_TOKEN_UP, NULL); 1868 if (HASEXCEPTION()) 1869 { 1870 goto ruledatecritEx; 1871 } 1872 1873 { 1874 1875 char *op; 1876 const struct rsp_query_field_map *rqfp; 1877 pANTLR3_STRING field; 1878 char buf[32]; 1879 int ret; 1880 1881 op = NULL; 1882 switch (o->getType(o)) 1883 { 1884 case BEFORE: 1885 op = " < "; 1886 break; 1887 1888 case AFTER: 1889 op = " > "; 1890 break; 1891 } 1892 1893 field = f->getText(f); 1894 1895 /* Field lookup */ 1896 rqfp = rsp_query_field_lookup((char *)field->chars, strlen((char *)field->chars)); 1897 if (!rqfp) 1898 { 1899 DPRINTF(E_LOG, L_RSP, "Field '%s' is not a valid field in queries\n", field->chars); 1900 retval.valid= 0; 1901 goto datecrit_valid_0; /* ABORT */ 1902 } 1903 1904 /* Check field type */ 1905 if (rqfp->field_type != RSP_TYPE_DATE) 1906 { 1907 DPRINTF(E_LOG, L_RSP, "Field '%s' is not a date field\n", field->chars); 1908 retval.valid= 0; 1909 goto datecrit_valid_0; /* ABORT */ 1910 } 1911 1912 ret = snprintf(buf, sizeof(buf), "%ld", d.date); 1913 if ((ret < 0) || (ret >= sizeof(buf))) 1914 { 1915 DPRINTF(E_LOG, L_RSP, "Date %ld too large for buffer, oops!\n", d.date); 1916 retval.valid= 0; 1917 goto datecrit_valid_0; /* ABORT */ 1918 } 1919 1920 retval.result= field->factory->newRaw(field->factory); 1921 retval.result->append8(retval.result, "f."); 1922 retval.result->appendS(retval.result, field); 1923 retval.result->append8(retval.result, op); 1924 retval.result->append8(retval.result, buf); 1925 1926 datecrit_valid_0: 1927 ; 1928 1929 } 1930 1931 } 1932 1933 } 1934 1935 1936 // This is where rules clean up and exit 1937 // 1938 goto ruledatecritEx; /* Prevent compiler warnings */ 1939 ruledatecritEx: ; 1940 1941 if (HASEXCEPTION()) 1942 { 1943 PREPORTERROR(); 1944 PRECOVER(); 1945 } 1946 1947 1948 return retval; 1949} 1950/* $ANTLR end datecrit */ 1951 1952/** 1953 * $ANTLR start dateop 1954 * RSP2SQL.g:377:1: dateop returns [ pANTLR3_COMMON_TOKEN op ] : (n= BEFORE | n= AFTER ); 1955 */ 1956static pANTLR3_COMMON_TOKEN 1957dateop(pRSP2SQL ctx) 1958{ 1959 pANTLR3_COMMON_TOKEN op = NULL; 1960 1961 pANTLR3_BASE_TREE n; 1962 1963 /* Initialize rule variables 1964 */ 1965 1966 1967 op= NULL; 1968 n = NULL; 1969 1970 { 1971 { 1972 // RSP2SQL.g:379:2: (n= BEFORE | n= AFTER ) 1973 1974 ANTLR3_UINT32 alt4; 1975 1976 alt4=2; 1977 1978 switch ( LA(1) ) 1979 { 1980 case BEFORE: 1981 { 1982 alt4=1; 1983 } 1984 break; 1985 case AFTER: 1986 { 1987 alt4=2; 1988 } 1989 break; 1990 1991 default: 1992 CONSTRUCTEX(); 1993 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 1994 EXCEPTION->message = (void *)""; 1995 EXCEPTION->decisionNum = 4; 1996 EXCEPTION->state = 0; 1997 1998 1999 goto ruledateopEx; 2000 } 2001 2002 switch (alt4) 2003 { 2004 case 1: 2005 // RSP2SQL.g:379:4: n= BEFORE 2006 { 2007 n = (pANTLR3_BASE_TREE) MATCHT(BEFORE, &FOLLOW_BEFORE_in_dateop505); 2008 if (HASEXCEPTION()) 2009 { 2010 goto ruledateopEx; 2011 } 2012 2013 { 2014 op= n->getToken(n); 2015 } 2016 2017 } 2018 break; 2019 case 2: 2020 // RSP2SQL.g:381:4: n= AFTER 2021 { 2022 n = (pANTLR3_BASE_TREE) MATCHT(AFTER, &FOLLOW_AFTER_in_dateop518); 2023 if (HASEXCEPTION()) 2024 { 2025 goto ruledateopEx; 2026 } 2027 2028 { 2029 op= n->getToken(n); 2030 } 2031 2032 } 2033 break; 2034 2035 } 2036 } 2037 } 2038 2039 2040 // This is where rules clean up and exit 2041 // 2042 goto ruledateopEx; /* Prevent compiler warnings */ 2043 ruledateopEx: ; 2044 2045 if (HASEXCEPTION()) 2046 { 2047 PREPORTERROR(); 2048 PRECOVER(); 2049 } 2050 2051 2052 return op; 2053} 2054/* $ANTLR end dateop */ 2055 2056/** 2057 * $ANTLR start datespec 2058 * RSP2SQL.g:385:1: datespec returns [ time_t date, int valid ] : (r= dateref | ^(o= dateop r= dateref m= INT i= dateintval ) ); 2059 */ 2060static RSP2SQL_datespec_return 2061datespec(pRSP2SQL ctx) 2062{ 2063 RSP2SQL_datespec_return retval; 2064 2065 pANTLR3_BASE_TREE m; 2066 RSP2SQL_dateref_return r; 2067 #undef RETURN_TYPE_r 2068 #define RETURN_TYPE_r RSP2SQL_dateref_return 2069 2070 pANTLR3_COMMON_TOKEN o; 2071 #undef RETURN_TYPE_o 2072 #define RETURN_TYPE_o pANTLR3_COMMON_TOKEN 2073 2074 RSP2SQL_dateintval_return i; 2075 #undef RETURN_TYPE_i 2076 #define RETURN_TYPE_i RSP2SQL_dateintval_return 2077 2078 /* Initialize rule variables 2079 */ 2080 2081 2082 retval.date= 0; retval.valid= 1; 2083 m = NULL; 2084 o = NULL; 2085 retval.start = LT(1); retval.stop = retval.start; 2086 2087 { 2088 { 2089 // RSP2SQL.g:387:2: (r= dateref | ^(o= dateop r= dateref m= INT i= dateintval ) ) 2090 2091 ANTLR3_UINT32 alt5; 2092 2093 alt5=2; 2094 2095 switch ( LA(1) ) 2096 { 2097 case DATE: 2098 case TODAY: 2099 { 2100 alt5=1; 2101 } 2102 break; 2103 case BEFORE: 2104 case AFTER: 2105 { 2106 alt5=2; 2107 } 2108 break; 2109 2110 default: 2111 CONSTRUCTEX(); 2112 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 2113 EXCEPTION->message = (void *)""; 2114 EXCEPTION->decisionNum = 5; 2115 EXCEPTION->state = 0; 2116 2117 2118 goto ruledatespecEx; 2119 } 2120 2121 switch (alt5) 2122 { 2123 case 1: 2124 // RSP2SQL.g:387:4: r= dateref 2125 { 2126 FOLLOWPUSH(FOLLOW_dateref_in_datespec546); 2127 r=dateref(ctx); 2128 2129 FOLLOWPOP(); 2130 if (HASEXCEPTION()) 2131 { 2132 goto ruledatespecEx; 2133 } 2134 2135 { 2136 2137 if (!r.valid) 2138 retval.valid= 0; 2139 else 2140 retval.date= r.date; 2141 2142 } 2143 2144 } 2145 break; 2146 case 2: 2147 // RSP2SQL.g:394:4: ^(o= dateop r= dateref m= INT i= dateintval ) 2148 { 2149 FOLLOWPUSH(FOLLOW_dateop_in_datespec560); 2150 o=dateop(ctx); 2151 2152 FOLLOWPOP(); 2153 if (HASEXCEPTION()) 2154 { 2155 goto ruledatespecEx; 2156 } 2157 2158 2159 MATCHT(ANTLR3_TOKEN_DOWN, NULL); 2160 if (HASEXCEPTION()) 2161 { 2162 goto ruledatespecEx; 2163 } 2164 2165 FOLLOWPUSH(FOLLOW_dateref_in_datespec566); 2166 r=dateref(ctx); 2167 2168 FOLLOWPOP(); 2169 if (HASEXCEPTION()) 2170 { 2171 goto ruledatespecEx; 2172 } 2173 2174 m = (pANTLR3_BASE_TREE) MATCHT(INT, &FOLLOW_INT_in_datespec572); 2175 if (HASEXCEPTION()) 2176 { 2177 goto ruledatespecEx; 2178 } 2179 2180 FOLLOWPUSH(FOLLOW_dateintval_in_datespec578); 2181 i=dateintval(ctx); 2182 2183 FOLLOWPOP(); 2184 if (HASEXCEPTION()) 2185 { 2186 goto ruledatespecEx; 2187 } 2188 2189 2190 MATCHT(ANTLR3_TOKEN_UP, NULL); 2191 if (HASEXCEPTION()) 2192 { 2193 goto ruledatespecEx; 2194 } 2195 2196 { 2197 2198 int32_t val; 2199 int ret; 2200 2201 if (!r.valid || !i.valid) 2202 { 2203 retval.valid= 0; 2204 goto datespec_valid_0; /* ABORT */ 2205 } 2206 2207 ret = safe_atoi32((char *)m->getText(m)->chars, &val); 2208 if (ret < 0) 2209 { 2210 DPRINTF(E_LOG, L_RSP, "Could not convert '%s' to integer\n", (char *)m->getText(m)); 2211 retval.valid= 0; 2212 goto datespec_valid_0; /* ABORT */ 2213 } 2214 2215 switch (o->getType(o)) 2216 { 2217 case BEFORE: 2218 retval.date= r.date - (val * i.period); 2219 break; 2220 2221 case AFTER: 2222 retval.date= r.date + (val * i.period); 2223 break; 2224 } 2225 2226 datespec_valid_0: 2227 ; 2228 2229 } 2230 2231 } 2232 break; 2233 2234 } 2235 } 2236 } 2237 2238 2239 // This is where rules clean up and exit 2240 // 2241 goto ruledatespecEx; /* Prevent compiler warnings */ 2242 ruledatespecEx: ; 2243 2244 if (HASEXCEPTION()) 2245 { 2246 PREPORTERROR(); 2247 PRECOVER(); 2248 } 2249 2250 2251 return retval; 2252} 2253/* $ANTLR end datespec */ 2254 2255/** 2256 * $ANTLR start dateref 2257 * RSP2SQL.g:429:1: dateref returns [ time_t date, int valid ] : (n= DATE | TODAY ); 2258 */ 2259static RSP2SQL_dateref_return 2260dateref(pRSP2SQL ctx) 2261{ 2262 RSP2SQL_dateref_return retval; 2263 2264 pANTLR3_BASE_TREE n; 2265 2266 /* Initialize rule variables 2267 */ 2268 2269 2270 retval.date= 0; retval.valid= 1; 2271 n = NULL; 2272 retval.start = LT(1); retval.stop = retval.start; 2273 2274 { 2275 { 2276 // RSP2SQL.g:431:2: (n= DATE | TODAY ) 2277 2278 ANTLR3_UINT32 alt6; 2279 2280 alt6=2; 2281 2282 switch ( LA(1) ) 2283 { 2284 case DATE: 2285 { 2286 alt6=1; 2287 } 2288 break; 2289 case TODAY: 2290 { 2291 alt6=2; 2292 } 2293 break; 2294 2295 default: 2296 CONSTRUCTEX(); 2297 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 2298 EXCEPTION->message = (void *)""; 2299 EXCEPTION->decisionNum = 6; 2300 EXCEPTION->state = 0; 2301 2302 2303 goto ruledaterefEx; 2304 } 2305 2306 switch (alt6) 2307 { 2308 case 1: 2309 // RSP2SQL.g:431:4: n= DATE 2310 { 2311 n = (pANTLR3_BASE_TREE) MATCHT(DATE, &FOLLOW_DATE_in_dateref607); 2312 if (HASEXCEPTION()) 2313 { 2314 goto ruledaterefEx; 2315 } 2316 2317 { 2318 2319 struct tm tm; 2320 char *ret; 2321 2322 ret = strptime((char *)n->getText(n), "%Y-%m-%d", &tm); 2323 if (!ret) 2324 { 2325 DPRINTF(E_LOG, L_RSP, "Date '%s' could not be interpreted\n", (char *)n->getText(n)); 2326 retval.valid= 0; 2327 goto dateref_valid_0; /* ABORT */ 2328 } 2329 else 2330 { 2331 if (*ret != '\0') 2332 DPRINTF(E_LOG, L_RSP, "Garbage at end of date '%s' ?!\n", (char *)n->getText(n)); 2333 2334 retval.date= mktime(&tm); 2335 if (retval.date == (time_t) -1) 2336 { 2337 DPRINTF(E_LOG, L_RSP, "Date '%s' could not be converted to an epoch\n", (char *)n->getText(n)); 2338 retval.valid= 0; 2339 goto dateref_valid_0; /* ABORT */ 2340 } 2341 } 2342 2343 dateref_valid_0: 2344 ; 2345 2346 } 2347 2348 } 2349 break; 2350 case 2: 2351 // RSP2SQL.g:460:4: TODAY 2352 { 2353 MATCHT(TODAY, &FOLLOW_TODAY_in_dateref616); 2354 if (HASEXCEPTION()) 2355 { 2356 goto ruledaterefEx; 2357 } 2358 2359 { 2360 retval.date= time(NULL); 2361 } 2362 2363 } 2364 break; 2365 2366 } 2367 } 2368 } 2369 2370 2371 // This is where rules clean up and exit 2372 // 2373 goto ruledaterefEx; /* Prevent compiler warnings */ 2374 ruledaterefEx: ; 2375 2376 if (HASEXCEPTION()) 2377 { 2378 PREPORTERROR(); 2379 PRECOVER(); 2380 } 2381 2382 2383 return retval; 2384} 2385/* $ANTLR end dateref */ 2386 2387/** 2388 * $ANTLR start dateintval 2389 * RSP2SQL.g:464:1: dateintval returns [ time_t period, int valid ] : ( DAY | WEEK | MONTH | YEAR ); 2390 */ 2391static RSP2SQL_dateintval_return 2392dateintval(pRSP2SQL ctx) 2393{ 2394 RSP2SQL_dateintval_return retval; 2395 2396 /* Initialize rule variables 2397 */ 2398 2399 2400 retval.period= 0; retval.valid= 1; 2401 retval.start = LT(1); retval.stop = retval.start; 2402 2403 { 2404 { 2405 // RSP2SQL.g:466:2: ( DAY | WEEK | MONTH | YEAR ) 2406 2407 ANTLR3_UINT32 alt7; 2408 2409 alt7=4; 2410 2411 switch ( LA(1) ) 2412 { 2413 case DAY: 2414 { 2415 alt7=1; 2416 } 2417 break; 2418 case WEEK: 2419 { 2420 alt7=2; 2421 } 2422 break; 2423 case MONTH: 2424 { 2425 alt7=3; 2426 } 2427 break; 2428 case YEAR: 2429 { 2430 alt7=4; 2431 } 2432 break; 2433 2434 default: 2435 CONSTRUCTEX(); 2436 EXCEPTION->type = ANTLR3_NO_VIABLE_ALT_EXCEPTION; 2437 EXCEPTION->message = (void *)""; 2438 EXCEPTION->decisionNum = 7; 2439 EXCEPTION->state = 0; 2440 2441 2442 goto ruledateintvalEx; 2443 } 2444 2445 switch (alt7) 2446 { 2447 case 1: 2448 // RSP2SQL.g:466:4: DAY 2449 { 2450 MATCHT(DAY, &FOLLOW_DAY_in_dateintval640); 2451 if (HASEXCEPTION()) 2452 { 2453 goto ruledateintvalEx; 2454 } 2455 2456 { 2457 retval.period= 24 * 60 * 60; 2458 } 2459 2460 } 2461 break; 2462 case 2: 2463 // RSP2SQL.g:468:4: WEEK 2464 { 2465 MATCHT(WEEK, &FOLLOW_WEEK_in_dateintval649); 2466 if (HASEXCEPTION()) 2467 { 2468 goto ruledateintvalEx; 2469 } 2470 2471 { 2472 retval.period= 7 * 24 * 60 * 60; 2473 } 2474 2475 } 2476 break; 2477 case 3: 2478 // RSP2SQL.g:470:4: MONTH 2479 { 2480 MATCHT(MONTH, &FOLLOW_MONTH_in_dateintval658); 2481 if (HASEXCEPTION()) 2482 { 2483 goto ruledateintvalEx; 2484 } 2485 2486 { 2487 retval.period= 30 * 24 * 60 * 60; 2488 } 2489 2490 } 2491 break; 2492 case 4: 2493 // RSP2SQL.g:472:4: YEAR 2494 { 2495 MATCHT(YEAR, &FOLLOW_YEAR_in_dateintval667); 2496 if (HASEXCEPTION()) 2497 { 2498 goto ruledateintvalEx; 2499 } 2500 2501 { 2502 retval.period= 365 * 24 * 60 * 60; 2503 } 2504 2505 } 2506 break; 2507 2508 } 2509 } 2510 } 2511 2512 2513 // This is where rules clean up and exit 2514 // 2515 goto ruledateintvalEx; /* Prevent compiler warnings */ 2516 ruledateintvalEx: ; 2517 2518 if (HASEXCEPTION()) 2519 { 2520 PREPORTERROR(); 2521 PRECOVER(); 2522 } 2523 2524 2525 return retval; 2526} 2527/* $ANTLR end dateintval */ 2528/* End of parsing rules 2529 * ============================================== 2530 */ 2531 2532/* ============================================== 2533 * Syntactic predicates 2534 */ 2535/* End of syntactic predicates 2536 * ============================================== 2537 */ 2538 2539 2540 2541 2542 2543 2544/* End of code 2545 * ============================================================================= 2546 */ 2547